use of org.pentaho.di.trans.dataservice.optimization.PushDownFactory in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceDialogTest method testBuilder.
@Test
public void testBuilder() 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(model) {
@Override
protected DataServiceDialog createDialog(DataServiceDelegate delegate) {
assertThat(delegate, sameInstance(mockDelegate));
assertThat(super.createDialog(delegate), isA(DataServiceDialog.class));
return dialog;
}
};
builder.serviceStep("step");
verify(model).setServiceStep("step");
builder.serviceStep("");
builder.serviceStep(null);
verify(model, times(2)).setServiceStep("");
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);
verify(model).setServiceName("Service");
verify(model).setServiceStep("OUTPUT");
verify(model).setPushDownOptimizations(optimizations);
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.PushDownFactory in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceDialogTest method testInitOptimizations.
@Test
public void testInitOptimizations() throws Exception {
PushDownFactory pushDownFactory;
ArrayList<PushDownFactory> factories = Lists.newArrayList();
XulTabbox tabBox = mock(XulTabbox.class, RETURNS_DEEP_STUBS);
when(controller.getElementById("optimizationTabs")).thenReturn(tabBox);
when(tabBox.getTabs().getTabCount()).thenReturn(2);
// Create first overlay, low priority
pushDownFactory = mock(PushDownFactory.class);
DataServiceDialog.OptimizationOverlay overlay1 = mock(DataServiceDialog.OptimizationOverlay.class);
when(pushDownFactory.createOverlay()).thenReturn(overlay1);
when(overlay1.getPriority()).thenReturn(100.0);
factories.add(pushDownFactory);
// Create another overlay, higher priority
pushDownFactory = mock(PushDownFactory.class);
DataServiceDialog.OptimizationOverlay overlay0 = mock(DataServiceDialog.OptimizationOverlay.class);
when(pushDownFactory.createOverlay()).thenReturn(overlay0);
when(overlay0.getPriority()).thenReturn(0.0);
factories.add(pushDownFactory);
// Create push down factory without overlay
pushDownFactory = mock(PushDownFactory.class);
when(pushDownFactory.createOverlay()).thenReturn(null);
factories.add(pushDownFactory);
dialog.initOptimizations(factories);
InOrder inOrder = inOrder(overlay0, overlay1);
inOrder.verify(overlay0).apply(dialog);
inOrder.verify(overlay1).apply(dialog);
inOrder.verifyNoMoreInteractions();
verify(tabBox).setSelectedIndex(0);
reset(tabBox);
when(tabBox.getTabs().getTabCount()).thenReturn(0);
dialog.initOptimizations(factories);
verify(tabBox, times(0)).setSelectedIndex(0);
}
use of org.pentaho.di.trans.dataservice.optimization.PushDownFactory in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceDialog method initOptimizations.
protected DataServiceDialog initOptimizations(List<PushDownFactory> pushDownFactories) throws KettleException {
ImmutableList<OptimizationOverlay> overlays = FluentIterable.from(pushDownFactories).transform(new Function<PushDownFactory, OptimizationOverlay>() {
@Override
public OptimizationOverlay apply(PushDownFactory input) {
return input.createOverlay();
}
}).filter(Predicates.notNull()).toSortedList(Ordering.natural().onResultOf(new Function<OptimizationOverlay, Comparable>() {
@Override
public Comparable apply(OptimizationOverlay input) {
return input.getPriority();
}
}));
for (OptimizationOverlay overlay : overlays) {
overlay.apply(this);
}
XulTabbox optimizationTabs = controller.getElementById("optimizationTabs");
if (optimizationTabs.getTabs().getTabCount() > 0) {
optimizationTabs.setSelectedIndex(0);
}
return this;
}
use of org.pentaho.di.trans.dataservice.optimization.PushDownFactory 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.PushDownFactory in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceMetaStoreUtilTest method setUp.
@Before
public void setUp() throws Exception {
when(repository.getRepositoryMeta().getRepositoryCapabilities().supportsReferences()).thenReturn(true);
when(repository.loadTransformation(any(ObjectId.class), isNull(String.class))).then(new Answer<TransMeta>() {
@Override
public TransMeta answer(InvocationOnMock invocation) throws Throwable {
if (invocation.getArguments()[0].equals(transMeta.getObjectId())) {
return transMeta;
} else {
throw notFoundException;
}
}
});
metaStore.setName(DataServiceMetaStoreUtilTest.class.getName());
when(repository.getMetaStore()).thenReturn(metaStore);
PushDownFactory optimizationFactory = mock(PushDownFactory.class);
when((Class) optimizationFactory.getType()).thenReturn(TestOptimization.class);
when(optimizationFactory.createPushDown()).then(new Answer<PushDownType>() {
@Override
public PushDownType answer(InvocationOnMock invocation) throws Throwable {
return new TestOptimization();
}
});
pushDownFactories.add(optimizationFactory);
metaStoreUtil = DataServiceMetaStoreUtil.create(context);
}
Aggregations