}
public void testSuccessPaths() {
startTest();
String testName = CO_TEST_NAME + "string_" + System.currentTimeMillis(); //$NON-NLS-1$
SimpleParameterProvider parameterProvider = new SimpleParameterProvider();
IRuntimeContext context =
run( "/test/platform/ContentOutputTest.xaction", parameterProvider, testName, CO_TEST_EXTN ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertEquals(
Messages.getInstance().getString( "BaseTest.USER_RUNNING_ACTION_SEQUENCE" ), IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus() ); //$NON-NLS-1$
IActionParameter rtn = context.getOutputParameter( "content" ); //$NON-NLS-1$
assertNotNull( rtn );
InputStream is = this.getInputStreamFromOutput( testName, CO_TEST_EXTN );
assertNotNull( is ); // Did the test execute properly...
String lookingFor = "This is sample output from the content-output component."; //$NON-NLS-1$
String wasRead = FileHelper.getStringFromInputStream( is );
assertTrue( wasRead.startsWith( lookingFor ) );
// Test different path - Byte Array Output Stream
lookingFor = "This is as sample bytearray output stream"; //$NON-NLS-1$
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
baos.write( lookingFor.getBytes() );
} catch ( Exception ex ) {
fail();
}
testName = CO_TEST_NAME + "ByteArrayOutputStream_" + System.currentTimeMillis(); //$NON-NLS-1$
parameterProvider.setParameter( "CONTENTOUTPUT", baos ); //$NON-NLS-1$
context = run( "/test/platform/ContentOutputTest_Bytearray.xaction", parameterProvider, testName, CO_TEST_EXTN ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertEquals( IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus() );
is = this.getInputStreamFromOutput( testName, CO_TEST_EXTN );
assertNotNull( is ); // Did the test execute properly...
wasRead = FileHelper.getStringFromInputStream( is );
FileHelper.getStringFromFile( new File( PentahoSystem.getApplicationContext().getSolutionPath(
"test/datasource/books.xml" ) ) ); //$NON-NLS-1$
try {
FileHelper.getBytesFromFile( new File( PentahoSystem.getApplicationContext().getSolutionPath(
"test/datasource/books.xml" ) ) ); //$NON-NLS-1$
} catch ( IOException io ) {
// do nothing
}
File f = null;
FileHelper.getStringFromFile( f );
assertTrue( wasRead.startsWith( lookingFor ) );
// Test different path - InputStream
testName = CO_TEST_NAME + "ByteArrayInputStream_" + System.currentTimeMillis(); //$NON-NLS-1$
lookingFor = "This is as a simple bytearray input stream"; //$NON-NLS-1$
ByteArrayInputStream bais = new ByteArrayInputStream( lookingFor.getBytes() );
parameterProvider.setParameter( "CONTENTOUTPUT", bais ); //$NON-NLS-1$
context = run( "/test/platform/ContentOutputTest_Bytearray.xaction", parameterProvider, testName, CO_TEST_EXTN ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertEquals( IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus() );
is = this.getInputStreamFromOutput( testName, CO_TEST_EXTN );
assertNotNull( is ); // Did the test execute properly...
String newText = FileHelper.getStringFromInputStream( is );