use of org.pentaho.platform.api.engine.IParameterManager 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));
}
use of org.pentaho.platform.api.engine.IParameterManager in project pentaho-platform by pentaho.
the class IsOutputParameterTest method testIsOutputParameter.
/**
* Assert parameters with is-output-parameter=false don't appear in output
*
* @throws XmlParseException
*/
public void testIsOutputParameter() throws XmlParseException {
startTest();
ISolutionEngine solutionEngine = ServiceTestHelper.getSolutionEngine();
String xactionStr = ServiceTestHelper.getXAction(SOLUTION_PATH, "services/" + xactionName);
Document actionSequenceDocument = XmlDom4JHelper.getDocFromString(xactionStr, null);
IActionSequence actionSequence = SequenceDefinition.ActionSequenceFactory(actionSequenceDocument, "", this, // $NON-NLS-1$
PentahoSystem.getApplicationContext(), DEBUG);
Map allParameters = actionSequence.getOutputDefinitions();
Set<String> outParameters = new HashSet<String>();
Set<String> nonOutParameters = new HashSet<String>();
for (Object key : allParameters.keySet()) {
IActionParameter param = (IActionParameter) allParameters.get(key);
if (param.isOutputParameter()) {
outParameters.add(param.getName());
} else {
nonOutParameters.add(param.getName());
}
}
Assert.assertEquals("expected 2 outputable parameters in xaction", 2, outParameters.size());
Assert.assertEquals("expected 1 paramater with is-output-parameter=false", 1, nonOutParameters.size());
IRuntimeContext runtimeContext = // $NON-NLS-1$
solutionEngine.execute(// $NON-NLS-1$
xactionStr, // $NON-NLS-1$
xactionName, // $NON-NLS-1$
"simple output test", // $NON-NLS-1$
false, // $NON-NLS-1$
true, // $NON-NLS-1$
null, // $NON-NLS-1$
false, // $NON-NLS-1$
new HashMap(), null, null, new SimpleUrlFactory(""), // $NON-NLS-1$
new ArrayList());
IParameterManager paramManager = runtimeContext.getParameterManager();
Assert.assertEquals(outParameters.size(), paramManager.getCurrentOutputNames().size());
for (Object key : paramManager.getCurrentOutputNames()) {
Assert.assertTrue("output parameter not found in definition", outParameters.contains(key));
Assert.assertFalse("non-output parameter in output", nonOutParameters.contains(key));
}
finishTest();
}
use of org.pentaho.platform.api.engine.IParameterManager in project pentaho-platform by pentaho.
the class TemplateUtilTest method testTableTemplate.
public void testTableTemplate() {
IRuntimeContext mockRuntimeContext = mock(IRuntimeContext.class);
IPentahoSession mockSession = mock(IPentahoSession.class);
IParameterManager mockParameterManager = mock(IParameterManager.class);
IPentahoResultSet mockPentahoResultSet = mock(IPentahoResultSet.class);
Object[] mockRow = new Object[] { "field0", "field1" };
when(mockPentahoResultSet.getColumnCount()).thenReturn(mockRow.length);
when(mockPentahoResultSet.getDataRow(0)).thenReturn(mockRow);
when(mockParameterManager.getCurrentInputNames()).thenReturn(new HashSet<Object>(Arrays.asList(new String[] { "param1" })));
when(mockRuntimeContext.getSession()).thenReturn(mockSession);
when(mockRuntimeContext.getParameterManager()).thenReturn(mockParameterManager);
when(mockRuntimeContext.getInputParameterValue("param1")).thenReturn(mockPentahoResultSet);
String template = "table {param1:col:1} and text";
IParameterResolver resolver = mock(IParameterResolver.class);
assertEquals("table field1 and text", TemplateUtil.applyTemplate(template, mockRuntimeContext, resolver));
}
use of org.pentaho.platform.api.engine.IParameterManager 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