use of org.pentaho.platform.api.repository2.unified.IAclNodeHelper in project pentaho-platform by pentaho.
the class SolutionRepositoryVfsFileObjectTest method initFileTest.
@Test
public void initFileTest() throws Exception {
String fileRef = "/etc/mondrian/SteelWheels/schema.xml";
String dsRef = "/etc/mondrian/SteelWheels";
SolutionRepositoryVfsFileObject fileObject = new SolutionRepositoryVfsFileObject(fileRef);
SolutionRepositoryVfsFileObject fileObjectSpy = spy(fileObject);
IAclNodeHelper aclNodeHelper = mock(IAclNodeHelper.class);
doReturn(aclNodeHelper).when(fileObjectSpy).getAclHelper();
RepositoryFile file = mock(RepositoryFile.class);
doReturn(true).when(aclNodeHelper).canAccess(file, EnumSet.of(RepositoryFilePermission.READ));
IUnifiedRepository repository = mock(IUnifiedRepository.class);
doReturn(file).when(repository).getFile(fileRef);
doReturn(repository).when(fileObjectSpy).getRepository();
fileObjectSpy.getName();
verify(repository, times(1)).getFile(eq(dsRef));
verify(repository, times(1)).getFile(eq(fileRef));
verify(aclNodeHelper, times(1)).canAccess(any(RepositoryFile.class), eq(EnumSet.of(RepositoryFilePermission.READ)));
fileRef = "/etca/mondriana/SteelWheels/schema.xml";
fileObject = new SolutionRepositoryVfsFileObject(fileRef);
fileObjectSpy = spy(fileObject);
doReturn(aclNodeHelper).when(fileObjectSpy).getAclHelper();
doReturn(false).when(aclNodeHelper).canAccess(file, EnumSet.of(RepositoryFilePermission.READ));
doReturn(repository).when(fileObjectSpy).getRepository();
fileObjectSpy.getName();
verify(repository, times(2)).getFile(eq(fileRef));
verify(aclNodeHelper, times(2)).canAccess(any(RepositoryFile.class), eq(EnumSet.of(RepositoryFilePermission.READ)));
}
use of org.pentaho.platform.api.repository2.unified.IAclNodeHelper in project pentaho-platform by pentaho.
the class SessionCachingMetadataDomainRepositoryIT method testGetDomain.
public void testGetDomain() throws Exception {
// $NON-NLS-1$
final String SESSION_ID = "1234-5678-90";
// $NON-NLS-1$
final String ID = "1";
// $NON-NLS-1$
final String ID2 = "2";
IAclNodeHelper aclNodeHelper = mock(IAclNodeHelper.class);
when(aclNodeHelper.canAccess(any(RepositoryFile.class), any(EnumSet.class))).thenReturn(true);
MockAclAwareMetadataDomainRepository mock = new MockAclAwareMetadataDomainRepository(aclNodeHelper, null);
mock.storeDomain(getTestDomain(ID), false);
SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository(mock);
// $NON-NLS-1$
PentahoSessionHolder.setSession(new StandaloneSession("Standalone Session", SESSION_ID));
// $NON-NLS-1$
assertEquals(0, mock.getInvocationCount("getDomain"));
Domain d = repo.getDomain(ID);
assertEquals(ID, d.getId());
// Make sure the domain we got back has our session embedded in it (tests mock repository)
assertEquals(SESSION_ID, d.getDescription(TEST_LOCALE));
// $NON-NLS-1$
assertEquals(1, mock.getInvocationCount("getDomain"));
// Cache should contain a domain for this session
assertEquals(1, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
repo.getDomain(ID);
// Make sure cache was hit and delegate was not called
// $NON-NLS-1$
assertEquals(1, mock.getInvocationCount("getDomain"));
// Cache should contain a domain for this session
assertEquals(1, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
mock.storeDomain(getTestDomain(ID2), false);
repo.getDomain(ID2);
// Cache should contain tow domains for this session
assertEquals(2, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
// Block access to domain ID2. Cache should be cleared for this domain
when(aclNodeHelper.canAccess(any(RepositoryFile.class), any(EnumSet.class))).thenReturn(false);
repo.getDomain(ID2);
// Make sure cache was hit and delegate was not called
// $NON-NLS-1$
assertEquals(2, mock.getInvocationCount("getDomain"));
// Cache should contain a domain for this session
assertEquals(1, PentahoSystem.getCacheManager(null).getAllKeysFromRegionCache(CACHE_NAME).size());
}
use of org.pentaho.platform.api.repository2.unified.IAclNodeHelper in project pentaho-platform by pentaho.
the class MondrianCatalogHelperIT method testAddCatalog.
@Test
public void testAddCatalog() throws Exception {
final String mondrianFolderPath = ClientRepositoryPaths.getEtcFolderPath() + RepositoryFile.SEPARATOR + "mondrian";
UnifiedRepositoryTestUtils.stubGetFolder(repo, mondrianFolderPath);
// return no children
UnifiedRepositoryTestUtils.stubGetChildren(repo, mondrianFolderPath);
final String steelWheelsFolderPath = mondrianFolderPath + RepositoryFile.SEPARATOR + CATALOG_NAME;
UnifiedRepositoryTestUtils.stubGetFileDoesNotExist(repo, steelWheelsFolderPath);
UnifiedRepositoryTestUtils.stubCreateFolder(repo, steelWheelsFolderPath);
final String metadataPath = steelWheelsFolderPath + RepositoryFile.SEPARATOR + "metadata";
UnifiedRepositoryTestUtils.stubCreateFile(repo, metadataPath);
final String olapFolderPath = ClientRepositoryPaths.getEtcFolderPath() + RepositoryFile.SEPARATOR + "olap-servers";
UnifiedRepositoryTestUtils.stubGetFolder(repo, olapFolderPath);
// return no children
UnifiedRepositoryTestUtils.stubGetChildren(repo, olapFolderPath);
IPentahoSession session = new StandaloneSession("admin");
MondrianCatalog cat = createTestCatalog();
File file = new File(TestResourceLocation.TEST_RESOURCES + "/solution/test/charts/steelwheels.mondrian.xml");
String mondrianSchema = IOUtils.toString(new FileInputStream(file));
session.setAttribute("MONDRIAN_SCHEMA_XML_CONTENT", mondrianSchema);
MondrianCatalogHelper helperSpy = spy(helper);
IAclNodeHelper aclNodeHelper = mock(IAclNodeHelper.class);
doNothing().when(aclNodeHelper).setAclFor(any(RepositoryFile.class), any(RepositoryFileAcl.class));
doReturn(aclNodeHelper).when(helperSpy).getAclHelper();
doReturn(true).when(helperSpy).catalogExists(any(MondrianCatalog.class), eq(session));
helperSpy.addCatalog(cat, true, session);
verify(repo).createFile(eq(UnifiedRepositoryTestUtils.makeIdObject(steelWheelsFolderPath)), argThat(UnifiedRepositoryTestUtils.isLikeFile(UnifiedRepositoryTestUtils.makeFileObject(metadataPath))), argThat(UnifiedRepositoryTestUtils.hasData(UnifiedRepositoryTestUtils.pathPropertyPair("/catalog/definition", "mondrian:/" + cat.getName()), UnifiedRepositoryTestUtils.pathPropertyPair("/catalog/datasourceInfo", cat.getDataSourceInfo()))), anyString());
verify(repo).createFile(eq(UnifiedRepositoryTestUtils.makeIdObject(steelWheelsFolderPath)), argThat(UnifiedRepositoryTestUtils.isLikeFile(UnifiedRepositoryTestUtils.makeFileObject(steelWheelsFolderPath + RepositoryFile.SEPARATOR + "schema.xml"))), any(IRepositoryFileData.class), anyString());
// cache should be cleared for this schema only
verify(olapService, times(1)).getConnection(CATALOG_NAME, session);
verify(mondrianCacheControl, times(1)).flushSchema(this.mondrianSchema);
}
use of org.pentaho.platform.api.repository2.unified.IAclNodeHelper in project pentaho-platform by pentaho.
the class MondrianCatalogHelperIT method addCatalog_WithAcl.
@Test
public void addCatalog_WithAcl() throws Exception {
initMondrianCatalogsCache();
MondrianCatalogHelper helperSpy = spy(helper);
IPentahoSession session = mock(IPentahoSession.class);
doNothing().when(helperSpy).init(session);
doReturn(Collections.<MondrianCatalog>emptyList()).when(helperSpy).getCatalogs(session);
doReturn(null).when(helperSpy).makeSchema(anyString());
MondrianCatalog cat = createTestCatalog();
RepositoryFileAcl acl = mock(RepositoryFileAcl.class);
IAclNodeHelper aclHelper = mock(IAclNodeHelper.class);
doNothing().when(aclHelper).setAclFor(any(RepositoryFile.class), eq(acl));
doReturn(aclHelper).when(helperSpy).getAclHelper();
doReturn(null).when(helperSpy).makeSchema(CATALOG_NAME);
doReturn(true).when(helperSpy).catalogExists(any(MondrianCatalog.class), eq(session));
MondrianCatalogRepositoryHelper repositoryHelper = mock(MondrianCatalogRepositoryHelper.class);
doReturn(repositoryHelper).when(helperSpy).getMondrianCatalogRepositoryHelper();
helperSpy.addCatalog(new ByteArrayInputStream(new byte[0]), cat, true, acl, session);
verify(aclHelper, times(1)).setAclFor(any(RepositoryFile.class), eq(acl));
doNothing().when(aclHelper).setAclFor(any(RepositoryFile.class), any(RepositoryFileAcl.class));
helperSpy.addCatalog(new ByteArrayInputStream(new byte[0]), cat, true, null, session);
verify(aclHelper, times(2)).setAclFor(any(RepositoryFile.class), any(RepositoryFileAcl.class));
}
use of org.pentaho.platform.api.repository2.unified.IAclNodeHelper in project pentaho-platform by pentaho.
the class MondrianCatalogHelperIT method removeCatalog_WithAcl.
@Test
public void removeCatalog_WithAcl() throws Exception {
IPentahoSession session = mock(IPentahoSession.class);
helper = spy(helper);
doReturn(createTestCatalog()).when(helper).getCatalog(eq(CATALOG_NAME), eq(session));
doNothing().when(helper).reInit(eq(session));
MondrianCatalogRepositoryHelper repositoryHelper = mock(MondrianCatalogRepositoryHelper.class);
doReturn(repositoryHelper).when(helper).getMondrianCatalogRepositoryHelper();
IAclNodeHelper aclHelper = mock(IAclNodeHelper.class);
when(aclHelper.canAccess(any(RepositoryFile.class), any(EnumSet.class))).thenReturn(true);
doReturn(aclHelper).when(helper).getAclHelper();
RepositoryFile file = mock(RepositoryFile.class);
when(file.getId()).thenReturn("1");
when(repo.getFile("/etc/mondrian/" + CATALOG_NAME)).thenReturn(file);
helper.removeCatalog(CATALOG_NAME, session);
verify(aclHelper).removeAclFor(any(RepositoryFile.class));
}
Aggregations