Search in sources :

Example 21 with DataServiceMeta

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

the class TransientResolverTest method testGetDataService.

private void testGetDataService(String fileSeparator) throws Exception {
    RepositoryDirectoryInterface directory = mock(RepositoryDirectoryInterface.class);
    when(root.findDirectory(fileSeparator + "path" + fileSeparator + "to")).thenReturn(directory);
    when(repository.getTransformationID("name", directory)).thenReturn(objectId);
    when(repository.loadTransformation(objectId, null)).thenReturn(transMeta);
    String transientId = TransientResolver.buildTransient(fileSeparator + "path" + fileSeparator + "to" + fileSeparator + "name", "data_service");
    DataServiceMeta dataServiceMeta = transientResolver.getDataService(transientId);
    assertNotNull(dataServiceMeta);
    assertThat(dataServiceMeta.getStepname(), is("data_service"));
    assertFalse(dataServiceMeta.isUserDefined());
    assertThat(dataServiceMeta, hasServiceCacheOptimization());
    int rowLimit = 1000;
    transientId = TransientResolver.buildTransient(fileSeparator + "path" + fileSeparator + "to" + fileSeparator + "name", "data_service", rowLimit);
    dataServiceMeta = transientResolver.getDataService(transientId);
    assertEquals(rowLimit, dataServiceMeta.getRowLimit());
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta)

Example 22 with DataServiceMeta

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

the class DataServiceMetaStoreUtilTest method testCheckConflict.

@Test
public void testCheckConflict() throws Exception {
    final ServiceTrans published = mock(ServiceTrans.class);
    when(published.getName()).thenReturn("PUBLISHED_SERVICE");
    metaStoreUtil = new DataServiceMetaStoreUtil(metaStoreUtil) {

        @Override
        protected MetaStoreFactory<ServiceTrans> getServiceTransFactory(IMetaStore metaStore) {
            return new MetaStoreFactory<ServiceTrans>(ServiceTrans.class, metaStore, NAMESPACE) {

                @Override
                public List<ServiceTrans> getElements() throws MetaStoreException {
                    return ImmutableList.of(published);
                }
            };
        }
    };
    DataServiceMeta local = createDataService("OTHER_SERVICE", transMeta);
    local.setStepname("OTHER_STEP");
    metaStoreUtil.getDataServiceFactory(transMeta).saveElement(local);
    // New data service with different properties
    metaStoreUtil.checkConflict(dataService, null);
    // Editing a data service with all new properties
    metaStoreUtil.checkConflict(dataService, local.getName());
    try {
        // New data service with the same name as an local data service
        dataService.setName(local.getName());
        metaStoreUtil.checkConflict(dataService, null);
        fail("Expected DataServiceAlreadyExistsException");
    } catch (DataServiceAlreadyExistsException e) {
        assertThat(e.getDataServiceMeta(), sameInstance(dataService));
    }
    // Editing a data service, no name change
    metaStoreUtil.checkConflict(dataService, local.getName());
    dataService = createDataService(DATA_SERVICE_NAME, transMeta);
    metaStoreUtil.checkConflict(dataService, null);
    try {
        // New data service with conflicting output step
        dataService.setStepname(local.getStepname());
        metaStoreUtil.checkConflict(dataService, null);
        fail("Expected DataServiceAlreadyExistsException");
    } catch (DataServiceAlreadyExistsException e) {
        assertThat(e.getDataServiceMeta(), sameInstance(dataService));
    }
    // Editing data service with same output step
    metaStoreUtil.checkConflict(dataService, local.getName());
    dataService = createDataService(DATA_SERVICE_NAME, transMeta);
    metaStoreUtil.checkConflict(dataService, null);
    dataService.setName(published.getName());
    when(published.getReferences()).thenReturn(ImmutableList.<ServiceTrans.Reference>of());
    metaStoreUtil.checkConflict(dataService, null);
    ServiceTrans.Reference reference = mock(ServiceTrans.Reference.class);
    when(reference.exists(repository)).thenReturn(false, true);
    when(published.getReferences()).thenReturn(ImmutableList.of(reference));
    metaStoreUtil.checkConflict(dataService, null);
    try {
        // New Data service with conflicting name in metastore
        metaStoreUtil.checkConflict(dataService, null);
        fail("Expected DataServiceAlreadyExistsException");
    } catch (DataServiceAlreadyExistsException e) {
        assertThat(e.getDataServiceMeta(), sameInstance(dataService));
    }
    try {
        // Editing Data service with conflicting name in metastore
        metaStoreUtil.checkConflict(dataService, local.getName());
        fail("Expected DataServiceAlreadyExistsException");
    } catch (DataServiceAlreadyExistsException e) {
        assertThat(e.getDataServiceMeta(), sameInstance(dataService));
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) MetaStoreFactory(org.pentaho.metastore.persist.MetaStoreFactory) DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) IMetaStore(org.pentaho.metastore.api.IMetaStore) Test(org.junit.Test) BaseTest(org.pentaho.di.trans.dataservice.BaseTest)

