Search in sources :

Example 26 with SimpleOutputHandler

use of org.pentaho.platform.engine.core.output.SimpleOutputHandler in project pentaho-platform by pentaho.

the class RuntimeIT method testForcePrompt.

public void testForcePrompt() {
    startTest();
    SimpleParameterProvider parameterProvider = new SimpleParameterProvider();
    // $NON-NLS-1$ //$NON-NLS-2$
    OutputStream outputStream = getOutputStream("RuntimeTest.testForcePrompt", ".html");
    SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true);
    outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_PARAMETERS);
    StandaloneSession session = // $NON-NLS-1$
    new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION"));
    ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, session);
    solutionEngine.setLoggingLevel(getLoggingLevel());
    solutionEngine.init(session);
    solutionEngine.setForcePrompt(true);
    IRuntimeContext context = run(solutionEngine, "/test/reporting/jfreereport-reports-test-param.xaction", null, false, parameterProvider, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    outputHandler);
    assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS, // $NON-NLS-1$
    context.getStatus());
    finishTest();
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) OutputStream(java.io.OutputStream) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 27 with SimpleOutputHandler

use of org.pentaho.platform.engine.core.output.SimpleOutputHandler in project pentaho-platform by pentaho.

the class ChartIT method runTimeSeriesChartTest.

/*
   * public void runPieChartTest(int chartType, String path, String testName) { SimpleUrlFactory urlFactory = new
   * SimpleUrlFactory("/testurl?"); //$NON-NLS-1$ ArrayList messages = new ArrayList();
   * 
   * int chartWidth = 400; int chartHeight = 400; PieDatasetChartComponent pieChartComponent = new
   * PieDatasetChartComponent(chartType, path, chartWidth, chartHeight, urlFactory, messages);
   * 
   * pieChartComponent.setLoggingLevel(ILogger.ERROR); pieChartComponent.setByRow(true);
   * 
   * pieChartComponent.setDataAction("/test-src/solutions/test/rules/department_stats.xaction", "rule-result");
   * //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
   * 
   * OutputStream outputStream = getOutputStream(SOLUTION_PATH, "ChartTest." + testName, ".html");
   * //$NON-NLS-1$//$NON-NLS-2$ String contentType = "text/html"; //$NON-NLS-1$
   * 
   * SimpleParameterProvider requestParameters = new SimpleParameterProvider(); SimpleParameterProvider
   * sessionParameters = new SimpleParameterProvider();
   * 
   * HashMap parameterProviders = new HashMap(); parameterProviders.put(IParameterProvider.SCOPE_REQUEST,
   * requestParameters); parameterProviders.put(IParameterProvider.SCOPE_SESSION, sessionParameters); StandaloneSession
   * session = new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
   * 
   * SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, false); BaseRequestHandler requestHandler
   * = new BaseRequestHandler(session, null, outputHandler, null, urlFactory);
   * 
   * try { pieChartComponent.validate(session, requestHandler); pieChartComponent.handleRequest(outputStream,
   * requestHandler, contentType, parameterProviders); } catch (IOException e) { e.printStackTrace(); }
   * 
   * }
   */
public void runTimeSeriesChartTest(int chartType, String path, String testName) {
    // $NON-NLS-1$
    SimpleUrlFactory urlFactory = new SimpleUrlFactory("/testurl?");
    ArrayList messages = new ArrayList();
    int chartWidth = 400;
    int chartHeight = 400;
    TimeSeriesCollectionChartComponent timeSeriesChartComponent = new TimeSeriesCollectionChartComponent(chartType, path, chartWidth, chartHeight, urlFactory, messages);
    timeSeriesChartComponent.setLoggingLevel(ILogger.ERROR);
    // $NON-NLS-1$ //$NON-NLS-2$
    timeSeriesChartComponent.setDataAction("/test/rules/department_stats.xaction", "rule-result");
    // $NON-NLS-1$//$NON-NLS-2$
    OutputStream outputStream = getOutputStream("ChartTest." + testName, ".html");
    // $NON-NLS-1$
    String contentType = "text/html";
    SimpleParameterProvider requestParameters = new SimpleParameterProvider();
    SimpleParameterProvider sessionParameters = new SimpleParameterProvider();
    HashMap parameterProviders = new HashMap();
    parameterProviders.put(IParameterProvider.SCOPE_REQUEST, requestParameters);
    parameterProviders.put(IParameterProvider.SCOPE_SESSION, sessionParameters);
    StandaloneSession session = // $NON-NLS-1$
    new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION"));
    SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, false);
    BaseRequestHandler requestHandler = new BaseRequestHandler(session, null, outputHandler, null, urlFactory);
    try {
        timeSeriesChartComponent.validate(session, requestHandler);
        timeSeriesChartComponent.handleRequest(outputStream, requestHandler, contentType, parameterProviders);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : HashMap(java.util.HashMap) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) IOException(java.io.IOException) BaseRequestHandler(org.pentaho.platform.engine.services.BaseRequestHandler) TimeSeriesCollectionChartComponent(org.pentaho.platform.uifoundation.chart.TimeSeriesCollectionChartComponent) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 28 with SimpleOutputHandler

