Search in sources :

Example 11 with SimpleContentItem

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()));
}
Also used : SimpleContentItem(org.pentaho.platform.engine.core.output.SimpleContentItem) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) StandaloneObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IContentItem(org.pentaho.platform.api.repository.IContentItem) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) BufferedContentItem(org.pentaho.platform.engine.core.output.BufferedContentItem) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 12 with SimpleContentItem

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();
}
Also used : SimpleContentItem(org.pentaho.platform.engine.core.output.SimpleContentItem) AuditHelper(org.pentaho.platform.engine.core.audit.AuditHelper) AuditEntry(org.pentaho.platform.engine.core.audit.AuditEntry) NullAuditEntry(org.pentaho.platform.engine.core.audit.NullAuditEntry) IAuditEntry(org.pentaho.platform.api.engine.IAuditEntry) StandaloneObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory) MessageTypes(org.pentaho.platform.engine.core.audit.MessageTypes) IAuditEntry(org.pentaho.platform.api.engine.IAuditEntry) BigDecimal(java.math.BigDecimal)

Aggregations

SimpleContentItem (org.pentaho.platform.engine.core.output.SimpleContentItem)12 OutputStream (java.io.OutputStream)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 IContentItem (org.pentaho.platform.api.repository.IContentItem)5 MultiOutputStream (org.pentaho.platform.engine.core.output.MultiOutputStream)3 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)3 StandaloneObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 BufferedContentItem (org.pentaho.platform.engine.core.output.BufferedContentItem)2 MultiContentItem (org.pentaho.platform.engine.core.output.MultiContentItem)2 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)2 FileOutputStream (java.io.FileOutputStream)1 Method (java.lang.reflect.Method)1 BigDecimal (java.math.BigDecimal)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Set (java.util.Set)1