Search in sources :

Example 6 with IAclNodeHelper

use of org.pentaho.platform.api.repository2.unified.IAclNodeHelper in project pentaho-platform by pentaho.

the class MondrianCatalogHelperIT method testListCatalog.

@Test
public void testListCatalog() throws Exception {
    File file1 = new File(TestResourceLocation.TEST_RESOURCES + "/solution/test/charts/steelwheels.mondrian.xml");
    String mondrianSchema1 = IOUtils.toString(new FileInputStream(file1));
    File file2 = new File(TestResourceLocation.TEST_RESOURCES + "/solution/samples/reporting/SampleData.mondrian.xml");
    String mondrianSchema2 = IOUtils.toString(new FileInputStream(file2));
    final String mondrianFolderPath = ClientRepositoryPaths.getEtcFolderPath() + RepositoryFile.SEPARATOR + "mondrian";
    UnifiedRepositoryTestUtils.stubGetFolder(repo, mondrianFolderPath);
    // return two child folders
    UnifiedRepositoryTestUtils.stubGetChildren(repo, mondrianFolderPath, "SampleData/", "SteelWheels/");
    final String olapFolderPath = ClientRepositoryPaths.getEtcFolderPath() + RepositoryFile.SEPARATOR + "olap-servers";
    UnifiedRepositoryTestUtils.stubGetFolder(repo, olapFolderPath);
    // return no children
    UnifiedRepositoryTestUtils.stubGetChildren(repo, olapFolderPath);
    final String sampleDataFolderPath = mondrianFolderPath + RepositoryFile.SEPARATOR + "SampleData";
    final String sampleDataMetadataPath = sampleDataFolderPath + RepositoryFile.SEPARATOR + "metadata";
    final String sampleDataSchemaPath = sampleDataFolderPath + RepositoryFile.SEPARATOR + "schema.xml";
    UnifiedRepositoryTestUtils.stubGetFile(repo, sampleDataMetadataPath);
    UnifiedRepositoryTestUtils.stubGetData(repo, sampleDataMetadataPath, "catalog", UnifiedRepositoryTestUtils.pathPropertyPair("/catalog/definition", "mondrian:/SampleData"), UnifiedRepositoryTestUtils.pathPropertyPair("/catalog/datasourceInfo", "Provider=mondrian;DataSource=SampleData;"));
    UnifiedRepositoryTestUtils.stubGetFile(repo, sampleDataSchemaPath);
    UnifiedRepositoryTestUtils.stubGetData(repo, sampleDataSchemaPath, mondrianSchema2);
    final String steelWheelsFolderPath = mondrianFolderPath + RepositoryFile.SEPARATOR + "SteelWheels";
    final String steelWheelsMetadataPath = steelWheelsFolderPath + RepositoryFile.SEPARATOR + "metadata";
    final String steelWheelsSchemaPath = steelWheelsFolderPath + RepositoryFile.SEPARATOR + "schema.xml";
    final String steelWheelsAnnotationsPath = steelWheelsFolderPath + RepositoryFile.SEPARATOR + "annotations.xml";
    UnifiedRepositoryTestUtils.stubGetFile(repo, steelWheelsMetadataPath);
    UnifiedRepositoryTestUtils.stubGetData(repo, steelWheelsMetadataPath, "catalog", UnifiedRepositoryTestUtils.pathPropertyPair("/catalog/definition", "mondrian:/SteelWheels"), UnifiedRepositoryTestUtils.pathPropertyPair("/catalog/datasourceInfo", "Provider=mondrian;DataSource=SteelWheels;"));
    UnifiedRepositoryTestUtils.stubGetFile(repo, steelWheelsSchemaPath);
    UnifiedRepositoryTestUtils.stubGetData(repo, steelWheelsSchemaPath, mondrianSchema1);
    UnifiedRepositoryTestUtils.stubGetFile(repo, steelWheelsAnnotationsPath);
    UnifiedRepositoryTestUtils.stubGetData(repo, steelWheelsAnnotationsPath, "<annotations></annotations>");
    IPentahoSession session = new StandaloneSession("admin");
    helper = spy(helper);
    IAclNodeHelper aclHelper = mock(IAclNodeHelper.class);
    when(aclHelper.canAccess(any(RepositoryFile.class), any(EnumSet.class))).thenReturn(true);
    doReturn(aclHelper).when(helper).getAclHelper();
    MondrianCatalog[] testCatalogs = new MondrianCatalog[] { spy(createTestCatalog()), spy(createTestCatalog()) };
    doReturn(true).when(testCatalogs[0]).isJndi();
    doReturn(false).when(testCatalogs[1]).isJndi();
    doReturn(Arrays.asList(testCatalogs)).when(helper).getCatalogs(session);
    Answer<String> answer = new Answer<String>() {

        @Override
        public String answer(final InvocationOnMock invocation) throws Throwable {
            try {
                return (String) invocation.callRealMethod();
            } catch (Exception throwable) {
                if (throwable.getCause() instanceof ClassCastException) {
                    fail("should not get ClassCastException here ");
                }
                throw throwable;
            }
        }
    };
    doAnswer(answer).when(helper).docAtUrlToString(any(String.class), any(IPentahoSession.class));
    List<MondrianCatalog> cats = helper.listCatalogs(session, true);
    assertEquals(1, cats.size());
    verify(mondrianCacheControl, never()).flushSchema(mondrianSchema);
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) EnumSet(java.util.EnumSet) Matchers.anyString(org.mockito.Matchers.anyString) FileInputStream(java.io.FileInputStream) MondrianException(mondrian.olap.MondrianException) Answer(org.mockito.stubbing.Answer) IAclNodeHelper(org.pentaho.platform.api.repository2.unified.IAclNodeHelper) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) Test(org.junit.Test)

