use of org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta in project pdi-dataservice-server-plugin by pentaho.
the class ParameterGenerationModelTest method testParameterSelection.
@Test
public void testParameterSelection() throws Exception {
Map<String, PushDownOptimizationMeta> parameterMap = Maps.newHashMap();
assertThat(model.getSelectedParameter(), nullValue());
assertThat(model.getSelectedOptimization(), nullValue());
assertThat(model.getParameterGeneration(), nullValue());
assertThat(model.getParameterMap(), anEmptyMap());
PushDownOptimizationMeta first = createParameterGeneration("first");
parameterMap.put("first", first);
model.setParameterMap(parameterMap);
assertThat(model.getParameterMap(), is(parameterMap));
assertThat(model.getSelectedParameter(), nullValue());
verify(changeSupport).firePropertyChange("parameterMap", ImmutableMap.of(), parameterMap);
reset(changeSupport);
model.setSelectedParameter("first");
assertThat(model.getSelectedParameter(), is("first"));
assertThat(model.getSelectedOptimization(), sameInstance(first));
assertThat(model.getParameterGeneration(), sameInstance(first.getType()));
verify(changeSupport).firePropertyChange("selectedParameter", null, "first");
reset(changeSupport);
PushDownOptimizationMeta second = createParameterGeneration("second");
parameterMap.put("second", second);
model.add(second);
verify(dialogModel).add(second);
assertThat(model.getParameterMap(), is(parameterMap));
assertThat(model.getParameterMap(), is(ImmutableMap.of("first", first, "second", second)));
verify(changeSupport).firePropertyChange("parameterMap", ImmutableMap.of("first", first), parameterMap);
verify(changeSupport).firePropertyChange("selectedParameter", null, "first");
reset(changeSupport);
model.setSelectedParameter("second");
assertThat(model.getSelectedParameter(), is("second"));
assertThat(model.getSelectedOptimization(), sameInstance(second));
assertThat(model.getParameterGeneration(), sameInstance(second.getType()));
verify(changeSupport).firePropertyChange("selectedParameter", "first", "second");
reset(changeSupport);
when(dialogModel.remove(second)).thenReturn(true);
optimizations.remove(second);
parameterMap.remove("second");
model.remove(second);
verify(dialogModel).remove(second);
assertThat(model.getParameterMap(), is(parameterMap));
assertThat(model.getSelectedParameter(), nullValue());
assertThat(model.getSelectedOptimization(), nullValue());
assertThat(model.getParameterGeneration(), nullValue());
verify(changeSupport).firePropertyChange("selectedParameter", "second", null);
}
use of org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta in project pdi-dataservice-server-plugin by pentaho.
the class ParameterGenerationModelTest method createParameterGeneration.
private PushDownOptimizationMeta createParameterGeneration(String parameterName) {
PushDownOptimizationMeta meta = new PushDownOptimizationMeta();
ParameterGeneration parameterGeneration = new ParameterGeneration(factory);
meta.setType(parameterGeneration);
parameterGeneration.setParameterName(parameterName);
optimizations.add(meta);
return meta;
}
use of org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta in project pdi-dataservice-server-plugin by pentaho.
the class ParameterPushdownFactoryTest method testCreateOverlay.
@Test
public void testCreateOverlay() throws Exception {
DataServiceDialog.OptimizationOverlay overlay = factory.createOverlay();
assertThat(overlay.getPriority(), greaterThan(1.0));
PushDownOptimizationMeta meta = new PushDownOptimizationMeta();
PushDownOptimizationMeta extra = new PushDownOptimizationMeta();
meta.setType(factory.createPushDown());
when(dialog.applyOverlay(overlay, ParameterPushdownFactory.XUL_SOURCE)).thenReturn(container);
when(dialog.getModel()).thenReturn(dialogModel);
when(dialogModel.getPushDownOptimizations(TYPE)).thenReturn(ImmutableList.<PushDownOptimizationMeta>of()).thenReturn(ImmutableList.of(meta, extra));
overlay.apply(dialog);
verify(dialogModel).add(metaCaptor.capture());
overlay.apply(dialog);
verify(dialogModel).removeAll(ImmutableList.of(extra));
verify(container, times(2)).addEventHandler(ctrlCaptor.capture());
assertThat(getDelegate(0), sameInstance(metaCaptor.getValue().getType()));
assertThat(getDelegate(1), sameInstance(meta.getType()));
}
use of org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceDialogTest method testBuilderTransMeta.
@Test
public void testBuilderTransMeta() throws Exception {
final DataServiceDelegate mockDelegate = mock(DataServiceDelegate.class);
final DataServiceDialog dialog = mock(DataServiceDialog.class);
when(dialog.getController()).thenReturn(controller);
// Intercept actual creation so we can inject our mock
DataServiceDialog.Builder builder = new DataServiceDialog.Builder(transMeta) {
@Override
protected DataServiceDialog createDialog(DataServiceDelegate delegate) {
assertThat(delegate, sameInstance(mockDelegate));
assertThat(super.createDialog(delegate), isA(DataServiceDialog.class));
return dialog;
}
};
builder.serviceStep("step");
builder.serviceStep("");
builder.serviceStep(null);
DataServiceMeta dataService = mock(DataServiceMeta.class);
when(dataService.getName()).thenReturn("Service");
when(dataService.getStepname()).thenReturn("OUTPUT");
ArrayList<PushDownOptimizationMeta> optimizations = Lists.newArrayList(mock(PushDownOptimizationMeta.class));
when(dataService.getPushDownOptimizationMeta()).thenReturn(optimizations);
builder.edit(dataService);
Shell shell = mock(Shell.class);
ArrayList<PushDownFactory> factories = Lists.newArrayList(mock(PushDownFactory.class));
when(mockDelegate.getShell()).thenReturn(shell);
when(mockDelegate.getPushDownFactories()).thenReturn(factories);
assertThat(builder.build(mockDelegate), sameInstance(dialog));
verify(controller).setDataService(dataService);
verify(dialog).loadXul(same(shell), any(KettleXulLoader.class), any(SwtXulRunner.class));
verify(dialog).initOptimizations(factories);
Throwable xulException = new XulException();
when(dialog.loadXul(same(shell), any(KettleXulLoader.class), any(SwtXulRunner.class))).thenThrow(xulException);
try {
builder.build(mockDelegate);
fail("Expected exception was not thrown");
} catch (KettleException e) {
assertThat(e.getCause(), equalTo(xulException));
}
}
use of org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceMetaStoreUtilTest method createDataService.
@Override
protected DataServiceMeta createDataService(String dataServiceName, TransMeta transMeta) {
DataServiceMeta dataService = super.createDataService(dataServiceName, transMeta);
PushDownOptimizationMeta optimization = new PushDownOptimizationMeta();
optimization.setName(OPTIMIZATION);
optimization.setStepName(OPTIMIZED_STEP);
TestOptimization optimizationType = new TestOptimization();
optimizationType.setValue(OPTIMIZATION_VALUE);
optimization.setType(optimizationType);
dataService.setPushDownOptimizationMeta(Lists.newArrayList(optimization));
return dataService;
}
Aggregations