Search in sources :

Example 26 with StandaloneSession

use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.

the class DashboardWidgetIT method testWidget2.

public void testWidget2() {
    // $NON-NLS-1$
    SimpleUrlFactory urlFactory = new SimpleUrlFactory("");
    ArrayList messages = new ArrayList();
    DashboardWidgetComponent widget = new DashboardWidgetComponent(DashboardWidgetComponent.TYPE_DIAL, getSolutionPath() + "/samples/charts/dashboardwidget1.dial.xml", 200, 200, urlFactory, // $NON-NLS-1$
    messages);
    widget.setValue(49);
    // $NON-NLS-1$
    widget.setTitle("test widget 1");
    // $NON-NLS-1$
    widget.setUnits("");
    // $NON-NLS-1$
    StandaloneSession session = new StandaloneSession("BaseTest.DEBUG_JUNIT_SESSION");
    widget.validate(session, null);
    SimpleParameterProvider requestParameters = new SimpleParameterProvider();
    SimpleParameterProvider sessionParameters = new SimpleParameterProvider();
    widget.setParameterProvider(HttpRequestParameterProvider.SCOPE_REQUEST, requestParameters);
    widget.setParameterProvider(HttpSessionParameterProvider.SCOPE_SESSION, sessionParameters);
    // $NON-NLS-1$
    String content = widget.getContent("text/html");
    // $NON-NLS-1$//$NON-NLS-2$
    OutputStream outputStream = getOutputStream("DashboardWidgetTest.testWidget1", ".html");
    try {
        outputStream.write(content.getBytes());
    } catch (Exception e) {
    // content check will test this
    }
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) IOException(java.io.IOException) DashboardWidgetComponent(org.pentaho.platform.uifoundation.chart.DashboardWidgetComponent) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 27 with StandaloneSession

use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.

the class HTMLComponentIT method testComponent2.

public void testComponent2() {
    startTest();
    // $NON-NLS-1$
    info(Messages.getInstance().getString("HTMLComponentTest.USER_ERRORS_EXPECTED_CONTENT_TYPE_INVALID"));
    // this should fail because the requested content type is not supported
    // $NON-NLS-1$
    String url = "http://www.pentaho.org/demo/news.html";
    // $NON-NLS-1$
    SimpleUrlFactory urlFactory = new SimpleUrlFactory("/testurl?");
    ArrayList messages = new ArrayList();
    // $NON-NLS-1$
    HtmlComponent component = new HtmlComponent(HtmlComponent.TYPE_URL, url, "", urlFactory, messages);
    component.setLoggingLevel(getLoggingLevel());
    // $NON-NLS-1$//$NON-NLS-2$
    OutputStream outputStream = getOutputStream("HTMLComponentTest.testComponent2", ".html");
    // $NON-NLS-1$
    String contentType = "text/xml";
    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 {
        component.validate(session, requestHandler);
        component.handleRequest(outputStream, requestHandler, contentType, parameterProviders);
    } catch (IOException e) {
        e.printStackTrace();
    }
    finishTest();
}
Also used : HashMap(java.util.HashMap) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) HtmlComponent(org.pentaho.platform.uifoundation.component.HtmlComponent) 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) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 28 with StandaloneSession

use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.

the class HTMLComponentIT method testComponent3.

public void testComponent3() {
    startTest();
    // $NON-NLS-1$
    info(Messages.getInstance().getString("HTMLComponentTest.USER_ERRORS_EXPECTED_URL_INVALID"));
    // this should fail because the url is bad
    // $NON-NLS-1$
    String url = "xttp://a";
    // $NON-NLS-1$
    SimpleUrlFactory urlFactory = new SimpleUrlFactory("/testurl?");
    ArrayList messages = new ArrayList();
    HtmlComponent component = new HtmlComponent(HtmlComponent.TYPE_URL, url, Messages.getInstance().getString("HTML.ERROR_0001_NOT_AVAILABLE"), urlFactory, // $NON-NLS-1$
    messages);
    component.setLoggingLevel(getLoggingLevel());
    // $NON-NLS-1$//$NON-NLS-2$
    OutputStream outputStream = getOutputStream("HTMLComponentTest.testComponent3", ".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 {
        component.validate(session, requestHandler);
        component.handleRequest(outputStream, requestHandler, contentType, parameterProviders);
    } catch (IOException e) {
        e.printStackTrace();
    }
    finishTest();
}
Also used : HashMap(java.util.HashMap) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) HtmlComponent(org.pentaho.platform.uifoundation.component.HtmlComponent) 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) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 29 with StandaloneSession

