Search in sources :

Example 1 with MetaStoreFactory

use of org.pentaho.metastore.persist.MetaStoreFactory 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 2 with MetaStoreFactory

use of org.pentaho.metastore.persist.MetaStoreFactory 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 3 with MetaStoreFactory

use of org.pentaho.metastore.persist.MetaStoreFactory in project pentaho-kettle by pentaho.

the class ConnectionManagerTest method testEncryptedField.

@Test
public void testEncryptedField() throws Exception {
    addOne();
    TestConnectionDetails testConnectionDetails1 = (TestConnectionDetails) connectionManager.getConnectionDetails(TestConnectionProvider.SCHEME, CONNECTION_NAME);
    Assert.assertEquals(PASSWORD, testConnectionDetails1.getPassword());
    Assert.assertEquals(PASSWORD2, testConnectionDetails1.getPassword1());
    MetaStoreFactory<TestConnectionDetails> metaStoreFactory = new MetaStoreFactory<>(TestConnectionDetails.class, memoryMetaStore, NAMESPACE);
    TestConnectionDetails testConnectionDetails = metaStoreFactory.loadElement(CONNECTION_NAME);
    Assert.assertTrue(testConnectionDetails.getPassword().startsWith("Encrypted "));
    Assert.assertTrue(testConnectionDetails.getPassword1().startsWith("Encrypted "));
}
Also used : MetaStoreFactory(org.pentaho.metastore.persist.MetaStoreFactory) TestConnectionDetails(org.pentaho.di.connections.common.bucket.TestConnectionDetails) Test(org.junit.Test)

Aggregations

MetaStoreFactory (org.pentaho.metastore.persist.MetaStoreFactory)3 Test (org.junit.Test)2 IMetaStore (org.pentaho.metastore.api.IMetaStore)2 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1 Before (org.junit.Before)1 TestConnectionDetails (org.pentaho.di.connections.common.bucket.TestConnectionDetails)1 KettleException (org.pentaho.di.core.exception.KettleException)1 ObjectId (org.pentaho.di.repository.ObjectId)1 RepositoryCapabilities (org.pentaho.di.repository.RepositoryCapabilities)1 RepositoryDirectory (org.pentaho.di.repository.RepositoryDirectory)1 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)1 StringObjectId (org.pentaho.di.repository.StringObjectId)1 TransMeta (org.pentaho.di.trans.TransMeta)1 BaseTest (org.pentaho.di.trans.dataservice.BaseTest)1 DataServiceMeta (org.pentaho.di.trans.dataservice.DataServiceMeta)1 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)1