use of org.pentaho.platform.api.engine.IPentahoSession 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.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class TemplateUtilTest method testKeyedTableTemplate.
public void testKeyedTableTemplate() {
IRuntimeContext mockRuntimeContext = mock(IRuntimeContext.class);
IPentahoSession mockSession = mock(IPentahoSession.class);
IParameterManager mockParameterManager = mock(IParameterManager.class);
IPentahoResultSet mockPentahoResultSet = createMockResultSet();
IPentahoMetaData mockPentahoMetaData = mock(IPentahoMetaData.class);
final Set inputNames = new HashSet<Object>(Arrays.asList(new String[] { "param1" }));
when(mockParameterManager.getCurrentInputNames()).thenReturn(inputNames);
when(mockRuntimeContext.getSession()).thenReturn(mockSession);
when(mockRuntimeContext.getParameterManager()).thenReturn(mockParameterManager);
when(mockRuntimeContext.getInputParameterValue("param1")).thenReturn(mockPentahoResultSet);
when(mockRuntimeContext.getInputNames()).thenReturn(inputNames);
// "key_value" is parsed as "key value"
String template = "{param1:keycol:key_Value:valcol:defaultValue}";
assertEquals("field Value", TemplateUtil.applyTemplate(template, mockRuntimeContext));
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class TemplateUtilTest method testGetSystemInput.
public void testGetSystemInput() {
final String USER_NAME = "userName";
IRuntimeContext mockRuntimeContext = mock(IRuntimeContext.class);
IPentahoSession mockSession = mock(IPentahoSession.class);
when(mockRuntimeContext.getSession()).thenReturn(mockSession);
when(mockSession.getName()).thenReturn(USER_NAME);
assertEquals(USER_NAME, TemplateUtil.getSystemInput("$user", mockRuntimeContext));
}
use of org.pentaho.platform.api.engine.IPentahoSession 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.api.engine.IPentahoSession 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);
}
Aggregations