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));
}
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");
}
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();
}
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();
}
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");
}
Aggregations