use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.
the class StandaloneSessionTest method testTempFileDeleter.
public void testTempFileDeleter() throws Exception {
// get one with an id. //$NON-NLS-1$
StandaloneSession session = new StandaloneSession("tempfiledeleter", UUIDUtil.getUUIDAsString());
StandaloneTempFileDeleter deleter = new StandaloneTempFileDeleter();
// $NON-NLS-1$ //$NON-NLS-2$
StandaloneApplicationContext appContext = new StandaloneApplicationContext(getSolutionRoot(), "");
// $NON-NLS-1$ //$NON-NLS-2$
File file1 = appContext.createTempFile(session, "testTempFileDeleter", "txt", true);
// File object was returned
assertNotNull(file1);
// File exists
assertTrue(file1.exists());
// Deleter wasn't bound to session, so no delete
assertFalse(deleter.hasTempFile(file1.getName()));
// Bind deleter to the session
session.setAttribute(ITempFileDeleter.DELETER_SESSION_VARIABLE, deleter);
// $NON-NLS-1$ //$NON-NLS-2$
File file2 = appContext.createTempFile(session, "testTempFileDeleter", "txt", true);
// File object was returned
assertNotNull(file2);
// File exists
assertTrue(file2.exists());
// Deleter is bound to session
assertTrue(deleter.hasTempFile(file2.getName()));
// File names should be unique
assertFalse(file1.getName().equals(file2.getName()));
deleter.doTempFileCleanup();
// This file will be left over
assertTrue(file1.exists());
// The deleter should have removed this
assertFalse(file2.exists());
// After doTempFileCleanup() the list should be empty
assertFalse(deleter.hasTempFile(file2.getName()));
// The tearDown should blow away everything else...
// Add known deleted file to the deleter
deleter.trackTempFile(file2);
// Validates cleanup doesn't choke on missing files
deleter.doTempFileCleanup();
// Test that IllegalArgumentException if passed a null
try {
deleter.trackTempFile(null);
fail();
} catch (IllegalArgumentException expected) {
// ignored
}
}
use of org.pentaho.platform.engine.core.system.StandaloneSession 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.StandaloneSession 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.StandaloneSession 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.StandaloneSession 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