use of org.pentaho.platform.engine.core.output.SimpleOutputHandler in project pentaho-platform by pentaho.

the class ChartIT method runCategoryChartTest.

/*
   * public void testChartComponent_AreaChart() { SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$
   * parameterProvider.setParameter("chart_type", "area"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream outputStream =
   * getOutputStream(SOLUTION_PATH, "Chart_Area", ".html"); //$NON-NLS-1$ //$NON-NLS-2$ StandaloneSession session = new
   * StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
   * SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); IRuntimeContext context = run(
   * SOLUTION_PATH + "/test/charts/", "ChartComponent_ChartTypes.xaction", parameterProvider, outputHandler);
   * //$NON-NLS-1$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
   * IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success
   * }
   */
/*
   * public void testChartComponent_BarChart() { SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$
   * parameterProvider.setParameter("chart_type", "bar"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream outputStream =
   * getOutputStream(SOLUTION_PATH, "Chart_Bar", ".html"); //$NON-NLS-1$ //$NON-NLS-2$ StandaloneSession session = new
   * StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
   * SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); IRuntimeContext context = run(
   * SOLUTION_PATH + "/test/charts/", "ChartComponent_ChartTypes.xaction", parameterProvider, outputHandler);
   * //$NON-NLS-1$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
   * IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success
   * }
   */
/*
   * public void testChartComponent_BubbleChart() { SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$
   * parameterProvider.setParameter("chart_type", "bubble"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream outputStream =
   * getOutputStream(SOLUTION_PATH, "Chart_Bubble", ".html"); //$NON-NLS-1$ //$NON-NLS-2$ StandaloneSession session =
   * new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
   * SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); IRuntimeContext context = run(
   * SOLUTION_PATH + "/test/charts/", "ChartComponent_ChartTypes.xaction", parameterProvider, outputHandler);
   * //$NON-NLS-1$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
   * IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success
   * }
   */
/*
   * public void testChartComponent_BarLineComboChart() { SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$
   * parameterProvider.setParameter("chart_type", "barline"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream outputStream =
   * getOutputStream(SOLUTION_PATH, "Chart_BarLineCombo", ".html"); //$NON-NLS-1$ //$NON-NLS-2$ StandaloneSession
   * session = new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
   * SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); IRuntimeContext context = run(
   * SOLUTION_PATH + "/test/charts/", "ChartComponent_ChartTypes.xaction", parameterProvider, outputHandler);
   * //$NON-NLS-1$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
   * IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success
   * }
   * 
   * public void testChartComponent_DialChart() { SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$
   * parameterProvider.setParameter("chart_type", "dial"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream outputStream =
   * getOutputStream(SOLUTION_PATH, "Chart_Dial", ".html"); //$NON-NLS-1$ //$NON-NLS-2$ StandaloneSession session = new
   * StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
   * SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); IRuntimeContext context = run(
   * SOLUTION_PATH + "/test/charts/", "ChartComponent_ChartTypes.xaction", parameterProvider, outputHandler);
   * //$NON-NLS-1$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
   * IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success
   * }
   */
