use of org.pentaho.platform.plugin.services.importer.PlatformImportException in project data-access by pentaho.
the class MetadataResourceTest method testImportMetadataDatasourceError.
@Test
public void testImportMetadataDatasourceError() throws Exception {
Response mockResponse = mock(Response.class);
FileResource mockFileResource = mock(FileResource.class);
String domainId = "domainId";
InputStream metadataFile = mock(InputStream.class);
FormDataContentDisposition metadataFileInfo = mock(FormDataContentDisposition.class);
String overwrite = "overwrite";
List<FormDataBodyPart> localeFiles = mock(List.class);
List<FormDataContentDisposition> localeFilesInfo = mock(List.class);
// Test 1
PentahoAccessControlException mockPentahoAccessControlException = mock(PentahoAccessControlException.class);
doThrow(mockPentahoAccessControlException).when(metadataResource.service).importMetadataDatasource(domainId, metadataFile, metadataFileInfo, false, localeFiles, localeFilesInfo, null);
doReturn(mockResponse).when(metadataResource).buildServerErrorResponse(mockPentahoAccessControlException);
Response response = metadataResource.importMetadataDatasourceLegacy(domainId, metadataFile, metadataFileInfo, overwrite, localeFiles, localeFilesInfo, null);
assertEquals(mockResponse, response);
// Test 2
PlatformImportException mockPlatformImportException = mock(PlatformImportException.class);
doThrow(mockPlatformImportException).when(metadataResource.service).importMetadataDatasource(domainId, metadataFile, metadataFileInfo, true, localeFiles, localeFilesInfo, null);
doReturn(10).when(mockPlatformImportException).getErrorStatus();
doReturn(mockFileResource).when(metadataResource).createFileResource();
doReturn(mockResponse).when(metadataResource).buildServerError003Response(domainId, mockFileResource);
response = metadataResource.importMetadataDatasourceLegacy(domainId, metadataFile, metadataFileInfo, overwrite, localeFiles, localeFilesInfo, null);
assertEquals(mockResponse, response);
// Test 3
RuntimeException mockException = mock(RuntimeException.class);
doThrow(mockPlatformImportException).when(metadataResource.service).importMetadataDatasource(domainId, metadataFile, metadataFileInfo, true, localeFiles, localeFilesInfo, null);
doReturn(1).when(mockPlatformImportException).getErrorStatus();
doReturn(mockResponse).when(metadataResource).buildOkResponse("1");
doReturn(mockException).when(mockPlatformImportException).getCause();
response = metadataResource.importMetadataDatasourceLegacy(domainId, metadataFile, metadataFileInfo, overwrite, localeFiles, localeFilesInfo, null);
assertEquals(mockResponse, response);
// Test
doThrow(mockException).when(metadataResource.service).importMetadataDatasource(domainId, metadataFile, metadataFileInfo, true, localeFiles, localeFilesInfo, null);
doReturn(mockResponse).when(metadataResource).buildServerError001Response();
response = metadataResource.importMetadataDatasourceLegacy(domainId, metadataFile, metadataFileInfo, overwrite, localeFiles, localeFilesInfo, null);
assertEquals(mockResponse, response);
verify(metadataResource, times(4)).importMetadataDatasourceLegacy(domainId, metadataFile, metadataFileInfo, overwrite, localeFiles, localeFilesInfo, null);
}
Aggregations