Example 23 with DataServiceMeta

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

the class DataServiceMetaStoreUtilTest method testClearReferences.

@Test
public void testClearReferences() throws Exception {
    MetaStoreFactory<DataServiceMeta> dataServiceFactory = metaStoreUtil.getDataServiceFactory(transMeta);
    MetaStoreFactory<ServiceTrans> serviceTransFactory = metaStoreUtil.getServiceTransFactory(metaStore);
    String otherName = "OTHER";
    DataServiceMeta other = createDataService(otherName, transMeta);
    dataServiceFactory.saveElement(dataService);
    dataServiceFactory.saveElement(other);
    serviceTransFactory.saveElement(ServiceTrans.create(dataService));
    serviceTransFactory.saveElement(ServiceTrans.create(other.getName(), mock(TransMeta.class)));
    assertThat(metaStoreUtil.getDataServiceNames(transMeta), containsInAnyOrder(DATA_SERVICE_NAME, otherName));
    assertThat(metaStoreUtil.getDataServiceNames(metaStore), containsInAnyOrder(DATA_SERVICE_NAME, otherName));
    metaStoreUtil.clearReferences(transMeta);
    // Local unchanged
    assertThat(metaStoreUtil.getDataServiceNames(transMeta), containsInAnyOrder(DATA_SERVICE_NAME, otherName));
    // Published data service should be removed from the metaStore
    assertThat(metaStoreUtil.getDataServiceNames(metaStore), contains(otherName));
}
Also used : DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) Test(org.junit.Test) BaseTest(org.pentaho.di.trans.dataservice.BaseTest)

Example 24 with DataServiceMeta

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

the class DataServiceReferenceSynchronizerTest method mockDataServiceMetas.

private List<DataServiceMeta> mockDataServiceMetas(String... names) {
    List<DataServiceMeta> metas = new ArrayList<>();
    for (String name : names) {
        DataServiceMeta meta = mock(DataServiceMeta.class);
        when(meta.getName()).thenReturn(name);
        when(meta.getServiceTrans()).thenReturn(transMeta);
        metas.add(meta);
    }
    return metas;
}
Also used : DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) ArrayList(java.util.ArrayList) Mockito.anyString(org.mockito.Mockito.anyString)

Example 25 with DataServiceMeta

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

the class CachedServiceTest method setUp.

@Before
public void setUp() throws Exception {
    rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaString("ID"));
    rowMeta.addValueMeta(new ValueMetaInteger("A"));
    rowMeta.addValueMeta(new ValueMetaInteger("B"));
    testData = Lists.newArrayListWithExpectedSize(100);
    for (long i = 0; i < 100; i++) {
        testData.add(new RowMetaAndData(rowMeta, String.valueOf(i), i % 13, i % 17));
    }
    when(serviceTrans.findRunThread(SERVICE_STEP)).thenReturn(serviceStep);
    when(serviceStep.getTrans()).thenReturn(serviceTrans);
    when(sqlTransGenerator.getInjectorStepName()).thenReturn(INJECTOR_STEP);
    transMeta = serviceTrans.getTransMeta();
    when(transMeta.getCacheVersion()).thenReturn(1);
    dataServiceMeta = new DataServiceMeta(transMeta);
    dataServiceMeta.setName(SERVICE_NAME);
    dataServiceMeta.setStepname(SERVICE_STEP);
    when(transMeta.getStepFields(SERVICE_STEP)).thenReturn(rowMeta);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) RowMeta(org.pentaho.di.core.row.RowMeta) DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) Before(org.junit.Before)

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