Search in sources :

Example 31 with SimpleUrlFactory

use of org.pentaho.platform.util.web.SimpleUrlFactory in project pentaho-platform by pentaho.

the class BaseTestCase method run.

public IRuntimeContext run(String actionSequencePath, String actionSequence, IParameterProvider parameterProvider, IOutputHandler outputHandler) {
    List messages = new ArrayList();
    String instanceId = null;
    ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, session);
    solutionEngine.setLoggingLevel(ILogger.ERROR);
    solutionEngine.init(session);
    HashMap parameterProviderMap = new HashMap();
    IPentahoUrlFactory urlFactory = new SimpleUrlFactory("");
    IRuntimeContext runtimeContext = null;
    Reader reader = null;
    try {
        File file = new File(actionSequencePath + actionSequence);
        StringBuilder str = new StringBuilder();
        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);
        runtimeContext = // $NON-NLS-1$
        solutionEngine.execute(// $NON-NLS-1$
        xactionStr, // $NON-NLS-1$
        actionSequence, // $NON-NLS-1$
        "action sequence test", // $NON-NLS-1$
        false, // $NON-NLS-1$
        true, // $NON-NLS-1$
        instanceId, // $NON-NLS-1$
        false, parameterProviderMap, null, null, urlFactory, messages);
    } catch (Exception e) {
        // we should not get here
        e.printStackTrace();
        assertTrue(e.getMessage(), false);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (Exception ex) {
                ex.printStackTrace();
                assertTrue(ex.getMessage(), false);
            }
        }
    }
    return runtimeContext;
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Reader(java.io.Reader) FileReader(java.io.FileReader) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) List(java.util.List) FileReader(java.io.FileReader) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) File(java.io.File)

Example 32 with SimpleUrlFactory

use of org.pentaho.platform.util.web.SimpleUrlFactory in project pentaho-platform by pentaho.

the class PojoComponentTest method testUnusedInput.

/**
 * Test that unused parameters being passed in do not impact the running of the PojoComponent. A warning is written to
 * the log for user feedback on execution.
 */
public void testUnusedInput() {
    startTest();
    ISolutionEngine solutionEngine = ServiceTestHelper.getSolutionEngine();
    try {
        String xactionStr = ServiceTestHelper.getXAction(SOLUTION_PATH, "test/pojo/pojo-bad4.xaction");
        PojoComponentTest.doneCalled = false;
        PojoComponentTest.executeCalled = false;
        PojoComponentTest.validateCalled = false;
        IRuntimeContext runtimeContext = // $NON-NLS-1$ //$NON-NLS-2$
        solutionEngine.execute(// $NON-NLS-1$ //$NON-NLS-2$
        xactionStr, // $NON-NLS-1$ //$NON-NLS-2$
        "test", // $NON-NLS-1$ //$NON-NLS-2$
        "invalid class setting test", // $NON-NLS-1$ //$NON-NLS-2$
        false, // $NON-NLS-1$ //$NON-NLS-2$
        true, // $NON-NLS-1$ //$NON-NLS-2$
        null, // $NON-NLS-1$ //$NON-NLS-2$
        false, new HashMap(), null, null, new SimpleUrlFactory(""), new ArrayList());
        assertNotNull("RuntimeContext is null", runtimeContext);
        assertEquals("Action sequence succeeded", IRuntimeContext.RUNTIME_STATUS_SUCCESS, runtimeContext.getStatus());
    } catch (Exception e) {
        // we should not get here
        e.printStackTrace();
        assertTrue(e.getMessage(), false);
    }
    finishTest();
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext)

Example 33 with SimpleUrlFactory

use of org.pentaho.platform.util.web.SimpleUrlFactory in project pentaho-platform by pentaho.

the class PojoComponentTest method testSimplePojoInput.

