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