use of org.pentaho.platform.engine.core.output.SimpleContentItem in project pentaho-platform by pentaho.
the class SimpleOutputHandlerTest method test1.
public void test1() throws Exception {
StandaloneObjectFactory factory = new StandaloneObjectFactory();
TestOutputHandler.contentItem = new SimpleContentItem();
factory.defineObject("testoutut", TestOutputHandler.class.getName(), StandaloneObjectFactory.Scope.LOCAL);
PentahoSystem.registerObjectFactory(factory);
StandaloneSession session = new StandaloneSession();
ByteArrayOutputStream out = new ByteArrayOutputStream();
SimpleOutputHandler handler = new SimpleOutputHandler(out, false);
MimeTypeListener listener = new MimeTypeListener();
handler.setMimeTypeListener(listener);
assertEquals(listener, handler.getMimeTypeListener());
assertFalse(handler.allowFeedback());
handler.setSession(session);
assertEquals(session, handler.getSession());
handler.setContentItem(new SimpleContentItem(), null, null);
IContentItem content2 = handler.getOutputContentItem("bogus", "testoutut:bogus", null, null);
assertEquals(TestOutputHandler.contentItem, content2);
content2 = handler.getOutputContentItem("bogus", "bogus", null, null);
assertNull(content2);
content2 = handler.getOutputContentItem(IOutputHandler.RESPONSE, IOutputHandler.CONTENT, null, null);
assertEquals(out, content2.getOutputStream(null));
assertFalse(handler.contentDone());
assertNull(handler.getFeedbackContentItem());
assertFalse(handler.contentDone());
handler.setOutputPreference(-1);
assertEquals(-1, handler.getOutputPreference());
handler.setMimeType("test/test");
assertEquals("test/test", handler.getMimeType());
handler.setOutput("bogus", null);
handler.setOutput("file:bogus", null);
IContentItem content3 = new BufferedContentItem(null);
OutputStream os = content3.getOutputStream(null);
os.write("test data".getBytes());
content3.closeOutputStream();
handler.setOutput(IOutputHandler.CONTENT, content3);
assertEquals("test data", new String(out.toByteArray()));
handler.setOutput(IOutputHandler.CONTENT, "+test data2");
assertEquals("test data+test data2", new String(out.toByteArray()));
}
use of org.pentaho.platform.engine.core.output.SimpleContentItem in project pentaho-platform by pentaho.
the class AuditEntryTest method testAuditEntry.
public void testAuditEntry() throws Exception {
StandaloneObjectFactory factory = new StandaloneObjectFactory();
PentahoSystem.registerObjectFactory(factory);
String jobId = "testjobid";
String instId = "testinstid";
String objId = "testobjid";
String objType = "testobjtype";
String actor = "testactor";
String messageType = "testtype";
String messageName = "testname";
String messageTxtValue = MessageTypes.INSTANCE_END;
BigDecimal messageNumValue = new BigDecimal(99);
float duration = (float) 1.23;
// this should not complain
AuditEntry.auditJobDuration(jobId, instId, objId, objType, actor, messageType, messageName, messageTxtValue, duration);
TestOutputHandler.contentItem = new SimpleContentItem();
factory.defineObject(IAuditEntry.class.getSimpleName(), TestAuditEntry.class.getName(), StandaloneObjectFactory.Scope.GLOBAL);
// this should not complain
AuditEntry.auditJobDuration(jobId, instId, objId, objType, actor, messageType, messageName, messageTxtValue, duration);
TestAuditEntry entry = (TestAuditEntry) factory.get(IAuditEntry.class, null);
assertEquals(jobId, entry.jobId);
assertEquals("1.23", Double.toString(entry.duration).substring(0, 4));
assertEquals(null, entry.messageNumValue);
assertEquals(messageType, entry.messageType);
assertEquals(messageName, entry.messageName);
assertEquals(messageTxtValue, entry.messageTxtValue);
AuditEntry.auditJobNumValue(jobId, instId, objId, objType, actor, messageType, messageName, messageNumValue);
assertEquals("0", Double.toString(entry.duration).substring(0, 1));
assertEquals(messageNumValue, entry.messageNumValue);
assertEquals(null, entry.messageTxtValue);
AuditEntry.auditJobTxtValue(jobId, instId, objId, objType, actor, messageType, messageName, messageTxtValue);
assertEquals("0", Double.toString(entry.duration).substring(0, 1));
assertEquals(null, entry.messageNumValue);
assertEquals(messageTxtValue, entry.messageTxtValue);
new MessageTypes();
new AuditHelper();
new AuditEntry();
}
Aggregations