Search in sources :

Example 56 with SimpleRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.

the class SimpleRepositoryFileDataTest method testExceptions.

@Test
public void testExceptions() {
    InputStream stream = mock(InputStream.class);
    try {
        doThrow(new IOException()).when(stream).available();
    } catch (Exception e) {
        fail("available Exception test failed");
    }
    file = new SimpleRepositoryFileData(stream, "", MIME_TYPE);
    long size = file.getDataSize();
    assertEquals(0, size);
}
Also used : SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 57 with SimpleRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.

the class SimpleRepositoryFileDataTest method setUp.

@Before
public void setUp() {
    inputStreamSpy = spy(INPUT_STREAM);
    file = new SimpleRepositoryFileData(inputStreamSpy, ENCODING, MIME_TYPE);
}
Also used : SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) Before(org.junit.Before)

Example 58 with SimpleRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.

the class SimpleRepositoryFileDataTest method testLongExcept.

@Test
public void testLongExcept() {
    String longExcerpt = "this is a really long string that exceeds the max length of 20 hopefully!";
    InputStream inputStream = new ByteArrayInputStream(longExcerpt.getBytes(StandardCharsets.UTF_8));
    inputStreamSpy = spy(inputStream);
    file = new SimpleRepositoryFileData(inputStreamSpy, ENCODING, MIME_TYPE);
    String theString = file.toString();
    assertTrue(theString.contains("..."));
    file = new SimpleRepositoryFileData(inputStreamSpy, "", MIME_TYPE);
    theString = file.toString();
    assertTrue(theString.contains("..."));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 59 with SimpleRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData in project pentaho-platform by pentaho.

the class GetResourceIT method testRepositoryFile.

@Test
public void testRepositoryFile() throws ServletException, IOException {
    final String repoFileName = "repo_file.jpg";
    final int repoFileLength = 100;
    final RepositoryFile repositoryFile = mock(RepositoryFile.class);
    final InputStream inputStream = mock(InputStream.class);
    when(inputStream.read(any(byte[].class))).thenReturn(repoFileLength, -1);
    final SimpleRepositoryFileData repositoryFileData = mock(SimpleRepositoryFileData.class);
    when(repositoryFileData.getStream()).thenReturn(inputStream);
    final IUnifiedRepository repo = mock(IUnifiedRepository.class);
    when(repo.getFile(eq(repoFileName))).thenReturn(repositoryFile);
    when(repo.getDataForRead(any(Serializable.class), eq(SimpleRepositoryFileData.class))).thenReturn(repositoryFileData);
    mp.defineInstance(IUnifiedRepository.class, repo);
    when(request.getParameter(RESOURCE_PARAM)).thenReturn(repoFileName);
    final ServletOutputStream outputStream = mock(ServletOutputStream.class);
    when(response.getOutputStream()).thenReturn(outputStream);
    servlet.service(request, response);
    verify(response).setContentType(eq(TEST_MIME_TYPE));
    verify(response).setHeader(eq(CONTENT_DISPOSITION_HEADER), endsWith(repoFileName));
    verify(response).setContentLength(repoFileLength);
}
Also used : Serializable(java.io.Serializable) SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) ServletOutputStream(javax.servlet.ServletOutputStream) InputStream(java.io.InputStream) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Mockito.anyString(org.mockito.Mockito.anyString) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Aggregations

SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)58 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)43 ByteArrayInputStream (java.io.ByteArrayInputStream)31 Test (org.junit.Test)25 Matchers.anyString (org.mockito.Matchers.anyString)18 ITenant (org.pentaho.platform.api.mt.ITenant)17 InputStream (java.io.InputStream)16 IOException (java.io.IOException)14 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)12 Serializable (java.io.Serializable)10 File (java.io.File)9 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)9 FileNotFoundException (java.io.FileNotFoundException)5 DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)5 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)5 VersionSummary (org.pentaho.platform.api.repository2.unified.VersionSummary)5 FileOutputStream (java.io.FileOutputStream)4 DomainAlreadyExistsException (org.pentaho.metadata.repository.DomainAlreadyExistsException)4 DomainIdNullException (org.pentaho.metadata.repository.DomainIdNullException)4 RepositoryRequest (org.pentaho.platform.api.repository2.unified.RepositoryRequest)4