Search in sources :

Example 1 with DataServiceFactory

use of org.pentaho.di.trans.dataservice.serialization.DataServiceFactory in project pdi-dataservice-server-plugin by pentaho.

the class ExecutorQueryServiceTest method testQueryBuildsWithMetastore.

@Test
public void testQueryBuildsWithMetastore() throws Exception {
    final DataServiceFactory factory = mock(DataServiceFactory.class);
    final DataServiceContext context = mock(DataServiceContext.class);
    final DataServiceResolver dataServiceResolver = mock(DataServiceResolver.class);
    final DataServiceExecutor dataServiceExecutor = mock(DataServiceExecutor.class);
    final Trans serviceTrans = mock(Trans.class);
    final Trans genTrans = mock(Trans.class);
    when(context.getMetaStoreUtil()).thenReturn(factory);
    DataServiceExecutor.Builder builder = mock(DataServiceExecutor.Builder.class);
    final IMetaStore metastore = mock(IMetaStore.class);
    final MetastoreLocator metastoreLocator = mock(MetastoreLocator.class);
    when(metastoreLocator.getMetastore()).thenReturn(metastore);
    SQL sql = new SQL("select field from table");
    HashMap<String, String> parameters = new HashMap<>();
    int rowLimit = 5432;
    ExecutorQueryService executorQueryService = new ExecutorQueryService(dataServiceResolver, metastoreLocator);
    when(dataServiceResolver.createBuilder(argThat(matchesSql(sql)))).thenReturn(builder);
    when(factory.getMetaStore()).thenReturn(metastore);
    when(builder.rowLimit(rowLimit)).thenReturn(builder);
    when(builder.parameters(parameters)).thenReturn(builder);
    when(builder.metastore(metastore)).thenReturn(builder);
    when(builder.windowMode(null)).thenReturn(builder);
    when(builder.windowSize(0)).thenReturn(builder);
    when(builder.windowEvery(0)).thenReturn(builder);
    when(builder.windowLimit(0)).thenReturn(builder);
    when(builder.build()).thenReturn(dataServiceExecutor);
    when(dataServiceExecutor.getServiceTrans()).thenReturn(serviceTrans);
    when(dataServiceExecutor.getGenTrans()).thenReturn(genTrans);
    Query result = executorQueryService.prepareQuery(sql.getSqlString(), rowLimit, parameters);
    assertEquals(ImmutableList.of(serviceTrans, genTrans), result.getTransList());
    verify(builder).rowLimit(rowLimit);
    verify(builder).parameters(parameters);
    verify(builder).metastore(metastore);
}
Also used : HashMap(java.util.HashMap) DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) DataServiceResolver(org.pentaho.di.trans.dataservice.resolvers.DataServiceResolver) MetastoreLocator(org.pentaho.osgi.metastore.locator.api.MetastoreLocator) IMetaStore(org.pentaho.metastore.api.IMetaStore) SQL(org.pentaho.di.core.sql.SQL) DataServiceContext(org.pentaho.di.trans.dataservice.DataServiceContext) DataServiceFactory(org.pentaho.di.trans.dataservice.serialization.DataServiceFactory) Trans(org.pentaho.di.trans.Trans) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 Test (org.junit.Test)1 SQL (org.pentaho.di.core.sql.SQL)1 Trans (org.pentaho.di.trans.Trans)1 DataServiceContext (org.pentaho.di.trans.dataservice.DataServiceContext)1 DataServiceExecutor (org.pentaho.di.trans.dataservice.DataServiceExecutor)1 DataServiceResolver (org.pentaho.di.trans.dataservice.resolvers.DataServiceResolver)1 DataServiceFactory (org.pentaho.di.trans.dataservice.serialization.DataServiceFactory)1 IMetaStore (org.pentaho.metastore.api.IMetaStore)1 MetastoreLocator (org.pentaho.osgi.metastore.locator.api.MetastoreLocator)1