use of org.pentaho.platform.plugin.services.importer.IPlatformImporter 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.platform.plugin.services.importer.IPlatformImporter 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);
}
use of org.pentaho.platform.plugin.services.importer.IPlatformImporter in project data-access by pentaho.
the class MetadataServiceTest method testImportMetadataDatasource.
@Test
public void testImportMetadataDatasource() throws Exception {
String domainId = DOMAIN_ID;
InputStream metadataFile = mock(InputStream.class);
FormDataContentDisposition metadataFileInfo = mock(FormDataContentDisposition.class);
boolean overwrite = true;
FormDataBodyPart mockFormDataBodyPart = mock(FormDataBodyPart.class);
List<FormDataBodyPart> localeFiles = new ArrayList<FormDataBodyPart>();
localeFiles.add(mockFormDataBodyPart);
List<FormDataContentDisposition> localeFilesInfo = new ArrayList<FormDataContentDisposition>();
FormDataContentDisposition mockFormDataContentDisposition = mock(FormDataContentDisposition.class);
localeFilesInfo.add(mockFormDataContentDisposition);
FileResource mockFileResource = mock(FileResource.class);
Response mockResponse = mock(Response.class);
IPentahoSession mockIPentahoSession = mock(IPentahoSession.class);
IPlatformImporter mockIPlatformImporter = mock(IPlatformImporter.class);
IPlatformImportBundle mockIPlatformImportBundle = mock(IPlatformImportBundle.class);
RepositoryFileImportBundle.Builder mockRepositoryFileImportBundleBuilder = mock(RepositoryFileImportBundle.Builder.class);
RepositoryFileImportBundle mockRepositoryFileImportBundle = mock(RepositoryFileImportBundle.class);
ByteArrayInputStream mockByteArrayInputStream = mock(ByteArrayInputStream.class);
doNothing().when(metadataService).accessValidation();
doReturn(metadataFile).when(metadataService).validateFileSize(any(InputStream.class), anyString());
doReturn(mockFileResource).when(metadataService).createNewFileResource();
doReturn(mockResponse).when(mockFileResource).doGetReservedChars();
doReturn(null).when(mockResponse).getEntity();
doReturn("\t\n/").when(metadataService).objectToString(null);
doReturn(mockRepositoryFileImportBundleBuilder).when(metadataService).createNewRepositoryFileImportBundleBuilder(metadataFile, false, domainId, null);
doReturn("fileName").when(mockFormDataContentDisposition).getFileName();
doReturn(mockByteArrayInputStream).when(metadataService).createNewByteArrayInputStream(any(byte[].class));
// doReturn( mockRepositoryFileImportBundle ).when( metadataService ).createNewRepositoryFileImportBundle(
// mockByteArrayInputStream, "fileName", domainId );
doReturn(mockRepositoryFileImportBundle).when(mockRepositoryFileImportBundleBuilder).build();
doReturn(mockIPlatformImporter).when(metadataService).getImporter();
doNothing().when(mockIPlatformImporter).importFile(mockIPlatformImportBundle);
doReturn(mockIPentahoSession).when(metadataService).getSession();
doNothing().when(metadataService).publish(mockIPentahoSession);
metadataService.importMetadataDatasource(domainId, metadataFile, metadataFileInfo, overwrite, localeFiles, localeFilesInfo, null);
verify(metadataService, times(1)).importMetadataDatasource(domainId, metadataFile, metadataFileInfo, overwrite, localeFiles, localeFilesInfo, null);
}
use of org.pentaho.platform.plugin.services.importer.IPlatformImporter in project data-access by pentaho.
the class MetadataServiceTest method testImportMetadataDatasourceWithACL.
@Test
public void testImportMetadataDatasourceWithACL() throws Exception {
String domainId = DOMAIN_ID;
InputStream metadataFile = mock(InputStream.class);
FormDataContentDisposition metadataFileInfo = mock(FormDataContentDisposition.class);
boolean overwrite = true;
FormDataBodyPart mockFormDataBodyPart = mock(FormDataBodyPart.class);
List<FormDataBodyPart> localeFiles = new ArrayList<FormDataBodyPart>();
localeFiles.add(mockFormDataBodyPart);
List<FormDataContentDisposition> localeFilesInfo = new ArrayList<FormDataContentDisposition>();
FormDataContentDisposition mockFormDataContentDisposition = mock(FormDataContentDisposition.class);
localeFilesInfo.add(mockFormDataContentDisposition);
FileResource mockFileResource = mock(FileResource.class);
Response mockResponse = mock(Response.class);
IPentahoSession mockIPentahoSession = mock(IPentahoSession.class);
IPlatformImporter mockIPlatformImporter = mock(IPlatformImporter.class);
IPlatformImportBundle mockIPlatformImportBundle = mock(IPlatformImportBundle.class);
RepositoryFileImportBundle.Builder mockRepositoryFileImportBundleBuilder = mock(RepositoryFileImportBundle.Builder.class);
RepositoryFileImportBundle mockRepositoryFileImportBundle = mock(RepositoryFileImportBundle.class);
ByteArrayInputStream mockByteArrayInputStream = mock(ByteArrayInputStream.class);
doNothing().when(metadataService).accessValidation();
doReturn(metadataFile).when(metadataService).validateFileSize(any(InputStream.class), anyString());
doReturn(mockFileResource).when(metadataService).createNewFileResource();
doReturn(mockResponse).when(mockFileResource).doGetReservedChars();
doReturn(null).when(mockResponse).getEntity();
doReturn("\t\n/").when(metadataService).objectToString(null);
doReturn(mockRepositoryFileImportBundleBuilder).when(metadataService).createNewRepositoryFileImportBundleBuilder(metadataFile, false, domainId, null);
doReturn("fileName").when(mockFormDataContentDisposition).getFileName();
doReturn(mockByteArrayInputStream).when(metadataService).createNewByteArrayInputStream(any(byte[].class));
// doReturn( mockRepositoryFileImportBundle ).when( metadataService ).createNewRepositoryFileImportBundle(
// mockByteArrayInputStream, "fileName", domainId );
doReturn(mockRepositoryFileImportBundle).when(mockRepositoryFileImportBundleBuilder).build();
doReturn(mockIPlatformImporter).when(metadataService).getImporter();
doNothing().when(mockIPlatformImporter).importFile(mockIPlatformImportBundle);
doReturn(mockIPentahoSession).when(metadataService).getSession();
doNothing().when(metadataService).publish(mockIPentahoSession);
final RepositoryFileAclDto acl = new RepositoryFileAclDto();
acl.setOwner("owner");
acl.setOwnerType(RepositoryFileSid.Type.USER.ordinal());
metadataService.importMetadataDatasource(domainId, metadataFile, metadataFileInfo, overwrite, localeFiles, localeFilesInfo, acl);
verify(metadataService, times(1)).importMetadataDatasource(domainId, metadataFile, metadataFileInfo, overwrite, localeFiles, localeFilesInfo, acl);
verify(metadataService.getImporter()).importFile(argThat(new ArgumentMatcher<IPlatformImportBundle>() {
@Override
public boolean matches(Object argument) {
IPlatformImportBundle bundle = (IPlatformImportBundle) argument;
return new RepositoryFileAclAdapter().unmarshal(acl).equals(bundle.getAcl());
}
}));
}
use of org.pentaho.platform.plugin.services.importer.IPlatformImporter in project data-access by pentaho.
the class MetadataServiceTest method testImportMetadataDatasourceLocaleFileStreams.
@Test
public void testImportMetadataDatasourceLocaleFileStreams() throws Exception {
String domainId = DOMAIN_ID;
InputStream metadataFile = mock(InputStream.class);
boolean overwrite = true;
InputStream mockLocalFileStream = mock(InputStream.class);
List<InputStream> localeFiles = new ArrayList<>();
localeFiles.add(mockLocalFileStream);
List<String> localeFilesInfo = new ArrayList<>();
localeFilesInfo.add("fileName");
FileResource mockFileResource = mock(FileResource.class);
Response mockResponse = mock(Response.class);
IPentahoSession mockIPentahoSession = mock(IPentahoSession.class);
IPlatformImporter mockIPlatformImporter = mock(IPlatformImporter.class);
IPlatformImportBundle mockIPlatformImportBundle = mock(IPlatformImportBundle.class);
RepositoryFileImportBundle.Builder mockRepositoryFileImportBundleBuilder = mock(RepositoryFileImportBundle.Builder.class);
RepositoryFileImportBundle mockRepositoryFileImportBundle = mock(RepositoryFileImportBundle.class);
ByteArrayInputStream mockByteArrayInputStream = mock(ByteArrayInputStream.class);
doNothing().when(metadataService).accessValidation();
doReturn(metadataFile).when(metadataService).validateFileSize(any(InputStream.class), anyString());
doReturn(mockFileResource).when(metadataService).createNewFileResource();
doReturn(mockResponse).when(mockFileResource).doGetReservedChars();
doReturn(null).when(mockResponse).getEntity();
doReturn("\t\n/").when(metadataService).objectToString(null);
doReturn(mockRepositoryFileImportBundleBuilder).when(metadataService).createNewRepositoryFileImportBundleBuilder(metadataFile, false, domainId, null);
doReturn(mockByteArrayInputStream).when(metadataService).createNewByteArrayInputStream(any(byte[].class));
// doReturn( mockRepositoryFileImportBundle ).when( metadataService ).createNewRepositoryFileImportBundle(
// mockByteArrayInputStream, "fileName", domainId );
doReturn(mockRepositoryFileImportBundle).when(mockRepositoryFileImportBundleBuilder).build();
doReturn(mockIPlatformImporter).when(metadataService).getImporter();
doNothing().when(mockIPlatformImporter).importFile(mockIPlatformImportBundle);
doReturn(mockIPentahoSession).when(metadataService).getSession();
doNothing().when(metadataService).publish(mockIPentahoSession);
final RepositoryFileAclDto acl = new RepositoryFileAclDto();
acl.setOwner("owner");
acl.setOwnerType(RepositoryFileSid.Type.USER.ordinal());
metadataService.importMetadataDatasource(domainId, metadataFile, overwrite, localeFiles, localeFilesInfo, acl);
verify(metadataService, times(1)).importMetadataDatasource(domainId, metadataFile, overwrite, localeFiles, localeFilesInfo, acl);
verify(metadataService.getImporter()).importFile(argThat(new ArgumentMatcher<IPlatformImportBundle>() {
@Override
public boolean matches(Object argument) {
IPlatformImportBundle bundle = (IPlatformImportBundle) argument;
return new RepositoryFileAclAdapter().unmarshal(acl).equals(bundle.getAcl());
}
}));
}
Aggregations