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);
}
}
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);
}
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);
}
}
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());
}
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());
}
Aggregations