Package net.minidev.json

Examples of net.minidev.json.JSONObject


    public void testJSONEventLayoutHasMDC() {
        MDC.put("foo", "bar");
        logger.warn("I should have MDC data in my log");
        String message = appender.getMessages()[0];
        Object obj = JSONValue.parse(message);
        JSONObject jsonObject = (JSONObject) obj;
        JSONObject mdc = (JSONObject) jsonObject.get("mdc");

        Assert.assertEquals("MDC is wrong","bar", mdc.get("foo"));
    }
View Full Code Here


        nestedMdc.put("bar","baz");
        MDC.put("foo",nestedMdc);
        logger.warn("I should have nested MDC data in my log");
        String message = appender.getMessages()[0];
        Object obj = JSONValue.parse(message);
        JSONObject jsonObject = (JSONObject) obj;
        JSONObject mdc = (JSONObject) jsonObject.get("mdc");
        JSONObject nested = (JSONObject) mdc.get("foo");

        Assert.assertTrue("Event is missing foo key", mdc.containsKey("foo"));
        Assert.assertEquals("Nested MDC data is wrong", "baz", nested.get("bar"));
    }
View Full Code Here

    public void testJSONEventLayoutExceptions() {
        String exceptionMessage = new String("shits on fire, yo");
        logger.fatal("uh-oh", new IllegalArgumentException(exceptionMessage));
        String message = appender.getMessages()[0];
        Object obj = JSONValue.parse(message);
        JSONObject jsonObject = (JSONObject) obj;
        JSONObject exceptionInformation = (JSONObject) jsonObject.get("exception");

        Assert.assertEquals("Exception class missing", "java.lang.IllegalArgumentException", exceptionInformation.get("exception_class"));
        Assert.assertEquals("Exception exception message", exceptionMessage, exceptionInformation.get("exception_message"));
    }
View Full Code Here

    @Test
    public void testJSONEventLayoutHasClassName() {
        logger.warn("warning dawg");
        String message = appender.getMessages()[0];
        Object obj = JSONValue.parse(message);
        JSONObject jsonObject = (JSONObject) obj;

        Assert.assertEquals("Logged class does not match", this.getClass().getCanonicalName().toString(), jsonObject.get("class"));
    }
View Full Code Here

    @Test
    public void testJSONEventHasFileName() {
        logger.warn("whoami");
        String message = appender.getMessages()[0];
        Object obj = JSONValue.parse(message);
        JSONObject jsonObject = (JSONObject) obj;

        Assert.assertNotNull("File value is missing", jsonObject.get("file"));
    }
View Full Code Here

    @Test
    public void testJSONEventHasLoggerName() {
        logger.warn("whoami");
        String message = appender.getMessages()[0];
        Object obj = JSONValue.parse(message);
        JSONObject jsonObject = (JSONObject) obj;
        Assert.assertNotNull("LoggerName value is missing", jsonObject.get("logger_name"));
    }
View Full Code Here

    @Test
    public void testJSONEventHasThreadName() {
        logger.warn("whoami");
        String message = appender.getMessages()[0];
        Object obj = JSONValue.parse(message);
        JSONObject jsonObject = (JSONObject) obj;
        Assert.assertNotNull("ThreadName value is missing", jsonObject.get("thread_name"));
    }
View Full Code Here

        layout.setLocationInfo(false);

        logger.warn("warning dawg");
        String message = appender.getMessages()[0];
        Object obj = JSONValue.parse(message);
        JSONObject jsonObject = (JSONObject) obj;

        Assert.assertFalse("atFields contains file value", jsonObject.containsKey("file"));
        Assert.assertFalse("atFields contains line_number value", jsonObject.containsKey("line_number"));
        Assert.assertFalse("atFields contains class value", jsonObject.containsKey("class"));
        Assert.assertFalse("atFields contains method value", jsonObject.containsKey("method"));

        // Revert the change to the layout to leave it as we found it.
        layout.setLocationInfo(prevLocationInfo);
    }
View Full Code Here

        }
    }

    private int query(String query) throws IOException {
        URL url = new URL("http://api.qubole.com/api/v1.2/commands");
        JSONObject queryJson = new JSONObject();
        queryJson.put("query", query);
        String body = queryJson.toString();
        Map response = makeRequest(url, body);
        return (Integer) response.get("id");
    }
View Full Code Here

        super(config);
    }

    @Override
    public String[] extractPartitions(Message message) {
        JSONObject jsonObject = (JSONObject) JSONValue.parse(message.getPayload());
        String result[] = { defaultDate };

        if (jsonObject != null) {
            Object fieldValue = jsonObject.get(mConfig.getMessageTimestampName());
            Object inputPattern = mConfig.getMessageTimestampInputPattern();
            if (fieldValue != null && inputPattern != null) {
                try {
                    SimpleDateFormat inputFormatter = new SimpleDateFormat(inputPattern.toString());
                    SimpleDateFormat outputFormatter = new SimpleDateFormat(defaultFormatter);
View Full Code Here

TOP

Related Classes of net.minidev.json.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.