/*
   * public void testChartComponent_LineChart() { SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$
   * parameterProvider.setParameter("chart_type", "line"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream outputStream =
   * getOutputStream(SOLUTION_PATH, "Chart_Line", ".html"); //$NON-NLS-1$ //$NON-NLS-2$ StandaloneSession session = new
   * StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
   * SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); IRuntimeContext context = run(
   * SOLUTION_PATH + "/test/charts/", "ChartComponent_ChartTypes.xaction", parameterProvider, outputHandler);
   * //$NON-NLS-1$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
   * IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success
   * }
   */
/*
   * public void testChartComponent_PieChart() { SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$
   * parameterProvider.setParameter("chart_type", "pie"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream outputStream =
   * getOutputStream(SOLUTION_PATH, "Chart_Pie", ".html"); //$NON-NLS-1$ //$NON-NLS-2$ StandaloneSession session = new
   * StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
   * SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); IRuntimeContext context = run(
   * SOLUTION_PATH + "/test/charts/", "ChartComponent_ChartTypes.xaction", parameterProvider, outputHandler);
   * //$NON-NLS-1$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
   * IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success
   * }
   */
/*
   * public void testChartComponent_PieGridChart() { SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$
   * parameterProvider.setParameter("chart_type", "piegrid"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream outputStream =
   * getOutputStream(SOLUTION_PATH, "Chart_PieGrid", ".html"); //$NON-NLS-1$ //$NON-NLS-2$ StandaloneSession session =
   * new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
   * SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); IRuntimeContext context = run(
   * SOLUTION_PATH + "/samples/charts/", "ChartComponent_ChartTypes.xaction", parameterProvider, outputHandler);
   * //$NON-NLS-1$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
   * IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success
   * }
   */
/*
   * public void testChartComponent_TimeSeriesChart() { SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$
   * parameterProvider.setParameter("chart_type", "timeseries"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream outputStream =
   * getOutputStream(SOLUTION_PATH, "Chart_TimeSeries", ".html"); //$NON-NLS-1$ //$NON-NLS-2$ StandaloneSession session
   * = new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
   * SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); IRuntimeContext context = run(
   * SOLUTION_PATH + "/test/charts/", "ChartComponent_ChartTypes.xaction", parameterProvider, outputHandler);
   * //$NON-NLS-1$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
   * IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success
   * }
   */
/*
   * public void testTimeSeriesChartCollection() { SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream
   * outputStream = getOutputStream(SOLUTION_PATH, "Chart_TimeSeries", ".html"); //$NON-NLS-1$ //$NON-NLS-2$
   * StandaloneSession session = new
   * StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
   * SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); IRuntimeContext context = run(
   * SOLUTION_PATH + "/test/charts/", "ChartComponent_ChartTypes.xaction", parameterProvider, outputHandler);
   * //$NON-NLS-1$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
   * IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success
   * }
   */
/*
   * public void testXYZChart() { SimpleParameterProvider parameterProvider = new SimpleParameterProvider();
   * parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream outputStream =
   * getOutputStream(SOLUTION_PATH, "Chart_XYZ", ".html"); //$NON-NLS-1$ //$NON-NLS-2$
   * parameterProvider.setParameter("chart_type", "xy"); //$NON-NLS-1$ //$NON-NLS-2$ StandaloneSession session = new
   * StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
   * SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); IRuntimeContext context = run(
   * SOLUTION_PATH + "/test/charts/", "ChartComponent_ChartTypes.xaction", parameterProvider, outputHandler);
   * //$NON-NLS-1$ assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"),
   * IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success
   * }
   */
