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);
}
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);
}
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");
}
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");
}
Aggregations