Example 7 with IAclNodeHelper

use of org.pentaho.platform.api.repository2.unified.IAclNodeHelper in project pentaho-platform by pentaho.

the class MondrianCatalogHelperIT method testRemoveCatalog.

@Test
public void testRemoveCatalog() throws Exception {
    File file1 = new File(TestResourceLocation.TEST_RESOURCES + "/solution/test/charts/steelwheels.mondrian.xml");
    String mondrianSchema1 = IOUtils.toString(new FileInputStream(file1));
    final String mondrianFolderPath = ClientRepositoryPaths.getEtcFolderPath() + RepositoryFile.SEPARATOR + "mondrian";
    UnifiedRepositoryTestUtils.stubGetFolder(repo, mondrianFolderPath);
    UnifiedRepositoryTestUtils.stubGetChildren(repo, mondrianFolderPath, "SteelWheels/");
    final String steelWheelsFolderPath = mondrianFolderPath + RepositoryFile.SEPARATOR + "SteelWheels";
    final String steelWheelsMetadataPath = steelWheelsFolderPath + RepositoryFile.SEPARATOR + "metadata";
    final String steelWheelsSchemaPath = steelWheelsFolderPath + RepositoryFile.SEPARATOR + "schema.xml";
    UnifiedRepositoryTestUtils.stubGetFile(repo, steelWheelsMetadataPath);
    UnifiedRepositoryTestUtils.stubGetData(repo, steelWheelsMetadataPath, "catalog", UnifiedRepositoryTestUtils.pathPropertyPair("/catalog/definition", "mondrian:/SteelWheels"), UnifiedRepositoryTestUtils.pathPropertyPair("/catalog/datasourceInfo", "Provider=mondrian;DataSource=SteelWheels;"));
    UnifiedRepositoryTestUtils.stubGetFile(repo, steelWheelsSchemaPath);
    UnifiedRepositoryTestUtils.stubGetData(repo, steelWheelsSchemaPath, mondrianSchema1);
    UnifiedRepositoryTestUtils.stubGetFolder(repo, steelWheelsFolderPath);
    IPentahoSession session = new StandaloneSession("admin");
    helper = spy(helper);
    IAclNodeHelper aclHelper = mock(IAclNodeHelper.class);
    when(aclHelper.canAccess(any(RepositoryFile.class), any(EnumSet.class))).thenReturn(true);
    doReturn(aclHelper).when(helper).getAclHelper();
    MondrianCatalogRepositoryHelper repositoryHelper = mock(MondrianCatalogRepositoryHelper.class);
    doReturn(repositoryHelper).when(helper).getMondrianCatalogRepositoryHelper();
    helper.removeCatalog("mondrian:/SteelWheels", session);
    verify(repo).deleteFile(eq(UnifiedRepositoryTestUtils.makeIdObject(steelWheelsFolderPath)), eq(true), 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 : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) 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) Matchers.anyString(org.mockito.Matchers.anyString) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 8 with IAclNodeHelper

