Search in sources :

Example 11 with PlatformImportException

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);
}
Also used : Response(javax.ws.rs.core.Response) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) InputStream(java.io.InputStream) FormDataBodyPart(com.sun.jersey.multipart.FormDataBodyPart) FileResource(org.pentaho.platform.web.http.api.resources.FileResource) FormDataContentDisposition(com.sun.jersey.core.header.FormDataContentDisposition) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) Test(org.junit.Test)

Aggregations

PlatformImportException (org.pentaho.platform.plugin.services.importer.PlatformImportException)11 Response (javax.ws.rs.core.Response)7 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)7 InputStream (java.io.InputStream)6 Test (org.junit.Test)6 FormDataContentDisposition (com.sun.jersey.core.header.FormDataContentDisposition)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 FileResource (org.pentaho.platform.web.http.api.resources.FileResource)3 FormDataBodyPart (com.sun.jersey.multipart.FormDataBodyPart)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 Consumes (javax.ws.rs.Consumes)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 RepositoryException (org.pentaho.platform.api.repository.RepositoryException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 StringInputStream (org.apache.tools.ant.filters.StringInputStream)1