use of org.pentaho.platform.api.engine.IRuntimeContext in project pentaho-platform by pentaho.
the class PojoComponentTest method testBadOutput.
public void testBadOutput() {
startTest();
ISolutionEngine solutionEngine = ServiceTestHelper.getSolutionEngine();
try {
String xactionStr = ServiceTestHelper.getXAction(SOLUTION_PATH, "test/pojo/pojo-bad5.xaction");
PojoComponentTest.doneCalled = false;
PojoComponentTest.executeCalled = false;
PojoComponentTest.validateCalled = false;
IRuntimeContext runtimeContext = // $NON-NLS-1$ //$NON-NLS-2$
solutionEngine.execute(// $NON-NLS-1$ //$NON-NLS-2$
xactionStr, // $NON-NLS-1$ //$NON-NLS-2$
"test", // $NON-NLS-1$ //$NON-NLS-2$
"invalid class setting test", // $NON-NLS-1$ //$NON-NLS-2$
false, // $NON-NLS-1$ //$NON-NLS-2$
true, // $NON-NLS-1$ //$NON-NLS-2$
null, // $NON-NLS-1$ //$NON-NLS-2$
false, new HashMap(), null, null, new SimpleUrlFactory(""), new ArrayList());
assertNotNull("RuntimeContext is null", runtimeContext);
assertEquals("Action sequence succeeded", runtimeContext.getStatus(), IRuntimeContext.RUNTIME_STATUS_FAILURE);
} catch (Exception e) {
// we should not get here
e.printStackTrace();
assertTrue(e.getMessage(), false);
}
finishTest();
}
use of org.pentaho.platform.api.engine.IRuntimeContext in project pentaho-platform by pentaho.
the class PojoComponentTest method testBadValidate.
public void testBadValidate() {
startTest();
ISolutionEngine solutionEngine = ServiceTestHelper.getSolutionEngine();
try {
String xactionStr = ServiceTestHelper.getXAction(SOLUTION_PATH, "test/pojo/pojo-bad3.xaction");
PojoComponentTest.doneCalled = false;
PojoComponentTest.executeCalled = false;
PojoComponentTest.validateCalled = false;
IRuntimeContext runtimeContext = // $NON-NLS-1$ //$NON-NLS-2$
solutionEngine.execute(// $NON-NLS-1$ //$NON-NLS-2$
xactionStr, // $NON-NLS-1$ //$NON-NLS-2$
"test", // $NON-NLS-1$ //$NON-NLS-2$
"invalid class setting test", // $NON-NLS-1$ //$NON-NLS-2$
false, // $NON-NLS-1$ //$NON-NLS-2$
true, // $NON-NLS-1$ //$NON-NLS-2$
null, // $NON-NLS-1$ //$NON-NLS-2$
false, new HashMap(), null, null, new SimpleUrlFactory(""), new ArrayList());
assertNotNull("RuntimeContext is null", runtimeContext);
assertEquals("execute was called", false, PojoComponentTest.executeCalled);
assertEquals("validate was not called", true, PojoComponentTest.validateCalled);
assertEquals("Action sequence execution succeeded", runtimeContext.getStatus(), IRuntimeContext.RUNTIME_STATUS_FAILURE);
} catch (Exception e) {
// we should not get here
e.printStackTrace();
assertTrue(e.getMessage(), false);
}
finishTest();
}
use of org.pentaho.platform.api.engine.IRuntimeContext 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.IRuntimeContext in project pentaho-platform by pentaho.
the class SoapHelperTest method testCreateSoapResponseDocumentFromContext.
/**
* Tests for SoapHelper.createSoapResponseDocument(IRuntimeContext, IOutputHandler, OutputStream, List)
*/
public void testCreateSoapResponseDocumentFromContext() {
// Set up test data
Set<Object> outputNames = new HashSet<>();
IActionParameter actionParameter = mock(IActionParameter.class);
when(actionParameter.getValue()).thenReturn("testValue");
IRuntimeContext context = mock(IRuntimeContext.class);
when(context.getOutputNames()).thenReturn(outputNames);
when(context.getStatus()).thenReturn(IRuntimeContext.RUNTIME_STATUS_SUCCESS);
when(context.getOutputParameter(anyString())).thenReturn(actionParameter);
List messages = new ArrayList();
IOutputHandler outputHandler = mock(IOutputHandler.class);
IContentItem contentItem = mock(IContentItem.class);
when(outputHandler.getOutputContentItem(anyString(), anyString(), anyString(), anyString())).thenReturn(contentItem);
when(contentItem.getMimeType()).thenReturn("text/xml");
OutputStream contentStream = mock(OutputStream.class);
when(contentStream.toString()).thenReturn("contentStreamTestString");
// Tests for document with two output names
outputNames.add("outputName1");
outputNames.add("outputName2");
Document d1 = SoapHelper.createSoapResponseDocument(context, outputHandler, contentStream, messages);
Element activityResponse1 = d1.getRootElement().element("SOAP-ENV:Body").element("ExecuteActivityResponse");
assertEquals(activityResponse1.elements().size(), 2);
assertNotNull(activityResponse1.element("outputName1"));
assertNotNull(activityResponse1.element("outputName2"));
// Test for document with one output name (different branch in createSoapResponseDocument())
outputNames.clear();
outputNames.add("outputName1");
Document d2 = SoapHelper.createSoapResponseDocument(context, outputHandler, contentStream, messages);
Element activityResponse2 = d2.getRootElement().element("SOAP-ENV:Body").element("ExecuteActivityResponse");
assertEquals(activityResponse2.elements().size(), 1);
assertNotNull(activityResponse2.element("outputName1"));
// Tests for document with no output names
outputNames.clear();
Document d3 = SoapHelper.createSoapResponseDocument(context, outputHandler, contentStream, messages);
Element activityResponse3 = d3.getRootElement().element("SOAP-ENV:Body").element("ExecuteActivityResponse");
assertTrue(activityResponse3.elements().isEmpty());
}
use of org.pentaho.platform.api.engine.IRuntimeContext 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));
}
Aggregations