use of org.pentaho.platform.api.engine.IPentahoUrlFactory in project pentaho-platform by pentaho.
the class ChartbeansIT method testChartbeansActionComponentOFC.
@SuppressWarnings("deprecation")
@Test
public void testChartbeansActionComponentOFC() {
microPlatform.init();
IPentahoUrlFactory urlFactory = new SimpleUrlFactory("");
ArrayList messages = new ArrayList();
SimpleParameterProvider parameterProvider = new SimpleParameterProvider();
// $NON-NLS-1$ //$NON-NLS-2$
parameterProvider.setParameter("solution", "test");
// $NON-NLS-1$ //$NON-NLS-2$
parameterProvider.setParameter("path", "chartbeans");
// $NON-NLS-1$ //$NON-NLS-2$
parameterProvider.setParameter("action", "Chartbeans_All_Inclusive_OFC.xaction");
ActionComponent component = new ActionComponent("test/chartbeans/Chartbeans_All_Inclusive_OFC.xaction", null, IOutputHandler.OUTPUT_TYPE_DEFAULT, urlFactory, // $NON-NLS-1$
messages);
component.setParameterProvider(IParameterProvider.SCOPE_REQUEST, parameterProvider);
component.validate(session, null);
// $NON-NLS-1$ //$NON-NLS-2$
OutputStream outputStream = getOutputStream("Chartbeans.testChartbeansAllInclusive_OFC", ".html");
// $NON-NLS-1$
String result = component.getContent("text/html");
try {
outputStream.write(result.getBytes());
// $NON-NLS-1$
assertTrue(result.startsWith("<html><head>"));
// $NON-NLS-1$
assertTrue(result.indexOf("function getChartData") > 0);
// $NON-NLS-1$
assertTrue(result.indexOf("/*JSON*/") > 0);
// $NON-NLS-1$
assertTrue(result.indexOf("/*END_JSON*/") > 0);
// $NON-NLS-1$
assertTrue(result.indexOf("</body></html>") > 0);
} catch (Exception e) {
// $NON-NLS-1$
assertTrue("An exception has been thrown: " + e.getMessage(), false);
}
}
use of org.pentaho.platform.api.engine.IPentahoUrlFactory in project pentaho-platform by pentaho.
the class BaseTest method run.
public IRuntimeContext run(ISolutionEngine solutionEngine, String actionPath, String instanceId, boolean persisted, IParameterProvider parameterProvider, IOutputHandler outputHandler) {
assertTrue(initOk);
// $NON-NLS-1$
info(Messages.getInstance().getString("BaseTest.INFO_START_TEST_MSG", actionPath));
info(actionPath);
// $NON-NLS-1$
String baseUrl = "";
HashMap<String, IParameterProvider> parameterProviderMap = new HashMap<String, IParameterProvider>();
parameterProviderMap.put(IParameterProvider.SCOPE_REQUEST, parameterProvider);
IPentahoUrlFactory urlFactory = new SimpleUrlFactory(baseUrl);
dispose();
context = solutionEngine.execute(actionPath, Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_TEST"), false, true, instanceId, persisted, parameterProviderMap, outputHandler, this, urlFactory, // $NON-NLS-1$
messages);
// $NON-NLS-1$
info(Messages.getInstance().getString("BaseTest.INFO_FINISH_TEST_MSG", actionPath));
return context;
}
use of org.pentaho.platform.api.engine.IPentahoUrlFactory in project pentaho-platform by pentaho.
the class SolutionEngineAgent method execute.
public int execute() {
PentahoSystem.systemEntryPoint();
try {
// create a generic session object
StandaloneSession session = new StandaloneSession(userId);
solutionEngine = PentahoSystem.get(SolutionEngine.class, session);
solutionEngine.init(session);
SimpleParameterProvider parameterProvider = new SimpleParameterProvider(parameters);
HashMap<String, IParameterProvider> parameterProviderMap = new HashMap<String, IParameterProvider>();
parameterProviderMap.put(IParameterProvider.SCOPE_REQUEST, parameterProvider);
IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
// $NON-NLS-1$
IPentahoUrlFactory urlFactory = new SimpleUrlFactory(requestContext.getContextPath());
String processName = description;
boolean persisted = false;
List messages = new ArrayList();
outputStream = new ByteArrayOutputStream(0);
SimpleOutputHandler outputHandler = null;
if (outputStream != null) {
outputHandler = new SimpleOutputHandler(outputStream, false);
outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
}
solutionEngine.execute(actionSequence, processName, false, true, null, persisted, parameterProviderMap, outputHandler, null, urlFactory, messages);
} finally {
PentahoSystem.systemExitPoint();
}
return solutionEngine.getStatus();
}
use of org.pentaho.platform.api.engine.IPentahoUrlFactory in project pentaho-platform by pentaho.
the class SolutionHelper method execute.
/**
* Runs an action sequence. This method uses the base URL set by the Application Context
*
* @param description
* An identifier for this process. This is used for auditing and logging purposes only.
* @param session
* The user session that is requesting this execution. This is used for auditing and logging and also
* can be used in action sequences (for example to filter data)
* @param actionSequence
* Path to the action sequence file
* @param parameters
* Parameters to be passed to the action sequence
* @param outputStream
* The output stream for content generated by the action sequence. Can be null.
* @param execListener
* An execution listener for feedback during execution. Can be null.
* @return
*/
public static ISolutionEngine execute(final String description, final IPentahoSession session, final String actionSequence, final Map parameters, OutputStream outputStream, final IExecutionListener execListener, final boolean collateMessages, final boolean manageHibernate) {
if (manageHibernate) {
PentahoSystem.systemEntryPoint();
}
ISolutionEngine solutionEngine = null;
try {
solutionEngine = PentahoSystem.get(ISolutionEngine.class, session);
solutionEngine.init(session);
solutionEngine.setlistener(execListener);
SimpleParameterProvider parameterProvider = new SimpleParameterProvider(parameters);
IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
String url = requestContext.getContextPath();
// Modifications by Ezequiel Cuellar
// Old code.
// String baseUrl = PentahoSystem.getApplicationContext().getBaseUrl();
// New code. Since the SubActionComponent is being instantiated below to return feedback
// it is necesary to configure the baseUrl to include the ViewAction.
Object actionUrlComponent = parameters.get(StandardSettings.ACTION_URL_COMPONENT);
if ((actionUrlComponent != null) && (actionUrlComponent.toString().length() > 0)) {
url += actionUrlComponent.toString();
} else {
// $NON-NLS-1$
url += "ViewAction?";
}
HashMap<String, IParameterProvider> parameterProviderMap = new HashMap<String, IParameterProvider>();
parameterProviderMap.put(IParameterProvider.SCOPE_REQUEST, parameterProvider);
IPentahoUrlFactory urlFactory = new SimpleUrlFactory(url);
String processName = description;
boolean persisted = false;
// for now, the messages list needs to be untyped since we may put exceptions as well as strings in it
List<?> messages = null;
if (collateMessages) {
messages = new ArrayList();
}
if (outputStream == null) {
outputStream = new ByteArrayOutputStream(0);
}
SimpleOutputHandler outputHandler = null;
if (outputStream != null) {
// Modifications by Ezequiel Cuellar
// Old code.
// outputHandler = new SimpleOutputHandler(outputStream, false);
// New code. Without setting the allowFeedback parameter to true it is assumed that SubActionComponent
// instances
// are never capable of returning feedback which may not always be the case.
outputHandler = new SimpleOutputHandler(outputStream, true);
outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
}
solutionEngine.execute(actionSequence, processName, false, true, null, persisted, parameterProviderMap, outputHandler, null, urlFactory, messages);
} finally {
if (manageHibernate) {
PentahoSystem.systemExitPoint();
}
}
return solutionEngine;
}
use of org.pentaho.platform.api.engine.IPentahoUrlFactory in project pentaho-platform by pentaho.
the class ReportingIT method testActionComponent.
/*
* public void testBIRTReport1() { startTest(); SimpleParameterProvider parameterProvider = new
* SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream
* outputStream = getOutputStream("ReportingTest.testBIRTReport1-a", ".html"); //$NON-NLS-1$ //$NON-NLS-2$
* SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); StandaloneSession session = new
* StandaloneSession(Messages.getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$ IRuntimeContext context = run(
* "test", "reporting", "quadrant-budget-hsql.xaction", null, false, parameterProvider, outputHandler, session);
* //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ assertEquals(
* Messages.getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
* context.getStatus()); //$NON-NLS-1$ outputStream = getOutputStream("ReportingTest.testBIRTReport1-b", ".pdf");
* //$NON-NLS-1$ //$NON-NLS-2$ outputHandler = new SimpleOutputHandler(outputStream, true);
* parameterProvider.setParameter("type", "pdf"); //$NON-NLS-1$ //$NON-NLS-2$ context = run( "test", "reporting",
* "quadrant-budget-hsql.xaction", null, false, parameterProvider, outputHandler, session); //$NON-NLS-1$
* //$NON-NLS-2$ //$NON-NLS-3$ assertEquals( Messages.getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
* IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ finishTest(); }
*
* public void testBIRTReport4() { startTest(); SimpleParameterProvider parameterProvider = new
* SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$
* parameterProvider.setParameter("REGION", "Eastern"); //$NON-NLS-1$ //$NON-NLS-2$
* parameterProvider.setParameter("DEPARTMENT", "Finance"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream outputStream =
* getOutputStream("ReportingTest.testBIRTReport4", ".html"); //$NON-NLS-1$ //$NON-NLS-2$ SimpleOutputHandler
* outputHandler = new SimpleOutputHandler(outputStream, true); StandaloneSession session = new
* StandaloneSession(Messages.getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$ IRuntimeContext context = run(
* "test", "reporting", "quadrant-budget-for-region-and-dept-to-repository.xaction", null, false, parameterProvider,
* outputHandler, session); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ assertEquals(
* Messages.getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
* context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success finishTest(); }
*
* public void testBIRTIntparm() { startTest(); SimpleParameterProvider parameterProvider = new
* SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$
* parameterProvider.setParameter("intparm", "300000"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream outputStream =
* getOutputStream("ReportingTest.testIntParm", ".html"); //$NON-NLS-1$ //$NON-NLS-2$ SimpleOutputHandler
* outputHandler = new SimpleOutputHandler(outputStream, true); StandaloneSession session = new
* StandaloneSession(Messages.getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$ IRuntimeContext context = run(
* "test", "reporting", "BIRT-quadrant-budget-hsql-intparm.xaction", null, false, parameterProvider, outputHandler,
* session); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ assertEquals(
* Messages.getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
* context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success finishTest(); }
*/
/*
* public void testJasperReports1() { startTest(); SimpleParameterProvider parameterProvider = new
* SimpleParameterProvider(); parameterProvider.setParameter("REGION", "Eastern"); //$NON-NLS-1$ //$NON-NLS-2$
* OutputStream outputStream = getOutputStream("ReportingTest.testJasperReports1", ".html"); //$NON-NLS-1$
* //$NON-NLS-2$ SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); StandaloneSession
* session = new StandaloneSession(Messages.getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$ IRuntimeContext
* context = run( "test", "reporting", "jasper-reports-test-1.xaction", null, false, parameterProvider, outputHandler,
* session); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ assertEquals(
* Messages.getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
* context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success finishTest(); }
*
* public void testJasperReports2() { startTest(); SimpleParameterProvider parameterProvider = new
* SimpleParameterProvider(); parameterProvider.setParameter("REGION", "Eastern"); //$NON-NLS-1$ //$NON-NLS-2$
* parameterProvider.setParameter("type", "pdf"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream outputStream =
* getOutputStream("ReportingTest.testJasperReports2", ".pdf"); //$NON-NLS-1$ //$NON-NLS-2$ SimpleOutputHandler
* outputHandler = new SimpleOutputHandler(outputStream, true); StandaloneSession session = new
* StandaloneSession(Messages.getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$ IRuntimeContext context = run(
* "test", "reporting", "jasper-reports-test-2.xaction", null, false, parameterProvider, outputHandler, session);
* //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ assertEquals(
* Messages.getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
* context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success finishTest(); }
*/
/*
* public void testBIRTReport3() { startTest(); SimpleParameterProvider parameterProvider = new
* SimpleParameterProvider(); parameterProvider.setParameter("type", "pdf"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream
* outputStream = getOutputStream("ReportingTest.testBIRTReport3", ".pdf"); //$NON-NLS-1$ //$NON-NLS-2$
* SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); StandaloneSession session = new
* StandaloneSession(Messages.getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$ IRuntimeContext context = run(
* "test", "reporting", "quadrant-budget-for-region-hsql.xaction", null, false, parameterProvider, outputHandler,
* session); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ assertEquals(
* Messages.getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
* context.getStatus()); //$NON-NLS-1$ finishTest(); }
*/
public void testActionComponent() {
startTest();
IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
IPentahoUrlFactory urlFactory = new SimpleUrlFactory(requestContext.getContextPath());
ArrayList messages = new ArrayList();
SimpleParameterProvider parameterProvider = new SimpleParameterProvider();
// $NON-NLS-1$ //$NON-NLS-2$
parameterProvider.setParameter("solution", "test");
// $NON-NLS-1$ //$NON-NLS-2$
parameterProvider.setParameter("path", "reporting");
// $NON-NLS-1$ //$NON-NLS-2$
parameterProvider.setParameter("action", "custom-parameter-page-example.xaction");
ActionComponent component = new ActionComponent("test/reporting/custom-parameter-page-example.xaction", null, IOutputHandler.OUTPUT_TYPE_DEFAULT, urlFactory, // $NON-NLS-1$
messages);
component.setParameterProvider(IParameterProvider.SCOPE_REQUEST, parameterProvider);
StandaloneSession session = // $NON-NLS-1$
new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION"));
component.validate(session, null);
// $NON-NLS-1$ //$NON-NLS-2$
OutputStream outputStream = getOutputStream("ReportingTest.testActionComponent", ".html");
// $NON-NLS-1$
String content = component.getContent("text/html");
try {
outputStream.write(content.getBytes());
} catch (Exception e) {
// ignore
}
finishTest();
}
Aggregations