public void testSimplePojoInput() {
    startTest();
    ISolutionEngine solutionEngine = ServiceTestHelper.getSolutionEngine();
    try {
        String xactionStr = ServiceTestHelper.getXAction(SOLUTION_PATH, "test/pojo/pojo1a.xaction");
        PojoComponentTest.doneCalled = false;
        PojoComponentTest.setSessionCalled = false;
        PojoComponentTest.setLoggerCalled = false;
        TestPojo1.int1 = 0;
        TestPojo1.int2 = null;
        SimpleParameterProvider inputs = new SimpleParameterProvider();
        inputs.setParameter("int2", new Integer(22));
        inputs.setParameter("bool2", new Boolean(true));
        inputs.setParameter("long2", new Long(99));
        inputs.setParameter("bigdecimal", new BigDecimal("77.7"));
        inputs.setParameter("float2", new Float(44.4));
        inputs.setParameter("double2", new Double(66.6));
        Map providers = new HashMap();
        providers.put(IParameterProvider.SCOPE_REQUEST, inputs);
        IRuntimeContext runtimeContext = // $NON-NLS-1$ //$NON-NLS-2$
        solutionEngine.execute(// $NON-NLS-1$ //$NON-NLS-2$
        xactionStr, // $NON-NLS-1$ //$NON-NLS-2$
        "test1a.xaction", // $NON-NLS-1$ //$NON-NLS-2$
        "empty action sequence test", // $NON-NLS-1$ //$NON-NLS-2$
        false, // $NON-NLS-1$ //$NON-NLS-2$
        true, // $NON-NLS-1$ //$NON-NLS-2$
        null, // $NON-NLS-1$ //$NON-NLS-2$
        false, providers, null, null, new SimpleUrlFactory(""), new ArrayList());
        assertNotNull("RuntimeContext is null", runtimeContext);
        IActionParameter param = runtimeContext.getOutputParameter("output1");
        assertNotNull("param is null", param);
        assertEquals("setting is wrong", "value1", TestPojo1.setting1);
        assertEquals("setting is wrong", "value2", TestPojo1.setting2);
        assertEquals("setting is wrong", null, TestPojo1.setting3);
        assertEquals("param is wrong", "abcdeabcde", param.getValue());
        assertEquals("setInt2 failed", new Integer(22), TestPojo1.int2);
        assertEquals("setBoolean2 failed", new Boolean(true), TestPojo1.bool2);
        assertEquals("setLong2 failed", new Long(99), TestPojo1.long2);
        assertEquals("setBigDecimal failed", new BigDecimal("77.7"), TestPojo1.bigDecimal);
        assertEquals("setFloat2 failed", "44.4", TestPojo1.float2.toString());
        assertEquals("setDouble2 failed", "66.6", TestPojo1.double2.toString());
        assertTrue("done() was not called", PojoComponentTest.doneCalled);
        assertTrue("setSession() was not called", PojoComponentTest.setSessionCalled);
        assertTrue("setLogger() was not called", PojoComponentTest.setLoggerCalled);
        assertEquals("Action sequence execution failed", runtimeContext.getStatus(), IRuntimeContext.RUNTIME_STATUS_SUCCESS);
    } catch (Exception e) {
        // we should not get here
        e.printStackTrace();
        assertTrue(e.getMessage(), false);
    }
    finishTest();
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) HashMap(java.util.HashMap) Map(java.util.Map) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 34 with SimpleUrlFactory

use of org.pentaho.platform.util.web.SimpleUrlFactory in project pentaho-platform by pentaho.

the class PojoComponentTest method testSimplestCase.

