use of org.pentaho.metadata.model.LogicalModel 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);
}
use of org.pentaho.metadata.model.LogicalModel 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");
}
use of org.pentaho.metadata.model.LogicalModel 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);
}
use of org.pentaho.metadata.model.LogicalModel 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");
}
use of org.pentaho.metadata.model.LogicalModel in project data-access by pentaho.
the class MultitableDatasourceService method serializeJoins.
public IDatasourceSummary serializeJoins(MultiTableDatasourceDTO dto, IDatabaseConnection connection) throws DatasourceServiceException {
try {
ModelerService modelerService = new ModelerService();
modelerService.initKettle();
DSWDatasourceServiceImpl datasourceService = new DSWDatasourceServiceImpl();
GeoContext geoContext = datasourceService.getGeoContext();
DatabaseMeta databaseMeta = this.getDatabaseMeta(connection);
MultiTableModelerSource multiTable = new MultiTableModelerSource(databaseMeta, dto.getSchemaModel(), dto.getDatasourceName(), dto.getSelectedTables(), geoContext);
Domain domain = multiTable.generateDomain(dto.isDoOlap());
String modelState = serializeModelState(dto);
for (LogicalModel lm : domain.getLogicalModels()) {
lm.setProperty("datasourceModel", modelState);
lm.setProperty("DatasourceType", "MULTI-TABLE-DS");
// BISERVER-6450 - add security settings to the logical model
applySecurity(lm);
}
modelerService.serializeModels(domain, dto.getDatasourceName(), dto.isDoOlap());
QueryDatasourceSummary summary = new QueryDatasourceSummary();
summary.setDomain(domain);
return summary;
} catch (Exception e) {
logger.error("Error serializing joins", e);
throw new DatasourceServiceException(e);
}
}
Aggregations