Search in sources :

Example 6 with DataServiceDelegate

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

the class AnnotationsQueryServiceTest method testGetsAnnotationsDefinedByStream.

@Test
public void testGetsAnnotationsDefinedByStream() throws Exception {
    final DataServiceDelegate dataServiceFactory = mock(DataServiceDelegate.class);
    final DataServiceContext dataServiceContext = mock(DataServiceContext.class);
    final DataServiceResolver dataServiceResolver = mock(DataServiceResolver.class);
    final MetastoreLocator metastoreLocator = mock(MetastoreLocator.class);
    when(dataServiceContext.getDataServiceDelegate()).thenReturn(dataServiceFactory);
    when(metastoreLocator.getMetastore()).thenReturn(null);
    final AnnotationsQueryService queryService = new AnnotationsQueryService(metastoreLocator, dataServiceResolver);
    URL resource = getClass().getClassLoader().getResource("showAnnotations.ktr");
    @SuppressWarnings("ConstantConditions") final TransMeta transMeta = new TransMeta(resource.getPath(), "show annotations");
    Document document = XMLHandler.loadXMLFile(resource);
    transMeta.loadXML(document.getFirstChild(), null, true);
    final DataServiceMeta dataServiceMeta = new DataServiceMeta(transMeta);
    dataServiceMeta.setName("annotatedService");
    dataServiceMeta.setStepname("Annotate Stream");
    when(dataServiceResolver.getDataService("annotatedService")).thenReturn(dataServiceMeta);
    Query query = queryService.prepareQuery("show annotations from annotatedService", 0, Collections.<String, String>emptyMap());
    AnnotationsQueryService.AnnotationsQuery spy = (AnnotationsQueryService.AnnotationsQuery) Mockito.spy(query);
    final ModelAnnotationGroup mag = new ModelAnnotationGroup(new ModelAnnotation<>(new CreateMeasure()));
    when(spy.getTrans(transMeta)).then(new Answer<Trans>() {

        @Override
        public Trans answer(final InvocationOnMock invocationOnMock) throws Throwable {
            Trans trans = (Trans) invocationOnMock.callRealMethod();
            trans.getExtensionDataMap().put("KEY_MODEL_ANNOTATIONS", mag);
            return trans;
        }
    });
    final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    spy.writeTo(outputStream);
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(outputStream.toByteArray());
    DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
    ThinResultSet thinResultSet = new ThinResultFactory().loadResultSet(dataInputStream, null);
    thinResultSet.next();
    String output = thinResultSet.getString(1);
    assertEquals(new ModelAnnotationGroupXmlWriter(mag).getXML().trim(), output);
    verify(metastoreLocator).getMetastore();
    assertEquals(0, query.getTransList().size());
    thinResultSet.close();
}
Also used : ModelAnnotationGroupXmlWriter(org.pentaho.agilebi.modeler.models.annotations.ModelAnnotationGroupXmlWriter) ThinResultFactory(org.pentaho.di.trans.dataservice.jdbc.ThinResultFactory) DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) MetastoreLocator(org.pentaho.osgi.metastore.locator.api.MetastoreLocator) Document(org.w3c.dom.Document) URL(java.net.URL) ThinResultSet(org.pentaho.di.trans.dataservice.jdbc.ThinResultSet) CreateMeasure(org.pentaho.agilebi.modeler.models.annotations.CreateMeasure) Trans(org.pentaho.di.trans.Trans) DummyTrans(org.pentaho.di.trans.steps.dummytrans.DummyTrans) ModelAnnotationGroup(org.pentaho.agilebi.modeler.models.annotations.ModelAnnotationGroup) DataServiceResolver(org.pentaho.di.trans.dataservice.resolvers.DataServiceResolver) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) DataServiceContext(org.pentaho.di.trans.dataservice.DataServiceContext) ByteArrayInputStream(java.io.ByteArrayInputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DataServiceDelegate(org.pentaho.di.trans.dataservice.ui.DataServiceDelegate) Test(org.junit.Test)

Example 7 with DataServiceDelegate

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

the class AnnotationsQueryServiceTest method testNoAnnotationsReturnsEmpty.

@Test
public void testNoAnnotationsReturnsEmpty() throws Exception {
    final DataServiceDelegate dataServiceFactory = mock(DataServiceDelegate.class);
    final DataServiceContext dataServiceContext = mock(DataServiceContext.class);
    final DataServiceResolver dataServiceResolver = mock(DataServiceResolver.class);
    final MetastoreLocator metastoreLocator = mock(MetastoreLocator.class);
    when(dataServiceContext.getDataServiceDelegate()).thenReturn(dataServiceFactory);
    when(metastoreLocator.getMetastore()).thenReturn(null);
    final AnnotationsQueryService queryService = new AnnotationsQueryService(metastoreLocator, dataServiceResolver);
    URL resource = getClass().getClassLoader().getResource("showAnnotations.ktr");
    @SuppressWarnings("ConstantConditions") final TransMeta transMeta = new TransMeta(resource.getPath(), "show annotations");
    Document document = XMLHandler.loadXMLFile(resource);
    transMeta.loadXML(document.getFirstChild(), null, true);
    final DataServiceMeta dataServiceMeta = new DataServiceMeta(transMeta);
    dataServiceMeta.setName("gridService");
    dataServiceMeta.setStepname("Data Grid");
    when(dataServiceResolver.getDataService("gridService")).thenReturn(dataServiceMeta);
    Query query = queryService.prepareQuery("show annotations from gridService", 0, Collections.<String, String>emptyMap());
    final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    query.writeTo(outputStream);
    String output = getResultString(outputStream);
    assertEquals("<annotations></annotations>", output.trim());
}
Also used : DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) 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) Document(org.w3c.dom.Document) URL(java.net.URL) DataServiceContext(org.pentaho.di.trans.dataservice.DataServiceContext) DataServiceDelegate(org.pentaho.di.trans.dataservice.ui.DataServiceDelegate) Test(org.junit.Test)

