KieServerDataSetProvider extends AbstractKieServerService implements DataSetProvider { protected List<List> performQuery(RemoteDataSetDef def, ConsoleDataSetLookup dataSetLookup, QueryServicesClient queryClient, QueryFilterSpec filterSpec) { if (dataSetLookup.testMode()) { QueryDefinition queryDefinition = QueryDefinition.builder() .name(dataSetLookup.getDataSetUUID()) .source(def.getDataSource()) .target(def.getQueryTarget()) .expression(def.getDbSQL()) .build(); kieServerIntegration.broadcastToKieServers(((RemoteDataSetDef) def).getServerTemplateId(), (KieServicesClient client) -> { QueryServicesClient instanceQueryClient = client.getServicesClient(QueryServicesClient.class); QueryDefinition registered = instanceQueryClient.replaceQuery(queryDefinition); if (registered.getColumns() != null) { for (Entry<String, String> entry : registered.getColumns().entrySet()) { if (def.getColumnById(entry.getKey()) == null) { def.addColumn(entry.getKey(), ColumnType.valueOf(entry.getValue())); } } } return registered; }); try { return queryClient.query( dataSetLookup.getDataSetUUID(), QueryServicesClient.QUERY_MAP_RAW, filterSpec, dataSetLookup.getRowOffset() / dataSetLookup.getNumberOfRows(), dataSetLookup.getNumberOfRows(), List.class ); } catch (Exception e) { queryClient.unregisterQuery(dataSetLookup.getDataSetUUID()); throw new RuntimeException(e); } } else { return queryClient.query( dataSetLookup.getDataSetUUID(), QueryServicesClient.QUERY_MAP_RAW, filterSpec, dataSetLookup.getRowOffset() / dataSetLookup.getNumberOfRows(), dataSetLookup.getNumberOfRows(), List.class ); } }  @Override DataSetProviderType getType(); @Override DataSetMetadata getDataSetMetadata(DataSetDef def); @Override DataSet lookupDataSet(DataSetDef def,
                                 DataSetLookup lookup); @Override boolean isDataSetOutdated(DataSetDef def); static final DataSetProviderType TYPE; }
@Test public void testPerformQueryTestMode() { QueryFilterSpec filterSpec = new QueryFilterSpec(); ConsoleDataSetLookup dataSetLookup = Mockito.mock(ConsoleDataSetLookup.class); when(dataSetLookup.testMode()).thenReturn(true); when(dataSetLookup.getNumberOfRows()).thenReturn(10); when(dataSetLookup.getRowOffset()).thenReturn(1); when(dataSetLookup.getDataSetUUID()).thenReturn(""); kieServerDataSetProvider.performQuery(dataSetDef, dataSetLookup, queryServicesClient, filterSpec); verify(kieServerIntegration).broadcastToKieServers(anyString(), any()); verify(dataSetLookup, times(1)).testMode(); verify(queryServicesClient).query(anyString(), anyString(), any(QueryFilterSpec.class), anyInt(), anyInt(), any()); }
@Test public void testPerformQueryRegularMode() { QueryFilterSpec filterSpec = new QueryFilterSpec(); ConsoleDataSetLookup dataSetLookup = Mockito.mock(ConsoleDataSetLookup.class); when(dataSetLookup.testMode()).thenReturn(false); when(dataSetLookup.getNumberOfRows()).thenReturn(10); when(dataSetLookup.getRowOffset()).thenReturn(1); when(dataSetLookup.getDataSetUUID()).thenReturn(""); kieServerDataSetProvider.performQuery(dataSetDef, dataSetLookup, queryServicesClient, filterSpec); verify(kieServerIntegration, times(0)).broadcastToKieServers(anyString(), any()); verify(dataSetLookup, times(1)).testMode(); verify(queryServicesClient).query(anyString(), anyString(), any(QueryFilterSpec.class), anyInt(), anyInt(), any()); }