Search in sources :

Example 26 with PushDownOptimizationMeta

use of org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta in project pdi-dataservice-server-plugin by pentaho.

the class ServiceCacheControllerTest method testLocateServiceCacheMeta.

@Test
public void testLocateServiceCacheMeta() throws Exception {
    controller = new ServiceCacheController(factory);
    when(factory.getType()).thenReturn(ServiceCache.class);
    when(model.getPushDownOptimizations(ServiceCache.class)).thenReturn(ImmutableList.<PushDownOptimizationMeta>of());
    when(factory.createPushDown()).thenReturn(serviceCache = mock(ServiceCache.class));
    meta = controller.locateServiceCacheMeta(model);
    assertThat(meta.isEnabled(), is(true));
    assertThat(meta.getType(), is((PushDownType) serviceCache));
    PushDownOptimizationMeta meta2 = mock(PushDownOptimizationMeta.class);
    when(model.getPushDownOptimizations(ServiceCache.class)).thenReturn(ImmutableList.of(meta, meta2));
    assertThat(controller.locateServiceCacheMeta(model), is(meta));
    verify(model).add(meta);
    verify(model).removeAll(ImmutableList.of(meta2));
}
Also used : PushDownOptimizationMeta(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta) PushDownType(org.pentaho.di.trans.dataservice.optimization.PushDownType) Test(org.junit.Test)

Example 27 with PushDownOptimizationMeta

use of org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta in project pdi-dataservice-server-plugin by pentaho.

the class AutoParameterGenerationServiceTest method testApply.

@Test
public void testApply() throws Exception {
    Map<String, Set<List<StepFieldOperations>>> operationPaths;
    List<StepFieldOperations> field1_input1 = Lists.newArrayList(new StepFieldOperations("Input 1", "field1_origin", null), new StepFieldOperations("Modifier", "field1", new MockOperations().put(ChangeType.DATA).put(ChangeType.METADATA)));
    List<StepFieldOperations> field2_input1 = Lists.newArrayList(new StepFieldOperations("Input 1", "field2_origin", null), new StepFieldOperations("Rename", "field2", new MockOperations().put(ChangeType.METADATA)));
    List<StepFieldOperations> field2_input2 = Lists.newArrayList(new StepFieldOperations("Input 2", "field2", null));
    operationPaths = Maps.newHashMap();
    operationPaths.put("field1", ImmutableSet.of(field1_input1));
    operationPaths.put("field2", ImmutableSet.of(field2_input1, field2_input2));
    when(lineageClient.getOperationPaths(same(transMeta), eq(SERVICE_STEP), eq(ImmutableList.copyOf(SERVICE_FIELDS)))).thenReturn(operationPaths);
    StepMeta input1Meta = mock(StepMeta.class);
    when(transMeta.findStep("Input 1")).thenReturn(input1Meta);
    when(serviceProvider.supportsStep(input1Meta)).thenReturn(true);
    List<PushDownOptimizationMeta> optimizationMetaList = service.apply(dataService);
    assertThat(optimizationMetaList, contains(allOf(hasProperty("stepName", equalTo("Input 1")), hasProperty("type", is(parameterGeneration)))));
    verify(parameterGeneration).setParameterName(anyString());
    verify(parameterGeneration).createFieldMapping("field2", "field2_origin");
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) StepFieldOperations(org.pentaho.metaverse.api.StepFieldOperations) PushDownOptimizationMeta(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta) Matchers.anyString(org.mockito.Matchers.anyString) StepMeta(org.pentaho.di.trans.step.StepMeta) Test(org.junit.Test)

Example 28 with PushDownOptimizationMeta

use of org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta in project pdi-dataservice-server-plugin by pentaho.

the class ParameterGenerationTest method testInit.

@Test
public void testInit() throws DuplicateParamException {
    DataServiceMeta dataService = mock(DataServiceMeta.class);
    PushDownOptimizationMeta pdo = new PushDownOptimizationMeta();
    pdo.setName(OPT_NAME);
    pdo.setStepName(OPT_STEP);
    when(transMeta.findStep(OPT_STEP)).thenReturn(null, stepMeta);
    when(serviceProvider.getService(stepMeta)).thenReturn(null, service);
    // Step not found
    paramGen.init(transMeta, dataService, pdo);
    // Service not found
    paramGen.init(transMeta, dataService, pdo);
    // Okay
    paramGen.init(transMeta, dataService, pdo);
    verify(transMeta, times(2)).addParameterDefinition(eq(PARAM_NAME), eq(""), anyString());
    verify(transMeta).addParameterDefinition(eq(PARAM_NAME), eq(EXPECTED_DEFAULT), anyString());
    doThrow(DuplicateParamException.class).when(transMeta).addParameterDefinition(eq(PARAM_NAME), eq(EXPECTED_DEFAULT), anyString());
    // Exception should be silently caught
    paramGen.init(transMeta, dataService, pdo);
    verify(transMeta, atLeast(3)).activateParameters();
}
Also used : DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) PushDownOptimizationMeta(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta) Test(org.junit.Test)

