Search in sources :

Example 6 with ISolutionEngine

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

the class PojoComponentTest method testBadClassSetting.

public void testBadClassSetting() {
    startTest();
    ISolutionEngine solutionEngine = ServiceTestHelper.getSolutionEngine();
    try {
        String xactionStr = ServiceTestHelper.getXAction(SOLUTION_PATH, "test/pojo/pojo-bad2.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("execute was called", false, PojoComponentTest.executeCalled);
        assertEquals("validate was called", false, PojoComponentTest.validateCalled);
        assertEquals("Action sequence validation succeeded", runtimeContext.getStatus(), IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_FAIL);
    } 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 7 with ISolutionEngine

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

the class PojoComponentTest method testRuntimeInputsAndOutputs.

public void testRuntimeInputsAndOutputs() {
    startTest();
    ISolutionEngine solutionEngine = ServiceTestHelper.getSolutionEngine();
    try {
        String xactionStr = ServiceTestHelper.getXAction(SOLUTION_PATH, "test/pojo/pojo5.xaction");
        IRuntimeContext runtimeContext = // $NON-NLS-1$ //$NON-NLS-2$
        solutionEngine.execute(// $NON-NLS-1$ //$NON-NLS-2$
        xactionStr, // $NON-NLS-1$ //$NON-NLS-2$
        "pojo5.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());
        assertNotNull("RuntimeContext is null", runtimeContext);
        assertEquals("Action sequence execution failed", runtimeContext.getStatus(), IRuntimeContext.RUNTIME_STATUS_SUCCESS);
        IActionParameter param = runtimeContext.getOutputParameter("output1");
        assertNotNull("param is null", param);
        assertEquals("hello", param.getValue().toString());
        param = runtimeContext.getOutputParameter("output2");
        assertNotNull("param is null", param);
        assertEquals("world", param.getValue().toString());
    } 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 8 with ISolutionEngine

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

the class PojoComponentTest method testBadOutput.

public void testBadOutput() {
    startTest();
    ISolutionEngine solutionEngine = ServiceTestHelper.getSolutionEngine();
    try {
        String xactionStr = ServiceTestHelper.getXAction(SOLUTION_PATH, "test/pojo/pojo-bad5.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", runtimeContext.getStatus(), IRuntimeContext.RUNTIME_STATUS_FAILURE);
    } 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 9 with ISolutionEngine

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

the class PojoComponentTest method testBadValidate.

public void testBadValidate() {
    startTest();
    ISolutionEngine solutionEngine = ServiceTestHelper.getSolutionEngine();
    try {
        String xactionStr = ServiceTestHelper.getXAction(SOLUTION_PATH, "test/pojo/pojo-bad3.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("execute was called", false, PojoComponentTest.executeCalled);
        assertEquals("validate was not called", true, PojoComponentTest.validateCalled);
        assertEquals("Action sequence execution succeeded", runtimeContext.getStatus(), IRuntimeContext.RUNTIME_STATUS_FAILURE);
    } 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 10 with ISolutionEngine

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

the class ServiceLayerTest method testEmptyActionSequence.

@Test
public void testEmptyActionSequence() throws IOException {
    List<Object> messages = new ArrayList<Object>();
    String instanceId = null;
    IPentahoSession session = new StandaloneSession("system");
    ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, session);
    solutionEngine.setLoggingLevel(ILogger.ERROR);
    solutionEngine.init(session);
    Map<Object, Object> parameterProviderMap = new HashMap<Object, Object>();
    IPentahoUrlFactory urlFactory = new SimpleUrlFactory("");
    Reader reader = null;
    try {
        File file = new File(SOLUTION_PATH + "/services_layer/test1.xaction");
        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);
        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$
        instanceId, false, parameterProviderMap, null, null, urlFactory, messages);
        assertNotNull("RuntimeContext is null", runtimeContext);
        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);
    } finally {
        if (reader != null) {
            reader.close();
        }
    }
}
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) PlatformInitializationException(org.pentaho.platform.engine.core.system.boot.PlatformInitializationException) IOException(java.io.IOException) FileReader(java.io.FileReader) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) File(java.io.File) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) 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