Search in sources :

Example 36 with ISolutionEngine

use of org.pentaho.platform.api.engine.ISolutionEngine in project pentaho-platform by pentaho.

the class GlobalOutputIT method testEmptyActionSequence.

public void testEmptyActionSequence() {
    startTest();
    List messages = new ArrayList();
    String instanceId = null;
    IPentahoSession session = new StandaloneSession("system");
    PentahoSessionHolder.setSession(session);
    ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class);
    solutionEngine.setLoggingLevel(ILogger.ERROR);
    solutionEngine.init(session);
    String baseUrl = PentahoSystem.getApplicationContext().getBaseUrl();
    HashMap parameterProviderMap = new HashMap();
    IPentahoUrlFactory urlFactory = new SimpleUrlFactory(baseUrl);
    try {
        File file = new File(getSolutionPath() + "/samples/platform/SetGlobalOutputTest.xaction");
        StringBuilder str = new StringBuilder();
        Reader 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);
        IRuntimeContext runtimeContext = solutionEngine.execute(xactionStr, "SetGlobalOutputTest.xaction", "empty action sequence test", false, true, instanceId, false, parameterProviderMap, null, null, urlFactory, // $NON-NLS-1$ //$NON-NLS-2$
        messages);
        assertNotNull("RuntimeContext is null", runtimeContext);
        assertEquals("Action sequence execution failed", runtimeContext.getStatus(), IRuntimeContext.RUNTIME_STATUS_SUCCESS);
        IParameterProvider provider = PentahoSystem.getGlobalParameters();
        // $NON-NLS-1$
        String parameter = provider.getStringParameter("GLOBAL_TEST", null);
        assertNotNull(parameter);
        // $NON-NLS-1$
        assertEquals("This is a test", parameter);
    } catch (Exception e) {
        // we should not get here
        e.printStackTrace();
        assertTrue(e.getMessage(), false);
    }
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) HashMap(java.util.HashMap) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) Reader(java.io.Reader) FileReader(java.io.FileReader) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) ArrayList(java.util.ArrayList) List(java.util.List) FileReader(java.io.FileReader) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) File(java.io.File) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext)

Example 37 with ISolutionEngine

use of org.pentaho.platform.api.engine.ISolutionEngine in project pentaho-platform by pentaho.

the class ViewActionServletIT method testBackgroundExecutionNoExecutor.

/**
 * This test covers execution without background parameter. In that case <code>servlet.error()</code>
 * wouldn't be executed.
 *
 * @throws ServletException
 * @throws IOException
 */
@Test
public void testBackgroundExecutionNoExecutor() throws ServletException, IOException {
    when(request.getParameter(eq("background"))).thenReturn(Boolean.TRUE.toString());
    final String actionPath = "test-path";
    when(request.getParameter(eq("path"))).thenReturn(actionPath);
    final String instanceID = "instance-id";
    when(request.getParameter(eq("instance-id"))).thenReturn(instanceID);
    final ServletOutputStream outputStream = mock(ServletOutputStream.class);
    when(response.getOutputStream()).thenReturn(outputStream);
    final ISolutionEngine solutionEngine = mock(ISolutionEngine.class);
    final IRuntimeContext runtime = mock(IRuntimeContext.class);
    when(runtime.getStatus()).thenReturn(IRuntimeContext.RUNTIME_STATUS_SUCCESS);
    when(solutionEngine.execute(eq(actionPath), eq(servlet.getClass().getName()), eq(false), eq(true), eq(instanceID), eq(true), any(Map.class), any(IOutputHandler.class), any(IActionCompleteListener.class), any(IPentahoUrlFactory.class), any(List.class))).thenReturn(runtime);
    mp.defineInstance(ISolutionEngine.class, solutionEngine);
    final IMessageFormatter messageFormatter = mock(IMessageFormatter.class);
    mp.defineInstance(IMessageFormatter.class, messageFormatter);
    servlet.service(request, response);
    verify(servlet).error(matches(".*ERROR_0001.*"));
    verify(outputStream).write(any(byte[].class));
    verify(messageFormatter).formatSuccessMessage(eq("text/html"), eq(runtime), any(StringBuffer.class), anyBoolean(), anyBoolean());
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IOutputHandler(org.pentaho.platform.api.engine.IOutputHandler) IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) IMessageFormatter(org.pentaho.platform.api.engine.IMessageFormatter) ServletOutputStream(javax.servlet.ServletOutputStream) List(java.util.List) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) Map(java.util.Map) IActionCompleteListener(org.pentaho.platform.api.engine.IActionCompleteListener) Test(org.junit.Test)

Aggregations

ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)37 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)27 ArrayList (java.util.ArrayList)26 HashMap (java.util.HashMap)25 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)22 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)13 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)11 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)9 IPentahoUrlFactory (org.pentaho.platform.api.engine.IPentahoUrlFactory)9 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)5 OutputStream (java.io.OutputStream)4 Iterator (java.util.Iterator)4 Map (java.util.Map)4 File (java.io.File)3 FileReader (java.io.FileReader)3 IOException (java.io.IOException)3 Reader (java.io.Reader)3 BigDecimal (java.math.BigDecimal)3