Package org.json.simple

Examples of org.json.simple.JSONObject.containsKey()


                conn = (HttpURLConnection) url.openConnection();
                conn.setRequestMethod("GET");
                assertEquals(HttpServletResponse.SC_OK, conn.getResponseCode());
                assertTrue(conn.getHeaderField("content-type").startsWith(RestConstants.JSON_CONTENT_TYPE));
                json = (JSONObject) JSONValue.parse(new InputStreamReader(conn.getInputStream()));
                assertTrue(json.containsKey(JsonTags.OOZIE_SAFE_MODE));
                assertTrue((Boolean) json.get(JsonTags.OOZIE_SAFE_MODE));

                MockDagEngineService.reset();
                params = new HashMap<String, String>();
                params.put(RestConstants.ACTION_PARAM, RestConstants.JOB_ACTION_START);
View Full Code Here


                conn = (HttpURLConnection) url.openConnection();
                conn.setRequestMethod("GET");
                assertEquals(HttpServletResponse.SC_OK, conn.getResponseCode());
                assertTrue(conn.getHeaderField("content-type").startsWith(RestConstants.JSON_CONTENT_TYPE));
                json = (JSONObject) JSONValue.parse(new InputStreamReader(conn.getInputStream()));
                assertTrue(json.containsKey(JsonTags.OOZIE_SAFE_MODE));
                assertFalse((Boolean) json.get(JsonTags.OOZIE_SAFE_MODE));

                MockDagEngineService.reset();
                params = new HashMap<String, String>();
                params.put(RestConstants.ACTION_PARAM, RestConstants.JOB_ACTION_START);
View Full Code Here

     */
    public <V> V getValue(ObjectName pObjectName,String pAttribute) {
        ObjectName requestMBean = getRequest().getObjectName();
        if (requestMBean.isPattern()) {
            JSONObject mAttributes = getAttributesForObjectNameWithPatternRequest(pObjectName);
            if (!mAttributes.containsKey(pAttribute)) {
                throw new IllegalArgumentException("No attribute " + pAttribute + " for ObjectName " + pObjectName + " returned for" +
                        " the given request");
            }
            return (V) mAttributes.get(pAttribute);
        } else {
View Full Code Here

        } else {
            JSONObject attributes = getValue();
            if (pAttribute == null) {
                throw new IllegalArgumentException("Cannot use null-attribute name to fetch a value from a multi-attribute request");
            }
            if (!attributes.containsKey(pAttribute)) {
                throw new IllegalArgumentException("No such key " + pAttribute + " in the set of returned attribute values");
            }
            return (V) attributes.get(pAttribute);
        }
    }
View Full Code Here

        Headers header = new Headers();
        ByteArrayOutputStream out = prepareResponse(handler, exchange, header);
        handler.doHandle(exchange);

        JSONObject resp = (JSONObject) new JSONParser().parse(out.toString());
        assertTrue(resp.containsKey("error"));
        assertEquals(resp.get("error_type"), IllegalArgumentException.class.getName());
        assertTrue(((String) resp.get("error")).contains("PUT"));
    }

    @Test(expectedExceptions = IllegalStateException.class,expectedExceptionsMessageRegExp = ".*not.*started.*")
 
View Full Code Here

                newHandler.doHandle(exchange);
            } finally {
                newHandler.stop();
            }
            JSONObject resp = (JSONObject) new JSONParser().parse(out.toString());
            assertTrue(resp.containsKey("error"));
            assertTrue(((String) resp.get("error")).contains(params[1]));
        }
    }

    @Test
View Full Code Here

    public void convertError() throws MalformedObjectNameException {
        BackendManager backendManager = new BackendManager(config,log);
        Exception exp = new IllegalArgumentException("Hans",new IllegalStateException("Kalb"));
        JmxRequest req = new JmxRequestBuilder(RequestType.READ,"java.lang:type=Memory").build();
        JSONObject jsonError = (JSONObject) backendManager.convertExceptionToJson(exp,req);
        assertTrue(!jsonError.containsKey("stackTrace"));
        assertEquals(jsonError.get("message"),"Hans");
        assertEquals(((JSONObject) jsonError.get("cause")).get("message"),"Kalb");
        backendManager.destroy();
    }
View Full Code Here

        assertEquals(res.get("number"),10);
        assertEquals(res.get("text"),"Test");
        assertFalse((Boolean) res.get("flag"));
        assertEquals( ((JSONObject) res.get("inner")).get("innerText"),"innerValue");
        assertNull(res.get("nulli"));
        assertTrue(!res.containsKey("forbiddenStream"));
        assertTrue(res.containsKey("nulli"));
        assertEquals(res.get("nacked"),"nacked object");
        assertEquals(res.get("self"),"[this]");

        JSONObject inner = (JSONObject) extractJson(this,"inner");
View Full Code Here

        assertEquals(res.get("text"),"Test");
        assertFalse((Boolean) res.get("flag"));
        assertEquals( ((JSONObject) res.get("inner")).get("innerText"),"innerValue");
        assertNull(res.get("nulli"));
        assertTrue(!res.containsKey("forbiddenStream"));
        assertTrue(res.containsKey("nulli"));
        assertEquals(res.get("nacked"),"nacked object");
        assertEquals(res.get("self"),"[this]");

        JSONObject inner = (JSONObject) extractJson(this,"inner");
        assertEquals(inner.get("innerText"),"innerValue");
View Full Code Here

        CompositeTypeAndJson cdj = new CompositeTypeAndJson(STRING, "name", "roland", INTEGER, "date", 1968);
        TabularData data = getMapTabularData(cdj.getType(),cdj.getCompositeData(),TEST_VALUE);

        JSONObject result = (JSONObject) extract(true,data);
        assertEquals(result.size(), 2);
        assertTrue(result.containsKey("indexNames"));
        assertTrue(result.containsKey("values"));
        List indexNames = (List) result.get("indexNames");
        assertEquals(indexNames.size(), 1);
        assertTrue(indexNames.contains("key"));
        List values = (List) result.get("values");
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.