Package com.couchbase.client.java.document.json

Examples of com.couchbase.client.java.document.json.JsonObject


                    .filter(new Func1<ClusterInfo, Boolean>() {
                        @Override
                        public Boolean call(ClusterInfo clusterInfo) {
                            boolean allHealthy = true;
                            for (Object n : clusterInfo.raw().getArray("nodes")) {
                                JsonObject node = (JsonObject) n;
                                if (!node.getString("status").equals("healthy")) {
                                    allHealthy = false;
                                    break;
                                }
                            }
                            return allHealthy;
View Full Code Here


        converter = new JsonTranscoder();
    }

    @Test
    public void shouldEncodeEmptyJsonObject() {
        JsonObject object = JsonObject.empty();

        Tuple2<ByteBuf, Integer> encoded = converter.encode(JsonDocument.create("id", object));
        assertEquals("{}", encoded.value1().toString(CharsetUtil.UTF_8));
        assertEquals(TranscoderUtils.JSON_COMPAT_FLAGS, (long) encoded.value2());
    }
View Full Code Here

        converter.decode("id", content, 0, 0, wrongFlags, ResponseStatus.SUCCESS);
    }

    @Test
    public void shouldEncodeObjectWithEmptyArray() {
        JsonObject object = JsonObject.create();
        object.put("array", JsonArray.create());

        Tuple2<ByteBuf, Integer> encoded = converter.encode(JsonDocument.create("id", object));
        assertEquals("{\"array\":[]}", encoded.value1().toString(CharsetUtil.UTF_8));
        assertEquals(TranscoderUtils.JSON_COMPAT_FLAGS, (long) encoded.value2());
    }
View Full Code Here

        assertTrue(decoded.content().getArray("array").isEmpty());
    }

    @Test
    public void shouldEncodeMixedJsonValues() throws Exception {
        JsonObject object = JsonObject.create();
        object.put("string", "Hello World");
        object.put("integer", 1);
        object.put("long", Long.MAX_VALUE);
        object.put("double", 11.3322);
        object.put("boolean", true);

        Tuple2<ByteBuf, Integer> encoded = converter.encode(JsonDocument.create("id", object));
        Map<String, Object> control = readJsonIntoMap(encoded.value1());

        assertEquals(5, control.size());
View Full Code Here

    @Test
    public void shouldDecodeMixedJsonValues() throws Exception {
        ByteBuf content = Unpooled.copiedBuffer("{\"boolean\":true,\"integer\":1,\"string\":\"Hello World\"," +
            "\"double\":11.3322,\"long\":9223372036854775807}", CharsetUtil.UTF_8);
        JsonDocument decoded = converter.decode("id", content, 0, 0, TranscoderUtils.JSON_COMMON_FLAGS, ResponseStatus.SUCCESS);
        JsonObject found = decoded.content();

        assertFalse(found.isEmpty());
        assertEquals(5, found.size());
        assertEquals(true, found.getBoolean("boolean"));
        assertEquals(1, (int) found.getInt("integer"));
        assertEquals("Hello World", found.getString("string"));
        assertEquals(11.3322, found.getDouble("double"), 0);
        assertEquals(Long.MAX_VALUE, (long) found.getLong("long"));
    }
View Full Code Here

    }

    @Test
    @SuppressWarnings("unchecked")
    public void shouldEncodeNestedObjects() throws Exception {
        JsonObject object = JsonObject.create();
        object.put("empty", JsonObject.create());
        object.put("nested", JsonObject.create().put("item", JsonArray.from("foo", "bar", 1)));

        Tuple2<ByteBuf, Integer> encoded = converter.encode(JsonDocument.create("id", object));
        Map<String, Object> control = readJsonIntoMap(encoded.value1());

        assertEquals(2, control.size());
View Full Code Here

        assertEquals(3, decoded.content().getObject("nested").getArray("item").size());
    }

    @Test
    public void shouldEncodeNestedArrays() throws Exception {
        JsonObject object = JsonObject.empty();
        object.put("1", JsonArray.create().add(JsonArray.create().add(JsonArray.create().add("Hello World"))));

        Tuple2<ByteBuf, Integer> encoded = converter.encode(JsonDocument.create("id", object));
        assertEquals("{\"1\":[[[\"Hello World\"]]]}", encoded.value1().toString(CharsetUtil.UTF_8));
        assertEquals(TranscoderUtils.JSON_COMPAT_FLAGS, (long) encoded.value2());
    }
View Full Code Here

    @Test
    public void shouldNotReleaseBufferWhenBufToJson() throws Exception {
        ByteBuf content = ReferenceCountUtil.releaseLater(
            Unpooled.copiedBuffer("{}", CharsetUtil.UTF_8));
        JsonObject decoded = converter.byteBufToJsonObject(content);
        assertEquals(1, content.refCnt());

        content = ReferenceCountUtil.releaseLater(
            Unpooled.copiedBuffer("thisIsNotJson", CharsetUtil.UTF_8));
        try {
View Full Code Here

TOP

Related Classes of com.couchbase.client.java.document.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.