Search in sources :

Example 36 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider in project pentaho-platform by pentaho.

the class AxisServiceExecutorTest method testRunGetErrorResponse.

@Test
public void testRunGetErrorResponse() throws Exception {
    Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
    SimpleParameterProvider pathParams = new SimpleParameterProvider();
    pathParams.setParameter("path", "/StubService/throwsError2");
    parameterProviders.put("path", pathParams);
    contentGenerator.setParameterProviders(parameterProviders);
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    request.setMethod("GET");
    request.setRequestURI("/pentaho/content/ws-run/StubService/throwsError2");
    request.setRequestURL("http://localhost:8080/pentaho/content/ws-run/StubService/throwsError2");
    request.setRemoteAddr(REMOTE_ADDRESS);
    pathParams.setParameter("httprequest", request);
    pathParams.setParameter("httpresponse", response);
    try {
        StubService.throwsError2Called = false;
        StubTransportSender.transportOutStr = null;
        contentGenerator.createContent();
        assertTrue(StubService.throwsError2Called);
        String content = StubTransportSender.transportOutStr;
        assertTrue("results are wrong", content.contains("soapenv:Fault"));
        assertTrue("results are wrong", content.contains("test error 2"));
    } catch (Exception e) {
        assertTrue("Exception occurred", false);
    }
}
Also used : IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HashMap(java.util.HashMap) MockHttpServletRequest(com.mockrunner.mock.web.MockHttpServletRequest) MockHttpServletResponse(com.mockrunner.mock.web.MockHttpServletResponse) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider) Test(org.junit.Test)

Example 37 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider in project pentaho-platform by pentaho.

the class AxisServiceExecutorTest method testRunPut.

@Test
public void testRunPut() throws Exception {
    Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
    SimpleParameterProvider pathParams = new SimpleParameterProvider();
    pathParams.setParameter("path", "/StubService");
    pathParams.setParameter("remoteaddr", "http:test");
    parameterProviders.put("path", pathParams);
    contentGenerator.setParameterProviders(parameterProviders);
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    request.setMethod("PUT");
    request.setRequestURI("/pentaho/content/ws-run/StubService");
    request.setRequestURL("http://localhost:8080/pentaho/content/ws-run/StubService");
    request.setRemoteAddr(REMOTE_ADDRESS);
    request.setContentType("application/soap+xml; charset=UTF-8; action=\"urn:getString\"");
    String xml = "<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv=\"http://www.w3" + ".org/2003/05/soap-envelope\"><soapenv:Body><ns2:getString xmlns:ns2=\"http://webservice.pentaho" + ".com\"></ns2:getString></soapenv:Body></soapenv:Envelope>";
    request.setBodyContent(xml);
    pathParams.setParameter("httprequest", request);
    pathParams.setParameter("httpresponse", response);
    try {
        StubTransportSender.transportOutStr = null;
        StubService.getStringCalled = false;
        contentGenerator.createContent();
        assertTrue(StubService.getStringCalled);
        String content = StubTransportSender.transportOutStr;
        assertEquals("result are wrong", "<ns:getStringResponse xmlns:ns=\"http://webservices.services.plugin.platform.test.pentaho.org\"><return>test" + " result</return></ns:getStringResponse>", content);
    } catch (Exception e) {
        assertTrue("Exception occurred", false);
    }
}
Also used : IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HashMap(java.util.HashMap) MockHttpServletRequest(com.mockrunner.mock.web.MockHttpServletRequest) MockHttpServletResponse(com.mockrunner.mock.web.MockHttpServletResponse) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider) Test(org.junit.Test)

Example 38 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider 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)

Example 39 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider in project pentaho-platform by pentaho.

the class WsdlPageTest method testMissingPathParamProvider.

@Test
public void testMissingPathParamProvider() throws Exception {
    // $NON-NLS-1$
    assertNotNull("Logger is null", contentGenerator.getLogger());
    Map<String, IParameterProvider> parameterProviders = Collections.<String, IParameterProvider>singletonMap(IParameterProvider.SCOPE_REQUEST, new SimpleParameterProvider());
    contentGenerator.setParameterProviders(parameterProviders);
    contentGenerator.createContent();
    String content = new String(out.toByteArray());
    assertTrue(content, content.contains(Messages.getInstance().getErrorString(// $NON-NLS-1$
    "WebServiceContentGenerator.ERROR_0004_PATH_PARAMS_IS_MISSING")));
}
Also used : IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider) Test(org.junit.Test)

Example 40 with SimpleParameterProvider

use of org.pentaho.platform.engine.core.solution.SimpleParameterProvider in project pentaho-platform by pentaho.

the class WsdlPageTest method testMissingServiceName.

@Test
public void testMissingServiceName() throws Exception {
    // $NON-NLS-1$
    assertNotNull("Logger is null", contentGenerator.getLogger());
    Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
    parameterProviders.put(IParameterProvider.SCOPE_REQUEST, new SimpleParameterProvider());
    // $NON-NLS-1$
    parameterProviders.put("path", new SimpleParameterProvider());
    contentGenerator.setParameterProviders(parameterProviders);
    contentGenerator.createContent();
    String content = new String(out.toByteArray());
    assertTrue(content, content.contains(Messages.getInstance().getErrorString(// $NON-NLS-1$
    "WebServiceContentGenerator.ERROR_0005_SERVICE_NAME_IS_MISSING")));
}
Also used : IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HashMap(java.util.HashMap) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider) Test(org.junit.Test)

Aggregations

SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)72 HashMap (java.util.HashMap)32 ArrayList (java.util.ArrayList)23 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)23 OutputStream (java.io.OutputStream)21 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)21 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)21 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)21 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)16 Test (org.junit.Test)13 IOException (java.io.IOException)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 MockHttpServletRequest (com.mockrunner.mock.web.MockHttpServletRequest)7 MockHttpServletResponse (com.mockrunner.mock.web.MockHttpServletResponse)7 Map (java.util.Map)5 IPentahoRequestContext (org.pentaho.platform.api.engine.IPentahoRequestContext)5 IPentahoUrlFactory (org.pentaho.platform.api.engine.IPentahoUrlFactory)5 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)5 BaseRequestHandler (org.pentaho.platform.engine.services.BaseRequestHandler)5 Iterator (java.util.Iterator)4