Search in sources :

Example 11 with SQL

use of org.pentaho.di.core.sql.SQL in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceExecutorTest method testStop.

@Test
public void testStop() throws KettleException {
    String sql = "SELECT * FROM " + DATA_SERVICE_NAME;
    when(serviceTrans.isRunning()).thenReturn(true);
    when(genTrans.isRunning()).thenReturn(true);
    DataServiceExecutor executor = new DataServiceExecutor.Builder(new SQL(sql), dataService, context).serviceTrans(serviceTrans).sqlTransGenerator(sqlTransGenerator).genTrans(genTrans).build();
    executor.stop();
    verify(serviceTrans).stopAll();
    verify(genTrans).stopAll();
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Matchers.anyString(org.mockito.Matchers.anyString) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 12 with SQL

use of org.pentaho.di.core.sql.SQL in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceExecutorTest method testHasErrors.

@Test
public void testHasErrors() throws KettleException {
    String sql = "SELECT * FROM " + DATA_SERVICE_NAME;
    when(serviceTrans.isRunning()).thenReturn(true);
    when(genTrans.isRunning()).thenReturn(true);
    when(sqlTransGenerator.getRowLimit()).thenReturn(999);
    DataServiceExecutor executor = new DataServiceExecutor.Builder(new SQL(sql), dataService, context).serviceTrans(serviceTrans).sqlTransGenerator(sqlTransGenerator).genTrans(genTrans).build();
    assertFalse(executor.hasErrors());
    when(serviceTrans.getErrors()).thenReturn(1);
    when(genTrans.getErrors()).thenReturn(1);
    assertTrue(executor.hasErrors());
    when(serviceTrans.getErrors()).thenReturn(0);
    when(genTrans.getErrors()).thenReturn(1);
    assertTrue(executor.hasErrors());
    when(serviceTrans.getErrors()).thenReturn(1);
    when(genTrans.getErrors()).thenReturn(0);
    assertTrue(executor.hasErrors());
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Matchers.anyString(org.mockito.Matchers.anyString) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 13 with SQL

use of org.pentaho.di.core.sql.SQL in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceExecutorTest method testStopStreaming.

@Test
public void testStopStreaming() throws KettleException {
    SQL sql = new SQL("SELECT * FROM " + DATA_SERVICE_NAME);
    when(serviceTrans.getTransMeta().listParameters()).thenReturn(new String[0]);
    when(sqlTransGenerator.getSql()).thenReturn(sql);
    PushDownOptimizationMeta optimization = mock(PushDownOptimizationMeta.class);
    when(optimization.isEnabled()).thenReturn(true);
    dataService.getPushDownOptimizationMeta().add(optimization);
    dataService.setStreaming(true);
    IMetaStore metastore = mock(IMetaStore.class);
    DataServiceExecutor executor = new DataServiceExecutor.Builder(sql, dataService, context).serviceTrans(serviceTrans).sqlTransGenerator(sqlTransGenerator).genTrans(genTrans).metastore(metastore).windowMode(IDataServiceClientService.StreamingMode.ROW_BASED).windowSize(1).windowEvery(0).windowLimit(0).build();
    executor.stop();
    verify(serviceTrans, times(0)).stopAll();
    verify(genTrans, times(0)).stopAll();
}
Also used : PushDownOptimizationMeta(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 14 with SQL

use of org.pentaho.di.core.sql.SQL in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceExecutorTest method testNullNotNullKeywords.

@Test
public void testNullNotNullKeywords() throws Exception {
    String sql = "SELECT * FROM " + DATA_SERVICE_NAME + " WHERE column1 IS NOT NULL AND column2 IS NULL";
    DataServiceExecutor executor = new DataServiceExecutor.Builder(new SQL(sql), dataService, context).serviceTrans(serviceTrans).sqlTransGenerator(sqlTransGenerator).genTrans(genTrans).build();
    Condition condition = executor.getSql().getWhereCondition().getCondition();
    Condition condition1 = condition.getCondition(0);
    Condition condition2 = condition.getCondition(1);
    assertEquals("column1", condition1.getLeftValuename());
    assertNull(condition1.getRightExact());
    assertEquals(Condition.FUNC_NOT_NULL, condition1.getFunction());
    assertEquals("column2", condition2.getLeftValuename());
    assertNull(condition2.getRightExact());
    assertEquals(Condition.FUNC_NULL, condition2.getFunction());
}
Also used : Condition(org.pentaho.di.core.Condition) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Matchers.anyString(org.mockito.Matchers.anyString) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 15 with SQL

use of org.pentaho.di.core.sql.SQL in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceExecutorTest method testBuilderBuildNullServiceTransformation.

@Test(expected = KettleException.class)
public void testBuilderBuildNullServiceTransformation() throws Exception {
    SQL sql = new SQL("SELECT * FROM " + DATA_SERVICE_NAME);
    dataService.setName(DATA_SERVICE_NAME);
    dataService.setServiceTrans(null);
    IMetaStore metastore = mock(IMetaStore.class);
    new DataServiceExecutor.Builder(sql, dataService, context).sqlTransGenerator(sqlTransGenerator).genTrans(genTrans).metastore(metastore).enableMetrics(false).normalizeConditions(false).rowLimit(50).build();
}
Also used : IMetaStore(org.pentaho.metastore.api.IMetaStore) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Aggregations

SQL (org.pentaho.di.core.sql.SQL)58 Test (org.junit.Test)49 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)31 RowMeta (org.pentaho.di.core.row.RowMeta)18 Matchers.anyString (org.mockito.Matchers.anyString)17 IMetaStore (org.pentaho.metastore.api.IMetaStore)17 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)16 SelectValuesMeta (org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta)12 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)11 DataServiceExecutor (org.pentaho.di.trans.dataservice.DataServiceExecutor)7 PushDownOptimizationMeta (org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta)7 Condition (org.pentaho.di.core.Condition)6 KettleException (org.pentaho.di.core.exception.KettleException)4 SQLCondition (org.pentaho.di.core.sql.SQLCondition)4 TransMeta (org.pentaho.di.trans.TransMeta)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 DataOutputStream (java.io.DataOutputStream)3 RowProducer (org.pentaho.di.trans.RowProducer)3 Trans (org.pentaho.di.trans.Trans)3 ImmutableMap (com.google.common.collect.ImmutableMap)2