http://git-wip-us.apache.org/repos/asf/ignite/blob/f177d431/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 9fd3044..ad667ed 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,24 +17,27 @@ package org.apache.ignite.internal.processors.rest; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.LineNumberReader; import java.io.Serializable; +import java.io.UnsupportedEncodingException; import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.text.DateFormat; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; -import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -import java.util.regex.Pattern; -import net.sf.json.JSONNull; -import net.sf.json.JSONObject; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.ignite.IgniteCache; import org.apache.ignite.cache.CacheAtomicityMode; import org.apache.ignite.cache.CacheMode; @@ -52,10 +55,12 @@ import org.apache.ignite.internal.processors.cache.IgniteCacheProxy; import org.apache.ignite.internal.processors.cache.query.GridCacheSqlIndexMetadata; import org.apache.ignite.internal.processors.cache.query.GridCacheSqlMetadata; import org.apache.ignite.internal.processors.rest.handlers.GridRestCommandHandler; +import org.apache.ignite.internal.processors.rest.protocols.http.jetty.GridJettyObjectMapper; import org.apache.ignite.internal.util.lang.GridTuple3; import org.apache.ignite.internal.util.typedef.C1; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.P1; +import org.apache.ignite.internal.util.typedef.T2; import org.apache.ignite.internal.util.typedef.internal.SB; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.internal.visor.cache.VisorCacheClearTask; @@ -103,6 +108,7 @@ import org.apache.ignite.lang.IgniteUuid; import org.apache.ignite.testframework.GridTestUtils; import static org.apache.ignite.IgniteSystemProperties.IGNITE_JETTY_PORT; +import static org.apache.ignite.internal.IgniteVersionUtils.VER_STR; /** * Tests for Jetty REST protocol. @@ -112,6 +118,15 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro /** Grid count. */ private static final int GRID_CNT = 3; + /** Url address to send HTTP request. */ + private final String TEST_URL = "http://" + LOC_HOST + ":" + restPort() + "/ignite?"; + + /** Used to sent request charset. */ + private static final String CHARSET = StandardCharsets.UTF_8.name(); + + /** JSON to java mapper. */ + private static final ObjectMapper JSON_MAPPER = new GridJettyObjectMapper(); + /** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { System.setProperty(IGNITE_JETTY_PORT, Integer.toString(restPort())); @@ -157,12 +172,12 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro * @throws Exception If failed. */ protected String content(Map<String, String> params) throws Exception { - String addr = "http://" + LOC_HOST + ":" + restPort() + "/ignite?"; + SB sb = new SB(TEST_URL); for (Map.Entry<String, String> e : params.entrySet()) - addr += e.getKey() + '=' + e.getValue() + '&'; + sb.a(e.getKey()).a('=').a(e.getValue()).a('&'); - URL url = new URL(addr); + URL url = new URL(sb.toString()); URLConnection conn = url.openConnection(); @@ -173,165 +188,255 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro InputStream in = conn.getInputStream(); - LineNumberReader rdr = new LineNumberReader(new InputStreamReader(in)); - StringBuilder buf = new StringBuilder(256); - for (String line = rdr.readLine(); line != null; line = rdr.readLine()) - buf.append(line); + try (LineNumberReader rdr = new LineNumberReader(new InputStreamReader(in, "UTF-8"))) { + for (String line = rdr.readLine(); line != null; line = rdr.readLine()) + buf.append(line); + } return buf.toString(); } /** - * @param json JSON response. - * @param ptrn Pattern to match. + * @param content Content to check. */ - @SuppressWarnings("TypeMayBeWeakened") - protected void jsonEquals(String json, String ptrn) { - assertTrue("JSON mismatch [json=" + json + ", ptrn=" + ptrn + ']', Pattern.matches(ptrn, json)); + private void assertResponseContainsError(String content) throws IOException { + assertNotNull(content); + assertFalse(content.isEmpty()); + + JsonNode node = JSON_MAPPER.readTree(content); + + assertEquals(1, node.get("successStatus").asInt()); + assertFalse(node.get("error").asText().isEmpty()); + assertTrue(node.get("response").isNull()); + assertTrue(node.get("sessionToken").asText().isEmpty()); } /** - * @param res Response. - * @param success Success flag. - * @return Regex pattern for JSON. + * @param content Content to check. + * @param err Error message. */ - private String cachePattern(String res, boolean success) { - return "\\{\\\"affinityNodeId\\\":\\\"\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}\\\"\\," + - "\\\"error\\\":\\\"\\\"\\," + - "\\\"response\\\":\\\"" + res + "\\\"\\," + - "\\\"sessionToken\\\":\\\"" + (securityEnabled() && success ? ".+" : "") + "\\\"," + - "\\\"successStatus\\\":" + (success ? 0 : 1) + "\\}"; + private void assertResponseContainsError(String content, String err) throws IOException { + assertNotNull(content); + assertFalse(content.isEmpty()); + + assertNotNull(err); + + JsonNode node = JSON_MAPPER.readTree(content); + + assertEquals(1, node.get("successStatus").asInt()); + + assertTrue(node.get("response").isNull()); + assertEquals(err, node.get("error").asText()); } /** - * @param err Error. - * @return Regex pattern for JSON. + * @param content Content to check. */ - private String errorPattern(String err) { - return "\\{" + - "\\\"error\\\":\\\"" + err + "\\\"\\," + - "\\\"response\\\":null\\," + - "\\\"sessionToken\\\":\\\"\\\"," + - "\\\"successStatus\\\":" + 1 + "\\}"; + private JsonNode jsonCacheOperationResponse(String content, boolean bulk) throws IOException { + assertNotNull(content); + assertFalse(content.isEmpty()); + + JsonNode node = JSON_MAPPER.readTree(content); + + assertEquals(bulk, node.get("affinityNodeId").asText().isEmpty()); + assertEquals(0, node.get("successStatus").asInt()); + assertTrue(node.get("error").asText().isEmpty()); + + assertNotSame(securityEnabled(), node.get("sessionToken").asText().isEmpty()); + + return node.get("response"); } /** + * @param content Content to check. * @param res Response. - * @param success Success flag. - * @return Regex pattern for JSON. */ - private String integerPattern(int res, boolean success) { - return "\\{\\\"error\\\":\\\"\\\"\\," + - "\\\"response\\\":" + res + "\\," + - "\\\"sessionToken\\\":\\\"" + (securityEnabled() && success ? ".+" : "") + "\\\"," + - "\\\"successStatus\\\":" + (success ? 0 : 1) + "\\}"; + private void assertCacheOperation(String content, Object res) throws IOException { + JsonNode ret = jsonCacheOperationResponse(content, false); + + assertEquals(String.valueOf(res), ret.asText()); } /** + * @param content Content to check. * @param res Response. - * @param success Success flag. - * @return Regex pattern for JSON. */ - private String cacheBulkPattern(String res, boolean success) { - return "\\{\\\"affinityNodeId\\\":\\\"\\\"\\," + - "\\\"error\\\":\\\"\\\"\\," + - "\\\"response\\\":" + res + "\\," + - "\\\"sessionToken\\\":\\\"" + (securityEnabled() && success ? ".+" : "") + "\\\"," + - "\\\"successStatus\\\":" + (success ? 0 : 1) + "\\}"; + private void assertCacheBulkOperation(String content, Object res) throws IOException { + JsonNode ret = jsonCacheOperationResponse(content, true); + + assertEquals(String.valueOf(res), ret.asText()); } /** - * @param res Response. - * @param success Success flag. - * @return Regex pattern for JSON. + * @param content Content to check. */ - private String cacheBulkPattern(int res, boolean success) { - return "\\{\\\"affinityNodeId\\\":\\\"\\\"\\," + - "\\\"error\\\":\\\"\\\"\\," + - "\\\"response\\\":" + res + "\\," + - "\\\"sessionToken\\\":\\\"" + (securityEnabled() && success ? ".+" : "") + "\\\"," + - "\\\"successStatus\\\":" + (success ? 0 : 1) + "\\}"; + private void assertCacheMetrics(String content) throws IOException { + JsonNode ret = jsonCacheOperationResponse(content, true); + + assertTrue(ret.isObject()); } /** - * @param res Response. - * @param success Success flag. - * @return Regex pattern for JSON. + * @param content Content to check. + * @return REST result. */ - private String cachePattern(boolean res, boolean success) { - return "\\{\\\"affinityNodeId\\\":\\\"\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}\\\"\\," + - "\\\"error\\\":\\\"\\\"\\," + - "\\\"response\\\":" + res + "\\," + - "\\\"sessionToken\\\":\\\"" + (securityEnabled() && success ? ".+" : "") + "\\\"," + - "\\\"successStatus\\\":" + (success ? 0 : 1) + "\\}"; + protected JsonNode jsonResponse(String content) throws IOException { + assertNotNull(content); + assertFalse(content.isEmpty()); + + JsonNode node = JSON_MAPPER.readTree(content); + + assertEquals(0, node.get("successStatus").asInt()); + assertTrue(node.get("error").asText().isEmpty()); + + assertNotSame(securityEnabled(), node.get("sessionToken").asText().isEmpty()); + + return node.get("response"); } /** - * @param res Response. - * @param success Success flag. - * @return Regex pattern for JSON. + * @param content Content to check. + * @return Task result. */ - private String cacheBulkPattern(boolean res, boolean success) { - return "\\{\\\"affinityNodeId\\\":\\\"\\\"\\," + - "\\\"error\\\":\\\"\\\"\\," + - "\\\"response\\\":" + res + "\\," + - "\\\"sessionToken\\\":\\\"" + (securityEnabled() && success ? ".+" : "") + "\\\"," + - "\\\"successStatus\\\":" + (success ? 0 : 1) + "\\}"; + protected JsonNode jsonTaskResult(String content) throws IOException { + assertNotNull(content); + assertFalse(content.isEmpty()); + + JsonNode node = JSON_MAPPER.readTree(content); + + assertEquals(0, node.get("successStatus").asInt()); + assertTrue(node.get("error").asText().isEmpty()); + assertFalse(node.get("response").isNull()); + + assertEquals(securityEnabled(), !node.get("sessionToken").asText().isEmpty()); + + JsonNode res = node.get("response"); + + assertTrue(res.isObject()); + + assertFalse(res.get("id").asText().isEmpty()); + assertTrue(res.get("finished").asBoolean()); + assertTrue(res.get("error").asText().isEmpty()); + + return res.get("result"); } /** - * @param res Response. - * @param success Success flag. - * @return Regex pattern for JSON. + * @throws Exception If failed. */ - private String cacheMetricsPattern(String res, boolean success) { - return "\\{\\\"affinityNodeId\\\":\\\"(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})?\\\"\\," + - "\\\"error\\\":\\\"\\\"\\," + - "\\\"response\\\":" + res + "\\," + - "\\\"sessionToken\\\":\\\"" + (securityEnabled() && success ? ".+" : "") + "\\\"," + - "\\\"successStatus\\\":" + (success ? 0 : 1) + "\\}"; + public void testGet() throws Exception { + jcache().put("getKey", "getVal"); + + String ret = content(F.asMap("cmd", GridRestCommand.CACHE_GET.key(), "key", "getKey")); + + info("Get command result: " + ret); + + assertCacheOperation(ret, "getVal"); } /** - * @param res Response. - * @param success Success flag. - * @return Regex pattern for JSON. + * @throws Exception If failed. */ - protected String pattern(String res, boolean success) { - return "\\{\\\"error\\\":\\\"" + (!success ? ".+" : "") + "\\\"\\," + - "\\\"response\\\":" + res + "\\," + - "\\\"sessionToken\\\":\\\"" + (securityEnabled() && success ? ".+" : "") + "\\\"," + - "\\\"successStatus\\\":" + (success ? 0 : 1) + "\\}"; + public void testSimpleObject() throws Exception { + SimplePerson p = new SimplePerson(1, "Test", java.sql.Date.valueOf("1977-01-26"), 1000.55, 39, "CIO", 25); + + jcache().put("simplePersonKey", p); + + String ret = content(F.asMap("cmd", GridRestCommand.CACHE_GET.key(), "key", "simplePersonKey")); + + info("Get command result: " + ret); + + JsonNode res = jsonCacheOperationResponse(ret, false); + + assertEquals(res.get("id").asInt(), p.id); + assertEquals(res.get("name").asText(), p.name); + assertEquals(res.get("birthday").asText(), p.birthday.toString()); + assertEquals(res.get("salary").asDouble(), p.salary); + assertNull(res.get("age")); + assertNull(res.get("post")); + assertNull(res.get("bonus")); } /** - * @param res Response. - * @param success Success flag. - * @return Regex pattern for JSON. + * @throws Exception If failed. */ - private String stringPattern(String res, boolean success) { - return "\\{\\\"error\\\":\\\"" + (!success ? ".+" : "") + "\\\"\\," + - "\\\"response\\\":\\\"" + res + "\\\"\\," + - "\\\"sessionToken\\\":\\\"" + (securityEnabled() && success ? ".+" : "") + "\\\"," + - "\\\"successStatus\\\":" + (success ? 0 : 1) + "\\}"; + public void testDate() throws Exception { + java.util.Date utilDate = new java.util.Date(); + + DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.US); + + String date = formatter.format(utilDate); + + jcache().put("utilDateKey", utilDate); + + String ret = content(F.asMap("cmd", GridRestCommand.CACHE_GET.key(), "key", "utilDateKey")); + + info("Get command result: " + ret); + + assertCacheOperation(ret, date); + + java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); + + jcache().put("sqlDateKey", sqlDate); + + ret = content(F.asMap("cmd", GridRestCommand.CACHE_GET.key(), "key", "sqlDateKey")); + + info("Get SQL result: " + ret); + + assertCacheOperation(ret, sqlDate.toString()); + + jcache().put("timestampKey", new java.sql.Timestamp(utilDate.getTime())); + + ret = content(F.asMap("cmd", GridRestCommand.CACHE_GET.key(), "key", "timestampKey")); + + info("Get timestamp: " + ret); + + assertCacheOperation(ret, date); } /** * @throws Exception If failed. */ - public void testGet() throws Exception { - jcache().put("getKey", "getVal"); + public void testUUID() throws Exception { + UUID uuid = UUID.randomUUID(); - String ret = content(F.asMap("cmd", GridRestCommand.CACHE_GET.key(), "key", "getKey")); + jcache().put("uuidKey", uuid); + + String ret = content(F.asMap("cmd", GridRestCommand.CACHE_GET.key(), "key", "uuidKey")); + + info("Get command result: " + ret); + + assertCacheOperation(ret, uuid.toString()); + + IgniteUuid igniteUuid = IgniteUuid.fromUuid(uuid); + + jcache().put("igniteUuidKey", igniteUuid); + + ret = content(F.asMap("cmd", GridRestCommand.CACHE_GET.key(), "key", "igniteUuidKey")); + + info("Get command result: " + ret); + + assertCacheOperation(ret, igniteUuid.toString()); + } + + /** + * @throws Exception If failed. + */ + public void testTuple() throws Exception { + T2 t = new T2("key", "value"); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); + jcache().put("tupleKey", t); + + String ret = content(F.asMap("cmd", GridRestCommand.CACHE_GET.key(), "key", "tupleKey")); info("Get command result: " + ret); - jsonEquals(ret, cachePattern("getVal", true)); + JsonNode res = jsonCacheOperationResponse(ret, false); + + assertEquals(t.getKey(), res.get("key").asText()); + assertEquals(t.getValue(), res.get("value").asText()); } /** @@ -344,12 +449,9 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.CACHE_SIZE.key())); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - info("Size command result: " + ret); - jsonEquals(ret, cacheBulkPattern(1, true)); + assertCacheBulkOperation(ret, 1); } /** @@ -358,12 +460,9 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro public void testIgniteName() throws Exception { String ret = content(F.asMap("cmd", GridRestCommand.NAME.key())); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - info("Name command result: " + ret); - jsonEquals(ret, stringPattern(getTestGridName(0), true)); + assertEquals(getTestGridName(0), jsonResponse(ret).asText()); } /** @@ -372,17 +471,13 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro public void testGetOrCreateCache() throws Exception { String ret = content(F.asMap("cmd", GridRestCommand.GET_OR_CREATE_CACHE.key(), "cacheName", "testCache")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - info("Name command result: " + ret); grid(0).cache("testCache").put("1", "1"); ret = content(F.asMap("cmd", GridRestCommand.DESTROY_CACHE.key(), "cacheName", "testCache")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); + assertTrue(jsonResponse(ret).isNull()); assertNull(grid(0).cache("testCache")); } @@ -391,20 +486,19 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro * @throws Exception If failed. */ public void testGetAll() throws Exception { - jcache().put("getKey1", "getVal1"); - jcache().put("getKey2", "getVal2"); + final Map<String, String> entries = F.asMap("getKey1", "getVal1", "getKey2", "getVal2"); - String ret = content(F.asMap("cmd", GridRestCommand.CACHE_GET_ALL.key(), "k1", "getKey1", "k2", "getKey2")); + jcache().putAll(entries); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); + String ret = content(F.asMap("cmd", GridRestCommand.CACHE_GET_ALL.key(), "k1", "getKey1", "k2", "getKey2")); info("Get all command result: " + ret); - jsonEquals(ret, - // getKey[12] is used since the order is not determined. - cacheBulkPattern("\\{\\\"getKey[12]\\\":\\\"getVal[12]\\\"\\,\\\"getKey[12]\\\":\\\"getVal[12]\\\"\\}", - true)); + JsonNode res = jsonCacheOperationResponse(ret, true); + + assertTrue(res.isObject()); + + assertTrue(entries.equals(JSON_MAPPER.treeToValue(res, Map.class))); } /** @@ -413,9 +507,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro public void testIncorrectPut() throws Exception { String ret = content(F.asMap("cmd", GridRestCommand.CACHE_PUT.key(), "key", "key0")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - jsonEquals(ret, errorPattern("Failed to find mandatory parameter in request: val")); + assertResponseContainsError(ret, "Failed to find mandatory parameter in request: val"); } /** @@ -426,10 +518,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.CACHE_CONTAINS_KEY.key(), "key", "key0")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, cachePattern(true, true)); + assertCacheOperation(ret, true); } /** @@ -442,10 +531,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.CACHE_CONTAINS_KEYS.key(), "k1", "key0", "k2", "key1")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, cacheBulkPattern(true, true)); + assertCacheBulkOperation(ret, true); } /** @@ -456,10 +542,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.CACHE_GET_AND_PUT.key(), "key", "key0", "val", "val1")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, cachePattern("val0", true)); + assertCacheOperation(ret, "val0"); assertEquals("val1", grid(0).cache(null).get("key0")); } @@ -473,10 +556,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.CACHE_GET_AND_PUT_IF_ABSENT.key(), "key", "key0", "val", "val1")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, cachePattern("val0", true)); + assertCacheOperation(ret, "val0"); assertEquals("val0", grid(0).cache(null).get("key0")); } @@ -488,10 +568,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.CACHE_PUT_IF_ABSENT.key(), "key", "key0", "val", "val1")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, cachePattern(true, true)); + assertCacheOperation(ret, true); assertEquals("val1", grid(0).cache(null).get("key0")); } @@ -505,20 +582,14 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.CACHE_REMOVE_VALUE.key(), "key", "key0", "val", "val1")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, cachePattern(false, true)); + assertCacheOperation(ret, false); assertEquals("val0", grid(0).cache(null).get("key0")); ret = content(F.asMap("cmd", GridRestCommand.CACHE_REMOVE_VALUE.key(), "key", "key0", "val", "val0")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, cachePattern(true, true)); + assertCacheOperation(ret, true); assertNull(grid(0).cache(null).get("key0")); } @@ -532,10 +603,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.CACHE_GET_AND_REMOVE.key(), "key", "key0")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, cachePattern("val0", true)); + assertCacheOperation(ret, "val0"); assertNull(grid(0).cache(null).get("key0")); } @@ -549,20 +617,14 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.CACHE_REPLACE_VALUE.key(), "key", "key0", "val", "val1", "val2", "val2")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, cachePattern(false, true)); + assertCacheOperation(ret, false); assertEquals("val0", grid(0).cache(null).get("key0")); ret = content(F.asMap("cmd", GridRestCommand.CACHE_REPLACE_VALUE.key(), "key", "key0", "val", "val1", "val2", "val0")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, cachePattern(true, true)); + assertCacheOperation(ret, true); assertEquals("val1", grid(0).cache(null).get("key0")); } @@ -576,10 +638,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.CACHE_GET_AND_REPLACE.key(), "key", "key0", "val", "val1")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, cachePattern("val0", true)); + assertCacheOperation(ret, "val0"); assertEquals("val1", grid(0).cache(null).get("key0")); } @@ -591,14 +650,11 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.CACHE_PUT.key(), "key", "putKey", "val", "putVal")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - info("Put command result: " + ret); assertEquals("putVal", jcache().localPeek("putKey", CachePeekMode.ONHEAP)); - jsonEquals(ret, cachePattern(true, true)); + assertCacheOperation(ret, true); } /** @@ -608,10 +664,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.CACHE_PUT.key(), "key", "putKey", "val", "putVal", "exp", "2000")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, cachePattern(true, true)); + assertCacheOperation(ret, true); assertEquals("putVal", jcache().get("putKey")); @@ -629,10 +682,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.CACHE_ADD.key(), "key", "addKey2", "val", "addVal2")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, cachePattern(true, true)); + assertCacheOperation(ret, true); assertEquals("addVal1", jcache().localPeek("addKey1", CachePeekMode.ONHEAP)); assertEquals("addVal2", jcache().localPeek("addKey2", CachePeekMode.ONHEAP)); @@ -645,10 +695,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.CACHE_ADD.key(), "key", "addKey", "val", "addVal", "exp", "2000")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, cachePattern(true, true)); + assertCacheOperation(ret, true); assertEquals("addVal", jcache().get("addKey")); @@ -665,15 +712,12 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro "k1", "putKey1", "k2", "putKey2", "v1", "putVal1", "v2", "putVal2")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - info("Put all command result: " + ret); assertEquals("putVal1", jcache().localPeek("putKey1", CachePeekMode.ONHEAP)); assertEquals("putVal2", jcache().localPeek("putKey2", CachePeekMode.ONHEAP)); - jsonEquals(ret, cacheBulkPattern(true, true)); + assertCacheBulkOperation(ret, true); } /** @@ -687,14 +731,11 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.CACHE_REMOVE.key(), "key", "rmvKey")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - info("Remove command result: " + ret); assertNull(jcache().localPeek("rmvKey", CachePeekMode.ONHEAP)); - jsonEquals(ret, cachePattern(true, true)); + assertCacheOperation(ret, true); } /** @@ -714,9 +755,6 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.CACHE_REMOVE_ALL.key(), "k1", "rmvKey1", "k2", "rmvKey2")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - info("Remove all command result: " + ret); assertNull(jcache().localPeek("rmvKey1", CachePeekMode.ONHEAP)); @@ -724,13 +762,10 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro assertEquals("rmvVal3", jcache().localPeek("rmvKey3", CachePeekMode.ONHEAP)); assertEquals("rmvVal4", jcache().localPeek("rmvKey4", CachePeekMode.ONHEAP)); - jsonEquals(ret, cacheBulkPattern(true, true)); + assertCacheBulkOperation(ret, true); ret = content(F.asMap("cmd", GridRestCommand.CACHE_REMOVE_ALL.key())); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - info("Remove all command result: " + ret); assertNull(jcache().localPeek("rmvKey1", CachePeekMode.ONHEAP)); @@ -739,7 +774,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro assertNull(jcache().localPeek("rmvKey4", CachePeekMode.ONHEAP)); assertTrue(jcache().localSize() == 0); - jsonEquals(ret, cacheBulkPattern(true, true)); + assertCacheBulkOperation(ret, true); } /** @@ -753,14 +788,11 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.CACHE_CAS.key(), "key", "casKey", "val2", "casOldVal", "val1", "casNewVal")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - info("CAS command result: " + ret); assertEquals("casNewVal", jcache().localPeek("casKey", CachePeekMode.ONHEAP)); - jsonEquals(ret, cachePattern(true, true)); + assertCacheOperation(ret, true); jcache().remove("casKey"); } @@ -776,14 +808,11 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.CACHE_REPLACE.key(), "key", "repKey", "val", "repVal")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - info("Replace command result: " + ret); assertEquals("repVal", jcache().localPeek("repKey", CachePeekMode.ONHEAP)); - jsonEquals(ret, cachePattern(true, true)); + assertCacheOperation(ret, true); } /** @@ -797,10 +826,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.CACHE_REPLACE.key(), "key", "replaceKey", "val", "replaceValNew", "exp", "2000")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, cachePattern(true, true)); + assertCacheOperation(ret, true); assertEquals("replaceValNew", jcache().get("replaceKey")); @@ -819,10 +845,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.CACHE_APPEND.key(), "key", "appendKey", "val", "_suffix")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, cachePattern(true, true)); + assertCacheOperation(ret, true); assertEquals("appendVal_suffix", jcache().get("appendKey")); } @@ -836,10 +859,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.CACHE_PREPEND.key(), "key", "prependKey", "val", "prefix_")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, cachePattern(true, true)); + assertCacheOperation(ret, true); assertEquals("prefix_prependVal", jcache().get("prependKey")); } @@ -851,20 +871,16 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.ATOMIC_INCREMENT.key(), "key", "incrKey", "init", "2", "delta", "3")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, integerPattern(5, true)); + JsonNode res = jsonResponse(ret); + assertEquals(5, res.asInt()); assertEquals(5, grid(0).atomicLong("incrKey", 0, true).get()); ret = content(F.asMap("cmd", GridRestCommand.ATOMIC_INCREMENT.key(), "key", "incrKey", "delta", "10")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, integerPattern(15, true)); + res = jsonResponse(ret); + assertEquals(15, res.asInt()); assertEquals(15, grid(0).atomicLong("incrKey", 0, true).get()); } @@ -875,21 +891,17 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.ATOMIC_DECREMENT.key(), "key", "decrKey", "init", "15", "delta", "10")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, integerPattern(5, true)); + JsonNode res = jsonResponse(ret); + assertEquals(5, res.asInt()); assertEquals(5, grid(0).atomicLong("decrKey", 0, true).get()); ret = content(F.asMap("cmd", GridRestCommand.ATOMIC_DECREMENT.key(), "key", "decrKey", "delta", "3")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, integerPattern(2, true)); + res = jsonResponse(ret); + assertEquals(2, res.asInt()); assertEquals(2, grid(0).atomicLong("decrKey", 0, true).get()); } @@ -904,14 +916,11 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.CACHE_CAS.key(), "key", "casKey", "val2", "casOldVal")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - info("CAR command result: " + ret); assertNull(jcache().localPeek("casKey", CachePeekMode.ONHEAP)); - jsonEquals(ret, cachePattern(true, true)); + assertCacheOperation(ret, true); } /** @@ -923,14 +932,11 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.CACHE_CAS.key(), "key", "casKey", "val1", "casNewVal")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - info("PutIfAbsent command result: " + ret); assertEquals("casNewVal", jcache().localPeek("casKey", CachePeekMode.ONHEAP)); - jsonEquals(ret, cachePattern(true, true)); + assertCacheOperation(ret, true); } /** @@ -943,14 +949,11 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.CACHE_CAS.key(), "key", "casKey")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - info("CAS Remove command result: " + ret); assertNull(jcache().localPeek("casKey", CachePeekMode.ONHEAP)); - jsonEquals(ret, cachePattern(true, true)); + assertCacheOperation(ret, true); } /** @@ -959,12 +962,9 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro public void testMetrics() throws Exception { String ret = content(F.asMap("cmd", GridRestCommand.CACHE_METRICS.key())); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - info("Cache metrics command result: " + ret); - jsonEquals(ret, cacheMetricsPattern("\\{.+\\}", true)); + assertCacheMetrics(ret); } /** @@ -981,20 +981,16 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(params); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - info("Cache metadata result: " + ret); - jsonEquals(ret, pattern("\\[.+\\]", true)); - - Collection<Map> results = (Collection)JSONObject.fromObject(ret).get("response"); + JsonNode arr = jsonResponse(ret); - assertEquals(metas.size(), results.size()); - assertEquals(cacheNameArg, F.first(results).get("cacheName")); + assertTrue(arr.isArray()); + assertEquals(metas.size(), arr.size()); - for (Map res : results) { - final Object cacheName = res.get("cacheName"); + for (JsonNode item : arr) { + JsonNode cacheNameNode = item.get("cacheName"); + final String cacheName = cacheNameNode != null ? cacheNameNode.asText() : null; GridCacheSqlMetadata meta = F.find(metas, null, new P1<GridCacheSqlMetadata>() { @Override public boolean apply(GridCacheSqlMetadata meta) { @@ -1004,49 +1000,60 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro assertNotNull("REST return metadata for unexpected cache: " + cacheName, meta); - Collection types = (Collection)res.get("types"); + JsonNode types = item.get("types"); assertNotNull(types); - assertEqualsCollections(meta.types(), types); + assertFalse(types.isNull()); - Map keyClasses = (Map)res.get("keyClasses"); + assertEqualsCollections(meta.types(), JSON_MAPPER.treeToValue(types, Collection.class)); + + JsonNode keyClasses = item.get("keyClasses"); assertNotNull(keyClasses); - assertTrue(meta.keyClasses().equals(keyClasses)); + assertFalse(keyClasses.isNull()); + + assertTrue(meta.keyClasses().equals(JSON_MAPPER.treeToValue(keyClasses, Map.class))); - Map valClasses = (Map)res.get("valClasses"); + JsonNode valClasses = item.get("valClasses"); assertNotNull(valClasses); - assertTrue(meta.valClasses().equals(valClasses)); + assertFalse(valClasses.isNull()); + + assertTrue(meta.valClasses().equals(JSON_MAPPER.treeToValue(valClasses, Map.class))); - Map fields = (Map)res.get("fields"); + JsonNode fields = item.get("fields"); assertNotNull(fields); - assertTrue(meta.fields().equals(fields)); + assertFalse(fields.isNull()); + assertTrue(meta.fields().equals(JSON_MAPPER.treeToValue(fields, Map.class))); - Map indexesByType = (Map)res.get("indexes"); + JsonNode indexesByType = item.get("indexes"); assertNotNull(indexesByType); + assertFalse(indexesByType.isNull()); assertEquals(meta.indexes().size(), indexesByType.size()); for (Map.Entry<String, Collection<GridCacheSqlIndexMetadata>> metaIndexes : meta.indexes().entrySet()) { - Collection<Map> indexes = (Collection<Map>)indexesByType.get(metaIndexes.getKey()); + JsonNode indexes = indexesByType.get(metaIndexes.getKey()); assertNotNull(indexes); + assertFalse(indexes.isNull()); assertEquals(metaIndexes.getValue().size(), indexes.size()); for (final GridCacheSqlIndexMetadata metaIdx : metaIndexes.getValue()) { - Map idx = F.find(indexes, null, new P1<Map>() { - @Override public boolean apply(Map map) { - return metaIdx.name().equals(map.get("name")); + JsonNode idx = F.find(indexes, null, new P1<JsonNode>() { + @Override public boolean apply(JsonNode idx) { + return metaIdx.name().equals(idx.get("name").asText()); } }); assertNotNull(idx); - assertEqualsCollections(metaIdx.fields(), (Collection)idx.get("fields")); - assertEqualsCollections(metaIdx.descendings(), (Collection)idx.get("descendings")); - assertEquals(metaIdx.unique(), idx.get("unique")); + assertEqualsCollections(metaIdx.fields(), + JSON_MAPPER.treeToValue(idx.get("fields"), Collection.class)); + assertEqualsCollections(metaIdx.descendings(), + JSON_MAPPER.treeToValue(idx.get("descendings"), Collection.class)); + assertEquals(metaIdx.unique(), idx.get("unique").asBoolean()); } } } @@ -1087,32 +1094,28 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro public void testTopology() throws Exception { String ret = content(F.asMap("cmd", GridRestCommand.TOPOLOGY.key(), "attr", "false", "mtr", "false")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - info("Topology command result: " + ret); - jsonEquals(ret, pattern("\\[\\{.+\\}\\]", true)); - - JSONObject json = JSONObject.fromObject(ret); + JsonNode res = jsonResponse(ret); - Collection<Map> nodes = (Collection)json.get("response"); + assertEquals(GRID_CNT, res.size()); - assertEquals(GRID_CNT, nodes.size()); + for (JsonNode node : res) { + assertTrue(node.get("attributes").isNull()); + assertTrue(node.get("metrics").isNull()); - for (Map node : nodes) { - assertEquals(JSONNull.getInstance(), node.get("attributes")); - assertEquals(JSONNull.getInstance(), node.get("metrics")); + JsonNode caches = node.get("caches"); - Collection<Map> caches = (Collection)node.get("caches"); + assertFalse(caches.isNull()); Collection<IgniteCacheProxy<?, ?>> publicCaches = grid(0).context().cache().publicCaches(); - assertNotNull(caches); assertEquals(publicCaches.size(), caches.size()); - for (Map cache : caches) { - final String cacheName = cache.get("name").equals("") ? null : (String)cache.get("name"); + for (JsonNode cache : caches) { + String cacheName0 = cache.get("name").asText(); + + final String cacheName = cacheName0.equals("") ? null : cacheName0; IgniteCacheProxy<?, ?> publicCache = F.find(publicCaches, null, new P1<IgniteCacheProxy<?, ?>>() { @Override public boolean apply(IgniteCacheProxy<?, ?> c) { @@ -1122,9 +1125,9 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro assertNotNull(publicCache); - CacheMode cacheMode = CacheMode.valueOf((String)cache.get("mode")); + CacheMode cacheMode = CacheMode.valueOf(cache.get("mode").asText()); - assertEquals(publicCache.getConfiguration(CacheConfiguration.class).getCacheMode(),cacheMode); + assertEquals(publicCache.getConfiguration(CacheConfiguration.class).getCacheMode(), cacheMode); } } } @@ -1136,31 +1139,30 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(F.asMap("cmd", GridRestCommand.NODE.key(), "attr", "true", "mtr", "true", "id", grid(0).localNode().id().toString())); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - info("Topology command result: " + ret); - jsonEquals(ret, pattern("\\{.+\\}", true)); + JsonNode res = jsonResponse(ret); - ret = content(F.asMap("cmd", GridRestCommand.NODE.key(), "attr", "false", "mtr", "false", "ip", LOC_HOST)); + assertTrue(res.get("attributes").isObject()); + assertTrue(res.get("metrics").isObject()); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); + ret = content(F.asMap("cmd", GridRestCommand.NODE.key(), "attr", "false", "mtr", "false", "ip", LOC_HOST)); info("Topology command result: " + ret); - jsonEquals(ret, pattern("\\{.+\\}", true)); + res = jsonResponse(ret); + + assertTrue(res.get("attributes").isNull()); + assertTrue(res.get("metrics").isNull()); ret = content(F.asMap("cmd", GridRestCommand.NODE.key(), "attr", "false", "mtr", "false", "ip", LOC_HOST, "id", UUID.randomUUID().toString())); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - info("Topology command result: " + ret); - jsonEquals(ret, pattern("null", true)); + res = jsonResponse(ret); + + assertTrue(res.isNull()); } /** @@ -1173,52 +1175,41 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro public void testExe() throws Exception { String ret = content(F.asMap("cmd", GridRestCommand.EXE.key())); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - info("Exe command result: " + ret); - jsonEquals(ret, pattern("null", false)); + assertResponseContainsError(ret); // Attempt to execute unknown task (UNKNOWN_TASK) will result in exception on server. ret = content(F.asMap("cmd", GridRestCommand.EXE.key(), "name", "UNKNOWN_TASK")); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - info("Exe command result: " + ret); - jsonEquals(ret, pattern("null", false)); + assertResponseContainsError(ret); grid(0).compute().localDeployTask(TestTask1.class, TestTask1.class.getClassLoader()); grid(0).compute().localDeployTask(TestTask2.class, TestTask2.class.getClassLoader()); ret = content(F.asMap("cmd", GridRestCommand.EXE.key(), "name", TestTask1.class.getName())); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - info("Exe command result: " + ret); - jsonEquals(ret, pattern("\\{.+\\}", true)); + JsonNode res = jsonTaskResult(ret); - ret = content(F.asMap("cmd", GridRestCommand.EXE.key(), "name", TestTask2.class.getName())); + assertTrue(res.isNull()); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); + ret = content(F.asMap("cmd", GridRestCommand.EXE.key(), "name", TestTask2.class.getName())); info("Exe command result: " + ret); - jsonEquals(ret, pattern("\\{.+" + TestTask2.RES + ".+\\}", true)); + res = jsonTaskResult(ret); - ret = content(F.asMap("cmd", GridRestCommand.RESULT.key())); + assertEquals(TestTask2.RES, res.asText()); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); + ret = content(F.asMap("cmd", GridRestCommand.RESULT.key())); info("Exe command result: " + ret); - jsonEquals(ret, pattern("null", false)); + assertResponseContainsError(ret); } /** @@ -1229,9 +1220,6 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro public void testVisorGateway() throws Exception { ClusterNode locNode = grid(1).localNode(); - final String successRes = pattern( - "\\{\\\"error\\\":\\\"\\\",\\\"finished\\\":true,\\\"id\\\":\\\"[^\\\"]+\\\",\\\"result\\\":.+}", true); - final IgniteUuid cid = grid(1).context().cache().internalCache("person").context().dynamicDeploymentId(); String ret = content(new VisorGatewayArgument(VisorCacheConfigurationCollectorTask.class) @@ -1240,10 +1228,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro info("VisorCacheConfigurationCollectorTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorCacheNodesTask.class) .forNode(locNode) @@ -1251,10 +1236,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro info("VisorCacheNodesTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorCacheLoadTask.class) .forNode(locNode) @@ -1262,10 +1244,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro info("VisorCacheLoadTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorCacheSwapBackupsTask.class) .forNode(locNode) @@ -1273,10 +1252,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro info("VisorCacheSwapBackupsTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorCacheRebalanceTask.class) .forNode(locNode) @@ -1284,10 +1260,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro info("VisorCacheRebalanceTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorCacheMetadataTask.class) .forNode(locNode) @@ -1295,10 +1268,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro info("VisorCacheMetadataTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorCacheResetMetricsTask.class) .forNode(locNode) @@ -1306,10 +1276,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro info("VisorCacheResetMetricsTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorIgfsSamplingStateTask.class) .forNode(locNode) @@ -1317,10 +1284,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro info("VisorIgfsSamplingStateTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorIgfsProfilerClearTask.class) .forNode(locNode) @@ -1328,10 +1292,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro info("VisorIgfsProfilerClearTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorIgfsProfilerTask.class) .forNode(locNode) @@ -1339,10 +1300,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro info("VisorIgfsProfilerTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorIgfsFormatTask.class) .forNode(locNode) @@ -1350,10 +1308,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro info("VisorIgfsFormatTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorIgfsResetMetricsTask.class) .forNode(locNode) @@ -1361,20 +1316,14 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro info("VisorIgfsResetMetricsTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorThreadDumpTask.class) .forNode(locNode)); info("VisorThreadDumpTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorLatestTextFilesTask.class) .forNode(locNode) @@ -1382,20 +1331,14 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro info("VisorLatestTextFilesTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorLatestVersionTask.class) .forNode(locNode)); info("VisorLatestVersionTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorFileBlockTask.class) .forNode(locNode) @@ -1403,10 +1346,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro info("VisorFileBlockTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorNodePingTask.class) .forNode(locNode) @@ -1414,45 +1354,31 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro info("VisorNodePingTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorNodeConfigurationCollectorTask.class) .forNode(locNode)); info("VisorNodeConfigurationCollectorTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorComputeResetMetricsTask.class) .forNode(locNode)); info("VisorComputeResetMetricsTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorQueryTask.class) .forNode(locNode) - .argument(VisorQueryArg.class, "person", URLEncoder.encode("select * from Person"), false, 1)); + .argument(VisorQueryArg.class, "person", URLEncoder.encode("select * from Person", CHARSET), false, 1)); info("VisorQueryTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); + JsonNode res = jsonTaskResult(ret); - jsonEquals(ret, successRes); - - JSONObject json = JSONObject.fromObject(ret); - - final String qryId = (String)((Map)((Map)((Map)json.get("response")).get("result")).get("value")).get("queryId"); + final String qryId = res.get("value").get("queryId").asText(); ret = content(new VisorGatewayArgument(VisorQueryNextPageTask.class) .forNode(locNode) @@ -1460,30 +1386,21 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro info("VisorQueryNextPageTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorQueryCleanupTask.class) .map(UUID.class, Set.class, F.asMap(locNode.id(), qryId))); info("VisorQueryCleanupTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorResolveHostNameTask.class) .forNode(locNode)); info("VisorResolveHostNameTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); // Multinode tasks @@ -1492,10 +1409,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro info("VisorComputeCancelSessionsTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorCacheMetricsCollectorTask.class) .pair(Boolean.class, Set.class, false, "person")); @@ -1508,39 +1422,27 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro info("VisorCacheMetricsCollectorTask (with nodes) result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorLogSearchTask.class) .argument(VisorLogSearchTask.VisorLogSearchArg.class, ".", ".", "abrakodabra.txt", 1)); info("VisorLogSearchTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorNodeGcTask.class)); info("VisorNodeGcTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorAckTask.class) .argument("MSG")); info("VisorAckTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorNodeEventsCollectorTask.class) .argument(VisorNodeEventsCollectorTask.VisorNodeEventsCollectorTaskArg.class, @@ -1548,10 +1450,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro info("VisorNodeEventsCollectorTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorNodeDataCollectorTask.class) .argument(VisorNodeDataCollectorTaskArg.class, false, @@ -1559,30 +1458,21 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro info("VisorNodeDataCollectorTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorComputeToggleMonitoringTask.class) .pair(String.class, Boolean.class, UUID.randomUUID(), false)); info("VisorComputeToggleMonitoringTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorNodeSuppressedErrorsTask.class) .map(UUID.class, Long.class, new HashMap())); info("VisorNodeSuppressedErrorsTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorCacheClearTask.class) .forNode(locNode) @@ -1590,10 +1480,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro info("VisorCacheClearTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); /** Spring XML to start cache via Visor task. */ final String START_CACHE = @@ -1608,14 +1495,12 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro "</beans>"; ret = content(new VisorGatewayArgument(VisorCacheStartTask.class) - .argument(VisorCacheStartTask.VisorCacheStartArg.class, false, "person2", URLEncoder.encode(START_CACHE))); + .argument(VisorCacheStartTask.VisorCacheStartArg.class, false, "person2", + URLEncoder.encode(START_CACHE, CHARSET))); info("VisorCacheStartTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); ret = content(new VisorGatewayArgument(VisorCacheStopTask.class) .forNode(locNode) @@ -1623,10 +1508,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro info("VisorCacheStopTask result: " + ret); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - jsonEquals(ret, successRes); + jsonTaskResult(ret); } /** @@ -1635,10 +1517,9 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro public void testVersion() throws Exception { String ret = content(F.asMap("cmd", GridRestCommand.VERSION.key())); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); + JsonNode res = jsonResponse(ret); - jsonEquals(ret, stringPattern(".+", true)); + assertEquals(VER_STR, res.asText()); } /** @@ -1652,18 +1533,13 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro params.put("type", "Person"); params.put("pageSize", "10"); params.put("cacheName", "person"); - params.put("qry", URLEncoder.encode(qry)); + params.put("qry", URLEncoder.encode(qry, CHARSET)); params.put("arg1", "1000"); params.put("arg2", "2000"); String ret = content(params); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - JSONObject json = JSONObject.fromObject(ret); - - List items = (List)((Map)json.get("response")).get("items"); + JsonNode items = jsonResponse(ret).get("items"); assertEquals(2, items.size()); @@ -1681,12 +1557,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(params); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - JSONObject json = JSONObject.fromObject(ret); - - List items = (List)((Map)json.get("response")).get("items"); + JsonNode items = jsonResponse(ret).get("items"); assertEquals(4, items.size()); @@ -1705,12 +1576,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro String ret = content(params); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - JSONObject json = JSONObject.fromObject(ret); - - List items = (List)((Map)json.get("response")).get("items"); + JsonNode items = jsonResponse(ret).get("items"); assertEquals(2, items.size()); @@ -1721,22 +1587,17 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro * @throws Exception If failed. */ public void testIncorrectFilterQueryScan() throws Exception { + String clsName = ScanFilter.class.getName() + 1; + Map<String, String> params = new HashMap<>(); params.put("cmd", GridRestCommand.EXECUTE_SCAN_QUERY.key()); params.put("pageSize", "10"); params.put("cacheName", "person"); - params.put("className", ScanFilter.class.getName() + 1); + params.put("className", clsName); String ret = content(params); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - JSONObject json = JSONObject.fromObject(ret); - - String err = (String)json.get("error"); - - assertTrue(err.contains("Failed to find target class")); + assertResponseContainsError(ret, "Failed to find target class: " + clsName); } /** @@ -1751,42 +1612,33 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro params.put("cmd", GridRestCommand.EXECUTE_SQL_QUERY.key()); params.put("type", "String"); params.put("pageSize", "1"); - params.put("qry", URLEncoder.encode("select * from String")); + params.put("qry", URLEncoder.encode("select * from String", CHARSET)); String ret = content(params); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - JSONObject json = JSONObject.fromObject(ret); - - Integer qryId = (Integer)((Map)json.get("response")).get("queryId"); + JsonNode qryId = jsonResponse(ret).get("queryId"); - assertNotNull(qryId); + assertFalse(jsonResponse(ret).get("queryId").isNull()); ret = content(F.asMap("cmd", GridRestCommand.FETCH_SQL_QUERY.key(), - "pageSize", "1", "qryId", String.valueOf(qryId))); + "pageSize", "1", "qryId", qryId.asText())); - json = JSONObject.fromObject(ret); + JsonNode res = jsonResponse(ret); - Integer qryId0 = (Integer)((Map)json.get("response")).get("queryId"); - - Boolean last = (Boolean)((Map)json.get("response")).get("last"); + JsonNode qryId0 = jsonResponse(ret).get("queryId"); assertEquals(qryId0, qryId); - assertFalse(last); + assertFalse(res.get("last").asBoolean()); ret = content(F.asMap("cmd", GridRestCommand.FETCH_SQL_QUERY.key(), - "pageSize", "1", "qryId", String.valueOf(qryId))); - - json = JSONObject.fromObject(ret); + "pageSize", "1", "qryId", qryId.asText())); - qryId0 = (Integer)((Map)json.get("response")).get("queryId"); + res = jsonResponse(ret); - last = (Boolean)((Map)json.get("response")).get("last"); + qryId0 = jsonResponse(ret).get("queryId"); assertEquals(qryId0, qryId); - assertTrue(last); + assertTrue(res.get("last").asBoolean()); assertFalse(queryCursorFound()); } @@ -1801,16 +1653,11 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro params.put("cmd", GridRestCommand.EXECUTE_SQL_FIELDS_QUERY.key()); params.put("pageSize", "10"); params.put("cacheName", "person"); - params.put("qry", URLEncoder.encode(qry)); + params.put("qry", URLEncoder.encode(qry, CHARSET)); String ret = content(params); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - JSONObject json = JSONObject.fromObject(ret); - - List items = (List)((Map)json.get("response")).get("items"); + JsonNode items = jsonResponse(ret).get("items"); assertEquals(4, items.size()); @@ -1827,29 +1674,25 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro params.put("cmd", GridRestCommand.EXECUTE_SQL_FIELDS_QUERY.key()); params.put("pageSize", "10"); params.put("cacheName", "person"); - params.put("qry", URLEncoder.encode(qry)); + params.put("qry", URLEncoder.encode(qry, CHARSET)); String ret = content(params); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); + JsonNode res = jsonResponse(ret); - JSONObject json = JSONObject.fromObject(ret); + JsonNode items = res.get("items"); - List items = (List)((Map)json.get("response")).get("items"); - - List meta = (List)((Map)json.get("response")).get("fieldsMetadata"); + JsonNode meta = res.get("fieldsMetadata"); assertEquals(4, items.size()); - assertEquals(2, meta.size()); - JSONObject o = (JSONObject)meta.get(0); + JsonNode o = 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").asText()); + assertEquals("java.lang.String", o.get("fieldTypeName").asText()); + assertEquals("person", o.get("schemaName").asText()); + assertEquals("PERSON", o.get("typeName").asText()); assertFalse(queryCursorFound()); } @@ -1865,32 +1708,23 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro params.put("type", "Person"); params.put("pageSize", "1"); params.put("cacheName", "person"); - params.put("qry", URLEncoder.encode(qry)); + params.put("qry", URLEncoder.encode(qry, CHARSET)); params.put("arg1", "1000"); params.put("arg2", "2000"); String ret = content(params); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - JSONObject json = JSONObject.fromObject(ret); + JsonNode res = jsonResponse(ret); - List items = (List)((Map)json.get("response")).get("items"); - - assertEquals(1, items.size()); + assertEquals(1, res.get("items").size()); assertTrue(queryCursorFound()); - Integer qryId = (Integer)((Map)json.get("response")).get("queryId"); - - assertNotNull(qryId); + assertFalse(res.get("queryId").isNull()); - ret = content(F.asMap("cmd", GridRestCommand.CLOSE_SQL_QUERY.key(), - "cacheName", "person", "qryId", String.valueOf(qryId))); + String qryId = res.get("queryId").asText(); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); + content(F.asMap("cmd", GridRestCommand.CLOSE_SQL_QUERY.key(), "cacheName", "person", "qryId", qryId)); assertFalse(queryCursorFound()); } @@ -1906,7 +1740,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro params.put("type", "Person"); params.put("pageSize", "1"); params.put("cacheName", "person"); - params.put("qry", URLEncoder.encode(qry)); + params.put("qry", URLEncoder.encode(qry, CHARSET)); params.put("arg1", "1000"); params.put("arg2", "2000"); @@ -1915,12 +1749,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro for (int i = 0; i < 10; ++i) ret = content(params); - assertNotNull(ret); - assertTrue(!ret.isEmpty()); - - JSONObject json = JSONObject.fromObject(ret); - - List items = (List)((Map)json.get("response")).get("items"); + JsonNode items = jsonResponse(ret).get("items"); assertEquals(1, items.size()); @@ -2238,7 +2067,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro * @param valCls Value class. * @param map Map. */ - public VisorGatewayArgument map(Class keyCls, Class valCls, Map<?, ?> map) { + public VisorGatewayArgument map(Class keyCls, Class valCls, Map<?, ?> map) throws UnsupportedEncodingException { put("p" + idx++, Map.class.getName()); put("p" + idx++, keyCls.getName()); put("p" + idx++, valCls.getName()); @@ -2259,7 +2088,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro first = false; } - put("p" + idx++, URLEncoder.encode(sb.toString())); + put("p" + idx++, URLEncoder.encode(sb.toString(), CHARSET)); return this; } @@ -2285,7 +2114,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro } return sb.toString(); - }; + } } /** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/f177d431/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/SimplePerson.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/SimplePerson.java b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/SimplePerson.java new file mode 100644 index 0000000..0185213 --- /dev/null +++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/SimplePerson.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.rest; + +import java.sql.Date; + +/** + * Test class with public fields and without getters and setters. + */ +public class SimplePerson { + /** Person ID. */ + public int id; + + /** Person name. */ + public String name; + + /** Person birthday. */ + public Date birthday; + + /** Person salary. */ + public double salary; + + /** Must be excluded on serialization. */ + public transient int age; + + /** Must be excluded on serialization. */ + protected String post; + + /** Must be excluded on serialization. */ + private int bonus; + + /** + * Default constructor. + */ + public SimplePerson() { + // No-op. + } + + /** + * Full constructor. + * + * @param id Person ID. + * @param name Person name. + * @param birthday Person birthday. + * @param salary Person salary. + * @param age Person age. + * @param post Person post. + * @param bonus Person bonus. + */ + public SimplePerson(int id, String name, Date birthday, double salary, int age, String post, int bonus) { + this.id = id; + this.name = name; + this.birthday = birthday; + this.salary = salary; + this.age = age; + this.post = post; + this.bonus = bonus; + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/f177d431/modules/core/pom.xml ---------------------------------------------------------------------- diff --git a/modules/core/pom.xml b/modules/core/pom.xml index 34368c8..5e32caf 100644 --- a/modules/core/pom.xml +++ b/modules/core/pom.xml @@ -76,6 +76,13 @@ </dependency> <dependency> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + <version>3.2.2</version> + <scope>test</scope> + </dependency> + + <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.4</version> @@ -153,14 +160,6 @@ </dependency> <dependency> - <groupId>net.sf.json-lib</groupId> - <artifactId>json-lib</artifactId> - <version>${jsonlib.version}</version> - <classifier>jdk15</classifier> - <scope>test</scope> - </dependency> - - <dependency> <groupId>org.gridgain</groupId> <artifactId>ignite-shmem</artifactId> <version>1.0.0</version> http://git-wip-us.apache.org/repos/asf/ignite/blob/f177d431/modules/core/src/main/java/org/apache/ignite/internal/LessNamingBean.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/LessNamingBean.java b/modules/core/src/main/java/org/apache/ignite/internal/LessNamingBean.java new file mode 100644 index 0000000..3b885f9 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/LessNamingBean.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal; + +import org.apache.ignite.internal.util.tostring.GridToStringExclude; + +/** + * Marker interface for beans with less naming conventions i.e., without "get" and "set" prefixes. + */ +@GridToStringExclude +public interface LessNamingBean { + // No-op. +} http://git-wip-us.apache.org/repos/asf/ignite/blob/f177d431/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlIndexMetadata.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlIndexMetadata.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlIndexMetadata.java index 539a156..94602f7 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlIndexMetadata.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlIndexMetadata.java @@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.cache.query; import java.io.Externalizable; import java.util.Collection; +import org.apache.ignite.internal.LessNamingBean; /** * Ignite index descriptor. @@ -27,7 +28,7 @@ import java.util.Collection; * {@link GridCacheSqlMetadata#indexes(String)} method. * @see GridCacheSqlMetadata */ -public interface GridCacheSqlIndexMetadata extends Externalizable { +public interface GridCacheSqlIndexMetadata extends Externalizable, LessNamingBean { /** * Gets name of the index. * http://git-wip-us.apache.org/repos/asf/ignite/blob/f177d431/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlMetadata.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlMetadata.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlMetadata.java index 724962e..c82d2cb 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlMetadata.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheSqlMetadata.java @@ -20,6 +20,7 @@ package org.apache.ignite.internal.processors.cache.query; import java.io.Externalizable; import java.util.Collection; import java.util.Map; +import org.apache.ignite.internal.LessNamingBean; import org.apache.ignite.spi.indexing.IndexingSpi; import org.jetbrains.annotations.Nullable; @@ -30,7 +31,7 @@ import org.jetbrains.annotations.Nullable; * can be used to gather information about what can * be queried using Ignite cache queries feature. */ -public interface GridCacheSqlMetadata extends Externalizable { +public interface GridCacheSqlMetadata extends Externalizable, LessNamingBean { /** * Cache name. * http://git-wip-us.apache.org/repos/asf/ignite/blob/f177d431/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteExceptionRegistry.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteExceptionRegistry.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteExceptionRegistry.java index 1c3a5b5..b7bb07e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteExceptionRegistry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteExceptionRegistry.java @@ -26,6 +26,7 @@ import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.atomic.AtomicLong; import org.apache.ignite.IgniteLogger; import org.apache.ignite.IgniteSystemProperties; +import org.apache.ignite.internal.LessNamingBean; import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.typedef.internal.A; import org.apache.ignite.internal.util.typedef.internal.S; @@ -156,7 +157,7 @@ public class IgniteExceptionRegistry { * Detailed info about suppressed error. */ @SuppressWarnings("PublicInnerClass") - public static class ExceptionInfo implements Serializable { + public static class ExceptionInfo implements Serializable, LessNamingBean { /** */ private static final long serialVersionUID = 0L; @@ -245,4 +246,4 @@ public class IgniteExceptionRegistry { return S.toString(ExceptionInfo.class, this); } } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/ignite/blob/f177d431/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java index f06813f..a440ac3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCache.java @@ -21,12 +21,12 @@ import java.io.Serializable; import java.util.Collection; import java.util.Collections; import java.util.Iterator; -import java.util.Set; import org.apache.ignite.IgniteCache; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.cache.CacheMode; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.LessNamingBean; import org.apache.ignite.internal.processors.cache.GridCacheAdapter; import org.apache.ignite.internal.processors.cache.GridCacheEntryEx; import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter; @@ -42,7 +42,7 @@ import org.jetbrains.annotations.Nullable; /** * Data transfer object for {@link IgniteCache}. */ -public class VisorCache implements Serializable { +public class VisorCache implements Serializable, LessNamingBean { /** */ private static final long serialVersionUID = 0L; http://git-wip-us.apache.org/repos/asf/ignite/blob/f177d431/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheAffinityConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheAffinityConfiguration.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheAffinityConfiguration.java index 7aa6215..371a514 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheAffinityConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheAffinityConfiguration.java @@ -21,6 +21,7 @@ import java.io.Serializable; import org.apache.ignite.cache.affinity.AffinityFunction; import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.internal.LessNamingBean; import org.apache.ignite.internal.util.typedef.internal.S; import org.jetbrains.annotations.Nullable; @@ -29,7 +30,7 @@ import static org.apache.ignite.internal.visor.util.VisorTaskUtils.compactClass; /** * Data transfer object for affinity configuration properties. */ -public class VisorCacheAffinityConfiguration implements Serializable { +public class VisorCacheAffinityConfiguration implements Serializable, LessNamingBean { /** */ private static final long serialVersionUID = 0L; @@ -113,4 +114,4 @@ public class VisorCacheAffinityConfiguration implements Serializable { @Override public String toString() { return S.toString(VisorCacheAffinityConfiguration.class, this); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/ignite/blob/f177d431/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheAggregatedMetrics.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheAggregatedMetrics.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheAggregatedMetrics.java index 0cba24b..c779051 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheAggregatedMetrics.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheAggregatedMetrics.java @@ -23,12 +23,13 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.internal.LessNamingBean; import org.apache.ignite.internal.util.typedef.internal.S; /** * Data transfer object for aggregated cache metrics. */ -public class VisorCacheAggregatedMetrics implements Serializable { +public class VisorCacheAggregatedMetrics implements Serializable, LessNamingBean { /** */ private static final long serialVersionUID = 0L;
