Search in sources :

Example 56 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider in project pentaho-platform by pentaho.

the class SimpleParameterProviderTest method testLongs.

public void testLongs() {
    SimpleParameterProvider params = new SimpleParameterProvider();
    params.setParameter("long", new Long(200));
    validateLong(params);
}
Also used : SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 57 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider in project pentaho-platform by pentaho.

the class SimpleParameterProviderTest method testConvert.

public void testConvert() {
    Map<String, Object> paramMap = new HashMap<String, Object>();
    paramMap.put("int-1", new Object[] { new Integer(100) });
    paramMap.put("int-2", new Object[] { new Integer(100), new Integer(999) });
    paramMap.put("long", new Long(200));
    SimpleParameterProvider params = new SimpleParameterProvider();
    params.copyAndConvertParameters(paramMap);
    assertEquals("param value is wrong", "100", params.getStringParameter("int-1", null));
    assertEquals("param value is wrong", 100, params.getLongParameter("int-1", -1));
    assertEquals("param value is wrong", "200", params.getStringParameter("long", null));
    assertEquals("param value is wrong", 200, params.getLongParameter("long", -1));
    assertEquals("param value is wrong", "100", params.getStringParameter("int-2", null));
    assertEquals("param value is wrong", 100, params.getLongParameter("int-2", -1));
    assertEquals("param value is wrong", -1, params.getLongParameter("int-3", -1));
    Object val = params.getArrayParameter("int-2", null);
    assertNotNull("param value is wrong", val);
}
Also used : HashMap(java.util.HashMap) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 58 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider 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 59 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider in project pentaho-platform by pentaho.

the class PojoComponentTest method testSimplePojoInputFormat2.

public void testSimplePojoInputFormat2() {
    // test the alternate action definition format
    startTest();
    ISolutionEngine solutionEngine = ServiceTestHelper.getSolutionEngine();
    try {
        String xactionStr = ServiceTestHelper.getXAction(SOLUTION_PATH, "test/pojo/pojo1-alternate.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 60 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider in project pentaho-platform by pentaho.

the class DefaultChartBeansGenerator method createAndRunActionSequence.

protected void createAndRunActionSequence(final IPentahoSession pentahoSession, final Map<String, Object> params, final Map<String, Object> defaultParameterMap, String contentLinkingTemplate, final OutputStream out) {
    SimpleParameterProvider parameterProvider = new SimpleParameterProvider(params);
    // add the default parameter values
    for (Map.Entry<String, Object> entry : defaultParameterMap.entrySet()) {
        parameterProvider.setParameter(entry.getKey(), entry.getValue());
    }
    Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
    parameterProviders.put(IParameterProvider.SCOPE_REQUEST, parameterProvider);
    SimpleOutputHandler outputHandler = new SimpleOutputHandler(out, true);
    outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
    ActionSequenceDocument doc = createActionSequenceDocument(defaultParameterMap.keySet(), contentLinkingTemplate);
    runActionSequence(pentahoSession, parameterProviders, outputHandler, doc);
    try {
        out.flush();
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HashMap(java.util.HashMap) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider) IActionSequenceDocument(org.pentaho.actionsequence.dom.IActionSequenceDocument) ActionSequenceDocument(org.pentaho.actionsequence.dom.ActionSequenceDocument)

Aggregations

SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)72 HashMap (java.util.HashMap)32 ArrayList (java.util.ArrayList)23 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)23 OutputStream (java.io.OutputStream)21 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)21 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)21 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)21 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)16 Test (org.junit.Test)13 IOException (java.io.IOException)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 MockHttpServletRequest (com.mockrunner.mock.web.MockHttpServletRequest)7 MockHttpServletResponse (com.mockrunner.mock.web.MockHttpServletResponse)7 Map (java.util.Map)5 IPentahoRequestContext (org.pentaho.platform.api.engine.IPentahoRequestContext)5 IPentahoUrlFactory (org.pentaho.platform.api.engine.IPentahoUrlFactory)5 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)5 BaseRequestHandler (org.pentaho.platform.engine.services.BaseRequestHandler)5 Iterator (java.util.Iterator)4