Search in sources :

Example 21 with SimpleUrlFactory

use of org.pentaho.platform.util.web.SimpleUrlFactory 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 22 with SimpleUrlFactory

use of org.pentaho.platform.util.web.SimpleUrlFactory 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 23 with SimpleUrlFactory

use of org.pentaho.platform.util.web.SimpleUrlFactory in project pentaho-platform by pentaho.

the class ActionDelegateTest method execute.

@SuppressWarnings("unchecked")
private void execute(String actionSequenceFile, boolean exceptionOnError, IAction... actions) throws ActionSequenceException {
    TestPluginManager pm = (TestPluginManager) PentahoSystem.get(IPluginManager.class);
    for (IAction action : actions) {
        pm.addAction(action);
    }
    // content outputs will write to this stream
    out = new ByteArrayOutputStream();
    // create SimpleOutputHandler (to handle outputs of type "response.content")
    outputHandler = new SimpleOutputHandler(out, false);
    outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
    IPentahoSession session = new StandaloneSession("system");
    ISolutionEngine solutionEngine = ServiceTestHelper.getSolutionEngine();
    outputHandler.setSession(session);
    String xactionStr = ServiceTestHelper.getXAction("src/test/resources/solution/test/ActionDelegateTest", actionSequenceFile);
    // execute the action sequence, providing the outputHandler created above
    IRuntimeContext rc = solutionEngine.execute(xactionStr, actionSequenceFile, "action sequence to test the TestAction", false, true, null, false, new HashMap(), outputHandler, null, new SimpleUrlFactory(""), new ArrayList());
    int status = rc.getStatus();
    if (status == IRuntimeContext.PARAMETERS_FAIL || status == IRuntimeContext.RUNTIME_CONTEXT_RESOLVE_FAIL || status == IRuntimeContext.RUNTIME_STATUS_FAILURE || status == IRuntimeContext.RUNTIME_STATUS_INITIALIZE_FAIL || status == IRuntimeContext.RUNTIME_STATUS_SETUP_FAIL) {
        throw new ActionSequenceException("Action sequence failed!");
    }
}
Also used : ActionSequenceException(org.pentaho.platform.api.engine.ActionSequenceException) ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IAction(org.pentaho.platform.api.action.IAction) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) HashMap(java.util.HashMap) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IPluginManager(org.pentaho.platform.api.engine.IPluginManager) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext)

Example 24 with SimpleUrlFactory

use of org.pentaho.platform.util.web.SimpleUrlFactory in project data-access by pentaho.

the class DSWDatasourceServiceImpl method listDatasourceNames.

public List<String> listDatasourceNames() throws IOException {
    synchronized (CsvDatasourceServiceImpl.lock) {
        // $NON-NLS-1$
        IPentahoUrlFactory urlFactory = new SimpleUrlFactory("");
        PMDUIComponent component = new PMDUIComponent(urlFactory, new ArrayList());
        component.validate(PentahoSessionHolder.getSession(), null);
        component.setAction(PMDUIComponent.ACTION_LIST_MODELS);
        Document document = component.getXmlContent();
        // $NON-NLS-1$
        List<DefaultElement> modelElements = document.selectNodes("//model_name");
        ArrayList<String> datasourceNames = new ArrayList<String>();
        for (DefaultElement element : modelElements) {
            datasourceNames.add(element.getText());
        }
        return datasourceNames;
    }
}
Also used : IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) DefaultElement(org.dom4j.tree.DefaultElement) ArrayList(java.util.ArrayList) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) PMDUIComponent(org.pentaho.platform.uifoundation.component.xml.PMDUIComponent) Document(org.dom4j.Document)

Example 25 with SimpleUrlFactory

use of org.pentaho.platform.util.web.SimpleUrlFactory in project pentaho-platform by pentaho.

the class AxisServiceWsdlGeneratorTest method testBadInit3.

@Test
public void testBadInit3() throws Exception {
    // $NON-NLS-1$
    StandaloneSession session = new StandaloneSession("test");
    AxisServiceWsdlGenerator contentGenerator = new AxisServiceWsdlGenerator();
    // $NON-NLS-1$
    assertNotNull("contentGenerator is null", contentGenerator);
    // $NON-NLS-1$
    assertNotNull("Logger is null", contentGenerator.getLogger());
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IOutputHandler outputHandler = new SimpleOutputHandler(out, false);
    // $NON-NLS-1$
    String baseUrl = "http://testhost:testport/testcontent";
    Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
    SimpleParameterProvider requestParams = new SimpleParameterProvider();
    parameterProviders.put(IParameterProvider.SCOPE_REQUEST, requestParams);
    // $NON-NLS-1$
    SimpleUrlFactory urlFactory = new SimpleUrlFactory(baseUrl + "?");
    List<String> messages = new ArrayList<String>();
    contentGenerator.setOutputHandler(outputHandler);
    MimeTypeListener mimeTypeListener = new MimeTypeListener();
    outputHandler.setMimeTypeListener(mimeTypeListener);
    contentGenerator.setMessagesList(messages);
    contentGenerator.setParameterProviders(parameterProviders);
    contentGenerator.setSession(session);
    contentGenerator.setUrlFactory(urlFactory);
    contentGenerator.createContent();
    String content = new String(out.toByteArray());
    System.out.println(content);
    assertTrue(content.indexOf(Messages.getInstance().getErrorString("WebServiceContentGenerator.ERROR_0001_AXIS_CONFIG_IS_NULL")) != // $NON-NLS-1$
    -1);
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AxisServiceWsdlGenerator(org.pentaho.platform.plugin.services.webservices.content.AxisServiceWsdlGenerator) IOutputHandler(org.pentaho.platform.api.engine.IOutputHandler) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider) Test(org.junit.Test)

Aggregations

SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)51 ArrayList (java.util.ArrayList)39 HashMap (java.util.HashMap)31 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)23 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)20 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)20 IPentahoUrlFactory (org.pentaho.platform.api.engine.IPentahoUrlFactory)17 OutputStream (java.io.OutputStream)16 SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)16 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)15 IOException (java.io.IOException)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)11 IPentahoRequestContext (org.pentaho.platform.api.engine.IPentahoRequestContext)11 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)9 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)8 List (java.util.List)6 Document (org.dom4j.Document)6 IOutputHandler (org.pentaho.platform.api.engine.IOutputHandler)6 BaseRequestHandler (org.pentaho.platform.engine.services.BaseRequestHandler)5