use of org.pentaho.platform.api.engine.IRuntimeContext in project pentaho-platform by pentaho.
the class KettleIT method testKettleValidatationFailure.
public void testKettleValidatationFailure() {
IRuntimeContext context = run("/test/etl/SampleTransformationInvalid.xaction", null, false, parameterProvider, outputHandler, session);
assertEquals(IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_FAIL, context.getStatus());
assertFailResult(context);
}
use of org.pentaho.platform.api.engine.IRuntimeContext in project pentaho-platform by pentaho.
the class ContentOutputComponentIT method testErrorPaths.
public void testErrorPaths() {
startTest();
// Tests with bad output stream
// $NON-NLS-1$
String neverWritten = "This data cannot be written";
// $NON-NLS-1$
String testName = CO_TEST_NAME + "BAD_OUTPUTSTREAM_" + System.currentTimeMillis();
SimpleParameterProvider parameterProvider = new SimpleParameterProvider();
parameterProvider.setParameter("CONTENTOUTPUT", neverWritten);
// $NON-NLS-1$
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
IRuntimeContext context = run("/test/platform/ContentOutputTest_Bytearray.xaction", parameterProvider, testName, CO_TEST_EXTN);
// $NON-NLS-1$
assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_FAILURE, context.getStatus());
// Another test with a bad output stream...
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
baos.write(neverWritten.getBytes());
} catch (Exception ex) {
fail();
}
// $NON-NLS-1$
parameterProvider.setParameter("CONTENTOUTPUT", baos);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
context = run("/test/platform/ContentOutputTest_Bytearray.xaction", parameterProvider, testName, CO_TEST_EXTN);
assertEquals(IRuntimeContext.RUNTIME_STATUS_FAILURE, context.getStatus());
// Final test with a bad output stream...
// $NON-NLS-1$
parameterProvider.setParameter("CONTENTOUTPUT", new ByteArrayInputStream(neverWritten.getBytes()));
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
context = run("/test/platform/ContentOutputTest_Bytearray.xaction", parameterProvider, testName, CO_TEST_EXTN);
assertEquals(IRuntimeContext.RUNTIME_STATUS_FAILURE, context.getStatus());
// Tests with bad action sequences
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
context = run("/test/platform/ContentOutputTest_error1.xaction");
assertEquals(IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_FAIL, context.getStatus());
// Empty Parameter Provider
parameterProvider = new SimpleParameterProvider();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
context = run("/test/platform/ContentOutputTest_error2.xaction", parameterProvider, testName, CO_TEST_EXTN);
assertEquals(IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_FAIL, context.getStatus());
// Test with an invalid input parameter
// $NON-NLS-1$
parameterProvider.setParameter("CONTENTOUTPUT", neverWritten.getBytes());
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
context = run("/test/platform/ContentOutputTest_Bytearray.xaction", parameterProvider, testName, CO_TEST_EXTN);
assertEquals(IRuntimeContext.RUNTIME_STATUS_FAILURE, context.getStatus());
finishTest();
}
use of org.pentaho.platform.api.engine.IRuntimeContext in project pentaho-platform by pentaho.
the class HQLConnectionIT method testHQLConnection.
public void testHQLConnection() {
SimpleParameterProvider parameters = new SimpleParameterProvider();
// $NON-NLS-1$ //$NON-NLS-2$
OutputStream outputStream = getOutputStream(SOLUTION_PATH, "Chart_Bubble", ".html");
SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true);
IRuntimeContext context = // $NON-NLS-1$
run(getSolutionPath() + "/test/datasource/", "HQL_Datasource.xaction", parameters, outputHandler);
assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS, // $NON-NLS-1$
context.getStatus());
}
use of org.pentaho.platform.api.engine.IRuntimeContext in project pentaho-platform by pentaho.
the class BaseTestCase method run.
public IRuntimeContext run(String actionSequencePath, String actionSequence, IParameterProvider parameterProvider, IOutputHandler outputHandler) {
List messages = new ArrayList();
String instanceId = null;
ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, session);
solutionEngine.setLoggingLevel(ILogger.ERROR);
solutionEngine.init(session);
HashMap parameterProviderMap = new HashMap();
IPentahoUrlFactory urlFactory = new SimpleUrlFactory("");
IRuntimeContext runtimeContext = null;
Reader reader = null;
try {
File file = new File(actionSequencePath + actionSequence);
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);
runtimeContext = // $NON-NLS-1$
solutionEngine.execute(// $NON-NLS-1$
xactionStr, // $NON-NLS-1$
actionSequence, // $NON-NLS-1$
"action sequence test", // $NON-NLS-1$
false, // $NON-NLS-1$
true, // $NON-NLS-1$
instanceId, // $NON-NLS-1$
false, parameterProviderMap, null, null, urlFactory, messages);
} catch (Exception e) {
// we should not get here
e.printStackTrace();
assertTrue(e.getMessage(), false);
} finally {
if (reader != null) {
try {
reader.close();
} catch (Exception ex) {
ex.printStackTrace();
assertTrue(ex.getMessage(), false);
}
}
}
return runtimeContext;
}
use of org.pentaho.platform.api.engine.IRuntimeContext in project pentaho-platform by pentaho.
the class TemplateUtilTest method testTableTemplate.
public void testTableTemplate() {
IRuntimeContext mockRuntimeContext = mock(IRuntimeContext.class);
IPentahoSession mockSession = mock(IPentahoSession.class);
IParameterManager mockParameterManager = mock(IParameterManager.class);
IPentahoResultSet mockPentahoResultSet = mock(IPentahoResultSet.class);
Object[] mockRow = new Object[] { "field0", "field1" };
when(mockPentahoResultSet.getColumnCount()).thenReturn(mockRow.length);
when(mockPentahoResultSet.getDataRow(0)).thenReturn(mockRow);
when(mockParameterManager.getCurrentInputNames()).thenReturn(new HashSet<Object>(Arrays.asList(new String[] { "param1" })));
when(mockRuntimeContext.getSession()).thenReturn(mockSession);
when(mockRuntimeContext.getParameterManager()).thenReturn(mockParameterManager);
when(mockRuntimeContext.getInputParameterValue("param1")).thenReturn(mockPentahoResultSet);
String template = "table {param1:col:1} and text";
IParameterResolver resolver = mock(IParameterResolver.class);
assertEquals("table field1 and text", TemplateUtil.applyTemplate(template, mockRuntimeContext, resolver));
}
Aggregations