use of org.pentaho.platform.engine.core.output.SimpleContentItem in project pentaho-platform by pentaho.
the class OutputTest method testMultiContentItemErrors.
public void testMultiContentItemErrors() {
ByteArrayOutputStream out1 = new ByteArrayOutputStream();
OutputStream out2 = new MockExceptionOutputStream();
SimpleContentItem item1 = new SimpleContentItem(out1);
SimpleContentItem item2 = new SimpleContentItem(out2);
MultiContentItem multiContent = new MultiContentItem();
multiContent.addContentItem(item1);
multiContent.addContentItem(item2);
byte[] in = "abcd".getBytes();
String outStr1 = "";
String outStr2 = "";
try {
OutputStream multi = multiContent.getOutputStream("");
multi.write('a');
// we should not get here
assertFalse("IOException expected", true);
} catch (IOException e) {
assertNotNull("IOException expected", e);
}
try {
multiContent.closeOutputStream();
} catch (Exception e) {
// we should not get here
assertEquals("IOException", null, e);
}
outStr1 = new String(out1.toByteArray());
assertEquals("Output stream 1", "a", outStr1);
}
use of org.pentaho.platform.engine.core.output.SimpleContentItem in project pentaho-platform by pentaho.
the class SimpleOutputHandlerTest method testGetOutputContentItemObjectNameImportant.
public void testGetOutputContentItemObjectNameImportant() throws Exception {
OutputStream out = new ByteArrayOutputStream();
TestOutputHandler.contentItem = new SimpleContentItem(out);
SimpleOutputHandler handler = new SimpleOutputHandler(out, false);
StandaloneObjectFactory factory = new StandaloneObjectFactory();
factory.defineObject("contentrepo", TestOutputHandler.class.getName(), StandaloneObjectFactory.Scope.GLOBAL);
PentahoSystem.registerObjectFactory(factory);
IContentItem contentItem = handler.getOutputContentItem("contentrepo", "myreport:contentrepo", null, null);
assertNotNull(contentItem);
assertEquals(out, contentItem.getOutputStream(null));
contentItem = handler.getOutputContentItem("", "myreport:contentrepo", null, null);
assertNull(contentItem);
}
use of org.pentaho.platform.engine.core.output.SimpleContentItem in project pentaho-platform by pentaho.
the class ApacheVFSOutputHandler method getFileOutputContentItem.
@Override
public IContentItem getFileOutputContentItem() {
String contentRef = getContentRef();
try {
// $NON-NLS-1$
String contentName = getHandlerId().substring(4) + ":" + contentRef;
FileSystemManager fsManager = getFileSystemManager();
if (fsManager == null) {
logError(Messages.getInstance().getString("ApacheVFSOutputHandler.ERROR_0001_CANNOT_GET_VFSMGR"));
return null;
}
FileObject file = fsManager.resolveFile(contentName);
if (file == null) {
logError(Messages.getInstance().getString("ApacheVFSOutputHandler.ERROR_0002_CANNOT_GET_VF", contentName));
return null;
}
if (!file.isWriteable()) {
logError(Messages.getInstance().getString("ApacheVFSOutputHandler.ERROR_0003_CANNOT_WRITE", contentName));
return null;
}
FileContent fileContent = file.getContent();
if (fileContent == null) {
logError(Messages.getInstance().getString("ApacheVFSOutputHandler.ERROR_0004_CANNOT_GET_CTX", contentName));
return null;
}
OutputStream outputStream = fileContent.getOutputStream();
SimpleContentItem content = new SimpleContentItem(outputStream);
return content;
} catch (Throwable t) {
Logger.error(ApacheVFSOutputHandler.class.getName(), Messages.getInstance().getString("ApacheVFSOutputHandler.ERROR_0005_CANNOT_GET_HANDLER", contentRef), // $NON-NLS-1$
t);
}
return null;
}
use of org.pentaho.platform.engine.core.output.SimpleContentItem in project pentaho-platform by pentaho.
the class OutputTest method testSimpleContentItem.
public void testSimpleContentItem() throws Exception {
OutputStream out = new ByteArrayOutputStream();
SimpleContentItem content = new SimpleContentItem();
content.setMimeType("test/test");
content.setOutputStream(out);
content.setName("testname");
// assertEquals("wrong value", null, content.getPath() );
// SimpleContentItem changed to not return null for path.
assertNotNull(content.getPath());
assertEquals("wrong value", "test/test", content.getMimeType());
assertEquals("wrong value", null, content.getInputStream());
assertEquals("wrong value", out, content.getOutputStream(null));
// these should not throw errors
content.closeOutputStream();
out = new MockExceptionOutputStream();
content.setOutputStream(out);
content.closeOutputStream();
}
use of org.pentaho.platform.engine.core.output.SimpleContentItem in project pentaho-platform by pentaho.
the class SimpleOutputHandlerTest method test2.
public void test2() throws Exception {
StandaloneSession session = new StandaloneSession();
OutputStream out = new MockExceptionOutputStream();
IContentItem content = new SimpleContentItem(out);
SimpleOutputHandler handler = new SimpleOutputHandler(content, true);
assertTrue(handler.allowFeedback());
assertFalse(handler.contentDone());
assertNotNull(handler.getFeedbackContentItem());
assertTrue(handler.contentDone());
IContentItem content2 = handler.getFeedbackContentItem();
assertEquals(content.getOutputStream(null), content2.getOutputStream(null));
IContentItem content3 = new BufferedContentItem(null);
content3.getOutputStream(null).write("test data".getBytes());
content3.closeOutputStream();
try {
handler.setOutput(IOutputHandler.CONTENT, content3);
fail("Exception not detected.");
} catch (Exception ex) {
// Test passed.
}
}
Aggregations