Search in sources :

Example 6 with DataServiceMeta

use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceStepDeleteExtensionPointPluginTest method testCallExtensionPoint.

@Test
public void testCallExtensionPoint() throws Exception {
    DataServiceContext context = mock(DataServiceContext.class);
    TransMeta trans = mock(TransMeta.class);
    DataServiceDelegate delegate = mock(DataServiceDelegate.class);
    when(context.getDataServiceDelegate()).thenReturn(delegate);
    when(delegate.showRemapConfirmationDialog(any(DataServiceMeta.class), anyList())).thenReturn(DataServiceRemapConfirmationDialog.Action.CANCEL, DataServiceRemapConfirmationDialog.Action.REMAP, DataServiceRemapConfirmationDialog.Action.DELETE);
    when(delegate.showRemapStepChooserDialog(any(DataServiceMeta.class), anyList(), any(TransMeta.class))).thenReturn(DataServiceRemapStepChooserDialog.Action.CANCEL);
    StepMeta step1 = mock(StepMeta.class);
    when(step1.getParentTransMeta()).thenReturn(trans);
    when(step1.getName()).thenReturn("Step1");
    when(trans.getStepNames()).thenReturn(new String[] { "Step1" });
    DataServiceMeta dataService = mock(DataServiceMeta.class);
    when(dataService.getStepname()).thenReturn("Step1");
    when(delegate.getDataServices(trans)).thenReturn(Arrays.asList(dataService));
    when(delegate.getDataServiceByStepName(trans, "Step1")).thenReturn(dataService);
    StepMeta[] steps = new StepMeta[] { step1 };
    DataServiceStepDeleteExtensionPointPlugin plugin = new DataServiceStepDeleteExtensionPointPlugin(context);
    try {
        plugin.callExtensionPoint(null, steps);
    } catch (KettleException ke) {
    // KettleException will be thrown on cancel
    }
    verify(delegate, times(0)).showRemapStepChooserDialog(any(DataServiceMeta.class), anyList(), any(TransMeta.class));
    try {
        plugin.callExtensionPoint(null, steps);
    } catch (KettleException ke) {
    // KettleException will be thrown on cancel
    }
    verify(delegate, times(1)).showRemapStepChooserDialog(any(DataServiceMeta.class), anyList(), any(TransMeta.class));
    plugin.callExtensionPoint(null, steps);
    verify(delegate, times(1)).removeDataService(dataService);
}
Also used : DataServiceContext(org.pentaho.di.trans.dataservice.DataServiceContext) KettleException(org.pentaho.di.core.exception.KettleException) DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) TransMeta(org.pentaho.di.trans.TransMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Test(org.junit.Test)

Example 7 with DataServiceMeta

use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceDialogControllerTest method testSaveAndCloseNoName.

@Test
public void testSaveAndCloseNoName() throws Exception {
    DataServiceMeta editingDataService = mock(DataServiceMeta.class);
    when(model.getServiceName()).thenReturn(null);
    controller.saveAndClose();
    verify(delegate, times(0)).save(dataServiceMeta);
    verify(delegate, times(0)).removeDataService(editingDataService);
    verify(synchronizationListener, times(0)).install(transMeta);
    verify(dialog, times(0)).dispose();
}
Also used : DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) Test(org.junit.Test)

Example 8 with DataServiceMeta

use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceRemapStepChooserDialogControllerTest method testInit.

