Search in sources :

Example 56 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.

the class StandaloneObjectFactoryTest method testGlobalObject1.

public void testGlobalObject1() throws Exception {
    StandaloneObjectFactory factory = new StandaloneObjectFactory();
    factory.defineObject(Object1.class.getSimpleName(), Object1.class.getName(), Scope.GLOBAL);
    factory.defineObject(BadObjectRuntime.class.getSimpleName(), BadObjectRuntime.class.getName(), Scope.GLOBAL);
    factory.defineObject(BadObject.class.getSimpleName(), BadObject.class.getName(), Scope.GLOBAL);
    // $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 not same", obj1 == obj2);
    try {
        factory.get(BadObjectRuntime.class, session1);
        assertFalse(true);
    } catch (RuntimeException e) {
        assertTrue(true);
    }
    try {
        factory.get(BadObject.class, session1);
        assertFalse(true);
    } catch (ObjectFactoryException e) {
        assertTrue(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)

Example 57 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.

the class StandaloneObjectFactoryTest method testLocalObject1.

public void testLocalObject1() throws Exception {
    StandaloneObjectFactory factory = new StandaloneObjectFactory();
    factory.defineObject(Object1.class.getSimpleName(), Object1.class.getName(), Scope.LOCAL);
    // $NON-NLS-1$
    IPentahoSession session1 = new StandaloneSession("test user 1");
    Object1 obj1 = factory.get(Object1.class, session1);
    // $NON-NLS-1$
    assertNotNull("Object is null", obj1);
    Object1 obj2 = factory.get(Object1.class, session1);
    // $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 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 58 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.

the class StandaloneObjectFactoryTest method testNoCreator.

public void testNoCreator() {
    // $NON-NLS-1$
    IPentahoSession session1 = new StandaloneSession("test user 1");
    StandaloneObjectFactory factory = new StandaloneObjectFactory();
    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)

Example 59 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.

the class PentahoSessionHolderTest method testNullSession.

@Test
public void testNullSession() {
    final IPentahoSession mockSession = mockery.mock(IPentahoSession.class);
    PentahoSessionHolder.setSession(mockSession);
    assertSame(mockSession, PentahoSessionHolder.getSession());
    PentahoSessionHolder.removeSession();
    assertNull("session should be null", PentahoSessionHolder.getSession());
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Test(org.junit.Test)

Example 60 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.

the class BootTest method testObjectFactoryAvailableThruShutdown.

@Test
public void testObjectFactoryAvailableThruShutdown() {
    final AtomicBoolean objectFactoryWasValid = new AtomicBoolean(false);
    IPentahoSystemListener listener = new IPentahoSystemListener() {

        @Override
        public boolean startup(IPentahoSession session) {
            return true;
        }

        @Override
        public void shutdown() {
            // Verify that the ObjectFactory is still valid at this point
            String s = PentahoSystem.get(String.class);
            // Not possible to assert within here as PentahoSystem catches all Exceptions, setting marker boolean instead.
            objectFactoryWasValid.set("Testing".equals(s));
        }
    };
    PentahoSystem.setSystemListeners(Collections.singletonList(listener));
    PentahoSystem.init();
    // Add an object to PentahoSystem, then verify that it can be retrieved
    PentahoSystem.registerObject("Testing");
    String s = PentahoSystem.get(String.class);
    assertEquals("Testing", s);
    PentahoSystem.shutdown();
    // At this point the shutdown() method on the listener has been called, check the boolean flag.
    assertTrue("ShutdownListener wasn't able to get object from PentahoSystem", objectFactoryWasValid.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IPentahoSystemListener(org.pentaho.platform.api.engine.IPentahoSystemListener) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Test(org.junit.Test)

Aggregations

IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)231 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)76 Test (org.junit.Test)70 Matchers.anyString (org.mockito.Matchers.anyString)40 ArrayList (java.util.ArrayList)32 ITenant (org.pentaho.platform.api.mt.ITenant)22 IOException (java.io.IOException)20 StandaloneObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory)18 File (java.io.File)17 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)16 Before (org.junit.Before)14 OutputStream (java.io.OutputStream)13 HashMap (java.util.HashMap)13 InputStream (java.io.InputStream)12 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)12 ModelInfo (org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo)12 Domain (org.pentaho.metadata.model.Domain)11 ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)11 List (java.util.List)10 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)10