Search in sources :

Example 36 with IRuntimeContext

use of org.pentaho.platform.api.engine.IRuntimeContext 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 37 with IRuntimeContext

use of org.pentaho.platform.api.engine.IRuntimeContext 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 38 with IRuntimeContext

use of org.pentaho.platform.api.engine.IRuntimeContext 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)

Example 39 with IRuntimeContext

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

the class SoapHelperTest method testCreateSoapResponseDocumentFromContext.

/**
 * Tests for SoapHelper.createSoapResponseDocument(IRuntimeContext, IOutputHandler, OutputStream, List)
 */
public void testCreateSoapResponseDocumentFromContext() {
    // Set up test data
    Set<Object> outputNames = new HashSet<>();
    IActionParameter actionParameter = mock(IActionParameter.class);
    when(actionParameter.getValue()).thenReturn("testValue");
    IRuntimeContext context = mock(IRuntimeContext.class);
    when(context.getOutputNames()).thenReturn(outputNames);
    when(context.getStatus()).thenReturn(IRuntimeContext.RUNTIME_STATUS_SUCCESS);
    when(context.getOutputParameter(anyString())).thenReturn(actionParameter);
    List messages = new ArrayList();
    IOutputHandler outputHandler = mock(IOutputHandler.class);
    IContentItem contentItem = mock(IContentItem.class);
    when(outputHandler.getOutputContentItem(anyString(), anyString(), anyString(), anyString())).thenReturn(contentItem);
    when(contentItem.getMimeType()).thenReturn("text/xml");
    OutputStream contentStream = mock(OutputStream.class);
    when(contentStream.toString()).thenReturn("contentStreamTestString");
    // Tests for document with two output names
    outputNames.add("outputName1");
    outputNames.add("outputName2");
    Document d1 = SoapHelper.createSoapResponseDocument(context, outputHandler, contentStream, messages);
    Element activityResponse1 = d1.getRootElement().element("SOAP-ENV:Body").element("ExecuteActivityResponse");
    assertEquals(activityResponse1.elements().size(), 2);
    assertNotNull(activityResponse1.element("outputName1"));
    assertNotNull(activityResponse1.element("outputName2"));
    // Test for document with one output name (different branch in createSoapResponseDocument())
    outputNames.clear();
    outputNames.add("outputName1");
    Document d2 = SoapHelper.createSoapResponseDocument(context, outputHandler, contentStream, messages);
    Element activityResponse2 = d2.getRootElement().element("SOAP-ENV:Body").element("ExecuteActivityResponse");
    assertEquals(activityResponse2.elements().size(), 1);
    assertNotNull(activityResponse2.element("outputName1"));
    // Tests for document with no output names
    outputNames.clear();
    Document d3 = SoapHelper.createSoapResponseDocument(context, outputHandler, contentStream, messages);
    Element activityResponse3 = d3.getRootElement().element("SOAP-ENV:Body").element("ExecuteActivityResponse");
    assertTrue(activityResponse3.elements().isEmpty());
}
Also used : IOutputHandler(org.pentaho.platform.api.engine.IOutputHandler) OutputStream(java.io.OutputStream) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) IContentItem(org.pentaho.platform.api.repository.IContentItem) ArrayList(java.util.ArrayList) List(java.util.List) Document(org.dom4j.Document) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) HashSet(java.util.HashSet)

Example 40 with IRuntimeContext

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

the class TemplateUtilTest method testKeyedTableTemplate.

public void testKeyedTableTemplate() {
    IRuntimeContext mockRuntimeContext = mock(IRuntimeContext.class);
    IPentahoSession mockSession = mock(IPentahoSession.class);
    IParameterManager mockParameterManager = mock(IParameterManager.class);
    IPentahoResultSet mockPentahoResultSet = createMockResultSet();
    IPentahoMetaData mockPentahoMetaData = mock(IPentahoMetaData.class);
    final Set inputNames = new HashSet<Object>(Arrays.asList(new String[] { "param1" }));
    when(mockParameterManager.getCurrentInputNames()).thenReturn(inputNames);
    when(mockRuntimeContext.getSession()).thenReturn(mockSession);
    when(mockRuntimeContext.getParameterManager()).thenReturn(mockParameterManager);
    when(mockRuntimeContext.getInputParameterValue("param1")).thenReturn(mockPentahoResultSet);
    when(mockRuntimeContext.getInputNames()).thenReturn(inputNames);
    // "key_value" is parsed as "key value"
    String template = "{param1:keycol:key_Value:valcol:defaultValue}";
    assertEquals("field Value", TemplateUtil.applyTemplate(template, mockRuntimeContext));
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) IParameterManager(org.pentaho.platform.api.engine.IParameterManager) Set(java.util.Set) HashSet(java.util.HashSet) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IPentahoMetaData(org.pentaho.commons.connection.IPentahoMetaData) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) HashSet(java.util.HashSet)

Aggregations

IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)100 ArrayList (java.util.ArrayList)28 HashMap (java.util.HashMap)28 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)28 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)24 SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)21 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)20 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)17 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)14 OutputStream (java.io.OutputStream)12 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)12 List (java.util.List)10 IPentahoUrlFactory (org.pentaho.platform.api.engine.IPentahoUrlFactory)9 IOException (java.io.IOException)8 Map (java.util.Map)8 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 IOutputHandler (org.pentaho.platform.api.engine.IOutputHandler)7 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)6 Document (org.dom4j.Document)5