1717
1818package io .cdap .plugin .servicenow .source ;
1919
20+ import io .cdap .cdap .api .data .schema .Schema ;
2021import io .cdap .plugin .servicenow .apiclient .ServiceNowTableAPIClientImpl ;
2122import io .cdap .plugin .servicenow .connector .ServiceNowConnectorConfig ;
2223import io .cdap .plugin .servicenow .restapi .RestAPIResponse ;
2324import io .cdap .plugin .servicenow .util .SourceApplication ;
2425import io .cdap .plugin .servicenow .util .SourceQueryMode ;
2526import io .cdap .plugin .servicenow .util .SourceValueType ;
26- import org .apache .http .HttpStatus ;
2727import org .apache .http .client .methods .CloseableHttpResponse ;
2828import org .apache .http .impl .client .CloseableHttpClient ;
2929import org .apache .http .impl .client .HttpClientBuilder ;
@@ -138,9 +138,14 @@ public void testFetchTableInfo() throws Exception {
138138 " }\n " +
139139 " ]\n " +
140140 "}" ;
141+ String schemaString = "{\" type\" :\" record\" ,\" name\" :\" ServiceNowColumnMetaData\" ,\" fields\" :[{\" name\" :" +
142+ "\" backgroundElementId\" ,\" type\" :\" long\" },{\" name\" :\" bgOrderPos\" ,\" type\" :\" long\" },{\" name\" :" +
143+ "\" description\" ,\" type\" :[\" string\" ,\" null\" ]},{\" name\" :\" userId\" ,\" type\" :\" string\" }]}" ;
144+ Schema schema = Schema .parseJson (schemaString );
141145 RestAPIResponse restAPIResponse = new RestAPIResponse (headers , responseBody , null );
142146 Mockito .when (restApi .executeGetWithRetries (Mockito .any ())).thenReturn (restAPIResponse );
143147 Mockito .when (restApi .parseResponseToResultListOfMap (restAPIResponse .getResponseBody ())).thenReturn (result );
148+ Mockito .when (restApi .fetchTableSchema ("table" , SourceValueType .SHOW_ACTUAL_VALUE )).thenReturn (schema );
144149 OAuthClient oAuthClient = Mockito .mock (OAuthClient .class );
145150 PowerMockito .whenNew (OAuthClient .class ).
146151 withArguments (Mockito .any (URLConnectionClient .class )).thenReturn (oAuthClient );
@@ -237,9 +242,18 @@ public void testFetchTableInfoReportingMode() throws Exception {
237242 " }\n " +
238243 " ]\n " +
239244 "}" ;
245+ String schemaString = "{\" type\" :\" record\" ,\" name\" :\" ServiceNowColumnMetaData\" ,\" fields\" :[{\" name\" :" +
246+ "\" backgroundElementId\" ,\" type\" :\" long\" },{\" name\" :\" bgOrderPos\" ,\" type\" :\" long\" },{\" name\" :" +
247+ "\" description\" ,\" type\" :[\" string\" ,\" null\" ]},{\" name\" :\" userId\" ,\" type\" :\" string\" }]}" ;
248+ Schema schema = Schema .parseJson (schemaString );
240249 RestAPIResponse restAPIResponse = new RestAPIResponse (headers , responseBody , null );
241250 Mockito .when (restApi .executeGetWithRetries (Mockito .any ())).thenReturn (restAPIResponse );
242251 Mockito .when (restApi .parseResponseToResultListOfMap (restAPIResponse .getResponseBody ())).thenReturn (result );
252+ Mockito .when (restApi .fetchTableSchema ("proc_po" , SourceValueType .SHOW_ACTUAL_VALUE )).thenReturn (schema );
253+ Mockito .when (restApi .fetchTableSchema ("proc_po_item" ,
254+ SourceValueType .SHOW_ACTUAL_VALUE )).thenReturn (schema );
255+ Mockito .when (restApi .fetchTableSchema ("proc_rec_slip" ,
256+ SourceValueType .SHOW_ACTUAL_VALUE )).thenReturn (schema );
243257 OAuthClient oAuthClient = Mockito .mock (OAuthClient .class );
244258 PowerMockito .whenNew (OAuthClient .class ).
245259 withArguments (Mockito .any (URLConnectionClient .class )).thenReturn (oAuthClient );
@@ -260,7 +274,7 @@ public void testFetchTableInfoReportingMode() throws Exception {
260274 thenReturn (response );
261275 SourceApplication application = SourceApplication .PROCUREMENT ;
262276 SourceValueType valueType = SourceValueType .SHOW_ACTUAL_VALUE ;
263- Assert .assertEquals (4 , ServiceNowInputFormat .fetchTableInfo (mode , connectorConfig , "table" ,
277+ Assert .assertEquals (3 , ServiceNowInputFormat .fetchTableInfo (mode , connectorConfig , "table" ,
264278 application , valueType , true ).size ());
265279 }
266280
0 commit comments