Search in sources :

Example 46 with HazelcastJsonValue

use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.

the class BasicMapTest method testJsonPutGet.

@Test
public void testJsonPutGet() {
    final IMap<String, HazelcastJsonValue> map = getInstance().getMap(randomMapName());
    HazelcastJsonValue value = new HazelcastJsonValue("{ \"age\": 4 }");
    map.put("item1", value);
    HazelcastJsonValue retrieved = map.get("item1");
    assertEquals(value, retrieved);
    assertEquals(4, Json.parse(retrieved.toString()).asObject().get("age").asInt());
}
Also used : HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 47 with HazelcastJsonValue

use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.

the class JsonIndexIntegrationTest method testIndex_viaQueries.

@Test
public void testIndex_viaQueries() {
    HazelcastInstance instance = createHazelcastInstance();
    IMap<Integer, HazelcastJsonValue> map = instance.getMap(MAP_NAME);
    map.addIndex(IndexType.HASH, "age");
    map.addIndex(IndexType.HASH, "active");
    map.addIndex(IndexType.HASH, "name");
    for (int i = 0; i < 1000; i++) {
        String jsonString = "{\"age\" : " + i + "  , \"name\" : \"sancar\" , \"active\" :  " + (i % 2 == 0) + " } ";
        map.put(i, new HazelcastJsonValue(jsonString));
    }
    assertEquals(500, map.values(Predicates.and(Predicates.equal("name", "sancar"), Predicates.equal("active", "true"))).size());
    assertEquals(299, map.values(Predicates.and(Predicates.greaterThan("age", 400), Predicates.equal("active", true))).size());
    assertEquals(1000, map.values(Predicates.sql("name == sancar")).size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 48 with HazelcastJsonValue

use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.

the class JsonIndexIntegrationTest method testViaAccessingInternalIndexes.

@Test
public void testViaAccessingInternalIndexes() {
    HazelcastInstance instance = createHazelcastInstance();
    IMap<Integer, HazelcastJsonValue> map = instance.getMap(MAP_NAME);
    map.addIndex(IndexType.HASH, "age");
    map.addIndex(IndexType.HASH, "active");
    map.addIndex(IndexType.HASH, "name");
    for (int i = 0; i < 1000; i++) {
        String jsonString = "{\"age\" : " + i + "  , \"name\" : \"sancar\" , \"active\" :  " + (i % 2 == 0) + " } ";
        map.put(i, new HazelcastJsonValue(jsonString));
    }
    Set<QueryableEntry> records = getRecords(instance, MAP_NAME, "age", 40);
    assertEquals(1, records.size());
    records = getRecords(instance, MAP_NAME, "active", true);
    assertEquals(500, records.size());
    records = getRecords(instance, MAP_NAME, "name", "sancar");
    assertEquals(1000, records.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 49 with HazelcastJsonValue

use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.

the class ConvertersTest method testJsonConverter.

@Test
public void testJsonConverter() {
    JsonConverter converter = JsonConverter.INSTANCE;
    checkConverter(converter, Converter.ID_JSON, JSON, HazelcastJsonValue.class);
    checkConverterConversions(converter, VARCHAR, JSON, OBJECT);
    assertEquals("[1,2,3]", converter.asVarchar(new HazelcastJsonValue("[1,2,3]")));
    assertEquals(new HazelcastJsonValue("[1,2,3]"), converter.asObject(new HazelcastJsonValue("[1,2,3]")));
    checkConverterSelf(converter);
}
Also used : HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 50 with HazelcastJsonValue

use of com.hazelcast.core.HazelcastJsonValue in project hazelcast by hazelcast.

the class RestTest method testMapGetWithJson.

@Test
public void testMapGetWithJson() throws IOException {
    final String mapName = "mapName";
    final String key = "key";
    String jsonValue = Json.object().add("arbitrary-attribute", "arbitrary-value").toString();
    instance.getMap(mapName).put(key, new HazelcastJsonValue(jsonValue));
    HTTPCommunicator.ConnectionResponse response = communicator.mapGet(mapName, key);
    assertContains(response.responseHeaders.get("Content-Type").iterator().next(), bytesToString(CONTENT_TYPE_JSON));
    assertEquals(jsonValue, response.response);
}
Also used : ConnectionResponse(com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) StringUtil.bytesToString(com.hazelcast.internal.util.StringUtil.bytesToString) HazelcastTestSupport.randomString(com.hazelcast.test.HazelcastTestSupport.randomString) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)99 Test (org.junit.Test)80 QuickTest (com.hazelcast.test.annotation.QuickTest)74 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)67 JsonObject (com.hazelcast.internal.json.JsonObject)25 JsonValue (com.hazelcast.internal.json.JsonValue)19 NavigableJsonInputAdapter (com.hazelcast.internal.serialization.impl.NavigableJsonInputAdapter)12 JsonArray (com.hazelcast.internal.json.JsonArray)9 IMap (com.hazelcast.map.IMap)9 Map (java.util.Map)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 Data (com.hazelcast.internal.serialization.Data)5 JsonSchemaNode (com.hazelcast.json.internal.JsonSchemaNode)3 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)2 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)2 CompactGenericRecord (com.hazelcast.internal.serialization.impl.compact.CompactGenericRecord)2 PortableGenericRecord (com.hazelcast.internal.serialization.impl.portable.PortableGenericRecord)2 StringUtil.bytesToString (com.hazelcast.internal.util.StringUtil.bytesToString)2 ExpressionValue (com.hazelcast.jet.sql.impl.support.expressions.ExpressionValue)2