Search in sources :

Example 1 with PushDownFactory

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));
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) KettleXulLoader(org.pentaho.di.ui.xul.KettleXulLoader) PushDownFactory(org.pentaho.di.trans.dataservice.optimization.PushDownFactory) Shell(org.eclipse.swt.widgets.Shell) XulException(org.pentaho.ui.xul.XulException) PushDownOptimizationMeta(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta) SwtXulRunner(org.pentaho.ui.xul.swt.SwtXulRunner) Test(org.junit.Test)

Example 2 with PushDownFactory

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);
}
Also used : InOrder(org.mockito.InOrder) XulTabbox(org.pentaho.ui.xul.containers.XulTabbox) PushDownFactory(org.pentaho.di.trans.dataservice.optimization.PushDownFactory) Test(org.junit.Test)

Example 3 with PushDownFactory

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;
}
Also used : Function(com.google.common.base.Function) XulTabbox(org.pentaho.ui.xul.containers.XulTabbox) PushDownFactory(org.pentaho.di.trans.dataservice.optimization.PushDownFactory)

Example 4 with PushDownFactory

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));
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) KettleXulLoader(org.pentaho.di.ui.xul.KettleXulLoader) PushDownFactory(org.pentaho.di.trans.dataservice.optimization.PushDownFactory) Shell(org.eclipse.swt.widgets.Shell) XulException(org.pentaho.ui.xul.XulException) PushDownOptimizationMeta(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta) SwtXulRunner(org.pentaho.ui.xul.swt.SwtXulRunner) Test(org.junit.Test)

Example 5 with PushDownFactory

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);
}
Also used : ObjectId(org.pentaho.di.repository.ObjectId) TransMeta(org.pentaho.di.trans.TransMeta) PushDownType(org.pentaho.di.trans.dataservice.optimization.PushDownType) PushDownFactory(org.pentaho.di.trans.dataservice.optimization.PushDownFactory) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Before(org.junit.Before)

Aggregations

PushDownFactory (org.pentaho.di.trans.dataservice.optimization.PushDownFactory)5 Test (org.junit.Test)3 Shell (org.eclipse.swt.widgets.Shell)2 KettleException (org.pentaho.di.core.exception.KettleException)2 DataServiceMeta (org.pentaho.di.trans.dataservice.DataServiceMeta)2 PushDownOptimizationMeta (org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta)2 KettleXulLoader (org.pentaho.di.ui.xul.KettleXulLoader)2 XulException (org.pentaho.ui.xul.XulException)2 XulTabbox (org.pentaho.ui.xul.containers.XulTabbox)2 SwtXulRunner (org.pentaho.ui.xul.swt.SwtXulRunner)2 Function (com.google.common.base.Function)1 Before (org.junit.Before)1 InOrder (org.mockito.InOrder)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 ObjectId (org.pentaho.di.repository.ObjectId)1 TransMeta (org.pentaho.di.trans.TransMeta)1 PushDownType (org.pentaho.di.trans.dataservice.optimization.PushDownType)1