Package com.google.gson

Examples of com.google.gson.JsonObject


     * status (error).
     * @throws Exception if failed
     */
    @Test
    public void status_error() throws Exception {
        JsonObject result = new JsonObject();
        result.addProperty("status", "error");
        result.addProperty("jrid", "testing");
        result.addProperty("message", "ERROR");
        JsonHandler handler = new JsonHandler(result);
        server.register("/jobs/testing", handler);

        HttpJobClient client = new HttpJobClient(baseUrl);

View Full Code Here


     * status (exception occurred).
     * @throws Exception if failed
     */
    @Test
    public void status_missing() throws Exception {
        JsonObject result = new JsonObject();
        result.addProperty("status", "initialized");
        result.addProperty("jrid", "testing");
        JsonHandler handler = new JsonHandler(result);
        server.register("/jobs/testing", handler);

        HttpJobClient client = new HttpJobClient(baseUrl);

View Full Code Here

     * submit.
     * @throws Exception if failed
     */
    @Test
    public void submit() throws Exception {
        JsonObject result = new JsonObject();
        result.addProperty("status", "waiting");
        result.addProperty("jrid", "testing");
        JsonHandler handler = new JsonHandler(result);
        server.register("/jobs/testing/execute", handler);

        HttpJobClient client = new HttpJobClient(baseUrl);
        client.submit(new JobId("testing"));
View Full Code Here

     * submit.
     * @throws Exception if failed
     */
    @Test
    public void submit_error() throws Exception {
        JsonObject result = new JsonObject();
        result.addProperty("status", "error");
        result.addProperty("message", "ERROR");
        JsonHandler handler = new JsonHandler(result);
        server.register("/jobs/testing/execute", handler);

        HttpJobClient client = new HttpJobClient(baseUrl);
        try {
View Full Code Here

     * submit.
     * @throws Exception if failed
     */
    @Test
    public void submit_missing() throws Exception {
        JsonObject result = new JsonObject();
        result.addProperty("status", "waiting");
        result.addProperty("jrid", "other");
        JsonHandler handler = new JsonHandler(result);
        server.register("/jobs/testing/execute", handler);

        HttpJobClient client = new HttpJobClient(baseUrl);
        try {
View Full Code Here

        @Override
        public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
            response.setStatusCode(status);
            if (code != null) {
                JsonObject object = new JsonObject();
                object.addProperty("error", code);
                object.addProperty("message", code);
                response.setEntity(new StringEntity(new Gson().toJson(object).toString(), HttpJobClient.CONTENT_TYPE));
            }
            if (request instanceof HttpEntityEnclosingRequest) {
                HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
                String content = EntityUtils.toString(entity, "UTF-8");
View Full Code Here

     * register.
     * @throws Exception if failed
     */
    @Test
    public void register() throws Exception {
        JsonObject result = new JsonObject();
        result.addProperty("status", "initialized");
        result.addProperty("jrid", "testing");
        JsonHandler handler = new JsonHandler(result);
        server.register("/jobs", handler);

        HttpJobClient client = new HttpJobClient(baseUrl);
        JobScript script = new JobScript();
        script.setBatchId("b");
        script.setFlowId("f");
        script.setExecutionId("e");
        script.setPhase(ExecutionPhase.MAIN);
        script.setStageId("s");
        script.setMainClassName("Cls");
        script.setProperties(new HashMap<String, String>());
        script.setEnvironmentVariables(new HashMap<String, String>());

        JobId id = client.register(script);
        assertThat(id, is(new JobId("testing")));

        assertThat(handler.requestElement, is(notNullValue()));
        JsonObject object = handler.requestElement;
        assertThat(object.get("batchId").getAsString(), is("b"));
        assertThat(object.get("flowId").getAsString(), is("f"));
        assertThat(object.get("executionId").getAsString(), is("e"));
        assertThat(object.get("phaseId").getAsString(), is("main"));
        assertThat(object.get("stageId").getAsString(), is("s"));
        assertThat(object.get("properties").isJsonObject(), is(true));
        assertThat(object.get("env").isJsonObject(), is(true));
    }
View Full Code Here

     * register error.
     * @throws Exception if failed
     */
    @Test
    public void register_error() throws Exception {
        JsonObject result = new JsonObject();
        result.addProperty("status", "error");
        JsonHandler handler = new JsonHandler(result);
        server.register("/jobs", handler);

        HttpJobClient client = new HttpJobClient(baseUrl);
        JobScript script = new JobScript();
View Full Code Here

     * register.
     * @throws Exception if failed
     */
    @Test
    public void register_auth() throws Exception {
        JsonObject result = new JsonObject();
        result.addProperty("status", "initialized");
        result.addProperty("jrid", "testing");
        JsonHandler handler = new JsonHandler(result);
        server.register("/jobs", new AuthHandler(handler));

        HttpJobClient client = new HttpJobClient(baseUrl, "a", "b");
        JobScript script = new JobScript();
View Full Code Here

     * register.
     * @throws Exception if failed
     */
    @Test
    public void register_unauth() throws Exception {
        JsonObject result = new JsonObject();
        result.addProperty("status", "initialized");
        result.addProperty("jrid", "testing");
        JsonHandler handler = new JsonHandler(result);
        server.register("/jobs", new AuthHandler(handler));

        HttpJobClient client = new HttpJobClient(baseUrl);
        JobScript script = new JobScript();
View Full Code Here

TOP

Related Classes of com.google.gson.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.