Search in sources :

Example 1 with ModelerWorkspace

use of org.pentaho.agilebi.modeler.ModelerWorkspace in project data-access by pentaho.

the class DataSourceWizardServiceTest method testRemoveDswById.

public void testRemoveDswById(String dswId) throws Exception {
    Domain mockDomain = mock(Domain.class);
    IPentahoSession mockIPentahoSession = mock(IPentahoSession.class);
    ModelerWorkspace mockModelerWorkspace = mock(ModelerWorkspace.class);
    LogicalModel mockLogicalModel = mock(LogicalModel.class);
    String mockObject = "not null";
    doNothing().when(dataSourceWizardService).ensureDataAccessPermissionCheck();
    doReturn(dswId).when(dataSourceWizardService).parseMondrianSchemaNameWrapper(dswId);
    doReturn(mockDomain).when(dataSourceWizardService.metadataDomainRepository).getDomain(dswId);
    doReturn(mockModelerWorkspace).when(dataSourceWizardService).createModelerWorkspace();
    doReturn(null).when(mockModelerWorkspace).getLogicalModel(ModelerPerspective.ANALYSIS);
    doReturn(mockLogicalModel).when(mockModelerWorkspace).getLogicalModel(ModelerPerspective.REPORTING);
    doReturn(mockObject).when(mockLogicalModel).getProperty("MondrianCatalogRef");
    doReturn(mockIPentahoSession).when(dataSourceWizardService).getSession();
    doNothing().when(dataSourceWizardService.mondrianCatalogService).removeCatalog("not null", mockIPentahoSession);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            returnedDswId = (String) args[0];
            return null;
        }
    }).when(dataSourceWizardService.metadataDomainRepository).removeDomain(dswId);
    dataSourceWizardService.removeDSW(dswId);
    assertEquals("The method should call removal for original id", dswId, returnedDswId);
    verify(dataSourceWizardService, times(1)).removeDSW(dswId);
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyString(org.mockito.Matchers.anyString) Domain(org.pentaho.metadata.model.Domain) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace)

Example 2 with ModelerWorkspace

use of org.pentaho.agilebi.modeler.ModelerWorkspace in project data-access by pentaho.

the class DataSourceWizardServiceTest method testDoGetDSWFilesAsDownload.

@Test
public void testDoGetDSWFilesAsDownload() throws Exception {
    Map<String, InputStream> mockFileData = mock(Map.class);
    ModelerWorkspace mockModelerWorkspace = mock(ModelerWorkspace.class);
    MondrianCatalogRepositoryHelper mockMondrianCatalogRepositoryHelper = mock(MondrianCatalogRepositoryHelper.class);
    LogicalModel mockLogicalModel = mock(LogicalModel.class);
    String mockObject = "not null";
    String dswId = "dswId";
    doReturn(true).when(dataSourceWizardService).canManageACL();
    doReturn(mockFileData).when(dataSourceWizardService).getMetadataFiles(dswId);
    doReturn(mockModelerWorkspace).when(dataSourceWizardService).createModelerWorkspace();
    doReturn(null).when(mockModelerWorkspace).getLogicalModel(ModelerPerspective.ANALYSIS);
    doReturn(mockLogicalModel).when(mockModelerWorkspace).getLogicalModel(ModelerPerspective.REPORTING);
    doReturn(mockObject).when(mockLogicalModel).getProperty("MondrianCatalogRef");
    doReturn(mockMondrianCatalogRepositoryHelper).when(dataSourceWizardService).createMondrianCatalogRepositoryHelper();
    doNothing().when(dataSourceWizardService).parseMondrianSchemaNameWrapper(dswId, mockFileData);
    Map<String, InputStream> response = dataSourceWizardService.doGetDSWFilesAsDownload("dswId");
    assertEquals(mockFileData, response);
    verify(dataSourceWizardService, times(1)).doGetDSWFilesAsDownload("dswId");
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) InputStream(java.io.InputStream) MondrianCatalogRepositoryHelper(org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper) Matchers.anyString(org.mockito.Matchers.anyString) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) Test(org.junit.Test)

Example 3 with ModelerWorkspace

use of org.pentaho.agilebi.modeler.ModelerWorkspace in project data-access by pentaho.

the class DataSourceWizardServiceTest method testDoGetDSWFilesAsDownloadError.

@Test
public void testDoGetDSWFilesAsDownloadError() throws Exception {
    Map<String, InputStream> mockFileData = mock(Map.class);
    ModelerWorkspace mockModelerWorkspace = mock(ModelerWorkspace.class);
    String dswId = "dswId";
    // Test 1
    doReturn(false).when(dataSourceWizardService).canManageACL();
    try {
        Map<String, InputStream> response = dataSourceWizardService.doGetDSWFilesAsDownload("dswId");
        fail();
    } catch (PentahoAccessControlException pace) {
    // expected
    }
    verify(dataSourceWizardService, times(1)).doGetDSWFilesAsDownload("dswId");
}
Also used : InputStream(java.io.InputStream) Matchers.anyString(org.mockito.Matchers.anyString) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) Test(org.junit.Test)

Example 4 with ModelerWorkspace

use of org.pentaho.agilebi.modeler.ModelerWorkspace in project data-access by pentaho.

the class DataSourceWizardServiceTest method testErrorRemovingMondrianDoesNotStopXMIRemoval.

