use of org.pentaho.metadata.util.XmiParser in project data-access by pentaho.
the class DataSourceWizardServiceTest method testPublishDswError.
@Test
public void testPublishDswError() throws Exception {
String domainId = "domainId";
InputStream metadataFile = mock(InputStream.class);
boolean overwrite = true;
boolean checkConnection = false;
XmiParser mockXmiParser = mock(XmiParser.class);
Domain mockDomain = mock(Domain.class);
InputStream mockInputStream = mock(InputStream.class);
IPlatformImportBundle mockMetadataBundle = mock(IPlatformImportBundle.class);
IPlatformImportBundle mockMondrianBundle = mock(IPlatformImportBundle.class);
IPlatformImporter mockIPlatformImporter = mock(IPlatformImporter.class);
IPentahoSession mockIPentahoSession = mock(IPentahoSession.class);
String mockObject = "not null";
String dswId = "dswId";
// Test 1
doReturn(false).when(dataSourceWizardService).hasManageAccessCheck();
try {
dataSourceWizardService.publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
fail();
} catch (PentahoAccessControlException e) {
// expected
}
// Test 2
doReturn(true).when(dataSourceWizardService).hasManageAccessCheck();
doReturn(false).when(dataSourceWizardService).endsWith(anyString(), anyString());
try {
dataSourceWizardService.publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
fail();
} catch (IllegalArgumentException e) {
// expected
}
// Test 3
doReturn(true).when(dataSourceWizardService).endsWith(anyString(), anyString());
try {
dataSourceWizardService.publishDsw(domainId, null, overwrite, checkConnection, null);
fail();
} catch (IllegalArgumentException e) {
// expected
}
// Test 4
List<String> mockList = new ArrayList<String>();
mockList.add("string1");
doReturn(mockList).when(dataSourceWizardService).getOverwrittenDomains(domainId);
try {
dataSourceWizardService.publishDsw(domainId, metadataFile, false, checkConnection, null);
fail();
} catch (Exception e) {
// expected
}
// Test 5
doReturn(mockXmiParser).when(dataSourceWizardService).createXmiParser();
RuntimeException mockException = mock(RuntimeException.class);
doThrow(mockException).when(mockXmiParser).parseXmi(metadataFile);
try {
dataSourceWizardService.publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
fail();
} catch (Exception e) {
// expected
}
// Test 6
doReturn(mockDomain).when(mockXmiParser).parseXmi(metadataFile);
doReturn(null).when(dataSourceWizardService).getMondrianDatasourceWrapper(mockDomain);
try {
dataSourceWizardService.publishDsw(domainId, metadataFile, overwrite, true, null);
fail();
} catch (Exception e) {
// expected
}
verify(dataSourceWizardService, times(3)).publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
verify(dataSourceWizardService, times(1)).publishDsw(domainId, null, overwrite, checkConnection, null);
verify(dataSourceWizardService, times(1)).publishDsw(domainId, metadataFile, false, checkConnection, null);
verify(dataSourceWizardService, times(1)).publishDsw(domainId, metadataFile, overwrite, true, null);
}
use of org.pentaho.metadata.util.XmiParser in project data-access by pentaho.
the class DataSourceWizardServiceTest method testPublishDsw.
@Test
public void testPublishDsw() throws Exception {
String domainId = DOMAIN_ID;
InputStream metadataFile = mock(InputStream.class);
boolean overwrite = true;
boolean checkConnection = false;
XmiParser mockXmiParser = mock(XmiParser.class);
Domain mockDomain = mock(Domain.class);
InputStream mockInputStream = mock(InputStream.class);
IPlatformImportBundle mockMetadataBundle = mock(IPlatformImportBundle.class);
IPlatformImportBundle mockMondrianBundle = mock(IPlatformImportBundle.class);
IPlatformImporter mockIPlatformImporter = mock(IPlatformImporter.class);
IPentahoSession mockIPentahoSession = mock(IPentahoSession.class);
String mockObject = "not null";
String dswId = "dswId";
final RepositoryFileAclDto aclDto = new RepositoryFileAclDto();
aclDto.setOwner("owner");
aclDto.setOwnerType(RepositoryFileSid.Type.USER.ordinal());
doReturn(true).when(dataSourceWizardService).hasManageAccessCheck();
doReturn(true).when(dataSourceWizardService).endsWith(anyString(), anyString());
doReturn(mockXmiParser).when(dataSourceWizardService).createXmiParser();
doReturn(mockDomain).when(mockXmiParser).parseXmi(metadataFile);
doReturn(mockInputStream).when(dataSourceWizardService).toInputStreamWrapper(mockDomain, mockXmiParser);
doReturn(mockMetadataBundle).when(dataSourceWizardService).createMetadataDswBundle(mockDomain, mockInputStream, overwrite, aclDto);
doReturn(mockMondrianBundle).when(dataSourceWizardService).createMondrianDswBundle(mockDomain, aclDto);
doReturn(mockIPlatformImporter).when(dataSourceWizardService).getIPlatformImporter();
doReturn(mockIPentahoSession).when(dataSourceWizardService).getSession();
String response = dataSourceWizardService.publishDsw(domainId, metadataFile, overwrite, checkConnection, aclDto);
verify(dataSourceWizardService, times(1)).publishDsw(domainId, metadataFile, overwrite, checkConnection, aclDto);
assertEquals(domainId, response);
checkConnection = true;
String testName = "クイズ";
doReturn(testName).when(dataSourceWizardService).getMondrianDatasourceWrapper(mockDomain);
doReturn(mock(IDatabaseConnection.class)).when(dataSourceWizardService.datasourceMgmtSvc).getDatasourceByName(anyString());
dataSourceWizardService.publishDsw(domainId, metadataFile, overwrite, checkConnection, aclDto);
verify(dataSourceWizardService.sanitizer).escape(testName);
verify(dataSourceWizardService, times(1)).publishDsw(domainId, metadataFile, overwrite, checkConnection, aclDto);
}
Aggregations