Search in sources :

Example 86 with IPentahoSession

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);
}
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 87 with IPentahoSession

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

Example 88 with IPentahoSession

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"));
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 89 with IPentahoSession

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));
}
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 90 with IPentahoSession

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));
}
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

IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)231 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)76 Test (org.junit.Test)70 Matchers.anyString (org.mockito.Matchers.anyString)40 ArrayList (java.util.ArrayList)32 ITenant (org.pentaho.platform.api.mt.ITenant)22 IOException (java.io.IOException)20 StandaloneObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory)18 File (java.io.File)17 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)16 Before (org.junit.Before)14 OutputStream (java.io.OutputStream)13 HashMap (java.util.HashMap)13 InputStream (java.io.InputStream)12 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)12 ModelInfo (org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo)12 Domain (org.pentaho.metadata.model.Domain)11 ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)11 List (java.util.List)10 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)10