2121import io .cdap .cdap .etl .api .validation .InvalidConfigPropertyException ;
2222import io .cdap .cdap .etl .mock .validation .MockFailureCollector ;
2323import io .cdap .plugin .http .common .http .HttpClient ;
24+ import io .cdap .plugin .http .common .http .KeyStoreType ;
2425import io .cdap .plugin .http .common .http .OAuthUtil ;
2526import io .cdap .plugin .http .common .pagination .BaseHttpPaginationIterator ;
2627import io .cdap .plugin .http .common .pagination .PaginationIteratorFactory ;
5354@ RunWith (PowerMockRunner .class )
5455@ PrepareForTest ({PaginationIteratorFactory .class , HttpClientBuilder .class , HttpClients .class , OAuthUtil .class ,
5556 HttpHost .class , EntityUtils .class , HttpClient .class })
56- @ PowerMockIgnore ("javax.management.*" )
57+ @ PowerMockIgnore ({ "javax.management.*" , "javax.net.ssl.*" } )
5758public class HttpBatchSourceConfigTest {
5859
5960 @ Mock
@@ -74,8 +75,8 @@ public void testMissingKeyValue() {
7475 HttpBatchSourceConfig config = HttpBatchSourceConfig .builder ()
7576 .setReferenceName ("test" ).setUrl ("http://localhost" ).setHttpMethod ("GET" ).setHeaders ("Auth:" )
7677 .setFormat ("JSON" ).setAuthType ("none" ).setErrorHandling (StringUtils .EMPTY )
77- .setRetryPolicy (StringUtils .EMPTY ).setMaxRetryDuration (600L ).setConnectTimeout (120 )
78- . setReadTimeout ( 120 ). setPaginationType ("NONE" ).setVerifyHttps ("true" ).build ();
78+ .setRetryPolicy (StringUtils .EMPTY ).setMaxRetryDuration (600L ).setConnectTimeout (120 ). setReadTimeout ( 120 )
79+ . setPaginationType ("NONE" ).setVerifyHttps ("false" ). setKeystoreType ( KeyStoreType . JKS ).build ();
7980 config .validate (collector );
8081 }
8182
@@ -85,7 +86,7 @@ public void testEmptySchemaKeyValue() {
8586 .setReferenceName ("test" ).setUrl ("http://localhost" ).setHttpMethod ("GET" ).setHeaders ("Auth:auth" )
8687 .setFormat ("JSON" ).setAuthType ("none" ).setErrorHandling (StringUtils .EMPTY )
8788 .setRetryPolicy (StringUtils .EMPTY ).setMaxRetryDuration (600L ).setConnectTimeout (120 )
88- .setReadTimeout (120 ).setPaginationType ("NONE" ).setVerifyHttps ("true" ).build ();
89+ .setReadTimeout (120 ).setPaginationType ("NONE" ).setVerifyHttps ("false" ). setKeystoreType ( KeyStoreType . JKS ).build ();
8990 config .validateSchema ();
9091 }
9192
@@ -96,8 +97,8 @@ public void testValidateOAuth2() throws Exception {
9697 .setUrl ("http://localhost" ).setHttpMethod ("GET" ).setHeaders ("Auth:auth" ).setFormat ("JSON" )
9798 .setErrorHandling (StringUtils .EMPTY ).setRetryPolicy (StringUtils .EMPTY )
9899 .setMaxRetryDuration (600L ).setConnectTimeout (120 ).setReadTimeout (120 )
99- .setPaginationType ("NONE" ).setVerifyHttps ("true " ).setAuthType ( "oAuth2" ). setClientId ( "id " )
100- .setClientSecret ("secret" ).setRefreshToken ("token" ).setScopes ("scope" )
100+ .setPaginationType ("NONE" ).setVerifyHttps ("false " ).setKeystoreType ( KeyStoreType . JKS ). setAuthType ( "oAuth2 " )
101+ .setClientId ( "id" ). setClientSecret ("secret" ).setRefreshToken ("token" ).setScopes ("scope" )
101102 .setTokenUrl ("https//:token" ).setRetryPolicy ("exponential" )
102103 .setOauth2GrantType ("refresh_token" ).build ();
103104 PowerMockito .mockStatic (PaginationIteratorFactory .class );
@@ -124,9 +125,10 @@ public void testValidateOAuth2CredentialsWithProxy() throws IOException {
124125 HttpBatchSourceConfig config = HttpBatchSourceConfig .builder ()
125126 .setReferenceName ("test" ).setUrl ("http://localhost" ).setHttpMethod ("GET" ).setHeaders ("Auth:auth" )
126127 .setFormat ("JSON" ).setAuthType ("none" ).setErrorHandling (StringUtils .EMPTY )
127- .setRetryPolicy (StringUtils .EMPTY ).setMaxRetryDuration (600L ).setConnectTimeout (120 )
128- .setReadTimeout (120 ).setPaginationType ("NONE" ).setVerifyHttps ("true" ).setAuthType ("oAuth2" ).setClientId ("id" ).
129- setClientSecret ("secret" ).setRefreshToken ("token" ).setScopes ("scope" ).setTokenUrl ("https//:token" ).setRetryPolicy (
128+ .setRetryPolicy (StringUtils .EMPTY ).setMaxRetryDuration (600L ).setConnectTimeout (120 ).setReadTimeout (120 )
129+ .setPaginationType ("NONE" ).setVerifyHttps ("false" ).setKeystoreType (KeyStoreType .JKS ).setAuthType ("oAuth2" )
130+ .setClientId ("id" ).setClientSecret ("secret" ).setRefreshToken ("token" ).setScopes ("scope" )
131+ .setTokenUrl ("https//:token" ).setRetryPolicy (
130132 "exponential" ).setProxyUrl ("https://proxy" ).setProxyUsername ("proxyuser" ).setProxyPassword ("proxypassword" )
131133 .setOauth2GrantType ("refresh_token" ).build ();
132134 HttpClientBuilder httpClientBuilder = Mockito .mock (HttpClientBuilder .class );
@@ -156,10 +158,10 @@ public void testValidateCredentialsOAuth2WithInvalidAccessTokenRequest() throws
156158 HttpBatchSourceConfig config = HttpBatchSourceConfig .builder ()
157159 .setReferenceName ("test" ).setUrl ("http://localhost" ).setHttpMethod ("GET" ).setHeaders ("Auth:auth" )
158160 .setFormat ("JSON" ).setErrorHandling (StringUtils .EMPTY )
159- .setRetryPolicy (StringUtils .EMPTY ).setMaxRetryDuration (600L ).setConnectTimeout (120 )
160- . setReadTimeout ( 120 ). setPaginationType ("NONE" ).setVerifyHttps ("true " ).setAuthType ( "oAuth2" ). setClientId ( "id" ).
161- setClientSecret ("secret" ).setRefreshToken ("token" ).setScopes ("scope" ). setTokenUrl ( "https//:token" ). setRetryPolicy (
162- "exponential" ).setOauth2GrantType ("refresh_token" ).build ();
161+ .setRetryPolicy (StringUtils .EMPTY ).setMaxRetryDuration (600L ).setConnectTimeout (120 ). setReadTimeout ( 120 )
162+ . setPaginationType ("NONE" ).setVerifyHttps ("false " ).setKeystoreType ( KeyStoreType . JKS ). setAuthType ( "oAuth2" )
163+ . setClientId ( "id" ). setClientSecret ("secret" ).setRefreshToken ("token" ).setScopes ("scope" )
164+ . setTokenUrl ( "https//:token" ). setRetryPolicy ( "exponential" ).setOauth2GrantType ("refresh_token" ).build ();
163165 CloseableHttpClient httpClientMock = Mockito .mock (CloseableHttpClient .class );
164166 CloseableHttpResponse httpResponse = Mockito .mock (CloseableHttpResponse .class );
165167 Mockito .when (httpClientMock .execute (Mockito .any ())).thenReturn (httpResponse );
@@ -193,10 +195,9 @@ public void testBasicAuthWithValidResponse() throws IOException {
193195 HttpBatchSourceConfig config = HttpBatchSourceConfig .builder ()
194196 .setReferenceName ("test" ).setUrl ("http://localhost" ).setHttpMethod ("GET" ).setHeaders ("Auth:auth" )
195197 .setFormat ("JSON" ).setAuthType ("none" ).setErrorHandling (StringUtils .EMPTY )
196- .setRetryPolicy (StringUtils .EMPTY ).setMaxRetryDuration (600L ).setConnectTimeout (120 )
197- .setReadTimeout (120 ).setPaginationType ("NONE" ).setVerifyHttps ("true" ).setAuthType ("basicAuth" ).setUsername (
198- "username" ).setPassword ("password" ).setRetryPolicy (
199- "exponential" ).build ();
198+ .setRetryPolicy (StringUtils .EMPTY ).setMaxRetryDuration (600L ).setConnectTimeout (120 ).setReadTimeout (120 )
199+ .setPaginationType ("NONE" ).setVerifyHttps ("false" ).setKeystoreType (KeyStoreType .JKS ).setAuthType ("basicAuth" )
200+ .setUsername ("username" ).setPassword ("password" ).setRetryPolicy ("exponential" ).build ();
200201 Mockito .when (httpClient .executeHTTP (Mockito .any ())).thenReturn (response );
201202 Mockito .when (response .getStatusLine ()).thenReturn (statusLine );
202203 Mockito .when (statusLine .getStatusCode ()).thenReturn (200 );
@@ -210,10 +211,9 @@ public void testValidConfigWithInvalidResponse() throws IOException {
210211 HttpBatchSourceConfig config = HttpBatchSourceConfig .builder ()
211212 .setReferenceName ("test" ).setUrl ("http://localhost" ).setHttpMethod ("GET" ).setHeaders ("Auth:auth" )
212213 .setFormat ("JSON" ).setAuthType ("none" ).setErrorHandling (StringUtils .EMPTY )
213- .setRetryPolicy (StringUtils .EMPTY ).setMaxRetryDuration (600L ).setConnectTimeout (120 )
214- .setReadTimeout (120 ).setPaginationType ("NONE" ).setVerifyHttps ("true" ).setAuthType ("basicAuth" ).setUsername (
215- "username" ).setPassword ("password" ).setRetryPolicy (
216- "exponential" ).build ();
214+ .setRetryPolicy (StringUtils .EMPTY ).setMaxRetryDuration (600L ).setConnectTimeout (120 ).setReadTimeout (120 )
215+ .setPaginationType ("NONE" ).setVerifyHttps ("false" ).setKeystoreType (KeyStoreType .JKS ).setAuthType ("basicAuth" )
216+ .setUsername ("username" ).setPassword ("password" ).setRetryPolicy ("exponential" ).build ();
217217 Mockito .when (httpClient .executeHTTP (Mockito .any ())).thenReturn (response );
218218 Mockito .when (response .getStatusLine ()).thenReturn (statusLine );
219219 Mockito .when (statusLine .getStatusCode ()).thenReturn (400 );
@@ -232,8 +232,8 @@ public void testValidateOAuth2WithClientCredentialsAndBodyAuthentication() throw
232232 HttpBatchSourceConfig config = HttpBatchSourceConfig .builder ().setReferenceName ("test" )
233233 .setUrl ("http://localhost" ).setHttpMethod ("GET" ).setHeaders ("Auth:auth" ).setFormat ("JSON" )
234234 .setErrorHandling (StringUtils .EMPTY ).setRetryPolicy (StringUtils .EMPTY )
235- .setMaxRetryDuration (600L ).setConnectTimeout (120 ).setReadTimeout (120 )
236- .setPaginationType ( "NONE " ).setVerifyHttps ( "true" ).setAuthType ("oAuth2" ).setClientId ("id" )
235+ .setMaxRetryDuration (600L ).setConnectTimeout (120 ).setReadTimeout (120 ). setPaginationType ( "NONE" )
236+ .setVerifyHttps ( "false " ).setKeystoreType ( KeyStoreType . JKS ).setAuthType ("oAuth2" ).setClientId ("id" )
237237 .setClientSecret ("secret" ).setScopes ("scope" ).setTokenUrl ("https//:token" )
238238 .setRetryPolicy ("exponential" ).setOauth2GrantType ("client_credentials" )
239239 .setOauth2ClientAuthentication ("body" ).build ();
@@ -264,8 +264,8 @@ public void testValidateOAuth2CredentialsWithProxyWithClientCredentialsAndBodyAu
264264 HttpBatchSourceConfig config = HttpBatchSourceConfig .builder ().setReferenceName ("test" )
265265 .setUrl ("http://localhost" ).setHttpMethod ("GET" ).setHeaders ("Auth:auth" ).setFormat ("JSON" )
266266 .setErrorHandling (StringUtils .EMPTY ).setRetryPolicy (StringUtils .EMPTY )
267- .setMaxRetryDuration (600L ).setConnectTimeout (120 ).setReadTimeout (120 )
268- .setPaginationType ( "NONE " ).setVerifyHttps ( "true" ).setAuthType ("oAuth2" ).setClientId ("id" )
267+ .setMaxRetryDuration (600L ).setConnectTimeout (120 ).setReadTimeout (120 ). setPaginationType ( "NONE" )
268+ .setVerifyHttps ( "false " ).setKeystoreType ( KeyStoreType . JKS ).setAuthType ("oAuth2" ).setClientId ("id" )
269269 .setClientSecret ("secret" ).setRefreshToken ("token" ).setScopes ("scope" )
270270 .setTokenUrl ("https//:token" ).setRetryPolicy ("exponential" ).setProxyUrl ("https://proxy" )
271271 .setProxyUsername ("proxyuser" ).setProxyPassword ("proxypassword" )
@@ -298,8 +298,8 @@ public void testValidateCredentialsOAuth2WithInvalidAccessTokenRequestForClientC
298298 HttpBatchSourceConfig config = HttpBatchSourceConfig .builder ().setReferenceName ("test" )
299299 .setUrl ("http://localhost" ).setHttpMethod ("GET" ).setHeaders ("Auth:auth" ).setFormat ("JSON" )
300300 .setErrorHandling (StringUtils .EMPTY ).setRetryPolicy (StringUtils .EMPTY )
301- .setMaxRetryDuration (600L ).setConnectTimeout (120 ).setReadTimeout (120 )
302- .setPaginationType ( "NONE " ).setVerifyHttps ( "true" ).setAuthType ("oAuth2" ).setClientId ("id" )
301+ .setMaxRetryDuration (600L ).setConnectTimeout (120 ).setReadTimeout (120 ). setPaginationType ( "NONE" )
302+ .setVerifyHttps ( "false " ).setKeystoreType ( KeyStoreType . JKS ).setAuthType ("oAuth2" ).setClientId ("id" )
303303 .setClientSecret ("secret" ).setRefreshToken ("token" ).setScopes ("scope" )
304304 .setTokenUrl ("https//:token" ).setRetryPolicy ("exponential" )
305305 .setOauth2GrantType ("client_credentials" ).setOauth2ClientAuthentication ("body" ).build ();
@@ -339,8 +339,8 @@ public void testValidateOAuth2WithClientCredentialsAndRequestParamAuthentication
339339 HttpBatchSourceConfig config = HttpBatchSourceConfig .builder ().setReferenceName ("test" )
340340 .setUrl ("http://localhost" ).setHttpMethod ("GET" ).setHeaders ("Auth:auth" ).setFormat ("JSON" )
341341 .setErrorHandling (StringUtils .EMPTY ).setRetryPolicy (StringUtils .EMPTY )
342- .setMaxRetryDuration (600L ).setConnectTimeout (120 ).setReadTimeout (120 )
343- .setPaginationType ( "NONE " ).setVerifyHttps ( "true" ).setAuthType ("oAuth2" ).setClientId ("id" )
342+ .setMaxRetryDuration (600L ).setConnectTimeout (120 ).setReadTimeout (120 ). setPaginationType ( "NONE" )
343+ .setVerifyHttps ( "false " ).setKeystoreType ( KeyStoreType . JKS ).setAuthType ("oAuth2" ).setClientId ("id" )
344344 .setClientSecret ("secret" ).setScopes ("scope" ).setTokenUrl ("https//:token" )
345345 .setRetryPolicy ("exponential" ).setOauth2GrantType ("client_credentials" )
346346 .setOauth2ClientAuthentication ("request_parameter" ).build ();
@@ -371,8 +371,8 @@ public void testValidateOAuth2CredentialsWithProxyWithClientCredentialsAndReques
371371 HttpBatchSourceConfig config = HttpBatchSourceConfig .builder ().setReferenceName ("test" )
372372 .setUrl ("http://localhost" ).setHttpMethod ("GET" ).setHeaders ("Auth:auth" ).setFormat ("JSON" )
373373 .setErrorHandling (StringUtils .EMPTY ).setRetryPolicy (StringUtils .EMPTY )
374- .setMaxRetryDuration (600L ).setConnectTimeout (120 ).setReadTimeout (120 )
375- .setPaginationType ( "NONE " ).setVerifyHttps ( "true" ).setAuthType ("oAuth2" ).setClientId ("id" )
374+ .setMaxRetryDuration (600L ).setConnectTimeout (120 ).setReadTimeout (120 ). setPaginationType ( "NONE" )
375+ .setVerifyHttps ( "false " ).setKeystoreType ( KeyStoreType . JKS ).setAuthType ("oAuth2" ).setClientId ("id" )
376376 .setClientSecret ("secret" ).setRefreshToken ("token" ).setScopes ("scope" )
377377 .setTokenUrl ("https//:token" ).setRetryPolicy ("exponential" ).setProxyUrl ("https://proxy" )
378378 .setProxyUsername ("proxyuser" ).setProxyPassword ("proxypassword" )
@@ -406,8 +406,8 @@ public void testValidateCredentialsOAuth2WithInvalidAccessTokenRequestForClientC
406406 HttpBatchSourceConfig config = HttpBatchSourceConfig .builder ().setReferenceName ("test" )
407407 .setUrl ("http://localhost" ).setHttpMethod ("GET" ).setHeaders ("Auth:auth" ).setFormat ("JSON" )
408408 .setErrorHandling (StringUtils .EMPTY ).setRetryPolicy (StringUtils .EMPTY )
409- .setMaxRetryDuration (600L ).setConnectTimeout (120 ).setReadTimeout (120 )
410- .setPaginationType ( "NONE " ).setVerifyHttps ( "true" ).setAuthType ("oAuth2" ).setClientId ("id" )
409+ .setMaxRetryDuration (600L ).setConnectTimeout (120 ).setReadTimeout (120 ). setPaginationType ( "NONE" )
410+ .setVerifyHttps ( "false " ).setKeystoreType ( KeyStoreType . JKS ).setAuthType ("oAuth2" ).setClientId ("id" )
411411 .setClientSecret ("secret" ).setRefreshToken ("token" ).setScopes ("scope" )
412412 .setTokenUrl ("https//:token" ).setRetryPolicy ("exponential" )
413413 .setOauth2GrantType ("client_credentials" ).setOauth2ClientAuthentication ("request_parameter" )
@@ -448,8 +448,8 @@ public void testValidateOAuth2WithClientCredentialsAndBasicAuthHeaderAuthenticat
448448 HttpBatchSourceConfig config = HttpBatchSourceConfig .builder ().setReferenceName ("test" )
449449 .setUrl ("http://localhost" ).setHttpMethod ("GET" ).setHeaders ("Auth:auth" ).setFormat ("JSON" )
450450 .setErrorHandling (StringUtils .EMPTY ).setRetryPolicy (StringUtils .EMPTY )
451- .setMaxRetryDuration (600L ).setConnectTimeout (120 ).setReadTimeout (120 )
452- . setPaginationType ( "NONE " ).setVerifyHttps ( "true" ).setAuthType ("oAuth2" ).setClientId ("id" )
451+ .setMaxRetryDuration (600L ).setConnectTimeout (120 ).setReadTimeout (120 ). setPaginationType ( "NONE" )
452+ . setVerifyHttps ( "false " ).setKeystoreType ( KeyStoreType . JKS ).setAuthType ("oAuth2" ).setClientId ("id" )
453453 .setClientSecret ("secret" ).setScopes ("scope" ).setTokenUrl ("https//:token" )
454454 .setRetryPolicy ("exponential" ).setOauth2GrantType ("client_credentials" )
455455 .setOauth2ClientAuthentication ("basic_auth_header" ).build ();
@@ -480,8 +480,8 @@ public void testValidateOAuth2CredentialsWithProxyWithClientCredentialsAndBasicA
480480 HttpBatchSourceConfig config = HttpBatchSourceConfig .builder ().setReferenceName ("test" )
481481 .setUrl ("http://localhost" ).setHttpMethod ("GET" ).setHeaders ("Auth:auth" ).setFormat ("JSON" )
482482 .setErrorHandling (StringUtils .EMPTY ).setRetryPolicy (StringUtils .EMPTY )
483- .setMaxRetryDuration (600L ).setConnectTimeout (120 ).setReadTimeout (120 )
484- . setPaginationType ( "NONE " ).setVerifyHttps ( "true" ).setAuthType ("oAuth2" ).setClientId ("id" )
483+ .setMaxRetryDuration (600L ).setConnectTimeout (120 ).setReadTimeout (120 ). setPaginationType ( "NONE" )
484+ . setVerifyHttps ( "false " ).setKeystoreType ( KeyStoreType . JKS ).setAuthType ("oAuth2" ).setClientId ("id" )
485485 .setClientSecret ("secret" ).setRefreshToken ("token" ).setScopes ("scope" )
486486 .setTokenUrl ("https//:token" ).setRetryPolicy ("exponential" ).setProxyUrl ("https://proxy" )
487487 .setProxyUsername ("proxyuser" ).setProxyPassword ("proxypassword" )
@@ -515,8 +515,8 @@ public void testValidateCredentialsOAuth2WithInvalidAccessTokenRequestForClientC
515515 HttpBatchSourceConfig config = HttpBatchSourceConfig .builder ().setReferenceName ("test" )
516516 .setUrl ("http://localhost" ).setHttpMethod ("GET" ).setHeaders ("Auth:auth" ).setFormat ("JSON" )
517517 .setErrorHandling (StringUtils .EMPTY ).setRetryPolicy (StringUtils .EMPTY )
518- .setMaxRetryDuration (600L ).setConnectTimeout (120 ).setReadTimeout (120 )
519- . setPaginationType ( "NONE " ).setVerifyHttps ( "true" ).setAuthType ("oAuth2" ).setClientId ("id" )
518+ .setMaxRetryDuration (600L ).setConnectTimeout (120 ).setReadTimeout (120 ). setPaginationType ( "NONE" )
519+ . setVerifyHttps ( "false " ).setKeystoreType ( KeyStoreType . JKS ).setAuthType ("oAuth2" ).setClientId ("id" )
520520 .setClientSecret ("secret" ).setRefreshToken ("token" ).setScopes ("scope" )
521521 .setTokenUrl ("https//:token" ).setRetryPolicy ("exponential" )
522522 .setOauth2GrantType ("client_credentials" ).setOauth2ClientAuthentication ("basic_auth_header" )
0 commit comments