Example 29 with PushDownOptimizationMeta

use of org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta in project pdi-dataservice-server-plugin by pentaho.

the class ParameterGenerationControllerTest method testAddParameterFailure.

@Test
public void testAddParameterFailure() throws Exception {
    when(factory.createPushDown()).thenReturn(new ParameterGeneration(factory));
    when(model.getParameterMap()).thenReturn(ImmutableMap.<String, PushDownOptimizationMeta>of());
    when(stepList.getSelectedItem()).thenReturn("Default Step");
    mockPromptBox("parameterName", XulDialogCallback.Status.CANCEL);
    controller.addParameter();
    mockPromptBox("", XulDialogCallback.Status.ACCEPT);
    controller.addParameter();
    mockPromptBox("parameterName", XulDialogCallback.Status.ACCEPT);
    when(model.getParameterMap()).thenReturn(ImmutableMap.of("parameterName", mock(PushDownOptimizationMeta.class)));
    controller.addParameter();
    verify(model, never()).add(any(PushDownOptimizationMeta.class));
    verify(messageBox, times(2)).setIcon(SWT.ICON_WARNING);
    verify(messageBox, times(2)).open();
}
Also used : ParameterGeneration(org.pentaho.di.trans.dataservice.optimization.paramgen.ParameterGeneration) PushDownOptimizationMeta(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta) Test(org.junit.Test)

Example 30 with PushDownOptimizationMeta

use of org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta in project pdi-dataservice-server-plugin by pentaho.

the class ParameterGenerationControllerTest method testAddParameter.

@Test
public void testAddParameter() throws Exception {
    ParameterGeneration parameterGeneration = new ParameterGeneration(factory);
    when(factory.createPushDown()).thenReturn(parameterGeneration);
    when(model.getParameterMap()).thenReturn(ImmutableMap.<String, PushDownOptimizationMeta>of());
    when(stepList.getSelectedItem()).thenReturn("Default Step");
    mockPromptBox("parameterName", XulDialogCallback.Status.ACCEPT);
    controller.addParameter();
    ArgumentCaptor<PushDownOptimizationMeta> optMetaCaptor = ArgumentCaptor.forClass(PushDownOptimizationMeta.class);
    verify(model).add(optMetaCaptor.capture());
    PushDownOptimizationMeta pushDownOptimizationMeta = optMetaCaptor.getValue();
    assertThat(pushDownOptimizationMeta, allOf(hasProperty("type", sameInstance(parameterGeneration)), hasProperty("enabled", is(true)), hasProperty("stepName", is("Default Step"))));
    assertThat(parameterGeneration.getParameterName(), equalTo("parameterName"));
    verify(model).setSelectedParameter("parameterName");
}
Also used : ParameterGeneration(org.pentaho.di.trans.dataservice.optimization.paramgen.ParameterGeneration) PushDownOptimizationMeta(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta) Test(org.junit.Test)

Aggregations

PushDownOptimizationMeta (org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta)41 Test (org.junit.Test)23 ParameterGeneration (org.pentaho.di.trans.dataservice.optimization.paramgen.ParameterGeneration)10 DataServiceMeta (org.pentaho.di.trans.dataservice.DataServiceMeta)8 SQL (org.pentaho.di.core.sql.SQL)7 IMetaStore (org.pentaho.metastore.api.IMetaStore)7 Matchers.anyString (org.mockito.Matchers.anyString)5 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 DataOutputStream (java.io.DataOutputStream)3 Set (java.util.Set)3 RowProducer (org.pentaho.di.trans.RowProducer)3 PushDownType (org.pentaho.di.trans.dataservice.optimization.PushDownType)3 DataServiceModel (org.pentaho.di.trans.dataservice.ui.model.DataServiceModel)3 XulException (org.pentaho.ui.xul.XulException)3 Shell (org.eclipse.swt.widgets.Shell)2 Before (org.junit.Before)2 InOrder (org.mockito.InOrder)2 KettleException (org.pentaho.di.core.exception.KettleException)2