use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.

the class JFreeReportIT method testJFreeReportParameterPage2.

public void testJFreeReportParameterPage2() {
    startTest();
    SimpleParameterProvider parameterProvider = new SimpleParameterProvider();
    // $NON-NLS-1$ //$NON-NLS-2$
    parameterProvider.setParameter("type", "html");
    // $NON-NLS-1$ //$NON-NLS-2$
    OutputStream outputStream = getOutputStream("ReportingTest.testJFreeReportParameterPage2", ".html");
    SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true);
    StandaloneSession session = // $NON-NLS-1$
    new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION"));
    IRuntimeContext context = run("/test/reporting/jfreereport-reports-test-param2.xaction", null, false, parameterProvider, outputHandler, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    session);
    assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS, // $NON-NLS-1$
    context.getStatus());
    // TODO need some validation of success
    finishTest();
}
Also used : 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 30 with StandaloneSession

use of org.pentaho.platform.engine.core.system.StandaloneSession in project pentaho-platform by pentaho.

the class JFreeReportIT method testJFreeReportWithChartActionComponent.

/*
   * public void testJFreeReportParameterPage3() { startTest(); SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream
   * outputStream = getOutputStream("ReportingTest.testJFreeReportParameterPage3", ".html"); //$NON-NLS-1$ //$NON-NLS-2$
   * SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); StandaloneSession session = new
   * StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$ IRuntimeContext
   * context = run( "test", "reporting", "jfreereport-reports-test-param3.xaction", null, false, parameterProvider,
   * outputHandler, session); //$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$ // TODO need some validation of success finishTest(); }
   */
/*
   * public void testJFreeReport1() { startTest(); SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream
   * outputStream = getOutputStream("ReportingTest.JFreeReporthtml", ".html"); //$NON-NLS-1$ //$NON-NLS-2$
   * SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); StandaloneSession session = new
   * StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$ IRuntimeContext
   * context = run( "test", "reporting", "jfreereport-reports-test-1.xaction", null, false, parameterProvider,
   * outputHandler, session); //$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$ // TODO need some validation of success finishTest(); }
   */
/*
   * public void testJFreeReport2() { startTest(); SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "pdf"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream
   * outputStream = getOutputStream("ReportingTest.JFreeReport-2-PDF", ".pdf"); //$NON-NLS-1$ //$NON-NLS-2$
   * SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); StandaloneSession session = new
   * StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$ IRuntimeContext
   * context = run( "test", "reporting", "jfreereport-reports-test-2.xaction", null, false, parameterProvider,
   * outputHandler, session); //$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$ // TODO need some validation of success finishTest(); }
   * 
   * public void testJFreeReport3() { startTest(); SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "xls"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream
   * outputStream = getOutputStream("ReportingTest.JFreeReportxls", ".xls"); //$NON-NLS-1$ //$NON-NLS-2$
   * SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); StandaloneSession session = new
   * StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$ IRuntimeContext
   * context = run( "test", "reporting", "jfreereport-reports-test-1.xaction", null, false, parameterProvider,
   * outputHandler, session); //$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$ // TODO need some validation of success finishTest(); }
   * 
   * public void testJFreeReport4() { startTest(); SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream
   * outputStream = getOutputStream("ReportingTest.JFreeReporthtml", ".html"); //$NON-NLS-1$ //$NON-NLS-2$
   * SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); StandaloneSession session = new
   * StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$ IRuntimeContext
   * context = run( "test", "reporting", "jfreereport-reports-test-1.xaction", null, false, parameterProvider,
   * outputHandler, session); //$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$ // TODO need some validation of success finishTest(); }
   * 
   * public void testJFreeReport5() { startTest(); SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "pdf"); //$NON-NLS-1$ //$NON-NLS-2$
   * parameterProvider.setParameter("solution", getSolutionPath()); //$NON-NLS-1$ //$NON-NLS-2$ IRuntimeContext context
   * = run( "test", "reporting", "jfreereport-reports-file.xaction", parameterProvider, "dummy", "txt"); //$NON-NLS-1$
   * //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ assertEquals(
   * Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
   * context.getStatus()); //$NON-NLS-1$ finishTest(); }
   */
