use of org.pentaho.platform.api.engine.ObjectFactoryException 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.ObjectFactoryException 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.ObjectFactoryException in project pentaho-platform by pentaho.
the class DefaultBackingRepositoryLifecycleManager method getTenantManager.
/**
* @return the {@link IBackingRepositoryLifecycleManager} that this instance will use. If none has been
* specified, it will default to getting the information from {@link PentahoSystem.get()}
*/
public ITenantManager getTenantManager() {
// Check ... if we haven't been injected with a lifecycle manager, get one from PentahoSystem
try {
IPentahoObjectFactory objectFactory = PentahoSystem.getObjectFactory();
IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
return (null != tenantManager ? tenantManager : objectFactory.get(ITenantManager.class, "tenantMgrProxy", pentahoSession));
} catch (ObjectFactoryException e) {
return null;
}
}
use of org.pentaho.platform.api.engine.ObjectFactoryException in project pentaho-platform by pentaho.
the class SimpleObjectFactory method get.
@SuppressWarnings("unchecked")
public <T> T get(Class<T> interfaceClass, String key, IPentahoSession session) throws ObjectFactoryException {
String classname = classnamesMap.get(key);
try {
Class implClass = Class.forName(classname);
T t = (T) implClass.newInstance();
if (t instanceof IPentahoInitializer) {
((IPentahoInitializer) t).init(session);
}
return t;
} catch (Throwable th) {
throw new ObjectFactoryException("Could not create instance for class " + classname, th);
}
}
use of org.pentaho.platform.api.engine.ObjectFactoryException in project data-access by pentaho.
the class DatasourceServiceTest method setUpClass.
@BeforeClass
public static void setUpClass() throws ObjectFactoryException {
authorizationPolicy = mock(IAuthorizationPolicy.class);
when(authorizationPolicy.isAllowed(RepositoryReadAction.NAME)).thenReturn(true);
when(authorizationPolicy.isAllowed(RepositoryCreateAction.NAME)).thenReturn(true);
IPentahoObjectFactory pentahoObjectFactory = mock(IPentahoObjectFactory.class);
when(pentahoObjectFactory.objectDefined(anyString())).thenReturn(true);
when(pentahoObjectFactory.get(anyClass(), anyString(), any(IPentahoSession.class))).thenAnswer((Answer<Object>) invocation -> {
if (invocation.getArguments()[0].equals(IAuthorizationPolicy.class)) {
return authorizationPolicy;
}
return null;
});
PentahoSystem.registerObjectFactory(pentahoObjectFactory);
}
Aggregations