@Test
public void testInit() throws InvocationTargetException, XulException {
    DataServiceRemapStepChooserModel model = mock(DataServiceRemapStepChooserModel.class);
    DataServiceMeta dataService = mock(DataServiceMeta.class);
    List<String> stepNames = Arrays.asList("step1");
    DataServiceDelegate delegate = mock(DataServiceDelegate.class);
    final SwtLabel label = mock(SwtLabel.class);
    final SwtListbox listbox = mock(SwtListbox.class);
    BindingFactory bindingFactory = mock(BindingFactory.class);
    when(bindingFactory.createBinding(same(model), anyString(), any(XulComponent.class), anyString())).thenReturn(mock(Binding.class));
    DataServiceRemapStepChooserDialogController controller = spy(new DataServiceRemapStepChooserDialogController(model, dataService, stepNames, delegate));
    doAnswer(new Answer() {

        private Object[] returnValues = { label, listbox };

        int invocations = 0;

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            return returnValues[invocations++];
        }
    }).when(controller).getElementById(anyString());
    doReturn(bindingFactory).when(controller).getBindingFactory();
    controller.init();
    verify(label).setValue(anyString());
    verify(listbox).setElements(same(stepNames));
    verify(bindingFactory).createBinding(same(model), anyString(), same(listbox), anyString());
}
Also used : Binding(org.pentaho.ui.xul.binding.Binding) DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) SwtListbox(org.pentaho.ui.xul.swt.tags.SwtListbox) Matchers.anyString(org.mockito.Matchers.anyString) SwtLabel(org.pentaho.ui.xul.swt.tags.SwtLabel) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DataServiceRemapStepChooserModel(org.pentaho.di.trans.dataservice.ui.model.DataServiceRemapStepChooserModel) DataServiceDelegate(org.pentaho.di.trans.dataservice.ui.DataServiceDelegate) XulComponent(org.pentaho.ui.xul.XulComponent) BindingFactory(org.pentaho.ui.xul.binding.BindingFactory) Test(org.junit.Test)

Example 9 with DataServiceMeta

use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceModelTest method testGetDataService.

@Test
public void testGetDataService() throws Exception {
    model.setServiceName("service");
    model.setServiceStep("step");
    PushDownOptimizationMeta optimizationMeta = mock(PushDownOptimizationMeta.class);
    model.setPushDownOptimizations(Lists.newArrayList(optimizationMeta));
    PushDownType pushDownType = mock(PushDownType.class);
    when(optimizationMeta.getType()).thenReturn(pushDownType);
    DataServiceMeta dataService = model.getDataService();
    assertThat(dataService, allOf(hasProperty("name", equalTo("service")), hasProperty("stepname", equalTo("step")), hasProperty("pushDownOptimizationMeta", contains(optimizationMeta))));
    verify(pushDownType).init(transMeta, dataService, optimizationMeta);
}
Also used : DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) PushDownOptimizationMeta(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta) PushDownType(org.pentaho.di.trans.dataservice.optimization.PushDownType) Test(org.junit.Test)

Example 10 with DataServiceMeta

use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.

the class AnnotationsQueryServiceTest method testAnnotationsOnCurrentStep2Paths.

