Search in sources :

Example 1 with MockSessionAwareMetadataDomainRepository

use of org.pentaho.test.platform.plugin.services.metadata.MockSessionAwareMetadataDomainRepository in project pentaho-platform by pentaho.

the class SessionCachingMetadataDomainRepositoryTest method testStoreAnnotationsXml.

@Test
public void testStoreAnnotationsXml() throws Exception {
    MockSessionAwareMetadataDomainRepository mock = spy(new MockSessionAwareMetadataDomainRepository());
    SessionCachingMetadataDomainRepository repo = spy(new SessionCachingMetadataDomainRepository(mock));
    PentahoMetadataDomainRepository delegate = mock(PentahoMetadataDomainRepository.class);
    String domainId = "myDomain";
    String annotationsXml = "<annotations/>";
    repo.storeAnnotationsXml(domainId, annotationsXml);
    verify(delegate, times(0)).storeAnnotationsXml(domainId, annotationsXml);
    // use a valid delegate
    repo = spy(new SessionCachingMetadataDomainRepository(delegate));
    repo.storeAnnotationsXml(domainId, annotationsXml);
    verify(delegate, times(1)).storeAnnotationsXml(domainId, annotationsXml);
}
Also used : MockSessionAwareMetadataDomainRepository(org.pentaho.test.platform.plugin.services.metadata.MockSessionAwareMetadataDomainRepository) Test(org.junit.Test)

Example 2 with MockSessionAwareMetadataDomainRepository

use of org.pentaho.test.platform.plugin.services.metadata.MockSessionAwareMetadataDomainRepository in project pentaho-platform by pentaho.

the class SessionCachingMetadataDomainRepositoryTest method testLoadAnnotationsXml.

@Test
public void testLoadAnnotationsXml() throws Exception {
    MockSessionAwareMetadataDomainRepository mock = spy(new MockSessionAwareMetadataDomainRepository());
    SessionCachingMetadataDomainRepository repo = spy(new SessionCachingMetadataDomainRepository(mock));
    PentahoMetadataDomainRepository delegate = mock(PentahoMetadataDomainRepository.class);
    String domainId = "myDomain";
    repo.loadAnnotationsXml(domainId);
    verify(delegate, times(0)).loadAnnotationsXml(domainId);
    // use a valid delegate
    repo = spy(new SessionCachingMetadataDomainRepository(delegate));
    repo.loadAnnotationsXml(domainId);
    verify(delegate, times(1)).loadAnnotationsXml(domainId);
}
Also used : MockSessionAwareMetadataDomainRepository(org.pentaho.test.platform.plugin.services.metadata.MockSessionAwareMetadataDomainRepository) Test(org.junit.Test)

Example 3 with MockSessionAwareMetadataDomainRepository

use of org.pentaho.test.platform.plugin.services.metadata.MockSessionAwareMetadataDomainRepository 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 4 with MockSessionAwareMetadataDomainRepository

use of org.pentaho.test.platform.plugin.services.metadata.MockSessionAwareMetadataDomainRepository 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)

Aggregations

Test (org.junit.Test)4 MockSessionAwareMetadataDomainRepository (org.pentaho.test.platform.plugin.services.metadata.MockSessionAwareMetadataDomainRepository)4 Domain (org.pentaho.metadata.model.Domain)2 ICacheManager (org.pentaho.platform.api.engine.ICacheManager)2 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)2 HashSet (java.util.HashSet)1