use of org.pentaho.platform.dataaccess.datasource.api.resources.MetadataTempFilesListDto in project data-access by pentaho.
the class DataSourceWizardServiceTest method testPublishDswFromTemp.
@Test
public void testPublishDswFromTemp() throws Exception {
InputStream metadataFile = getClass().getClassLoader().getResourceAsStream(TEST_XMI_FILE_PATH);
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);
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();
doReturn(metadataFile).when(dataSourceWizardService).createInputStreamFromFile(anyString());
MetadataTempFilesListDto fileList = new MetadataTempFilesListDto();
fileList.setXmiFileName(XMI_TEMP_FILE_NAME);
String list = "{\"xmiFileName\":\"" + XMI_TEMP_FILE_NAME + "\"}";
String response = dataSourceWizardService.publishDswFromTemp(DOMAIN_ID, fileList, overwrite, checkConnection, aclDto);
assertEquals(DOMAIN_ID + DataSourceWizardService.METADATA_EXT, response);
}
use of org.pentaho.platform.dataaccess.datasource.api.resources.MetadataTempFilesListDto in project data-access by pentaho.
the class MetadataServiceTest method testIsContainsModel.
private void testIsContainsModel(final boolean isContainsValue) throws Exception {
InputStream metadataFile = getClass().getClassLoader().getResourceAsStream(TEST_XMI_FILE_PATH);
fillServiceMock(DOMAIN_ID, metadataFile);
doReturn(isContainsValue).when(metadataService).isContainsModel(any(Domain.class));
doReturn(metadataFile).when(metadataService).createInputStreamFromFile(any(String.class));
MetadataTempFilesListDto fileList = new MetadataTempFilesListDto();
fileList.setXmiFileName(XMI_TEMP_FILE_NAME);
assertEquals(metadataService.isContainsModel(XMI_TEMP_FILE_NAME), isContainsValue);
}
use of org.pentaho.platform.dataaccess.datasource.api.resources.MetadataTempFilesListDto in project data-access by pentaho.
the class MetadataService method uploadMetadataFilesToTempDir.
public MetadataTempFilesListDto uploadMetadataFilesToTempDir(InputStream metadataFile, List<InputStream> localeFileStreams, List<String> localeFileNames) throws Exception {
String fileName = uploadFile(metadataFile);
MetadataTempFilesListDto dto = new MetadataTempFilesListDto();
dto.setXmiFileName(fileName);
logger.info("metadata file uploaded: " + fileName);
if (localeFileStreams != null && localeFileStreams.size() != 0) {
List<MetadataTempFilesListBundleDto> bundles = new ArrayList<MetadataTempFilesListBundleDto>();
int cntr = 0;
for (InputStream inputStream : localeFileStreams) {
fileName = uploadFile(inputStream);
MetadataTempFilesListBundleDto bundle = new MetadataTempFilesListBundleDto(localeFileNames.get(cntr), fileName);
bundles.add(bundle);
logger.info("locale file uploaded: " + fileName);
cntr++;
}
dto.setBundles(bundles);
}
return dto;
}
use of org.pentaho.platform.dataaccess.datasource.api.resources.MetadataTempFilesListDto in project data-access by pentaho.
the class MetadataServiceTest method testImportMetadataFromTemp.
@Test
public void testImportMetadataFromTemp() throws Exception {
final boolean IS_CONTAINS_MODEL = true;
InputStream metadataFile = mock(InputStream.class);
boolean overwrite = true;
when(metadataFile.read(any())).thenReturn(-1);
fillServiceMock(DOMAIN_ID, metadataFile);
doReturn(IS_CONTAINS_MODEL).when(metadataService).isContainsModel(any(Domain.class));
doReturn(metadataFile).when(metadataService).createInputStreamFromFile(anyString());
MetadataTempFilesListDto fileList = new MetadataTempFilesListDto();
fileList.setXmiFileName(XMI_TEMP_FILE_NAME);
metadataService.importMetadataFromTemp(DOMAIN_ID, fileList, overwrite, null);
verify(metadataService, times(1)).importMetadataDatasource(DOMAIN_ID, metadataFile, overwrite, new ArrayList<InputStream>(), new ArrayList<String>(), null);
}
use of org.pentaho.platform.dataaccess.datasource.api.resources.MetadataTempFilesListDto in project data-access by pentaho.
the class MetadataServiceTest method testUploadMetadataFilesToTempDir.
@Test
public void testUploadMetadataFilesToTempDir() throws Exception {
InputStream metadataFile = mock(InputStream.class);
fillServiceMock(DOMAIN_ID, metadataFile);
doReturn(new StringInputStream("")).when(metadataService).createInputStreamFromFile(any(String.class));
doReturn(XMI_TEMP_FILE_NAME).when(metadataService).uploadFile(any(InputStream.class));
MetadataTempFilesListDto res = metadataService.uploadMetadataFilesToTempDir(metadataFile, null, null);
assertEquals(res.getXmiFileName(), XMI_TEMP_FILE_NAME);
}
Aggregations