Search in sources :

Example 6 with Domain

use of org.pentaho.metadata.model.Domain in project pentaho-platform by pentaho.

the class PentahoMetadataDomainRepositoryTest method testLoadLocaleStrings.

@Test
public void testLoadLocaleStrings() throws Exception {
    // Add a domain with no external locale information
    domainRepositorySpy.setXmiParser(new XmiParser());
    final Domain steelWheels = loadDomain(STEEL_WHEELS, "./steel-wheels.xmi");
    domainRepositorySpy.storeDomain(steelWheels, true);
    final int initialLocaleSize = steelWheels.getLocaleCodes().length;
    assertEquals(initialLocaleSize, steelWheels.getLocales().size());
    domainRepositorySpy.loadLocaleStrings(STEEL_WHEELS, steelWheels);
    assertEquals(initialLocaleSize, steelWheels.getLocaleCodes().length);
    assertEquals(initialLocaleSize, steelWheels.getLocales().size());
    final Properties newLocale = new Properties();
    newLocale.put("[LogicalModel-BV_HUMAN_RESOURCES].[description]", "New Description in Italian");
    domainRepositorySpy.addLocalizationFile(STEEL_WHEELS, "it_IT", newLocale);
    domainRepositorySpy.loadLocaleStrings(STEEL_WHEELS, steelWheels);
    final int newLocaleSize = initialLocaleSize + 1;
    assertEquals(newLocaleSize, steelWheels.getLocales().size());
    domainRepositorySpy.loadLocaleStrings(STEEL_WHEELS, steelWheels);
    assertEquals(newLocaleSize, steelWheels.getLocaleCodes().length);
    assertEquals(newLocaleSize, steelWheels.getLocales().size());
}
Also used : XmiParser(org.pentaho.metadata.util.XmiParser) Domain(org.pentaho.metadata.model.Domain) Properties(java.util.Properties) Test(org.junit.Test)

Example 7 with Domain

use of org.pentaho.metadata.model.Domain in project pentaho-platform by pentaho.

the class SessionCachingMetadataDomainRepositoryTest method shouldUseDomainIdsCacheIfEnabled.

@Test
public void shouldUseDomainIdsCacheIfEnabled() throws Exception {
    MockSessionAwareMetadataDomainRepository mock = spy(new MockSessionAwareMetadataDomainRepository());
    PentahoSessionHolder.setSession(new StandaloneSession("session", "1"));
    SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository(mock);
    Domain domain = new Domain();
    domain.setId("id");
    mock.setPersistedDomains(domain);
    ICacheManager manager = mock(ICacheManager.class);
    Set<String> ids = new HashSet<>(Arrays.asList("domainId1", "domainId2"));
    when(manager.getFromRegionCache("metadata-domain-repository", "domain-id-cache-for-session:1")).thenReturn(ids);
    repo.cacheManager = manager;
    repo.domainIdsCacheEnabled = true;
    Set<String> domainIds = repo.getDomainIds();
    assertEquals(ids, domainIds);
    verify(mock, times(0)).reloadDomains();
    verify(manager, times(1)).getFromRegionCache("metadata-domain-repository", "domain-id-cache-for-session:1");
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) MockSessionAwareMetadataDomainRepository(org.pentaho.test.platform.plugin.services.metadata.MockSessionAwareMetadataDomainRepository) ICacheManager(org.pentaho.platform.api.engine.ICacheManager) Domain(org.pentaho.metadata.model.Domain) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with Domain

use of org.pentaho.metadata.model.Domain in project pentaho-platform by pentaho.

the class SessionCachingMetadataDomainRepositoryTest method shouldNotUseDomainIdsCacheIfDisabled.

@Test
public void shouldNotUseDomainIdsCacheIfDisabled() throws Exception {
    MockSessionAwareMetadataDomainRepository mock = spy(new MockSessionAwareMetadataDomainRepository());
    PentahoSessionHolder.setSession(new StandaloneSession("session", "1"));
    SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository(mock);
    Domain domain = new Domain();
    domain.setId("id");
    mock.setPersistedDomains(domain);
    ICacheManager manager = mock(ICacheManager.class);
    repo.cacheManager = manager;
    repo.domainIdsCacheEnabled = false;
    Set<String> domainIds = repo.getDomainIds();
    assertEquals(1, domainIds.size());
    assertTrue(domainIds.contains("id"));
    verify(mock, times(1)).getDomainIds();
    verify(mock, times(1)).reloadDomains();
    verify(manager, times(0)).getFromRegionCache("metadata-domain-repository", "domain-id-cache-for-session:1");
    verify(manager, times(0)).addCacheRegion("domain-id-cache-for-session:1");
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) MockSessionAwareMetadataDomainRepository(org.pentaho.test.platform.plugin.services.metadata.MockSessionAwareMetadataDomainRepository) ICacheManager(org.pentaho.platform.api.engine.ICacheManager) Domain(org.pentaho.metadata.model.Domain) Test(org.junit.Test)

Example 9 with Domain

use of org.pentaho.metadata.model.Domain in project pentaho-platform by pentaho.

the class PentahoMetadataDomainRepositoryConcurrencyTest method mockXmiParser.

private XmiParser mockXmiParser() throws Exception {
    XmiParser parser = mock(XmiParser.class);
    when(parser.generateXmi(any(Domain.class))).thenReturn("");
    when(parser.parseXmi(any(InputStream.class))).thenAnswer(new Answer<Domain>() {

        @Override
        public Domain answer(InvocationOnMock invocation) throws Throwable {
            return new Domain();
        }
    });
    return parser;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) XmiParser(org.pentaho.metadata.util.XmiParser) Domain(org.pentaho.metadata.model.Domain)

