Search in sources :

Example 6 with ObjectFactoryException

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);
    }
}
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 7 with ObjectFactoryException

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);
    }
}
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 8 with ObjectFactoryException

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;
    }
}
Also used : IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession)

Example 9 with ObjectFactoryException

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);
    }
}
Also used : IPentahoInitializer(org.pentaho.platform.api.engine.IPentahoInitializer) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException)

Example 10 with ObjectFactoryException

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);
}
Also used : RepositoryCreateAction(org.pentaho.platform.security.policy.rolebased.actions.RepositoryCreateAction) BeforeClass(org.junit.BeforeClass) PublishAction(org.pentaho.platform.security.policy.rolebased.actions.PublishAction) RepositoryReadAction(org.pentaho.platform.security.policy.rolebased.actions.RepositoryReadAction) LogicalModel(org.pentaho.metadata.model.LogicalModel) PentahoSystem(org.pentaho.platform.engine.core.system.PentahoSystem) Matchers.anyString(org.mockito.Matchers.anyString) Domain(org.pentaho.metadata.model.Domain) ArrayList(java.util.ArrayList) ArgumentMatcher(org.mockito.ArgumentMatcher) Answer(org.mockito.stubbing.Answer) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) Assert.fail(org.junit.Assert.fail) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) Matchers.any(org.mockito.Matchers.any) AdministerSecurityAction(org.pentaho.platform.security.policy.rolebased.actions.AdministerSecurityAction) List(java.util.List) Matchers.argThat(org.mockito.Matchers.argThat) Assert.assertFalse(org.junit.Assert.assertFalse) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Mockito.mock(org.mockito.Mockito.mock) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) BeforeClass(org.junit.BeforeClass)

Aggregations

ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)27 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)10 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)10 StandaloneObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory)7 IPentahoObjectFactory (org.pentaho.platform.api.engine.IPentahoObjectFactory)5 DataSource (javax.sql.DataSource)4 IDBDatasourceService (org.pentaho.platform.api.data.IDBDatasourceService)4 ArrayList (java.util.ArrayList)3 DBDatasourceServiceException (org.pentaho.platform.api.data.DBDatasourceServiceException)3 StandaloneSpringPentahoObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)3 SQLException (java.sql.SQLException)2 List (java.util.List)2 IOException (java.io.IOException)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 Principal (java.security.Principal)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1 PBEKeySpec (javax.crypto.spec.PBEKeySpec)1 PBEParameterSpec (javax.crypto.spec.PBEParameterSpec)1