Search in sources :

Example 11 with FormDataBodyPart

use of com.sun.jersey.multipart.FormDataBodyPart in project data-access by pentaho.

the class MetadataResourceTest method testImportMetadataDatasource.

@Test
public void testImportMetadataDatasource() throws Exception {
    Response mockResponse = Response.ok().status(new Integer(3)).type(MediaType.TEXT_PLAIN).build();
    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);
    doNothing().when(metadataResource.service).importMetadataDatasource(domainId, metadataFile, metadataFileInfo, true, localeFiles, localeFilesInfo, null);
    doReturn(mockResponse).when(metadataResource).buildOkResponse("3");
    Response response = metadataResource.importMetadataDatasourceLegacy(domainId, metadataFile, metadataFileInfo, overwrite, localeFiles, localeFilesInfo, null);
    verify(metadataResource, times(1)).importMetadataDatasourceLegacy(domainId, metadataFile, metadataFileInfo, overwrite, localeFiles, localeFilesInfo, null);
    assertEquals(mockResponse.getStatus(), response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) InputStream(java.io.InputStream) FormDataBodyPart(com.sun.jersey.multipart.FormDataBodyPart) FormDataContentDisposition(com.sun.jersey.core.header.FormDataContentDisposition) Test(org.junit.Test)

Example 12 with FormDataBodyPart

use of com.sun.jersey.multipart.FormDataBodyPart in project data-access by pentaho.

the class MetadataResourceTest method uploadMetadataFilesToTempDir.

@Test
public void uploadMetadataFilesToTempDir() throws Exception {
    Response mockResponse = Response.ok().status(new Integer(3)).type(MediaType.TEXT_PLAIN).build();
    MetadataTempFilesListDto metaDto = new MetadataTempFilesListDto();
    InputStream metadataFile = mock(InputStream.class);
    List<FormDataBodyPart> localeFiles = mock(List.class);
    List<FormDataContentDisposition> localeFilesInfo = mock(List.class);
    doReturn(metaDto).when(metadataResource.service).uploadMetadataFilesToTempDir(metadataFile, localeFiles);
    doReturn(mockResponse).when(metadataResource).buildOkResponse("3");
    String res = metadataResource.uploadMetadataFilesToTempDir(metadataFile, localeFiles);
    verify(metadataResource, times(1)).uploadMetadataFilesToTempDir(metadataFile, localeFiles);
    assertEquals(metaDto.toJSONString(), res);
}
Also used : Response(javax.ws.rs.core.Response) InputStream(java.io.InputStream) FormDataBodyPart(com.sun.jersey.multipart.FormDataBodyPart) FormDataContentDisposition(com.sun.jersey.core.header.FormDataContentDisposition) Test(org.junit.Test)

Example 13 with FormDataBodyPart

use of com.sun.jersey.multipart.FormDataBodyPart 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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StringInputStream(org.apache.tools.ant.filters.StringInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) FileResource(org.pentaho.platform.web.http.api.resources.FileResource) Matchers.anyString(org.mockito.Matchers.anyString) Response(javax.ws.rs.core.Response) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) ByteArrayInputStream(java.io.ByteArrayInputStream) FormDataBodyPart(com.sun.jersey.multipart.FormDataBodyPart) RepositoryFileImportBundle(org.pentaho.platform.plugin.services.importer.RepositoryFileImportBundle) FormDataContentDisposition(com.sun.jersey.core.header.FormDataContentDisposition) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter) Test(org.junit.Test)

Example 14 with FormDataBodyPart

use of com.sun.jersey.multipart.FormDataBodyPart 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());
        }
    }));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StringInputStream(org.apache.tools.ant.filters.StringInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) ArrayList(java.util.ArrayList) FileResource(org.pentaho.platform.web.http.api.resources.FileResource) Matchers.anyString(org.mockito.Matchers.anyString) Response(javax.ws.rs.core.Response) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) ByteArrayInputStream(java.io.ByteArrayInputStream) FormDataBodyPart(com.sun.jersey.multipart.FormDataBodyPart) ArgumentMatcher(org.mockito.ArgumentMatcher) RepositoryFileImportBundle(org.pentaho.platform.plugin.services.importer.RepositoryFileImportBundle) FormDataContentDisposition(com.sun.jersey.core.header.FormDataContentDisposition) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter) RepositoryFileAclAdapter(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAdapter) Test(org.junit.Test)

Aggregations

FormDataBodyPart (com.sun.jersey.multipart.FormDataBodyPart)14 Test (org.junit.Test)12 FileInputStream (java.io.FileInputStream)10 InputStream (java.io.InputStream)9 FormDataContentDisposition (com.sun.jersey.core.header.FormDataContentDisposition)7 ClientResponse (com.sun.jersey.api.client.ClientResponse)6 WebResource (com.sun.jersey.api.client.WebResource)6 FormDataMultiPart (com.sun.jersey.multipart.FormDataMultiPart)6 MultiPart (com.sun.jersey.multipart.MultiPart)6 JerseyTest (com.sun.jersey.test.framework.JerseyTest)6 Response (javax.ws.rs.core.Response)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 RepositoryFileAclDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto)4 FileResource (org.pentaho.platform.web.http.api.resources.FileResource)4 ArrayList (java.util.ArrayList)3 StringInputStream (org.apache.tools.ant.filters.StringInputStream)3 Matchers.anyString (org.mockito.Matchers.anyString)3 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2 IPlatformImportBundle (org.pentaho.platform.api.repository2.unified.IPlatformImportBundle)2 IPlatformImporter (org.pentaho.platform.plugin.services.importer.IPlatformImporter)2