xtern commented on a change in pull request #7648:
URL: https://github.com/apache/ignite/pull/7648#discussion_r413659651



##########
File path: 
modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
##########
@@ -344,6 +355,252 @@ private void checkJson(String json, Person p) throws 
IOException {
         assertEquals(p.getSalary(), res.get("salary").asDouble());
     }
 
+    /**
+     * Test that after adding the object to the cache, it is available for 
query.
+     *
+     * @throws Exception If failed.
+     */
+    @Test
+    public void testPutJsonQueryEntity() throws Exception {
+        String cacheName = "person";
+
+        Person simple = new Person(100, "John", "Doe", 10000);
+
+        putObject(cacheName, "300", simple);
+
+        String ret = content(cacheName, GridRestCommand.CACHE_GET,
+            "keyType", "int",
+            "key", "300"
+        );
+
+        info("Get command result: " + ret);
+
+        checkJson(ret, simple);
+
+        JsonNode val = queryObject(
+            cacheName,
+            "type", Person.class.getSimpleName(),
+            "pageSize", "1",
+            "qry", "orgId = ?",
+            "arg1", String.valueOf(simple.getOrganizationId())
+        );
+
+        assertEquals(simple.getOrganizationId().intValue(), 
val.get("orgId").intValue());
+        assertEquals(simple.getSalary(), val.get("salary").doubleValue());
+        assertEquals(simple.getFirstName(), val.get("firstName").textValue());
+        assertEquals(simple.getLastName(), val.get("lastName").textValue());
+
+        initCache();
+    }
+
+    /**
+     * Test adding a new (unregistered) binary object.
+     *
+     * @throws Exception If failed.
+     */
+    @Test
+    @SuppressWarnings("ThrowableNotThrown")
+    public void testPutUnregistered() throws Exception {
+        LinkedHashMap<String, String> fields = new LinkedHashMap<>();
+
+        fields.put("id", Long.class.getName());
+        fields.put("name", String.class.getName());
+        fields.put("timestamp", Timestamp.class.getName());
+        fields.put("bytes", long[].class.getName());
+        fields.put("igniteUuid", IgniteUuid.class.getName());
+
+        CacheConfiguration<Object, Object> ccfg = new 
CacheConfiguration<>("testCache");
+
+        String valType = "SomeNewType";
+
+        ccfg.setQueryEntities(
+            Collections.singletonList(
+                new QueryEntity()
+                    .setKeyType("java.lang.Integer")
+                    .setValueType(valType)
+                    .setFields(fields)
+                    .setIndexes(Collections.singleton(new QueryIndex("id"))))
+        );
+
+        IgniteCache cache = grid(0).createCache(ccfg);
+
+        List<Integer> list = F.asList(1, 2, 3);
+
+        OuterClass newType = new OuterClass(Long.MAX_VALUE, "unregistered", 
0.1d, list,
+            Timestamp.valueOf("2004-08-26 16:47:03.141592"),  new long[] 
{Long.MAX_VALUE, -1, Long.MAX_VALUE},
+            UUID.randomUUID(), IgniteUuid.randomUuid(), null);
+
+        putObject(cache.getName(), "300", newType, valType);
+
+        GridTestUtils.assertThrowsWithCause(() -> cache.get(300), 
ClassNotFoundException.class);
+
+        assertEquals(newType, getObject(cache.getName(), "300", 
OuterClass.class));
+
+        // Sending "optional" (new) field for registered binary type.
+        OuterClass newTypeUpdate = new OuterClass(-1, "update", 0.7d, list,
+            Timestamp.valueOf("2004-08-26 16:47:03.14"), new long[] 
{Long.MAX_VALUE, 0, Long.MAX_VALUE},
+            UUID.randomUUID(), IgniteUuid.randomUuid(), new 
OuterClass.OptionalObject("test"));
+
+        putObject(cache.getName(), "301", newTypeUpdate, valType);
+
+        assertEquals(newTypeUpdate, getObject(cache.getName(), "301", 
OuterClass.class));
+
+        // Check query result.
+        JsonNode res = queryObject(
+            cache.getName(),
+            "type", valType,
+            "pageSize", "1",
+            "keepBinary", "true",
+            "qry", "timestamp < ?",
+            "arg1", "2004-08-26 16:47:03.141"
+        );
+
+        assertEquals(newTypeUpdate, JSON_MAPPER.treeToValue(res, 
OuterClass.class));
+
+        grid(0).destroyCache(ccfg.getName());
+    }
+
+    /**
+     * Check serialization of the nested binary object.
+     *
+     * @throws Exception If failed.
+     */
+    @Test
+    public void testPutNestedBinaryObject() throws Exception {
+        IgniteBinary binary = grid(0).binary();
+
+        BinaryObjectBuilder nested = binary.builder("Nested");
+
+        nested.setField("str1", "stringValue");
+        nested.setField("sqlDate", java.sql.Date.valueOf("2019-01-01"));
+
+        // Registering "Nested" type.
+        jcache().put(-1, nested.build());
+
+        BinaryObjectBuilder parent = binary.builder("Parent");
+
+        parent.setField("nested", nested.build());
+        parent.setField("id", Long.MAX_VALUE);
+        parent.setField("byteVal", (byte)1);
+        parent.setField("timestamp", new Timestamp(new 
java.util.Date().getTime()));
+
+        BinaryObject obj = parent.build();
+
+        // Registering "Parent" type.
+        jcache().put(2, obj);
+
+        // Adding another "Parent" object via REST.
+        JsonNode jsonNode = JSON_MAPPER.valueToTree(obj);
+
+        ((ObjectNode)jsonNode).put("id", Long.MIN_VALUE);

Review comment:
       Done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to