Search in sources :

Example 31 with PushDownOptimizationMeta

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);
}
Also used : PushDownOptimizationMeta(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta) Test(org.junit.Test)

Example 32 with PushDownOptimizationMeta

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;
}
Also used : ParameterGeneration(org.pentaho.di.trans.dataservice.optimization.paramgen.ParameterGeneration) PushDownOptimizationMeta(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta)

Example 33 with PushDownOptimizationMeta

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()));
}
Also used : DataServiceDialog(org.pentaho.di.trans.dataservice.ui.DataServiceDialog) PushDownOptimizationMeta(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta) Test(org.junit.Test)

Example 34 with PushDownOptimizationMeta

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));
    }
}
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 35 with PushDownOptimizationMeta

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;
}
Also used : DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) PushDownOptimizationMeta(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta)

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