public void testSimplestCase() {
    startTest();
    ISolutionEngine solutionEngine = ServiceTestHelper.getSolutionEngine();
    try {
        String xactionStr = ServiceTestHelper.getXAction(SOLUTION_PATH, "test/pojo/pojo4.xaction");
        PojoComponentTest.doneCalled = false;
        IRuntimeContext runtimeContext = // $NON-NLS-1$ //$NON-NLS-2$
        solutionEngine.execute(// $NON-NLS-1$ //$NON-NLS-2$
        xactionStr, // $NON-NLS-1$ //$NON-NLS-2$
        "pojo4.xaction", // $NON-NLS-1$ //$NON-NLS-2$
        "empty action sequence test", // $NON-NLS-1$ //$NON-NLS-2$
        false, // $NON-NLS-1$ //$NON-NLS-2$
        true, // $NON-NLS-1$ //$NON-NLS-2$
        null, // $NON-NLS-1$ //$NON-NLS-2$
        false, new HashMap(), null, null, new SimpleUrlFactory(""), new ArrayList());
        IActionParameter param = runtimeContext.getOutputParameter("output1");
        assertNotNull("RuntimeContext is null", runtimeContext);
        assertNotNull("param is null", param);
        assertEquals("abcdeabcde", param.getValue().toString());
        assertEquals("done() was called", false, PojoComponentTest.doneCalled);
        assertEquals("Action sequence execution failed", runtimeContext.getStatus(), IRuntimeContext.RUNTIME_STATUS_SUCCESS);
    } catch (Exception e) {
        // we should not get here
        e.printStackTrace();
        assertTrue(e.getMessage(), false);
    }
    finishTest();
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 35 with SimpleUrlFactory

use of org.pentaho.platform.util.web.SimpleUrlFactory in project pentaho-platform by pentaho.

the class PojoComponentTest method testStreamingPojo.

public void testStreamingPojo() {
    String instanceId = null;
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    SimpleOutputHandler outputHandler = new SimpleOutputHandler(out, false);
    outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
    startTest();
    IPentahoSession session = new StandaloneSession("system");
    ISolutionEngine solutionEngine = ServiceTestHelper.getSolutionEngine();
    if (outputHandler != null) {
        outputHandler.setSession(session);
    }
    try {
        String xactionStr = ServiceTestHelper.getXAction(SOLUTION_PATH, "test/pojo/pojo2.xaction");
        PojoComponentTest.setActionSequenceResourceCalled = false;
        IRuntimeContext runtimeContext = // $NON-NLS-1$ //$NON-NLS-2$
        solutionEngine.execute(// $NON-NLS-1$ //$NON-NLS-2$
        xactionStr, // $NON-NLS-1$ //$NON-NLS-2$
        "test1.xaction", // $NON-NLS-1$ //$NON-NLS-2$
        "empty action sequence test", // $NON-NLS-1$ //$NON-NLS-2$
        false, // $NON-NLS-1$ //$NON-NLS-2$
        true, // $NON-NLS-1$ //$NON-NLS-2$
        null, // $NON-NLS-1$ //$NON-NLS-2$
        false, new HashMap(), outputHandler, null, new SimpleUrlFactory(""), new ArrayList());
        IActionParameter param = runtimeContext.getOutputParameter("outputstream");
        assertNotNull("RuntimeContext is null", runtimeContext);
        assertEquals("Action sequence execution failed", runtimeContext.getStatus(), IRuntimeContext.RUNTIME_STATUS_SUCCESS);
        assertTrue("setResource was not called", PojoComponentTest.setResourceInputStreamCalled);
        assertTrue("setResource was not called", PojoComponentTest.setActionSequenceResourceCalled);
    } catch (Exception e) {
        // we should not get here
        e.printStackTrace();
        assertTrue(e.getMessage(), false);
    }
    String output = new String(out.toByteArray());
    assertEquals("outputstream", "abcdeabcde", output);
    finishTest();
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) HashMap(java.util.HashMap) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Aggregations

SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)51 ArrayList (java.util.ArrayList)39 HashMap (java.util.HashMap)31 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)23 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)20 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)20 IPentahoUrlFactory (org.pentaho.platform.api.engine.IPentahoUrlFactory)17 OutputStream (java.io.OutputStream)16 SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)16 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)15 IOException (java.io.IOException)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)11 IPentahoRequestContext (org.pentaho.platform.api.engine.IPentahoRequestContext)11 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)9 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)8 List (java.util.List)6 Document (org.dom4j.Document)6 IOutputHandler (org.pentaho.platform.api.engine.IOutputHandler)6 BaseRequestHandler (org.pentaho.platform.engine.services.BaseRequestHandler)5