Search in sources :

Example 6 with StandaloneSpringPentahoObjectFactory

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

the class AuditConnectionTest method testAuditConnection_cannot_establish_connection.

public void testAuditConnection_cannot_establish_connection() {
    startTest();
    try {
        // Load mock object factory with mock datasource service that produces null datasources
        StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
        factory.init("src/test/resources/solution/system/pentahoObjects.datasourceservice.null.spring.xml", null);
        PentahoSystem.registerObjectFactory(factory);
        AuditConnection auditConnection = new AuditConnection();
        // make sure we get a datasource from the object factory
        auditConnection.setUseNewDatasourceService(true);
        auditConnection.initialize();
        MockDataSourceService.setThrowExceptionOnGetConnection(true);
        auditConnection.getAuditConnection();
        fail("Expected exception when no audit connection could be established");
    } catch (SQLException ex) {
        ex.printStackTrace();
        assertTrue("Expected AUDSQLENT.ERROR_0001", ex.getMessage().contains("AUDSQLENT.ERROR_0001"));
    } finally {
        finishTest();
    }
}
Also used : SQLException(java.sql.SQLException) AuditConnection(org.pentaho.platform.engine.services.audit.AuditConnection) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)

Example 7 with StandaloneSpringPentahoObjectFactory

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

the class StandaloneSpringPentahoObjectFactoryTest method testPriority.

public void testPriority() throws Exception {
    StandaloneSession session = new StandaloneSession();
    StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
    factory.init("src/test/resources/solution/system/pentahoObjects.spring.xml", null);
    PentahoSystem.registerObjectFactory(factory);
    MimeTypeListener obj = PentahoSystem.get(MimeTypeListener.class, session);
    assertEquals("Higher Priority MimeTypeListener", obj.name);
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)

Example 8 with StandaloneSpringPentahoObjectFactory

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

the class StandaloneSpringPentahoObjectFactoryTest method testFallbackPenBean.

/**
 * Test <pen:bean> fallback behavior when no object is published matching the request. It should fall-back to
 * PentahoSystem.get() behavior where beans matching the simple-name of the queried class are returned.
 *
 * @throws Exception
 */
public void testFallbackPenBean() throws Exception {
    PentahoSystem.shutdown();
    ISystemConfig config = mock(ISystemConfig.class);
    when(config.getProperty("system.dampening-timeout")).thenReturn("3000");
    PentahoSystem.registerObject(config);
    StandaloneSession session = new StandaloneSession();
    PentahoSessionHolder.setSession(session);
    StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
    factory.init("src/test/resources/solution/system/pentahoObjects.spring.xml", null);
    PentahoSystem.registerObjectFactory(factory);
    // fallback
    SimpleObjectHolder integerHolder = PentahoSystem.get(SimpleObjectHolder.class, "SimpleIntegerHolder", session);
    // to
    // simpleName
    assertNotNull(integerHolder);
    assertEquals(123, (int) integerHolder.getVal());
    // fallback
    SimpleObjectHolder stringHolder = PentahoSystem.get(SimpleObjectHolder.class, "SimpleStringHolder", session);
    // to
    // simpleName
    assertNotNull(stringHolder);
    assertEquals("testing_fallback_by_interface", stringHolder.getVal().toString());
    // checks
    SimpleObjectHolder integerHolder2 = PentahoSystem.get(SimpleObjectHolder.class, "SimpleIntegerHolder2", session);
    // ID
    assertNotNull(integerHolder2);
    assertEquals(456, (int) integerHolder2.getVal());
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)

Example 9 with StandaloneSpringPentahoObjectFactory

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

the class StandaloneSpringPentahoObjectFactoryTest method testReferences.

public void testReferences() throws Exception {
    StandaloneSession session = new StandaloneSession();
    StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
    factory.init("src/test/resources/solution/system/pentahoObjects.spring.xml", null);
    PentahoSystem.registerObjectFactory(factory);
    IPentahoObjectReference reference = PentahoSystem.getObjectReference(MimeTypeListener.class, session);
    assertEquals("30", reference.getAttributes().get("priority"));
    assertEquals(((MimeTypeListener) reference.getObject()).name, "Higher Priority MimeTypeListener");
}
Also used : IPentahoObjectReference(org.pentaho.platform.api.engine.IPentahoObjectReference) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)

Example 10 with StandaloneSpringPentahoObjectFactory

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

the class StandaloneSpringPentahoObjectFactoryTest method testGetByProperty.

public void testGetByProperty() throws Exception {
    StandaloneSession session = new StandaloneSession();
    StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
    factory.init("src/test/resources/solution/system/pentahoObjects.spring.xml", null);
    PentahoSystem.registerObjectFactory(factory);
    MimeTypeListener obj = PentahoSystem.get(MimeTypeListener.class, session, Collections.singletonMap("someKey", "1"));
    assertEquals("Test Attr1", obj.name);
    obj = PentahoSystem.get(MimeTypeListener.class, session, Collections.singletonMap("someKey", "2"));
    assertEquals("Test Attr2", obj.name);
    // Multiple Attributes
    HashMap<String, String> map = new HashMap<String, String>();
    map.put("someKey", "3");
    map.put("foo", "bar");
    obj = PentahoSystem.get(MimeTypeListener.class, session, map);
    assertEquals("Test Attr3", obj.name);
    // Not found, will default to
    map = new HashMap<String, String>();
    map.put("someKey", "3");
    map.put("foo", "bang");
    obj = PentahoSystem.get(MimeTypeListener.class, session, map);
    assertEquals(null, obj);
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) HashMap(java.util.HashMap) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)

Aggregations

StandaloneSpringPentahoObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)35 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)21 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)10 IPentahoObjectFactory (org.pentaho.platform.api.engine.IPentahoObjectFactory)9 Test (org.junit.Test)8 StandaloneApplicationContext (org.pentaho.platform.engine.core.system.StandaloneApplicationContext)8 PathBasedSystemSettings (org.pentaho.platform.engine.core.system.PathBasedSystemSettings)7 File (java.io.File)5 IMimeTypeListener (org.pentaho.platform.api.engine.IMimeTypeListener)5 AggregateObjectFactory (org.pentaho.platform.engine.core.system.objfac.AggregateObjectFactory)5 HashMap (java.util.HashMap)3 ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)3 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)3 ApplicationContext (org.springframework.context.ApplicationContext)3 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)3 FileSystemXmlApplicationContext (org.springframework.context.support.FileSystemXmlApplicationContext)3 BeforeClass (org.junit.BeforeClass)2 IPentahoObjectRegistration (org.pentaho.platform.api.engine.IPentahoObjectRegistration)2 IPlatformPlugin (org.pentaho.platform.api.engine.IPlatformPlugin)2 ISystemConfig (org.pentaho.platform.api.engine.ISystemConfig)2