@Test
public void testErrorRemovingMondrianDoesNotStopXMIRemoval() throws Exception {
    Domain mockDomain = mock(Domain.class);
    IPentahoSession mockIPentahoSession = mock(IPentahoSession.class);
    ModelerWorkspace mockModelerWorkspace = mock(ModelerWorkspace.class);
    LogicalModel mockLogicalModel = mock(LogicalModel.class);
    String mockObject = "not null";
    String dswId = "dswId";
    doNothing().when(dataSourceWizardService).ensureDataAccessPermissionCheck();
    doReturn(dswId).when(dataSourceWizardService).parseMondrianSchemaNameWrapper(dswId);
    doReturn(mockDomain).when(dataSourceWizardService.metadataDomainRepository).getDomain(dswId);
    doReturn(mockModelerWorkspace).when(dataSourceWizardService).createModelerWorkspace();
    doReturn(null).when(mockModelerWorkspace).getLogicalModel(ModelerPerspective.ANALYSIS);
    doReturn(mockLogicalModel).when(mockModelerWorkspace).getLogicalModel(ModelerPerspective.REPORTING);
    doReturn(mockObject).when(mockLogicalModel).getProperty("MondrianCatalogRef");
    doReturn(mockIPentahoSession).when(dataSourceWizardService).getSession();
    doThrow(new MondrianCatalogServiceException("who cares")).when(dataSourceWizardService.mondrianCatalogService).removeCatalog("not null", mockIPentahoSession);
    doNothing().when(dataSourceWizardService.metadataDomainRepository).removeDomain(dswId);
    dataSourceWizardService.removeDSW("dswId");
    verify(dataSourceWizardService, times(1)).removeDSW("dswId");
    verify(dataSourceWizardService.metadataDomainRepository).removeDomain(dswId);
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) MondrianCatalogServiceException(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Matchers.anyString(org.mockito.Matchers.anyString) Domain(org.pentaho.metadata.model.Domain) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) Test(org.junit.Test)

Example 5 with ModelerWorkspace

use of org.pentaho.agilebi.modeler.ModelerWorkspace in project data-access by pentaho.

the class DataSourceWizardServiceTest method testRemoveDSWError.

@Test
public void testRemoveDSWError() throws Exception {
    Domain mockDomain = mock(Domain.class);
    IPentahoSession mockIPentahoSession = mock(IPentahoSession.class);
    ModelerWorkspace mockModelerWorkspace = mock(ModelerWorkspace.class);
    LogicalModel mockLogicalModel = mock(LogicalModel.class);
    String mockObject = "not null";
    String dswId = "dswId";
    // Test 1
    ConnectionServiceException cse = new ConnectionServiceException();
    doThrow(cse).when(dataSourceWizardService).ensureDataAccessPermissionCheck();
    try {
        dataSourceWizardService.removeDSW("dswId");
        fail();
    } catch (PentahoAccessControlException pace) {
    // expected
    }
    // Test 2
    DatasourceServiceException mockDatasourceServiceException = mock(DatasourceServiceException.class);
    doNothing().when(dataSourceWizardService).ensureDataAccessPermissionCheck();
    doReturn(dswId).when(dataSourceWizardService).parseMondrianSchemaNameWrapper(dswId);
    doReturn(mockDomain).when(dataSourceWizardService.metadataDomainRepository).getDomain(dswId);
    doReturn(mockModelerWorkspace).when(dataSourceWizardService).createModelerWorkspace();
    doReturn(null).when(mockModelerWorkspace).getLogicalModel(ModelerPerspective.ANALYSIS);
    doReturn(mockLogicalModel).when(mockModelerWorkspace).getLogicalModel(ModelerPerspective.REPORTING);
    doReturn(mockObject).when(mockLogicalModel).getProperty("MondrianCatalogRef");
    doReturn(mockIPentahoSession).when(dataSourceWizardService).getSession();
    doNothing().when(dataSourceWizardService.mondrianCatalogService).removeCatalog("not null", mockIPentahoSession);
    doThrow(mockDatasourceServiceException).when(dataSourceWizardService.dswService).deleteLogicalModel(null, null);
    dataSourceWizardService.removeDSW("dswId");
    verify(dataSourceWizardService, times(2)).removeDSW("dswId");
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Matchers.anyString(org.mockito.Matchers.anyString) Domain(org.pentaho.metadata.model.Domain) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException) Test(org.junit.Test)

Aggregations

ModelerWorkspace (org.pentaho.agilebi.modeler.ModelerWorkspace)17 Domain (org.pentaho.metadata.model.Domain)10 LogicalModel (org.pentaho.metadata.model.LogicalModel)10 Test (org.junit.Test)8 Matchers.anyString (org.mockito.Matchers.anyString)7 GwtModelerWorkspaceHelper (org.pentaho.agilebi.modeler.gwt.GwtModelerWorkspaceHelper)7 DatasourceServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)6 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)5 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)5 MondrianCatalogServiceException (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException)5 IOException (java.io.IOException)4 File (java.io.File)3 InputStream (java.io.InputStream)3 DomainIdNullException (org.pentaho.metadata.repository.DomainIdNullException)3 DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)3 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)3 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)3 IMondrianCatalogService (org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService)3 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2