use of org.pentaho.platform.api.engine.IPentahoSession 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.engine.IPentahoSession in project pentaho-platform by pentaho.
the class MondrianCatalogHelperIT method testAddCatalogWithException.
@Test(expected = MondrianException.class)
public void testAddCatalogWithException() {
initMondrianCatalogsCache();
MondrianCatalogHelper helperSpy = spy(helper);
doThrow(new MondrianException()).when(helperSpy).reInit(any(IPentahoSession.class));
IPentahoSession session = mock(IPentahoSession.class);
doNothing().when(helperSpy).init(session);
MondrianCatalog cat = createTestCatalog();
MondrianCatalogRepositoryHelper repositoryHelper = mock(MondrianCatalogRepositoryHelper.class);
doReturn(repositoryHelper).when(helperSpy).getMondrianCatalogRepositoryHelper();
try {
helperSpy.addCatalog(new ByteArrayInputStream(new byte[0]), cat, true, null, session);
} catch (MondrianException e) {
// verifying the repository rolled back and the cache reinitialized
verify(repositoryHelper, times(1)).deleteHostedCatalog(anyString());
verify(helperSpy, times(2)).reInit(any(IPentahoSession.class));
}
helperSpy.addCatalog(new ByteArrayInputStream(new byte[0]), cat, true, null, session);
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class MondrianCatalogHelperIT method testNoDspApplied_WhenNoDynamicSchemaProcessorParameterInDataSourceInfo.
@Test
public void testNoDspApplied_WhenNoDynamicSchemaProcessorParameterInDataSourceInfo() throws Exception {
final String replaceTemplate = "REPLACE_TEMPLATE";
final String DATA_SOURCE_INFO_WITHOUT_DSP = "DataSource=TestDataSource";
final String SCHEMA_MOCK = "Test Schema Mock " + replaceTemplate;
MondrianCatalogHelper helperSpy = spy(helper);
doReturn(SCHEMA_MOCK).when(helperSpy).docAtUrlToString(anyString(), any(IPentahoSession.class));
IPentahoSession session = new StandaloneSession("admin");
String schema = helperSpy.applyDSP(session, DATA_SOURCE_INFO_WITHOUT_DSP, SCHEMA_MOCK);
assertNotNull(schema);
verify(helperSpy).docAtUrlToString(anyString(), any(IPentahoSession.class));
assertFalse(schema.contains("REPLACE_TOKEN"));
}
use of org.pentaho.platform.api.engine.IPentahoSession 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.engine.IPentahoSession 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