Package org.apache.wink.json4j

Examples of org.apache.wink.json4j.JSONObject


        node.stop();
    }

    @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");

        Assert.assertEquals("Runtime Exception", jsonErr.getString("message"));
    }
View Full Code Here


        Assert.assertEquals("Runtime Exception", jsonErr.getString("message"));
    }

    @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");

        Assert.assertEquals("Business Exception", jsonErr.getString("message"));
    }  
View Full Code Here

        node.stop();
    }

    @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

        Assert.assertEquals("echo: Hello JSON-RPC", jsonResp.getString("result"));
    }
   
    @Test
    public void testEchoWithJSONRPC20Binding() throws Exception {
        JSONObject jsonRequest = new JSONObject("{ \"jsonrpc\": \"2.0\", \"method\": \"echo\", \"params\": [\"Hello JSON-RPC\"], \"id\": 1}");

        WebConversation wc = new WebConversation();
        WebRequest request   = new PostMethodWebRequest( SERVICE20_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 testEchoWithJSONRPC20BindingBatch() throws Exception {
        JSONObject jsonRequest1 = new JSONObject("{ \"jsonrpc\": \"2.0\", \"method\": \"echo\", \"params\": [\"Hello JSON-RPC\"], \"id\": 1}");
        JSONObject jsonRequest2 = new JSONObject("{ \"jsonrpc\": \"2.0\", \"method\": \"echo\", \"params\": [\"Hello JSON-RPC 2.0\"], \"id\": 2}");
        JSONArray batchReq = new JSONArray();
        batchReq.put(jsonRequest1);
        batchReq.put(jsonRequest2);
       
        WebConversation wc = new WebConversation();
View Full Code Here

        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

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

        node.stop();
    }

    @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());

        Assert.assertEquals(12345, jsonResp.getInt("result"));
    }
View Full Code Here

        Assert.assertEquals(12345, jsonResp.getInt("result"));
    }

    @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());

        Assert.assertEquals(true, jsonResp.getBoolean("result"));
    }
View Full Code Here

        Assert.assertEquals(true, jsonResp.getBoolean("result"));
    }

    @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());

        Assert.assertEquals("JSON-RPC", jsonResp.getJSONObject("result").getJSONObject("map").getString("Binding"));
    }
View Full Code Here

TOP

Related Classes of org.apache.wink.json4j.JSONObject

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.