Search in sources :

Example 1 with IParameterManager

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

Example 2 with IParameterManager

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();
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IActionSequence(org.pentaho.platform.api.engine.IActionSequence) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Document(org.dom4j.Document) IParameterManager(org.pentaho.platform.api.engine.IParameterManager) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) HashMap(java.util.HashMap) Map(java.util.Map) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) HashSet(java.util.HashSet)

Example 3 with IParameterManager

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));
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) IParameterManager(org.pentaho.platform.api.engine.IParameterManager) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) IParameterResolver(org.pentaho.platform.api.engine.IParameterResolver)

Example 4 with IParameterManager

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

IParameterManager (org.pentaho.platform.api.engine.IParameterManager)4 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)4 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)2 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Set (java.util.Set)1 Document (org.dom4j.Document)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1 IPentahoMetaData (org.pentaho.commons.connection.IPentahoMetaData)1 IActionSequence (org.pentaho.platform.api.engine.IActionSequence)1 IParameterResolver (org.pentaho.platform.api.engine.IParameterResolver)1 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)1 ActionParameter (org.pentaho.platform.engine.services.actionsequence.ActionParameter)1 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)1