Search in sources :

Example 26 with StandaloneObjectFactory

use of org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory in project pentaho-platform by pentaho.

the class StandaloneObjectFactoryTest method testThreadObject2.

public void testThreadObject2() throws Exception {
    StandaloneObjectFactory factory = new StandaloneObjectFactory();
    factory.defineObject(Object2.class.getSimpleName(), Object2.class.getName(), Scope.THREAD);
    // $NON-NLS-1$
    IPentahoSession session1 = new StandaloneSession("test user 1");
    Object2 obj1 = factory.get(Object2.class, session1);
    // $NON-NLS-1$
    assertNotNull("Object is null", obj1);
    Object2 obj2 = factory.get(Object2.class, session1);
    // $NON-NLS-1$
    assertNotNull("Object is null", obj2);
    // $NON-NLS-1$
    assertTrue("Objects are not same", obj1 == obj2);
    Object2 obj3 = factory.get(Object2.class, session1);
    // $NON-NLS-1$
    assertTrue("Objects are not same", obj1 == obj3);
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) StandaloneObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory)

Example 27 with StandaloneObjectFactory

use of org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory 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

StandaloneObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory)27 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)21 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)18 ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)7 SimpleContentItem (org.pentaho.platform.engine.core.output.SimpleContentItem)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStream (java.io.OutputStream)2 IAuditEntry (org.pentaho.platform.api.engine.IAuditEntry)2 IContentItem (org.pentaho.platform.api.repository.IContentItem)2 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)2 File (java.io.File)1 BigDecimal (java.math.BigDecimal)1 Before (org.junit.Before)1 Test (org.junit.Test)1 IMimeTypeListener (org.pentaho.platform.api.engine.IMimeTypeListener)1 AuditEntry (org.pentaho.platform.engine.core.audit.AuditEntry)1 AuditHelper (org.pentaho.platform.engine.core.audit.AuditHelper)1 MessageTypes (org.pentaho.platform.engine.core.audit.MessageTypes)1 NullAuditEntry (org.pentaho.platform.engine.core.audit.NullAuditEntry)1 BufferedContentItem (org.pentaho.platform.engine.core.output.BufferedContentItem)1