IGNITE-1223 Use Gson in "client" module everywhere as possible.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/e7f6cdb9 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/e7f6cdb9 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/e7f6cdb9 Branch: refs/heads/ignite-1223 Commit: e7f6cdb97c38bd91f07267c87e2dfbb8a931fab8 Parents: 5c6f60e Author: sevdokimov <sevdoki...@gridgain.com> Authored: Tue Aug 11 15:35:51 2015 +0300 Committer: sevdokimov <sevdoki...@gridgain.com> Committed: Tue Aug 11 15:35:51 2015 +0300 ---------------------------------------------------------------------- modules/clients/pom.xml | 6 ++ .../JettyRestProcessorAbstractSelfTest.java | 64 +++++++++++--------- parent/pom.xml | 5 ++ 3 files changed, 47 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e7f6cdb9/modules/clients/pom.xml ---------------------------------------------------------------------- diff --git a/modules/clients/pom.xml b/modules/clients/pom.xml index 0374bdf..45e80ab 100644 --- a/modules/clients/pom.xml +++ b/modules/clients/pom.xml @@ -83,6 +83,12 @@ </dependency> <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <scope>test</scope> + </dependency> + + <dependency> <groupId>org.apache.ignite</groupId> <artifactId>ignite-core</artifactId> <version>${project.version}</version> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e7f6cdb9/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java index 090e030..07f3c7d 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java @@ -17,7 +17,7 @@ package org.apache.ignite.internal.processors.rest; -import net.sf.json.*; +import com.google.gson.*; import org.apache.ignite.*; import org.apache.ignite.cache.*; import org.apache.ignite.cache.query.*; @@ -1029,9 +1029,9 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro assertNotNull(ret); assertTrue(!ret.isEmpty()); - JSONObject json = JSONObject.fromObject(ret); + JsonObject resp = parseResponse(ret); - List items = (List)((Map)json.get("response")).get("items"); + JsonArray items = (JsonArray)resp.get("items"); assertEquals(2, items.size()); @@ -1057,20 +1057,18 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro assertNotNull(ret); assertTrue(!ret.isEmpty()); - JSONObject json = JSONObject.fromObject(ret); + JsonObject resp = parseResponse(ret); - Integer qryId = (Integer)((Map)json.get("response")).get("queryId"); - - assertNotNull(qryId); + int qryId = resp.getAsJsonPrimitive("queryId").getAsInt(); ret = content(F.asMap("cmd", GridRestCommand.FETCH_SQL_QUERY.key(), "pageSize", "1", "qryId", String.valueOf(qryId))); - json = JSONObject.fromObject(ret); + resp = parseResponse(ret); - Integer qryId0 = (Integer)((Map)json.get("response")).get("queryId"); + int qryId0 = resp.getAsJsonPrimitive("queryId").getAsInt(); - Boolean last = (Boolean)((Map)json.get("response")).get("last"); + Boolean last = resp.getAsJsonPrimitive("last").getAsBoolean(); assertEquals(qryId0, qryId); assertFalse(last); @@ -1078,11 +1076,11 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro ret = content(F.asMap("cmd", GridRestCommand.FETCH_SQL_QUERY.key(), "pageSize", "1", "qryId", String.valueOf(qryId))); - json = JSONObject.fromObject(ret); + resp = parseResponse(ret); - qryId0 = (Integer)((Map)json.get("response")).get("queryId"); + qryId0 = resp.getAsJsonPrimitive("queryId").getAsInt(); - last = (Boolean)((Map)json.get("response")).get("last"); + last = resp.getAsJsonPrimitive("last").getAsBoolean(); assertEquals(qryId0, qryId); assertTrue(last); @@ -1107,9 +1105,9 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro assertNotNull(ret); assertTrue(!ret.isEmpty()); - JSONObject json = JSONObject.fromObject(ret); + JsonObject resp = parseResponse(ret); - List items = (List)((Map)json.get("response")).get("items"); + JsonArray items = (JsonArray)resp.get("items"); assertEquals(4, items.size()); @@ -1133,22 +1131,22 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro assertNotNull(ret); assertTrue(!ret.isEmpty()); - JSONObject json = JSONObject.fromObject(ret); + JsonObject resp = parseResponse(ret); - List items = (List)((Map)json.get("response")).get("items"); + JsonArray items = (JsonArray)resp.get("items"); - List meta = (List)((Map)json.get("response")).get("fieldsMetadata"); + JsonArray meta = (JsonArray)resp.get("fieldsMetadata"); assertEquals(4, items.size()); assertEquals(2, meta.size()); - JSONObject o = (JSONObject)meta.get(0); + JsonObject o = (JsonObject)meta.get(0); - assertEquals("FIRSTNAME", o.get("fieldName")); - assertEquals("java.lang.String", o.get("fieldTypeName")); - assertEquals("person", o.get("schemaName")); - assertEquals("PERSON", o.get("typeName")); + assertEquals("FIRSTNAME", o.get("fieldName").getAsString()); + assertEquals("java.lang.String", o.get("fieldTypeName").getAsString()); + assertEquals("person", o.get("schemaName").getAsString()); + assertEquals("PERSON", o.get("typeName").getAsString()); assertFalse(queryCursorFound()); } @@ -1173,17 +1171,15 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro assertNotNull(ret); assertTrue(!ret.isEmpty()); - JSONObject json = JSONObject.fromObject(ret); + JsonObject resp = parseResponse(ret); - List items = (List)((Map)json.get("response")).get("items"); + JsonArray items = (JsonArray)resp.get("items"); assertEquals(1, items.size()); assertTrue(queryCursorFound()); - Integer qryId = (Integer)((Map)json.get("response")).get("queryId"); - - assertNotNull(qryId); + int qryId = resp.getAsJsonPrimitive("queryId").getAsInt(); ret = content(F.asMap("cmd", GridRestCommand.CLOSE_SQL_QUERY.key(), "cacheName", "person", "qryId", String.valueOf(qryId))); @@ -1194,6 +1190,9 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro assertFalse(queryCursorFound()); } + /** + * + */ protected abstract String signature() throws Exception; /** @@ -1245,6 +1244,15 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro } /** + * @param text Text. + */ + private JsonObject parseResponse(String text) { + JsonObject json = (JsonObject)new JsonParser().parse(text); + + return (JsonObject)json.get("response"); + } + + /** * Person class. */ public static class Person implements Serializable { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e7f6cdb9/parent/pom.xml ---------------------------------------------------------------------- diff --git a/parent/pom.xml b/parent/pom.xml index efa6494..c01369f 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -130,6 +130,11 @@ </exclusion> </exclusions> </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <version>2.3.1</version> + </dependency> </dependencies> </dependencyManagement>