Example 8 with DataServiceDelegate

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

the class AnnotationsQueryServiceTest method testLogsExceptionOnWriteEror.

@Test
public void testLogsExceptionOnWriteEror() throws Exception {
    final DataServiceDelegate dataServiceFactory = mock(DataServiceDelegate.class);
    final DataServiceContext dataServiceContext = mock(DataServiceContext.class);
    final DataServiceResolver dataServiceResolver = mock(DataServiceResolver.class);
    final MetastoreLocator metastoreLocator = mock(MetastoreLocator.class);
    when(dataServiceContext.getDataServiceDelegate()).thenReturn(dataServiceFactory);
    when(metastoreLocator.getMetastore()).thenReturn(null);
    final AnnotationsQueryService queryService = new AnnotationsQueryService(metastoreLocator, dataServiceResolver);
    Query query = queryService.prepareQuery("show annotations from annotatedService", 0, Collections.<String, String>emptyMap());
    MetaStoreException metaStoreException = new MetaStoreException("Unable to load dataservice annotatedService");
    when(dataServiceResolver.getDataService("annotatedService")).thenReturn(null);
    try {
        query.writeTo(new ByteArrayOutputStream());
        fail("should have got exception");
    } catch (IOException e) {
        assertEquals("Error while executing 'show annotations from annotatedService'", e.getMessage());
    }
}
Also used : DataServiceContext(org.pentaho.di.trans.dataservice.DataServiceContext) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) DataServiceDelegate(org.pentaho.di.trans.dataservice.ui.DataServiceDelegate) DataServiceResolver(org.pentaho.di.trans.dataservice.resolvers.DataServiceResolver) MetastoreLocator(org.pentaho.osgi.metastore.locator.api.MetastoreLocator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Test(org.junit.Test)

Example 9 with DataServiceDelegate

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

the class DataServiceDialogControllerTest method testShowDriverDetails.

@Test
public void testShowDriverDetails() {
    DataServiceDelegate delegate = mock(DataServiceDelegate.class);
    controller = spy(new DataServiceDialogController(null, delegate));
    SwtDialog dialog = mock(SwtDialog.class);
    doReturn(dialog).when(controller).getDialog();
    Shell shell = mock(Shell.class);
    doReturn(shell).when(dialog).getShell();
    doCallRealMethod().when(controller).showDriverDetailsDialog();
    controller.showDriverDetailsDialog();
    verify(delegate).showDriverDetailsDialog(shell);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) SwtDialog(org.pentaho.ui.xul.swt.tags.SwtDialog) DataServiceDelegate(org.pentaho.di.trans.dataservice.ui.DataServiceDelegate) Test(org.junit.Test)

Example 10 with DataServiceDelegate

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

the class DataServiceRemapConfirmationDialogControllerTest method testRemapErrorOnNoSteps.

@Test
public void testRemapErrorOnNoSteps() {
    DataServiceDelegate delegate = mock(DataServiceDelegate.class);
    DataServiceRemapConfirmationDialogController controller = spy(new DataServiceRemapConfirmationDialogController(mock(DataServiceMeta.class), new ArrayList<String>(), delegate));
    doReturn(mock(SwtDialog.class)).when(controller).getDialog();
    Assert.assertEquals(controller.getAction(), DataServiceRemapConfirmationDialog.Action.CANCEL);
    controller.remap();
    verify(delegate, times(1)).showRemapNoStepsDialog(any(Shell.class));
}
Also used : Shell(org.eclipse.swt.widgets.Shell) SwtDialog(org.pentaho.ui.xul.swt.tags.SwtDialog) ArrayList(java.util.ArrayList) DataServiceDelegate(org.pentaho.di.trans.dataservice.ui.DataServiceDelegate) Test(org.junit.Test)

Aggregations

DataServiceDelegate (org.pentaho.di.trans.dataservice.ui.DataServiceDelegate)12 Test (org.junit.Test)11 DataServiceContext (org.pentaho.di.trans.dataservice.DataServiceContext)6 DataServiceMeta (org.pentaho.di.trans.dataservice.DataServiceMeta)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 DataServiceResolver (org.pentaho.di.trans.dataservice.resolvers.DataServiceResolver)5 MetastoreLocator (org.pentaho.osgi.metastore.locator.api.MetastoreLocator)5 SwtDialog (org.pentaho.ui.xul.swt.tags.SwtDialog)5 TransMeta (org.pentaho.di.trans.TransMeta)4 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)4 ModelAnnotationGroup (org.pentaho.agilebi.modeler.models.annotations.ModelAnnotationGroup)3 URL (java.net.URL)2 Shell (org.eclipse.swt.widgets.Shell)2 Matchers.anyString (org.mockito.Matchers.anyString)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 CreateAttribute (org.pentaho.agilebi.modeler.models.annotations.CreateAttribute)2 TransHopMeta (org.pentaho.di.trans.TransHopMeta)2 DataServiceRemapStepChooserModel (org.pentaho.di.trans.dataservice.ui.model.DataServiceRemapStepChooserModel)2 StepMeta (org.pentaho.di.trans.step.StepMeta)2 Document (org.w3c.dom.Document)2