QueryServiceDelegate implements Query.Service { @Override public Query prepareQuery( String sql, int maxRows, Map<String, String> parameters ) throws KettleException { for ( Query.Service queryService : queryServices ) { Query query = queryService.prepareQuery( sql, maxRows, parameters ); if ( query != null ) { return query; } } return null; } QueryServiceDelegate( List<Query.Service> queryServices ); @Override Query prepareQuery( String sql, int maxRows, Map<String, String> parameters ); @Override Query prepareQuery( String sql, IDataServiceClientService.StreamingMode windowMode,
                                       long windowSize, long windowEvery, long windowLimit,
                                       final Map<String, String> parameters );  }
@Test public void testPrepareQuery() throws KettleException { when( service1.prepareQuery( TEST_SQL_QUERY, MAX_ROWS, parameters ) ).thenReturn( query1 ); when( service2.prepareQuery( TEST_SQL_QUERY, MAX_ROWS, parameters ) ).thenReturn( query2 ); when( service1.prepareQuery( TEST_SQL_QUERY, null, 0, 0, 0, parameters ) ).thenReturn( query1 ); when( service2.prepareQuery( TEST_SQL_QUERY, null, 0, 0, 0, parameters ) ).thenReturn( query2 ); Query result = client.prepareQuery( TEST_SQL_QUERY, MAX_ROWS, parameters ); assertEquals( query1, result ); result = client.prepareQuery( TEST_SQL_QUERY, null, 0, 0, 0, parameters ); assertEquals( query1, result ); when( service1.prepareQuery( TEST_SQL_QUERY, MAX_ROWS, parameters ) ).thenReturn( null ); result = client.prepareQuery( TEST_SQL_QUERY, MAX_ROWS, parameters ); assertEquals( query2, result ); when( service1.prepareQuery( TEST_SQL_QUERY, null, 0, 0, 0, parameters ) ).thenReturn( null ); result = client.prepareQuery( TEST_SQL_QUERY, null, 0, 0, 0, parameters ); assertEquals( query2, result ); when( service2.prepareQuery( TEST_SQL_QUERY, MAX_ROWS, parameters ) ).thenReturn( null ); result = client.prepareQuery( TEST_SQL_QUERY, MAX_ROWS, parameters ); assertNull( result ); when( service2.prepareQuery( TEST_SQL_QUERY, null, 0, 0, 0, parameters ) ).thenReturn( null ); result = client.prepareQuery( TEST_SQL_QUERY, null, 0, 0, 0, parameters ); assertNull( result ); }