Search in sources :

Example 16 with StandaloneObjectFactory

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

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

the class StandaloneObjectFactoryTest method testLocalObject2.

public void testLocalObject2() throws Exception {
    StandaloneObjectFactory factory = new StandaloneObjectFactory();
    factory.defineObject(Object2.class.getSimpleName(), Object2.class.getName(), Scope.LOCAL);
    // $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 same", obj1 != obj2);
    Object2 obj3 = factory.get(Object2.class, session1);
    // $NON-NLS-1$
    assertTrue("Objects are 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 18 with StandaloneObjectFactory

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

the class StandaloneObjectFactoryTest method testImplementingClassNotFound.

public void testImplementingClassNotFound() throws Exception {
    StandaloneObjectFactory factory = new StandaloneObjectFactory();
    // $NON-NLS-1$ //$NON-NLS-2$
    factory.defineObject("bogus", "NotARealClass", Scope.GLOBAL);
    try {
        factory.getImplementingClass("bogus");
        fail("exception was expected");
    } catch (RuntimeException e) {
    // ignored
    }
}
Also used : StandaloneObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory)

Example 19 with StandaloneObjectFactory

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

the class StandaloneObjectFactoryTest method testSessionObject1.

public void testSessionObject1() throws Exception {
    StandaloneObjectFactory factory = new StandaloneObjectFactory();
    factory.defineObject(Object1.class.getSimpleName(), Object1.class.getName(), Scope.SESSION);
    // $NON-NLS-1$
    IPentahoSession session1 = new StandaloneSession("test user 1");
    // $NON-NLS-1$
    IPentahoSession session2 = new StandaloneSession("test user 2");
    Object1 obj1 = factory.get(Object1.class, session1);
    // $NON-NLS-1$
    assertNotNull("Object is null", obj1);
    Object1 obj2 = factory.get(Object1.class, session2);
    // $NON-NLS-1$
    assertNotNull("Object is null", obj2);
    // $NON-NLS-1$
    assertTrue("Objects are same", obj1 != obj2);
    Object1 obj3 = factory.get(Object1.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 20 with StandaloneObjectFactory

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

the class StandaloneObjectFactoryTest method testGlobalObjectFail.

public void testGlobalObjectFail() throws Exception {
    StandaloneObjectFactory factory = new StandaloneObjectFactory();
    // $NON-NLS-1$
    factory.defineObject(Object1.class.getSimpleName(), "bogus", Scope.GLOBAL);
    // $NON-NLS-1$
    IPentahoSession session1 = new StandaloneSession("test user 1");
    try {
        factory.get(Object1.class, session1);
        // $NON-NLS-1$
        assertFalse("exception expected", true);
    } catch (ObjectFactoryException e) {
        // $NON-NLS-1$
        assertTrue("exception expected", true);
    }
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) StandaloneObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory)

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