/*
   * public void testJFreeReport6() { startTest(); SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "csv"); //$NON-NLS-1$ //$NON-NLS-2$
   * IRuntimeContext context = run( "test", "reporting", "jfreereport-reports-file.xaction", parameterProvider, "dummy",
   * "txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ assertEquals(
   * Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
   * context.getStatus()); //$NON-NLS-1$ finishTest(); }
   * 
   * public void testJFreeReport7() { startTest(); SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "xls"); //$NON-NLS-1$ //$NON-NLS-2$
   * IRuntimeContext context = run( "test", "reporting", "jfreereport-reports-file.xaction", parameterProvider, "dummy",
   * "txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ assertEquals(
   * Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
   * context.getStatus()); //$NON-NLS-1$ finishTest(); }
   * 
   * public void testJFreeReport8() { startTest(); SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "rtf"); //$NON-NLS-1$ //$NON-NLS-2$
   * IRuntimeContext context = run( "test", "reporting", "jfreereport-reports-file.xaction", parameterProvider, "dummy",
   * "txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ assertEquals(
   * Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
   * context.getStatus()); //$NON-NLS-1$ finishTest(); }
   */
/*
   * public void testJFreeReport9() { startTest(); SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "zip"); //$NON-NLS-1$ //$NON-NLS-2$
   * IRuntimeContext context = run( "test", "reporting", "jfreereport-reports-file.xaction", parameterProvider, "dummy",
   * "txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ assertEquals(
   * Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
   * context.getStatus()); //$NON-NLS-1$ finishTest(); }
   * 
   * public void testJFreeReport10() { startTest(); SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "xml"); //$NON-NLS-1$ //$NON-NLS-2$
   * IRuntimeContext context = run( "test", "reporting", "jfreereport-reports-file.xaction", parameterProvider, "dummy",
   * "txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ assertEquals(
   * Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
   * context.getStatus()); //$NON-NLS-1$ finishTest(); }
   */
public void testJFreeReportWithChartActionComponent() {
    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", "JFree_XQuery_Chart_report.xaction");
    ActionComponent component = new ActionComponent("samples/reporting/JFree_XQuery_Chart_report.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.testJFreeReportWithChartActionComponent", ".html");
    // $NON-NLS-1$
    String content = component.getContent("text/html");
    try {
        outputStream.write(content.getBytes());
    } catch (Exception e) {
    // ignore
    }
    finishTest();
}
Also used : IPentahoRequestContext(org.pentaho.platform.api.engine.IPentahoRequestContext) IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) ActionComponent(org.pentaho.platform.uifoundation.component.ActionComponent) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Aggregations

StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)218 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)74 ArrayList (java.util.ArrayList)46 Authentication (org.springframework.security.core.Authentication)39 Test (org.junit.Test)38 OutputStream (java.io.OutputStream)34 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)30 GrantedAuthority (org.springframework.security.core.GrantedAuthority)30 User (org.springframework.security.core.userdetails.User)30 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)29 UserDetails (org.springframework.security.core.userdetails.UserDetails)29 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)24 File (java.io.File)21 SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)21 StandaloneObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory)21 StandaloneSpringPentahoObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)21 IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)20 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)20 HashMap (java.util.HashMap)16 Before (org.junit.Before)16