Search in sources :

Example 1 with ModelAnnotationGroupXmlWriter

use of org.pentaho.agilebi.modeler.models.annotations.ModelAnnotationGroupXmlWriter 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)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 URL (java.net.URL)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 CreateMeasure (org.pentaho.agilebi.modeler.models.annotations.CreateMeasure)1 ModelAnnotationGroup (org.pentaho.agilebi.modeler.models.annotations.ModelAnnotationGroup)1 ModelAnnotationGroupXmlWriter (org.pentaho.agilebi.modeler.models.annotations.ModelAnnotationGroupXmlWriter)1 Trans (org.pentaho.di.trans.Trans)1 TransMeta (org.pentaho.di.trans.TransMeta)1 DataServiceContext (org.pentaho.di.trans.dataservice.DataServiceContext)1 DataServiceMeta (org.pentaho.di.trans.dataservice.DataServiceMeta)1 ThinResultFactory (org.pentaho.di.trans.dataservice.jdbc.ThinResultFactory)1 ThinResultSet (org.pentaho.di.trans.dataservice.jdbc.ThinResultSet)1 DataServiceResolver (org.pentaho.di.trans.dataservice.resolvers.DataServiceResolver)1 DataServiceDelegate (org.pentaho.di.trans.dataservice.ui.DataServiceDelegate)1 DummyTrans (org.pentaho.di.trans.steps.dummytrans.DummyTrans)1 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)1 MetastoreLocator (org.pentaho.osgi.metastore.locator.api.MetastoreLocator)1