use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.
the class FilterDefinitionIT method getSession.
private IPentahoSession getSession() {
IPentahoResultSet rs = getFakeResultSet();
// $NON-NLS-1$
IPentahoSession session = new StandaloneSession("REPOSTEST.JUNIT_TEST_SESSION");
// $NON-NLS-1$
session.setAttribute("customerNamesList", rs);
return session;
}
use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.
the class ServiceLayerTest method testEmptyActionSequence.
@Test
public void testEmptyActionSequence() throws IOException {
List<Object> messages = new ArrayList<Object>();
String instanceId = null;
IPentahoSession session = new StandaloneSession("system");
ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, session);
solutionEngine.setLoggingLevel(ILogger.ERROR);
solutionEngine.init(session);
Map<Object, Object> parameterProviderMap = new HashMap<Object, Object>();
IPentahoUrlFactory urlFactory = new SimpleUrlFactory("");
Reader reader = null;
try {
File file = new File(SOLUTION_PATH + "/services_layer/test1.xaction");
StringBuilder str = new StringBuilder();
reader = new FileReader(file);
char[] buffer = new char[4096];
int n = reader.read(buffer);
while (n != -1) {
str.append(buffer, 0, n);
n = reader.read(buffer);
}
String xactionStr = str.toString();
solutionEngine.setSession(session);
IRuntimeContext runtimeContext = // $NON-NLS-1$ //$NON-NLS-2$
solutionEngine.execute(// $NON-NLS-1$ //$NON-NLS-2$
xactionStr, // $NON-NLS-1$ //$NON-NLS-2$
"test1.xaction", // $NON-NLS-1$ //$NON-NLS-2$
"empty action sequence test", // $NON-NLS-1$ //$NON-NLS-2$
false, // $NON-NLS-1$ //$NON-NLS-2$
true, // $NON-NLS-1$ //$NON-NLS-2$
instanceId, false, parameterProviderMap, null, null, urlFactory, messages);
assertNotNull("RuntimeContext is null", runtimeContext);
assertEquals("Action sequence execution failed", runtimeContext.getStatus(), IRuntimeContext.RUNTIME_STATUS_SUCCESS);
} catch (Exception e) {
// we should not get here
e.printStackTrace();
assertTrue(e.getMessage(), false);
} finally {
if (reader != null) {
reader.close();
}
}
}
use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.
the class ActionDelegateTest method execute.
@SuppressWarnings("unchecked")
private void execute(String actionSequenceFile, boolean exceptionOnError, IAction... actions) throws ActionSequenceException {
TestPluginManager pm = (TestPluginManager) PentahoSystem.get(IPluginManager.class);
for (IAction action : actions) {
pm.addAction(action);
}
// content outputs will write to this stream
out = new ByteArrayOutputStream();
// create SimpleOutputHandler (to handle outputs of type "response.content")
outputHandler = new SimpleOutputHandler(out, false);
outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
IPentahoSession session = new StandaloneSession("system");
ISolutionEngine solutionEngine = ServiceTestHelper.getSolutionEngine();
outputHandler.setSession(session);
String xactionStr = ServiceTestHelper.getXAction("src/test/resources/solution/test/ActionDelegateTest", actionSequenceFile);
// execute the action sequence, providing the outputHandler created above
IRuntimeContext rc = solutionEngine.execute(xactionStr, actionSequenceFile, "action sequence to test the TestAction", false, true, null, false, new HashMap(), outputHandler, null, new SimpleUrlFactory(""), new ArrayList());
int status = rc.getStatus();
if (status == IRuntimeContext.PARAMETERS_FAIL || status == IRuntimeContext.RUNTIME_CONTEXT_RESOLVE_FAIL || status == IRuntimeContext.RUNTIME_STATUS_FAILURE || status == IRuntimeContext.RUNTIME_STATUS_INITIALIZE_FAIL || status == IRuntimeContext.RUNTIME_STATUS_SETUP_FAIL) {
throw new ActionSequenceException("Action sequence failed!");
}
}
use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.
the class StandaloneObjectFactoryTest method testGlobalObject3.
public void testGlobalObject3() throws Exception {
StandaloneObjectFactory factory = new StandaloneObjectFactory();
factory.defineObject(Object2.class.getSimpleName(), Object2.class.getName(), Scope.GLOBAL, getClass().getClassLoader());
// $NON-NLS-1$
IPentahoSession session1 = new StandaloneSession("test user 1");
// $NON-NLS-1$
IPentahoSession session2 = new StandaloneSession("test user 2");
Object2 obj1 = factory.get(Object2.class, session1);
// $NON-NLS-1$
assertNotNull("Object is null", obj1);
Object2 obj2 = factory.get(Object2.class, session2);
// $NON-NLS-1$
assertNotNull("Object is null", obj2);
// $NON-NLS-1$
assertTrue("Objects are not same", obj1 == obj2);
}
use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.
the class StandaloneObjectFactoryTest method testThreadObject1.
public void testThreadObject1() throws Exception {
StandaloneObjectFactory factory = new StandaloneObjectFactory();
factory.defineObject(Object1.class.getSimpleName(), Object1.class.getName(), Scope.THREAD);
// $NON-NLS-1$
IPentahoSession session1 = new StandaloneSession("test user 1");
Object1 obj1 = factory.get(Object1.class, session1);
// $NON-NLS-1$
assertNotNull("Object is null", obj1);
Object1 obj2 = factory.get(Object1.class, session1);
// $NON-NLS-1$
assertNotNull("Object is null", obj2);
// $NON-NLS-1$
assertTrue("Objects are not same", obj1 == obj2);
Object1 obj3 = factory.get(Object1.class, session1);
// $NON-NLS-1$
assertTrue("Objects are not same", obj1 == obj3);
}
Aggregations