Example 10 with Domain

use of org.pentaho.metadata.model.Domain in project pentaho-platform by pentaho.

the class PentahoMetadataDomainRepositoryTest method testStoreDomain.

@Test
public void testStoreDomain() throws Exception {
    try {
        domainRepositorySpy.storeDomain(null, true);
        fail("Invalid domain should throw exception");
    } catch (DomainIdNullException success) {
    // ignored
    }
    try {
        domainRepositorySpy.storeDomain(new MockDomain(null), true);
        fail("Null domain id should throw exception");
    } catch (DomainIdNullException success) {
    // ignored
    }
    try {
        domainRepositorySpy.storeDomain(new MockDomain(""), true);
        fail("Empty domain id should throw exception");
    } catch (DomainIdNullException success) {
    // ignored
    }
    try {
        domainRepositorySpy.storeDomain(null, null, true);
        fail("Null InputStream should throw an exception");
    } catch (IllegalArgumentException success) {
    // ignored
    }
    try {
        domainRepositorySpy.storeDomain(null, "", true);
        fail("Null InputStream should throw an exception");
    } catch (IllegalArgumentException success) {
    // ignored
    }
    try {
        domainRepositorySpy.storeDomain(null, "valid", true);
        fail("Null InputStream should throw an exception");
    } catch (IllegalArgumentException success) {
    // ignored
    }
    try {
        domainRepositorySpy.storeDomain(EMPTY_INPUT_STREAM, null, true);
        fail("Invalid domain id should throw exception");
    } catch (DomainIdNullException success) {
    // ignored
    }
    try {
        domainRepositorySpy.storeDomain(EMPTY_INPUT_STREAM, "", true);
        fail("Invalid domain id should throw exception");
    } catch (DomainIdNullException success) {
    // ignored
    }
    // Have the XmiParser fail
    try {
        domainRepositorySpy.storeDomain(new MockDomain("exception"), true);
        fail("An unexpected exception should throw a DomainStorageException");
    } catch (DomainStorageException success) {
    // ignored
    }
    try {
        domainRepositorySpy.storeDomain(new ByteArrayInputStream(null), "valid", true);
        fail("Error with byte array input stream should throw exception");
    } catch (Exception success) {
    // ignored
    }
    domainRepositorySpy.removeDomain("steel-wheels_test");
    domainRepositorySpy.removeDomain(STEEL_WHEELS);
    domainRepositorySpy.removeDomain(SAMPLE_DOMAIN_ID);
    final MockDomain sample = new MockDomain(SAMPLE_DOMAIN_ID);
    domainRepositorySpy.storeDomain(sample, false);
    doReturn(true).when(aclNodeHelper).canAccess(any(RepositoryFile.class), eq(EnumSet.of(RepositoryFilePermission.READ)));
    final Domain domain = domainRepositorySpy.getDomain(SAMPLE_DOMAIN_ID);
    assertNotNull(domain);
    final List<LogicalModel> logicalModels = domain.getLogicalModels();
    assertNotNull(logicalModels);
    assertEquals(0, logicalModels.size());
    try {
        domainRepositorySpy.storeDomain(sample, false);
        fail("A duplicate domain with overwrite=false should fail");
    } catch (DomainAlreadyExistsException success) {
    // ignored
    }
    sample.addLogicalModel("test");
    domainRepositorySpy.storeDomain(sample, true);
    assertEquals(1, domainRepositorySpy.getDomain(SAMPLE_DOMAIN_ID).getLogicalModels().size());
    MockDomain xmiExtensionSample = new MockDomain(SAMPLE_DOMAIN_ID + ".xmi");
    try {
        domainRepositorySpy.storeDomain(xmiExtensionSample, false);
        fail("A duplicate domain with overwrite=false should fail");
    } catch (DomainAlreadyExistsException success) {
    // ignored
    }
    xmiExtensionSample.addLogicalModel("test1");
    xmiExtensionSample.addLogicalModel("test2");
    domainRepositorySpy.storeDomain(xmiExtensionSample, true);
    assertEquals(2, domainRepositorySpy.getDomain(SAMPLE_DOMAIN_ID).getLogicalModels().size());
    final RepositoryFile folder = domainRepositorySpy.getMetadataDir();
    assertNotNull(folder);
    assertTrue(folder.isFolder());
    assertEquals(1, repository.getChildren(folder.getId()).size());
    final Domain steelWheelsDomain = loadDomain(STEEL_WHEELS, "./steel-wheels.xmi");
    domainRepositorySpy.storeDomain(steelWheelsDomain, true);
    assertEquals(2, repository.getChildren(folder.getId()).size());
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) ByteArrayInputStream(java.io.ByteArrayInputStream) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) Domain(org.pentaho.metadata.model.Domain) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Domain (org.pentaho.metadata.model.Domain)76 LogicalModel (org.pentaho.metadata.model.LogicalModel)29 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)17 IOException (java.io.IOException)13 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)13 DatasourceServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)13 Matchers.anyString (org.mockito.Matchers.anyString)12 ModelerWorkspace (org.pentaho.agilebi.modeler.ModelerWorkspace)11 DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)11 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)11 InputStream (java.io.InputStream)10 DomainAlreadyExistsException (org.pentaho.metadata.repository.DomainAlreadyExistsException)10 XmiParser (org.pentaho.metadata.util.XmiParser)10 SqlPhysicalModel (org.pentaho.metadata.model.SqlPhysicalModel)9 DomainIdNullException (org.pentaho.metadata.repository.DomainIdNullException)9 LogicalColumn (org.pentaho.metadata.model.LogicalColumn)8 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)8 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)7 BusinessData (org.pentaho.platform.dataaccess.datasource.beans.BusinessData)7