Search in sources :

Example 11 with DataServiceMeta

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

the class AnnotationsQueryServiceTest method testAnnotationsOnCurrentStep.

@Test
public void testAnnotationsOnCurrentStep() throws Exception {
    TransMeta transMeta = new TransMeta();
    DummyTransMeta src1Meta = new DummyTransMeta();
    StepMeta src1 = new StepMeta("src", 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 = Mockito.spy(new StepMeta("annot", annot1Meta));
    transMeta.addStep(annot1);
    TransHopMeta src1ToAnnot1 = new TransHopMeta(src1, annot1);
    transMeta.addTransHop(src1ToAnnot1);
    final DataServiceMeta dsA = new DataServiceMeta(transMeta);
    dsA.setName("dsa");
    dsA.setStepname("annot");
    final DataServiceMeta ds1 = new DataServiceMeta(transMeta);
    ds1.setName("ds");
    ds1.setStepname("src");
    final DataServiceDelegate dataServiceFactory = mock(DataServiceDelegate.class);
    final DataServiceContext dataServiceContext = mock(DataServiceContext.class);
    when(dataServiceContext.getDataServiceDelegate()).thenReturn(dataServiceFactory);
    final DataServiceResolver dataServiceResolver = mock(DataServiceResolver.class);
    when(dataServiceResolver.getDataService("ds")).thenReturn(ds1);
    when(dataServiceResolver.getDataService("dsa")).thenReturn(dsA);
    final MetastoreLocator metastoreLocator = mock(MetastoreLocator.class);
    when(metastoreLocator.getMetastore()).thenReturn(null);
    final AnnotationsQueryService queryService = new AnnotationsQueryService(metastoreLocator, dataServiceResolver);
    Query query = queryService.prepareQuery("show annotations from dsa", 0, Collections.<String, String>emptyMap());
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    query.writeTo(outputStream);
    String result = getResultString(outputStream);
    assertTrue(result.contains(name1));
    query = queryService.prepareQuery("show annotations from ds", 0, Collections.<String, String>emptyMap());
    outputStream = new ByteArrayOutputStream();
    query.writeTo(outputStream);
    result = getResultString(outputStream);
    String output = getResultString(outputStream);
    assertEquals("<annotations></annotations>", output.trim());
}
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)

Example 12 with DataServiceMeta

use of org.pentaho.di.trans.dataservice.DataServiceMeta 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 13 with DataServiceMeta

use of org.pentaho.di.trans.dataservice.DataServiceMeta 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 14 with DataServiceMeta

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

the class AutoParameterGenerationServiceTest method setUp.

@Before
public void setUp() throws Exception {
    dataService = new DataServiceMeta(transMeta);
    dataService.setName(NAME);
    dataService.setStepname(SERVICE_STEP);
    RowMeta serviceRowMeta = mock(RowMeta.class);
    when(transMeta.getStepFields(SERVICE_STEP)).thenReturn(serviceRowMeta);
    when(serviceRowMeta.getFieldNames()).thenReturn(SERVICE_FIELDS);
    when(serviceProvider.createPushDown()).thenReturn(parameterGeneration);
}
Also used : DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) RowMeta(org.pentaho.di.core.row.RowMeta) Before(org.junit.Before)

Example 15 with DataServiceMeta

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

the class ParameterGenerationControllerTest method testRunAutoGenerate.

@Test
public void testRunAutoGenerate() throws Exception {
    DataServiceModel dataServiceModel = mock(DataServiceModel.class);
    when(model.getDialogModel()).thenReturn(dataServiceModel);
    AutoParameterGenerationService parameterGenerationService = mock(AutoParameterGenerationService.class);
    when(factory.createAutoOptimizationService()).thenReturn(parameterGenerationService);
    DataServiceMeta dataServiceMeta = mock(DataServiceMeta.class);
    when(dataServiceModel.getDataService()).thenReturn(dataServiceMeta);
    List<PushDownOptimizationMeta> generatedOptimizations = ImmutableList.of(mock(PushDownOptimizationMeta.class));
    when(parameterGenerationService.apply(dataServiceMeta)).thenReturn(generatedOptimizations);
    when(dataServiceModel.addAll(generatedOptimizations)).thenReturn(true);
    controller.runAutoGenerate();
    verify(dataServiceModel).addAll(generatedOptimizations);
    verify(model).updateParameterMap();
    verify(messageBox).open();
}
Also used : DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) DataServiceModel(org.pentaho.di.trans.dataservice.ui.model.DataServiceModel) PushDownOptimizationMeta(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta) AutoParameterGenerationService(org.pentaho.di.trans.dataservice.optimization.paramgen.AutoParameterGenerationService) 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