Search in sources :

Example 6 with ActionParameter

use of org.pentaho.platform.engine.services.actionsequence.ActionParameter in project pentaho-platform by pentaho.

the class TemplateUtilTest method testGetProperty.

public void testGetProperty() {
    IRuntimeContext mockRuntimeContext = mock(IRuntimeContext.class);
    IPentahoSession mockSession = mock(IPentahoSession.class);
    IParameterManager mockParameterManager = mock(IParameterManager.class);
    when(mockRuntimeContext.getParameterManager()).thenReturn(mockParameterManager);
    when(mockRuntimeContext.getSession()).thenReturn(mockSession);
    // Load up various parameter types to target code sections
    Map<String, IActionParameter> paramMap = new HashMap<String, IActionParameter>();
    IActionParameter param1 = new ActionParameter("param1", "String", "one", null, "defone");
    paramMap.put("param1", param1);
    Map<String, Object> inputMap = new HashMap<String, Object>();
    inputMap.putAll(paramMap);
    inputMap.put("param2", "two");
    inputMap.put("param3", new TestObject("three"));
    inputMap.put("param4", new TestObject[] { new TestObject("four-0"), new TestObject("four-1") });
    inputMap.put("param5", createMockResultSet());
    // Set up a captor to return the appropriate parameter
    ArgumentCaptor<String> paramNameArgument = ArgumentCaptor.forClass(String.class);
    when(mockRuntimeContext.getInputParameterValue(paramNameArgument.capture())).thenAnswer(new Answer() {

        public Object answer(InvocationOnMock invocation) {
            return inputMap.get(paramNameArgument.getValue());
        }
    });
    when(mockParameterManager.getCurrentInputNames()).thenReturn(paramMap.keySet());
    when(mockParameterManager.getAllParameters()).thenReturn(paramMap);
    when(mockRuntimeContext.getInputNames()).thenReturn(inputMap.keySet());
    // Now we can test
    // action parameter
    assertEquals("one", TemplateUtil.applyTemplate("{param1}", mockRuntimeContext));
    // simple String
    assertEquals("two", TemplateUtil.applyTemplate("{param2}", mockRuntimeContext));
    // single arbitrary object
    assertEquals("three", TemplateUtil.applyTemplate("{param3}", mockRuntimeContext));
    // array of
    assertEquals("four-0','four-1", TemplateUtil.applyTemplate("{param4}", mockRuntimeContext));
    // arbitrary objects
    // result set
    assertEquals("key Value", TemplateUtil.applyTemplate("{param5}", mockRuntimeContext));
}
Also used : HashMap(java.util.HashMap) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ActionParameter(org.pentaho.platform.engine.services.actionsequence.ActionParameter) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) Answer(org.mockito.stubbing.Answer) IParameterManager(org.pentaho.platform.api.engine.IParameterManager) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Aggregations

IActionParameter (org.pentaho.platform.api.engine.IActionParameter)6 ActionParameter (org.pentaho.platform.engine.services.actionsequence.ActionParameter)6 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 ActionSequenceException (org.pentaho.platform.api.engine.ActionSequenceException)2 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ListOrderedMap (org.apache.commons.collections.map.ListOrderedMap)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1 IPeekable (org.pentaho.commons.connection.IPeekable)1 ActionExecutionException (org.pentaho.platform.api.engine.ActionExecutionException)1 IParameterManager (org.pentaho.platform.api.engine.IParameterManager)1 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)1 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)1