public void runCategoryChartTest(int chartType, String path, String testName) {
    // $NON-NLS-1$
    SimpleUrlFactory urlFactory = new SimpleUrlFactory("/testurl?");
    ArrayList messages = new ArrayList();
    int chartWidth = 400;
    int chartHeight = 400;
    CategoryDatasetChartComponent categoryChartComponent = new CategoryDatasetChartComponent(chartType, path, chartWidth, chartHeight, urlFactory, messages);
    categoryChartComponent.setLoggingLevel(ILogger.ERROR);
    categoryChartComponent.setByRow(true);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    categoryChartComponent.setDataAction("/test-src/solution/test/rules/department_stats.xaction", "rule-result");
    // $NON-NLS-1$//$NON-NLS-2$
    OutputStream outputStream = getOutputStream("ChartTest." + testName, ".html");
    // $NON-NLS-1$
    String contentType = "text/html";
    SimpleParameterProvider requestParameters = new SimpleParameterProvider();
    SimpleParameterProvider sessionParameters = new SimpleParameterProvider();
    HashMap parameterProviders = new HashMap();
    parameterProviders.put(IParameterProvider.SCOPE_REQUEST, requestParameters);
    parameterProviders.put(IParameterProvider.SCOPE_SESSION, sessionParameters);
    StandaloneSession session = // $NON-NLS-1$
    new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION"));
    // $NON-NLS-1$
    UserSession usession = new UserSession("Admin", Locale.US, true, requestParameters);
    usession.doStartupActions(requestParameters);
    // $NON-NLS-1$
    UserSession usessionNoAuth = new UserSession("Admin", Locale.US, requestParameters);
    usessionNoAuth.doStartupActions(requestParameters);
    SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, false);
    BaseRequestHandler requestHandler = new BaseRequestHandler(session, null, outputHandler, null, urlFactory);
    try {
        categoryChartComponent.validate(session, requestHandler);
        categoryChartComponent.handleRequest(outputStream, requestHandler, contentType, parameterProviders);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : HashMap(java.util.HashMap) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) IOException(java.io.IOException) BaseRequestHandler(org.pentaho.platform.engine.services.BaseRequestHandler) CategoryDatasetChartComponent(org.pentaho.platform.uifoundation.chart.CategoryDatasetChartComponent) UserSession(org.pentaho.platform.engine.core.system.UserSession) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 29 with SimpleOutputHandler

use of org.pentaho.platform.engine.core.output.SimpleOutputHandler 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());
}
Also used : OutputStream(java.io.OutputStream) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 30 with SimpleOutputHandler

use of org.pentaho.platform.engine.core.output.SimpleOutputHandler in project pentaho-platform by pentaho.

the class ContentGeneratorUtil method getContentAsString.

/**
 * Convenience method for executing a content generator and getting back it's output as a string. Useful for
 * testing.
 *
 * @param cg
 *          the content generator to execute
 * @return the output of the content generator
 * @throws Exception
 *           if there was a problem creating the content
 */
public static String getContentAsString(IContentGenerator cg) throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IOutputHandler outputHandler = new SimpleOutputHandler(out, false);
    Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
    SimpleParameterProvider requestParams = new SimpleParameterProvider();
    parameterProviders.put(IParameterProvider.SCOPE_REQUEST, requestParams);
    // $NON-NLS-1$
    SimpleUrlFactory urlFactory = new SimpleUrlFactory("?");
    List<String> messages = new ArrayList<String>();
    cg.setOutputHandler(outputHandler);
    IMimeTypeListener mimeTypeListener = new IMimeTypeListener() {

        @SuppressWarnings("unused")
        public String mimeType = null;

        @SuppressWarnings("unused")
        public String name = null;

        public void setMimeType(String mimeType) {
            this.mimeType = mimeType;
        }

        public void setName(String name) {
            this.name = name;
        }
    };
    outputHandler.setMimeTypeListener(mimeTypeListener);
    cg.setMessagesList(messages);
    cg.setParameterProviders(parameterProviders);
    cg.setSession(PentahoSessionHolder.getSession());
    cg.setUrlFactory(urlFactory);
    cg.createContent();
    String content = new String(out.toByteArray());
    return content;
}
Also used : IMimeTypeListener(org.pentaho.platform.api.engine.IMimeTypeListener) IOutputHandler(org.pentaho.platform.api.engine.IOutputHandler) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Aggregations

SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)43 OutputStream (java.io.OutputStream)25 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)24 SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)22 ArrayList (java.util.ArrayList)20 HashMap (java.util.HashMap)20 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)17 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)15 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)12 IOException (java.io.IOException)8 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)8 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)6 IContentItem (org.pentaho.platform.api.repository.IContentItem)6 BaseRequestHandler (org.pentaho.platform.engine.services.BaseRequestHandler)6 IOutputHandler (org.pentaho.platform.api.engine.IOutputHandler)5 Iterator (java.util.Iterator)4 List (java.util.List)4 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)4 IPentahoUrlFactory (org.pentaho.platform.api.engine.IPentahoUrlFactory)4