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));
}
Aggregations