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);
}
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);
}
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("..."));
}
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);
}
Aggregations