Search in sources :

Example 1 with IAclNodeHelper

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)));
}
Also used : IAclNodeHelper(org.pentaho.platform.api.repository2.unified.IAclNodeHelper) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 2 with IAclNodeHelper

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());
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IAclNodeHelper(org.pentaho.platform.api.repository2.unified.IAclNodeHelper) EnumSet(java.util.EnumSet) SessionCachingMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.SessionCachingMetadataDomainRepository) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Domain(org.pentaho.metadata.model.Domain)

Example 3 with IAclNodeHelper

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);
}
Also used : IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IAclNodeHelper(org.pentaho.platform.api.repository2.unified.IAclNodeHelper) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 4 with IAclNodeHelper

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));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IAclNodeHelper(org.pentaho.platform.api.repository2.unified.IAclNodeHelper) MondrianCatalogRepositoryHelper(org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) Test(org.junit.Test)

Example 5 with IAclNodeHelper

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));
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IAclNodeHelper(org.pentaho.platform.api.repository2.unified.IAclNodeHelper) EnumSet(java.util.EnumSet) MondrianCatalogRepositoryHelper(org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Test(org.junit.Test)

Aggregations

IAclNodeHelper (org.pentaho.platform.api.repository2.unified.IAclNodeHelper)9 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)9 Test (org.junit.Test)7 EnumSet (java.util.EnumSet)6 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)6 File (java.io.File)4 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)4 MondrianCatalogRepositoryHelper (org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper)4 FileInputStream (java.io.FileInputStream)3 Matchers.anyString (org.mockito.Matchers.anyString)3 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)2 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 MondrianException (mondrian.olap.MondrianException)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1 Domain (org.pentaho.metadata.model.Domain)1 IRepositoryFileData (org.pentaho.platform.api.repository2.unified.IRepositoryFileData)1 PlatformInitializationException (org.pentaho.platform.engine.core.system.boot.PlatformInitializationException)1