Search in sources :

Example 36 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceFactoryTest method testLocalMetaStore.

@Test
public void testLocalMetaStore() throws Exception {
    DataServiceFactory.localPentahoMetaStore = new MemoryMetaStore();
    assertThat(factory.getRepository(), sameInstance(repository));
    assertThat(factory.getMetaStore(), sameInstance((IMetaStore) metaStore));
    when(supplier.get()).thenReturn(null);
    assertThat(factory.getRepository(), nullValue());
    assertThat(factory.getMetaStore(), sameInstance(DataServiceFactory.localPentahoMetaStore));
}
Also used : MemoryMetaStore(org.pentaho.metastore.stores.memory.MemoryMetaStore) IMetaStore(org.pentaho.metastore.api.IMetaStore) Test(org.junit.Test)

Example 37 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore 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 38 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceReferenceSynchronizerTest method before.

@Before
public void before() {
    ObjectId transId = new StringObjectId("transId");
    when(transMeta.getMetaStore()).thenReturn(externalMetastore);
    when(transMeta.getEmbeddedMetaStore()).thenReturn(embeddedMetastore);
    when(transMeta.getObjectId()).thenReturn(transId);
    when(transMeta.getRepository()).thenReturn(repository);
    when(repository.getRepositoryMeta()).thenReturn(repositoryMeta);
    when(repositoryMeta.getRepositoryCapabilities()).thenReturn(mock(RepositoryCapabilities.class));
    RepositoryDirectoryInterface root = mock(RepositoryDirectoryInterface.class);
    RepositoryDirectoryInterface dir = new RepositoryDirectory(root, "location");
    when(root.findDirectory(eq("/"))).thenReturn(dir);
    try {
        when(repository.getTransformationID(eq("location"), eq(dir))).thenReturn(transId);
        when(repository.loadRepositoryDirectoryTree()).thenReturn(root);
    } catch (KettleException ke) {
    // Noop
    }
    when(context.getPushDownFactories()).thenReturn(Collections.emptyList());
    synchronizer = new DataServiceReferenceSynchronizer(context) {

        protected <T> MetaStoreFactory<T> getMetastoreFactory(IMetaStore metaStore, Class<T> clazz) {
            return externalMetaStoreFactory;
        }

        protected MetaStoreFactory<DataServiceMeta> getEmbeddedMetaStoreFactory(TransMeta meta) {
            return embeddedMetaStoreFactory;
        }
    };
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) MetaStoreFactory(org.pentaho.metastore.persist.MetaStoreFactory) TransMeta(org.pentaho.di.trans.TransMeta) StringObjectId(org.pentaho.di.repository.StringObjectId) IMetaStore(org.pentaho.metastore.api.IMetaStore) RepositoryCapabilities(org.pentaho.di.repository.RepositoryCapabilities) Before(org.junit.Before)

Example 39 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.

the class AbstractMetaTest method testGetSetImportMetaStore.

@Test(expected = KettlePluginException.class)
public void testGetSetImportMetaStore() throws Exception {
    assertNull(meta.getMetaStore());
    meta.importFromMetaStore();
    IMetaStore metastore = mock(IMetaStore.class);
    meta.setMetaStore(metastore);
    assertEquals(metastore, meta.getMetaStore());
    meta.importFromMetaStore();
    IMetaStoreElementType elementType = mock(IMetaStoreElementType.class);
    when(metastore.getElementTypeByName(PentahoDefaults.NAMESPACE, PentahoDefaults.DATABASE_CONNECTION_ELEMENT_TYPE_NAME)).thenReturn(elementType);
    when(metastore.getElements(PentahoDefaults.NAMESPACE, elementType)).thenReturn(new ArrayList<IMetaStoreElement>());
    meta.importFromMetaStore();
    IMetaStoreElement element = mock(IMetaStoreElement.class);
    when(metastore.getElements(PentahoDefaults.NAMESPACE, elementType)).thenReturn(Arrays.asList(element));
    meta.importFromMetaStore();
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) IMetaStore(org.pentaho.metastore.api.IMetaStore) Test(org.junit.Test)

Example 40 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.

the class TransMetaTest method testTransWithOneStepIsConsideredUsed.

@Test
public void testTransWithOneStepIsConsideredUsed() throws Exception {
    TransMeta transMeta = new TransMeta(getClass().getResource("one-step-trans.ktr").getPath());
    assertEquals(1, transMeta.getUsedSteps().size());
    Repository rep = mock(Repository.class);
    ProgressMonitorListener monitor = mock(ProgressMonitorListener.class);
    List<CheckResultInterface> remarks = new ArrayList<>();
    IMetaStore metaStore = mock(IMetaStore.class);
    transMeta.checkSteps(remarks, false, monitor, new Variables(), rep, metaStore);
    assertEquals(4, remarks.size());
    for (CheckResultInterface remark : remarks) {
        assertEquals(CheckResultInterface.TYPE_RESULT_OK, remark.getType());
    }
}
Also used : Variables(org.pentaho.di.core.variables.Variables) Repository(org.pentaho.di.repository.Repository) ArrayList(java.util.ArrayList) CheckResultInterface(org.pentaho.di.core.CheckResultInterface) ProgressMonitorListener(org.pentaho.di.core.ProgressMonitorListener) IMetaStore(org.pentaho.metastore.api.IMetaStore) Test(org.junit.Test)

Aggregations

IMetaStore (org.pentaho.metastore.api.IMetaStore)75 Test (org.junit.Test)55 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)20 SQL (org.pentaho.di.core.sql.SQL)17 Repository (org.pentaho.di.repository.Repository)17 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)11 TransMeta (org.pentaho.di.trans.TransMeta)11 Matchers.anyString (org.mockito.Matchers.anyString)10 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)10 StepMeta (org.pentaho.di.trans.step.StepMeta)10 KettleException (org.pentaho.di.core.exception.KettleException)9 IMetaStoreElementType (org.pentaho.metastore.api.IMetaStoreElementType)9 Node (org.w3c.dom.Node)8 ArrayList (java.util.ArrayList)7 Variables (org.pentaho.di.core.variables.Variables)7 PushDownOptimizationMeta (org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta)7 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)7 IMetaStoreElement (org.pentaho.metastore.api.IMetaStoreElement)6 CheckResultInterface (org.pentaho.di.core.CheckResultInterface)5 StringObjectId (org.pentaho.di.repository.StringObjectId)5