@Test
public void testAnnotationsOnCurrentStep2Paths() throws Exception {
    TransMeta transMeta = new TransMeta();
    DummyTransMeta src1Meta = new DummyTransMeta();
    StepMeta src1 = new StepMeta("src1", src1Meta);
    transMeta.addStep(src1);
    final ModelAnnotationGroup mag1 = new ModelAnnotationGroup(new ModelAnnotation<CreateAttribute>(new CreateAttribute()));
    final String name1 = mag1.get(0).getName();
    DummyTransMeta annot1Meta = createPseudoAnnotate(mag1);
    StepMeta annot1 = new StepMeta("annot1", annot1Meta);
    transMeta.addStep(annot1);
    TransHopMeta src1ToAnnot1 = new TransHopMeta(src1, annot1);
    transMeta.addTransHop(src1ToAnnot1);
    DummyTransMeta src2Meta = new DummyTransMeta();
    StepMeta src2 = new StepMeta("src2", src2Meta);
    transMeta.addStep(src2);
    final ModelAnnotationGroup mag2 = new ModelAnnotationGroup(new ModelAnnotation<CreateAttribute>(new CreateAttribute()));
    final String name2 = mag2.get(0).getName();
    DummyTransMeta annot2Meta = createPseudoAnnotate(mag2);
    StepMeta annot2 = new StepMeta("annot2", annot2Meta);
    transMeta.addStep(annot2);
    TransHopMeta src2ToAnnot2 = new TransHopMeta(src2, annot2);
    transMeta.addTransHop(src2ToAnnot2);
    DummyTransMeta mergedMeta = new DummyTransMeta();
    StepMeta mergedStepMeta = new StepMeta("merged", mergedMeta);
    transMeta.addStep(mergedStepMeta);
    transMeta.addTransHop(new TransHopMeta(annot1, mergedStepMeta));
    transMeta.addTransHop(new TransHopMeta(annot2, mergedStepMeta));
    final DataServiceMeta ds1 = new DataServiceMeta((TransMeta) transMeta.clone());
    ds1.setName("dsa");
    ds1.setStepname("annot1");
    final DataServiceMeta dsAll = new DataServiceMeta((TransMeta) transMeta.clone());
    dsAll.setName("ds");
    dsAll.setStepname("merged");
    final DataServiceDelegate dataServiceFactory = mock(DataServiceDelegate.class);
    final DataServiceResolver dataServiceResolver = mock(DataServiceResolver.class);
    when(dataServiceResolver.getDataService("dsAll")).thenReturn(dsAll);
    when(dataServiceResolver.getDataService("ds1")).thenReturn(ds1);
    final DataServiceContext dataServiceContext = mock(DataServiceContext.class);
    when(dataServiceContext.getDataServiceDelegate()).thenReturn(dataServiceFactory);
    final MetastoreLocator metastoreLocator = mock(MetastoreLocator.class);
    when(metastoreLocator.getMetastore()).thenReturn(null);
    AnnotationsQueryService queryService = new AnnotationsQueryService(metastoreLocator, dataServiceResolver);
    Query query = queryService.prepareQuery("show annotations from ds1", 0, Collections.<String, String>emptyMap());
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    query.writeTo(outputStream);
    String result = getResultString(outputStream);
    assertTrue(result.contains(name1));
    assertFalse(result.contains(name2));
    queryService = new AnnotationsQueryService(metastoreLocator, dataServiceResolver);
    query = queryService.prepareQuery("show annotations from dsAll", 0, Collections.<String, String>emptyMap());
    outputStream = new ByteArrayOutputStream();
    query.writeTo(outputStream);
    String result2 = getResultString(outputStream);
    assertTrue(result2.contains(name1));
    assertTrue(result2.contains(name2));
}
Also used : ModelAnnotationGroup(org.pentaho.agilebi.modeler.models.annotations.ModelAnnotationGroup) DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) CreateAttribute(org.pentaho.agilebi.modeler.models.annotations.CreateAttribute) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) DataServiceResolver(org.pentaho.di.trans.dataservice.resolvers.DataServiceResolver) MetastoreLocator(org.pentaho.osgi.metastore.locator.api.MetastoreLocator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) DataServiceContext(org.pentaho.di.trans.dataservice.DataServiceContext) DataServiceDelegate(org.pentaho.di.trans.dataservice.ui.DataServiceDelegate) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Test(org.junit.Test)

Aggregations

DataServiceMeta (org.pentaho.di.trans.dataservice.DataServiceMeta)52 Test (org.junit.Test)29 TransMeta (org.pentaho.di.trans.TransMeta)16 PushDownOptimizationMeta (org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta)9 KettleException (org.pentaho.di.core.exception.KettleException)8 DataServiceContext (org.pentaho.di.trans.dataservice.DataServiceContext)6 DataServiceDelegate (org.pentaho.di.trans.dataservice.ui.DataServiceDelegate)6 StepMeta (org.pentaho.di.trans.step.StepMeta)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Before (org.junit.Before)4 RowMeta (org.pentaho.di.core.row.RowMeta)4 DataServiceResolver (org.pentaho.di.trans.dataservice.resolvers.DataServiceResolver)4 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)4 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)4 MetastoreLocator (org.pentaho.osgi.metastore.locator.api.MetastoreLocator)4 ModelAnnotationGroup (org.pentaho.agilebi.modeler.models.annotations.ModelAnnotationGroup)3 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)3 File (java.io.File)2 IOException (java.io.IOException)2 URL (java.net.URL)2