Search in sources :

Example 16 with IPlatformImporter

use of org.pentaho.platform.plugin.services.importer.IPlatformImporter in project data-access by pentaho.

the class MetadataServiceTest method testImportMetadataDatasourceMaxFileSize.

@Test(expected = PlatformImportException.class)
public void testImportMetadataDatasourceMaxFileSize() throws Exception {
    // test should work in case max-file-limit is set
    int fileDefaultSize = 10000000;
    String maxFileLimit = PentahoSystem.getSystemSetting("file-upload-defaults/max-file-limit", // $NON-NLS-1$
    String.valueOf(fileDefaultSize));
    assertEquals(fileDefaultSize, Integer.parseInt(maxFileLimit));
    // fileDefaultSize will be exceeded
    byte[] bytes = new byte[fileDefaultSize + 1];
    InputStream metadataFile = new ByteArrayInputStream(bytes);
    FileResource mockFileResource = mock(FileResource.class);
    Response mockResponse = mock(Response.class);
    IPlatformImporter mockIPlatformImporter = mock(IPlatformImporter.class);
    doNothing().when(metadataService).accessValidation();
    doReturn(mockFileResource).when(metadataService).createNewFileResource();
    doReturn(mockResponse).when(mockFileResource).doGetReservedChars();
    doReturn(mockIPlatformImporter).when(metadataService).getImporter();
    metadataService.importMetadataDatasource("test_file", metadataFile, null, false, null, null, null);
}
Also used : Response(javax.ws.rs.core.Response) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) StringInputStream(org.apache.tools.ant.filters.StringInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileResource(org.pentaho.platform.web.http.api.resources.FileResource) Matchers.anyString(org.mockito.Matchers.anyString) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter) Test(org.junit.Test)

Aggregations

IPlatformImporter (org.pentaho.platform.plugin.services.importer.IPlatformImporter)16 IPlatformImportBundle (org.pentaho.platform.api.repository2.unified.IPlatformImportBundle)13 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)9 FileInputStream (java.io.FileInputStream)8 InputStream (java.io.InputStream)8 Test (org.junit.Test)8 Matchers.anyString (org.mockito.Matchers.anyString)7 RepositoryFileImportBundle (org.pentaho.platform.plugin.services.importer.RepositoryFileImportBundle)7 Response (javax.ws.rs.core.Response)6 FileResource (org.pentaho.platform.web.http.api.resources.FileResource)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 FormDataContentDisposition (com.sun.jersey.core.header.FormDataContentDisposition)4 ArrayList (java.util.ArrayList)4 StringInputStream (org.apache.tools.ant.filters.StringInputStream)4 Domain (org.pentaho.metadata.model.Domain)4 XmiParser (org.pentaho.metadata.util.XmiParser)4 File (java.io.File)3 Description (org.hamcrest.Description)3 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)3 Expectations (org.jmock.Expectations)3