use of org.pentaho.platform.api.repository2.unified.IAclNodeHelper in project pentaho-platform by pentaho.

the class MondrianCatalogHelperIT method removeCatalog_WhenProhibited.

@Test(expected = MondrianCatalogServiceException.class)
public void removeCatalog_WhenProhibited() 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(false);
    doReturn(aclHelper).when(helper).getAclHelper();
    helper.removeCatalog(CATALOG_NAME, session);
}
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)

Example 9 with IAclNodeHelper

use of org.pentaho.platform.api.repository2.unified.IAclNodeHelper in project pentaho-platform by pentaho.

the class UserRoleMapperIT method init0.

@Before
public void init0() {
    IAclNodeHelper aclHelper = mock(IAclNodeHelper.class);
    when(aclHelper.canAccess(any(RepositoryFile.class), any(EnumSet.class))).thenReturn(true);
    MondrianCatalogHelper catalogService = new MondrianCatalogHelper(aclHelper);
    microPlatform = new MicroPlatform(TestResourceLocation.TEST_RESOURCES + "/solution");
    microPlatform.define(ISolutionEngine.class, SolutionEngine.class);
    microPlatform.define(IUnifiedRepository.class, FileSystemBackedUnifiedRepository.class, Scope.GLOBAL);
    microPlatform.defineInstance(IMondrianCatalogService.class, catalogService);
    microPlatform.define("connection-SQL", SQLConnection.class);
    microPlatform.define("connection-MDX", MDXConnection.class);
    microPlatform.define(IDBDatasourceService.class, JndiDatasourceService.class, Scope.GLOBAL);
    microPlatform.define(IUserRoleListService.class, TestUserRoleListService.class, Scope.GLOBAL);
    microPlatform.define(UserDetailsService.class, TestUserDetailsService.class, Scope.GLOBAL);
    FileSystemBackedUnifiedRepository repo = (FileSystemBackedUnifiedRepository) PentahoSystem.get(IUnifiedRepository.class);
    repo.setRootDir(new File(TestResourceLocation.TEST_RESOURCES + "/solution"));
    try {
        microPlatform.start();
    } catch (PlatformInitializationException ex) {
        Assert.fail();
    }
    catalogService.setDataSourcesConfig("file:" + PentahoSystem.getApplicationContext().getSolutionPath("test/analysis/test-datasources.xml"));
    // JNDI
    System.setProperty("java.naming.factory.initial", "org.osjava.sj.SimpleContextFactory");
    System.setProperty("org.osjava.sj.root", TestResourceLocation.TEST_RESOURCES + "/solution/system/simple-jndi");
    System.setProperty("org.osjava.sj.delimiter", "/");
}
Also used : MondrianCatalogHelper(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogHelper) IAclNodeHelper(org.pentaho.platform.api.repository2.unified.IAclNodeHelper) PlatformInitializationException(org.pentaho.platform.engine.core.system.boot.PlatformInitializationException) EnumSet(java.util.EnumSet) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) FileSystemBackedUnifiedRepository(org.pentaho.platform.repository2.unified.fs.FileSystemBackedUnifiedRepository) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Before(org.junit.Before)

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