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