Package com.meterware.httpunit

Examples of com.meterware.httpunit.WebConversation


    @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 testEchoWithJSONRPCBinding() 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());
        Assert.assertEquals("echo: Hello JSON-RPC", jsonResp.getString("result"));
View Full Code Here

    @Test
    public void testJSONRPCBindingGET() throws Exception {
        String params = Base64.encode("[\"Hello JSON-RPC\"]".getBytes());
        String queryString = "?method=echo&params=" + URLEncoder.encode(params,"UTF-8") + "&id=1";

        WebConversation wc = new WebConversation();
        WebRequest request = new GetMethodWebRequest(SERVICE_URL + queryString);
        WebResponse response = wc.getResource(request);

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

        JSONObject jsonResp = new JSONObject(response.getText());
        Assert.assertEquals("echo: Hello JSON-RPC", jsonResp.getString("result"));
View Full Code Here

   
    @Test
    public void testEchoVoidWithJSONRPCBinding() throws Exception {
        JSONObject jsonRequest = new JSONObject("{ \"method\": \"echoVoid\", \"params\": [], \"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());
        Assert.assertEquals(0, jsonResp.getString("result").length());
View Full Code Here

    @Test
    public void testInt() throws Exception {
        JSONObject jsonRequest = new JSONObject(
        "{ \"method\": \"echoInt\", \"params\": [12345], \"id\": 4}");

        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

    @Test
    public void testBoolean() throws Exception {
        JSONObject jsonRequest = new JSONObject(
        "{ \"method\": \"echoBoolean\", \"params\": [true], \"id\": 5}");

        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

    @Test
    public void testMap() throws Exception {
        JSONObject jsonRequest = new JSONObject(
        "{ \"method\": \"echoMap\", \"params\": [ {\"javaClass\": \"java.util.HashMap\", \"map\": { \"Binding\": \"JSON-RPC\"}}], \"id\": 6}");

        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

    @Test
    public void testBean() throws Exception {
        JSONObject jsonRequest = new JSONObject(
        "{ \"method\": \"echoBean\", \"params\": [ {\"javaClass\": \"bean.TestBean\", \"testString\": \"JSON-RPC\", \"testInt\":1234}], \"id\": 7}");

        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

    @Test
    public void testList() throws Exception {
        JSONObject jsonRequest = new JSONObject(
        "{ \"method\": \"echoList\", \"params\": [[0,1,2,3,4]], \"id\": 8}");

        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.WebConversation

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.