Package com.meterware.httpunit

Examples of com.meterware.httpunit.PostMethodWebRequest


  public void testArrayString() throws Exception {
    JSONObject jsonRequest = new JSONObject(
        "{\"params\":[[\"1\",\"2\"]],\"method\":\"echoArrayString\",\"id\":9}");

    WebConversation wc = new WebConversation();
    WebRequest request = new PostMethodWebRequest(SERVICE_URL,
        new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
    WebResponse response = wc.getResource(request);

    Assert.assertEquals(200, response.getResponseCode());
View Full Code Here


  public void testArrayInt() throws Exception {
    JSONObject jsonRequest = new JSONObject(
        "{\"params\":[[1,2]],\"method\":\"echoArrayInt\",\"id\":10}");

    WebConversation wc = new WebConversation();
    WebRequest request = new PostMethodWebRequest(SERVICE_URL,
        new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
    WebResponse response = wc.getResource(request);

    Assert.assertEquals(200, response.getResponseCode());
View Full Code Here

  public void testSet() throws Exception {
    JSONObject jsonRequest = new JSONObject(
        "{ \"method\": \"echoSet\", \"params\": [ {\"javaClass\": \"java.util.HashSet\", \"set\": {\"1\": \"red\", \"2\": \"blue\"}}],\"id\": 11}");

    WebConversation wc = new WebConversation();
    WebRequest request = new PostMethodWebRequest(SERVICE_URL,
        new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")), "application/json");
    WebResponse response = wc.getResource(request);

    Assert.assertEquals(200, response.getResponseCode());
View Full Code Here

    private static final String CONTENT_TYPE = "text/xml";
   

    @Test
    public void testHttpClient() throws Exception {
        WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/hello", new ByteArrayInputStream(POST_DATA.getBytes()), "text/xml; charset=UTF-8");
        ServletUnitClient client = newClient();
        WebResponse response = client.getResponse(req);
       
        assertEquals("Get wrong content type", "text/xml", response.getContentType());
        assertTrue("UTF-8".equalsIgnoreCase(response.getCharacterSet()));
        assertEquals("Get a wrong message header", "/hello", response.getHeaderField("PATH"));
        assertEquals("The response message is wrong ", "OK", response.getResponseMessage());
       
        req = new PostMethodWebRequest(CONTEXT_URL + "/services/helloworld", new ByteArrayInputStream(POST_DATA.getBytes()), "text/xml; charset=UTF-8");
        response = client.getResponse(req);
       
        assertEquals("Get wrong content type", "text/xml", response.getContentType());
        assertTrue("UTF-8".equalsIgnoreCase(response.getCharacterSet()));
        assertEquals("Get a wrong message header", "/helloworld", response.getHeaderField("PATH"));
View Full Code Here

        client.setExceptionsThrownOnErrorStatus(false);
    }
   
    @Test
    public void testHttpConverter() throws Exception {
        WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/testConverter", new ByteArrayInputStream(POST_DATA.getBytes()), "text/xml; charset=UTF-8");
        ServletUnitClient client = newClient();
        client.setExceptionsThrownOnErrorStatus(false);
        WebResponse response = client.getResponse(req);       
        assertEquals("The response message is wrong ", "OK", response.getResponseMessage());
        assertEquals("The response body is wrong", "Bye World", response.getText());
View Full Code Here

    private static final String POST_DATA = "<request> hello world </request>";
    private static final String CONTENT_TYPE = "text/xml";

    @Test
    public void testHttpClient() throws Exception {
        WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/hello", new ByteArrayInputStream(POST_DATA.getBytes()), "text/xml; charset=UTF-8");
        ServletUnitClient client = newClient();
        WebResponse response = client.getResponse(req);
       
        assertEquals("Get wrong content type", "text/xml", response.getContentType());
        assertTrue("UTF-8".equalsIgnoreCase(response.getCharacterSet()));
        assertEquals("Get a wrong message header", "/hello", response.getHeaderField("PATH"));
        assertEquals("The response message is wrong ", "OK", response.getResponseMessage());
       
        req = new PostMethodWebRequest(CONTEXT_URL + "/services/helloworld", new ByteArrayInputStream(POST_DATA.getBytes()), "text/xml; charset=UTF-8");
        response = client.getResponse(req);
       
        assertEquals("Get wrong content type", "text/xml", response.getContentType());
        assertTrue("UTF-8".equalsIgnoreCase(response.getCharacterSet()));
        assertEquals("Get a wrong message header", "/helloworld", response.getHeaderField("PATH"));
View Full Code Here

        client.setExceptionsThrownOnErrorStatus(false);
    }
   
    @Test
    public void testHttpConverter() throws Exception {
        WebRequest req = new PostMethodWebRequest(CONTEXT_URL + "/services/testConverter", new ByteArrayInputStream(POST_DATA.getBytes()), "text/xml; charset=UTF-8");
        ServletUnitClient client = newClient();
        client.setExceptionsThrownOnErrorStatus(false);
        WebResponse response = client.getResponse(req);       
        assertEquals("The response message is wrong ", "OK", response.getResponseMessage());
        assertEquals("The response body is wrong", "Bye World", response.getText());
View Full Code Here

    @Test
    public void testRuntimeException() throws Exception{
      JSONObject jsonRequest = new JSONObject("{ \"method\": \"echoRuntimeException\", \"params\": [], \"id\": 2}");
     
      WebConversation wc = new WebConversation();
        WebRequest request   = new PostMethodWebRequest( SERVICE_URL, new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")),"application/json");
        WebResponse response = wc.getResource(request);

        Assert.assertEquals(200, response.getResponseCode());
       
        JSONObject jsonErr = new JSONObject(response.getText()).getJSONObject("error");
View Full Code Here

    @Test
    public void testBusinessException() throws Exception{
      JSONObject jsonRequest = new JSONObject("{ \"method\": \"echoBusinessException\", \"params\": [], \"id\": 3}");
     
      WebConversation wc = new WebConversation();
        WebRequest request   = new PostMethodWebRequest( SERVICE_URL, new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")),"application/json");
        WebResponse response = wc.getResource(request);

        Assert.assertEquals(200, response.getResponseCode());
       
        JSONObject jsonErr = new JSONObject(response.getText()).getJSONObject("error");
View Full Code Here

    @Test
    public void testJSONRPCBinding() throws Exception {
        JSONObject jsonRequest = new JSONObject("{ \"method\": \"echo\", \"params\": [\"Hello JSON-RPC\"], \"id\": 1}");

        WebConversation wc = new WebConversation();
        WebRequest request   = new PostMethodWebRequest( SERVICE_URL, new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")),"application/json");
        WebResponse response = wc.getResource(request);

        Assert.assertEquals(200, response.getResponseCode());

        JSONObject jsonResp = new JSONObject(response.getText());
View Full Code Here

TOP

Related Classes of com.meterware.httpunit.PostMethodWebRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.