This is an automated email from the ASF dual-hosted git repository.

klund pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git

commit 40e84e7fa17cb4aa78d5322a2b8866487a9d7974
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Fri Sep 1 12:33:21 2017 -0700

    GEODE-3552: move and rename TypedJson tests
---
 .../cache/query/TypedJsonQueryIntegrationTest.java | 102 ++++++++
 .../geode/management/TypedJsonJUnitTest.java       | 281 ---------------------
 .../cli/json/TypedJsonPdxIntegrationTest.java      | 117 +++++++++
 .../internal/cli/json/TypedJsonTest.java           | 139 +++++++++-
 4 files changed, 354 insertions(+), 285 deletions(-)

diff --git 
a/geode-core/src/test/java/org/apache/geode/cache/query/TypedJsonQueryIntegrationTest.java
 
b/geode-core/src/test/java/org/apache/geode/cache/query/TypedJsonQueryIntegrationTest.java
new file mode 100644
index 0000000..bb54859
--- /dev/null
+++ 
b/geode-core/src/test/java/org/apache/geode/cache/query/TypedJsonQueryIntegrationTest.java
@@ -0,0 +1,102 @@
+/*
+ * 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.geode.cache.query;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.query.data.Portfolio;
+import org.apache.geode.cache.query.data.Position;
+import org.apache.geode.cache.util.ObjectSizer;
+import 
org.apache.geode.management.internal.cli.json.TypedJsonPdxIntegrationTest;
+import org.apache.geode.management.internal.cli.json.GfJsonException;
+import org.apache.geode.management.internal.cli.json.GfJsonObject;
+import org.apache.geode.management.internal.cli.json.TypedJson;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+
+/**
+ * Integration tests for {@link TypedJson} querying {@link Portfolio}.<p>
+ *
+ * Extracted from {@link TypedJsonPdxIntegrationTest}.<p>
+ *
+ * TODO: add real assertions
+ */
+@Category(IntegrationTest.class)
+public class TypedJsonQueryIntegrationTest {
+
+  private static final String RESULT = "result";
+
+  @Test
+  public void testUserObject() throws Exception {
+    Portfolio p = new Portfolio(2);
+
+    TypedJson typedJson = new TypedJson(RESULT, p);
+
+    checkResult(typedJson);
+  }
+
+  @Test
+  public void testUserObjectArray() throws Exception {
+    Portfolio[] portfolios = createPortfoliosAndPositions(2);
+
+    TypedJson typedJson = new TypedJson(RESULT, portfolios);
+
+    checkResult(typedJson);
+  }
+
+  @Test
+  public void testMemUsage() throws Exception {
+    Portfolio[] portfolios = createPortfoliosAndPositions(1000);
+    System.out.println("Size Of port " + 
ObjectSizer.REFLECTION_SIZE.sizeof(portfolios));
+
+    TypedJson typedJson = new TypedJson(RESULT, portfolios);
+    System.out.println("Size Of json " + 
ObjectSizer.REFLECTION_SIZE.sizeof(typedJson));
+
+    checkResult(typedJson);
+  }
+
+  @Test
+  public void testQueryLike() throws Exception {
+    Portfolio[] portfolios = createPortfoliosAndPositions(2);
+
+    TypedJson typedJson = new TypedJson(RESULT, null);
+    typedJson.add("member", "server1");
+    // checkResult(typedJson); -- fails
+
+    for (int i = 0; i < 2; i++) {
+      typedJson.add(RESULT, portfolios[i]);
+    }
+    checkResult(typedJson);
+  }
+
+  private Portfolio[] createPortfoliosAndPositions(final int count) {
+    Position.cnt = 0; // reset Portfolio counter
+    Portfolio[] portfolios = new Portfolio[count];
+    for (int i = 0; i < count; i++) {
+      portfolios[i] = new Portfolio(i);
+    }
+    return portfolios;
+  }
+
+  private void checkResult(final TypedJson typedJson) throws GfJsonException {
+    GfJsonObject gfJsonObject = new GfJsonObject(typedJson.toString());
+    System.out.println(gfJsonObject);
+    assertThat(gfJsonObject.get(RESULT)).isNotNull();
+  }
+}
diff --git 
a/geode-core/src/test/java/org/apache/geode/management/TypedJsonJUnitTest.java 
b/geode-core/src/test/java/org/apache/geode/management/TypedJsonJUnitTest.java
deleted file mode 100644
index 7823195..0000000
--- 
a/geode-core/src/test/java/org/apache/geode/management/TypedJsonJUnitTest.java
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- * 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.geode.management;
-
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.CacheFactory;
-import org.apache.geode.cache.query.data.Portfolio;
-import org.apache.geode.cache.query.data.Position;
-import org.apache.geode.cache.util.ObjectSizer;
-import org.apache.geode.distributed.DistributedSystem;
-import org.apache.geode.management.internal.cli.json.GfJsonException;
-import org.apache.geode.management.internal.cli.json.GfJsonObject;
-import org.apache.geode.management.internal.cli.json.TypedJson;
-import org.apache.geode.pdx.PdxInstance;
-import org.apache.geode.pdx.PdxInstanceFactory;
-import org.apache.geode.pdx.internal.PdxInstanceFactoryImpl;
-import org.apache.geode.test.junit.categories.IntegrationTest;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.util.*;
-
-import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
-
-@Category(IntegrationTest.class)
-public class TypedJsonJUnitTest {
-
-  public enum Currency {
-    PENNY, NICKLE, DIME, QUARTER
-  };
-
-  private static final String RESULT = "result";
-
-
-  public void checkResult(TypedJson tjson) {
-
-    GfJsonObject gfJsonObj;
-    try {
-      gfJsonObj = new GfJsonObject(tjson.toString());
-      System.out.println(gfJsonObj);
-      assertNotNull(gfJsonObj.get(RESULT));
-    } catch (GfJsonException e) {
-      fail("Result could not be found");
-    }
-
-  }
-
-  @Test
-  public void testArrayList() {
-
-    List<String> ls = new ArrayList<String>();
-    ls.add("ONE");
-    ls.add("TWO");
-    ls.add("THREE");
-    TypedJson tjson = new TypedJson(RESULT, ls);
-
-    checkResult(tjson);
-  }
-
-  @Test
-  public void testArray() {
-
-    int[] arr = new int[3];
-    for (int i = 0; i < 3; i++) {
-      arr[i] = i;
-    }
-    TypedJson tjson = new TypedJson(RESULT, arr);
-    checkResult(tjson);
-
-  }
-
-  @Test
-  public void testBigList() {
-
-    List<String> ls = new ArrayList<String>();
-    for (int i = 0; i < 1000; i++) {
-      ls.add("BIG_COLL_" + i);
-    }
-    TypedJson tjson = new TypedJson(RESULT, ls);
-    checkResult(tjson);
-  }
-
-  @Test
-  public void testEnum() {
-    EnumContainer test = new EnumContainer(Currency.DIME);
-    TypedJson tjson = new TypedJson(RESULT, test);
-    checkResult(tjson);
-    TypedJson enumObj = new TypedJson(RESULT, Currency.DIME);
-    checkResult(enumObj);
-
-  }
-
-  @Test
-  public void testEnumList() {
-    List ls = new ArrayList();
-    ls.add(Currency.DIME);
-    ls.add(Currency.NICKLE);
-    ls.add(Currency.QUARTER);
-    ls.add(Currency.NICKLE);
-    TypedJson tjson = new TypedJson(RESULT, ls);
-    System.out.println(tjson);
-
-  }
-
-  @Test
-  public void testMap() {
-    Map<String, String> testMap = new HashMap<String, String>();
-    testMap.put("1", "ONE");
-    testMap.put("2", "TWO");
-    testMap.put("3", "THREE");
-    testMap.put("4", "FOUR");
-    TypedJson tjson = new TypedJson(RESULT, testMap);
-    System.out.println(tjson);
-
-  }
-
-  @Test
-  public void testBigDecimal() {
-    java.math.BigDecimal dc = new java.math.BigDecimal(20);
-    TypedJson tjson = new TypedJson(RESULT, dc);
-    System.out.println(tjson);
-
-  }
-
-  @Test
-  public void testUserObject() {
-    Portfolio p = new Portfolio(2);
-    TypedJson tjson = new TypedJson(RESULT, p);
-    System.out.println(tjson);
-
-  }
-
-  @Test
-  public void testObjects() {
-    Object obj = new Object();
-    TypedJson tjson = new TypedJson(RESULT, obj);
-    System.out.println(tjson);
-  }
-
-  @Test
-  public void testPDXObject() {
-    final Properties props = new Properties();
-    props.setProperty(MCAST_PORT, "0");
-    DistributedSystem.connect(props);
-    Cache cache = new CacheFactory().create();
-    PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", 
false);
-    Portfolio p = new Portfolio(2);
-    pf.writeInt("ID", 111);
-    pf.writeString("status", "active");
-    pf.writeString("secId", "IBM");
-    pf.writeObject("portfolio", p);
-    PdxInstance pi = pf.create();
-
-    TypedJson tJsonObj = new TypedJson(RESULT, pi);
-    System.out.println(tJsonObj);
-    cache.close();
-
-  }
-
-  @Test
-  public void testNestedPDXObject() {
-    final Properties props = new Properties();
-    props.setProperty(MCAST_PORT, "0");
-    DistributedSystem.connect(props);
-    Cache cache = new CacheFactory().create();
-
-    PdxInstanceFactory pf = PdxInstanceFactoryImpl.newCreator("Portfolio", 
false);
-
-    pf.writeInt("ID", 111);
-    pf.writeString("status", "active");
-    pf.writeString("secId", "IBM");
-    PdxInstance pi = pf.create();
-
-    PDXContainer cont = new PDXContainer(1);
-    cont.setPi(pi);
-
-    TypedJson tJsonObj = new TypedJson(RESULT, cont);
-    System.out.println(tJsonObj);
-    cache.close();
-
-  }
-
-  @Test
-  public void testUserObjectArray() {
-    Portfolio[] p = createPortfoliosAndPositions(2);
-    TypedJson t1 = new TypedJson(RESULT, p);
-    System.out.println(t1);
-  }
-
-  @Test
-  public void testMemUsage() {
-    Portfolio[] p = createPortfoliosAndPositions(1000);
-    System.out.println("Size Of port " + 
ObjectSizer.REFLECTION_SIZE.sizeof(p));
-    TypedJson t1 = new TypedJson(RESULT, p);
-    System.out.println("Size Of json " + 
ObjectSizer.REFLECTION_SIZE.sizeof(t1));
-
-  }
-
-
-  @Test
-  public void testQueryLike() {
-    Portfolio[] p = createPortfoliosAndPositions(2);
-    TypedJson t1 = new TypedJson(RESULT, null);
-    t1.add("member", "server1");
-    System.out.println(t1);
-    for (int i = 0; i < 2; i++) {
-      t1.add(RESULT, p[i]);
-
-    }
-    System.out.println(t1);
-
-
-  }
-
-  private static class EnumContainer {
-
-    Currency curr;
-
-    public EnumContainer(Currency curr) {
-      this.curr = curr;
-    }
-
-    public Currency getCurr() {
-      return curr;
-    }
-
-    public void setCurr(Currency curr) {
-      this.curr = curr;
-    }
-
-  }
-
-  private static class PDXContainer {
-    PdxInstance pi;
-    int counter;
-
-    public PDXContainer(int count) {
-      this.counter = count;
-    }
-
-    public PdxInstance getPi() {
-      return pi;
-    }
-
-    public void setPi(PdxInstance pi) {
-      this.pi = pi;
-    }
-
-    public int getCounter() {
-      return counter;
-    }
-
-    public void setCounter(int counter) {
-      this.counter = counter;
-    }
-  }
-
-  public Portfolio[] createPortfoliosAndPositions(int count) {
-    Position.cnt = 0; // reset Portfolio counter
-    Portfolio[] portfolios = new Portfolio[count];
-    for (int i = 0; i < count; i++) {
-      portfolios[i] = new Portfolio(i);
-    }
-    return portfolios;
-  }
-
-}
diff --git 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/json/TypedJsonPdxIntegrationTest.java
 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/json/TypedJsonPdxIntegrationTest.java
new file mode 100644
index 0000000..07289d2
--- /dev/null
+++ 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/json/TypedJsonPdxIntegrationTest.java
@@ -0,0 +1,117 @@
+/*
+ * 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.geode.management.internal.cli.json;
+
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.Serializable;
+import java.util.Properties;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.distributed.DistributedSystem;
+import org.apache.geode.pdx.PdxInstance;
+import org.apache.geode.pdx.PdxInstanceFactory;
+import org.apache.geode.pdx.internal.PdxInstanceFactoryImpl;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+
+/**
+ * Integration tests for {@link TypedJson}.<p>
+ *
+ * TODO: add actual assertions
+ */
+@Category(IntegrationTest.class)
+public class TypedJsonPdxIntegrationTest {
+
+  private static final String RESULT = "result";
+
+  private DistributedSystem system;
+  private PdxInstanceFactory pdxInstanceFactory;
+
+  @Before
+  public void setUp() throws Exception {
+    Properties config = new Properties();
+    config.setProperty(LOCATORS, "");
+    config.setProperty(MCAST_PORT, "0");
+
+    system = DistributedSystem.connect(config);
+    new CacheFactory().create();
+    pdxInstanceFactory = PdxInstanceFactoryImpl.newCreator("Portfolio", false);
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    system.disconnect();
+  }
+
+  @Test
+  public void supportsPdxInstance() throws Exception {
+    pdxInstanceFactory.writeInt("ID", 111);
+    pdxInstanceFactory.writeString("status", "active");
+    pdxInstanceFactory.writeString("secId", "IBM");
+    pdxInstanceFactory.writeObject("object", new SerializableObject(2));
+    PdxInstance pdxInstance = pdxInstanceFactory.create();
+
+    TypedJson typedJson = new TypedJson(RESULT, pdxInstance);
+
+    checkResult(typedJson);
+  }
+
+  @Test
+  public void supportsObjectContainingPdxInstance() throws Exception {
+    pdxInstanceFactory.writeInt("ID", 111);
+    pdxInstanceFactory.writeString("status", "active");
+    pdxInstanceFactory.writeString("secId", "IBM");
+    PdxContainer pdxContainer = new PdxContainer(pdxInstanceFactory.create(), 
1);
+
+    TypedJson typedJson = new TypedJson(RESULT, pdxContainer);
+
+    checkResult(typedJson);
+  }
+
+  private void checkResult(TypedJson typedJson) throws GfJsonException {
+    GfJsonObject gfJsonObject = new GfJsonObject(typedJson.toString());
+    System.out.println(gfJsonObject);
+    assertThat(gfJsonObject.get(RESULT)).isNotNull();
+  }
+
+  private static class SerializableObject implements Serializable {
+
+    private final int id;
+
+    SerializableObject(final int id) {
+      this.id = id;
+    }
+  }
+
+  private static class PdxContainer {
+
+    private final PdxInstance pdxInstance;
+    private final int count;
+
+    PdxContainer(final PdxInstance pdxInstance, final int count) {
+      this.pdxInstance = pdxInstance;
+      this.count = count;
+    }
+  }
+}
diff --git 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/json/TypedJsonTest.java
 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/json/TypedJsonTest.java
index c894594..48baa7e 100644
--- 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/json/TypedJsonTest.java
+++ 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/json/TypedJsonTest.java
@@ -14,19 +14,35 @@
  */
 package org.apache.geode.management.internal.cli.json;
 
-import static org.mockito.Mockito.*;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.io.Writer;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
-import org.apache.geode.test.junit.categories.UnitTest;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import java.io.Writer;
+import org.apache.geode.test.junit.categories.UnitTest;
 
+/**
+ * Extracted from {@link TypedJsonPdxIntegrationTest}.<p>
+ *
+ * TODO: add actual assertions
+ */
 @Category(UnitTest.class)
 public class TypedJsonTest {
 
+  private static final String RESULT = "result";
+
   @Test
-  public void shouldBeMockable() throws Exception {
+  public void canBeMocked() throws Exception {
     TypedJson mockTypedJson = mock(TypedJson.class);
     Writer writer = null;
     Object value = new Object();
@@ -35,4 +51,119 @@ public class TypedJsonTest {
 
     verify(mockTypedJson, times(1)).writeVal(writer, value);
   }
+
+  @Test
+  public void testArrayList() throws Exception {
+    List<String> list = new ArrayList<>();
+    list.add("ONE");
+    list.add("TWO");
+    list.add("THREE");
+
+    TypedJson typedJson = new TypedJson(RESULT, list);
+
+    checkResult(typedJson);
+  }
+
+  @Test
+  public void testArray() throws Exception {
+    int[] intArray = new int[3];
+    for (int i = 0; i < 3; i++) {
+      intArray[i] = i;
+    }
+
+    TypedJson typedJson = new TypedJson(RESULT, intArray);
+
+    checkResult(typedJson);
+  }
+
+  @Test
+  public void testBigList() throws Exception {
+    List<String> list = new ArrayList<>();
+    for (int i = 0; i < 1000; i++) {
+      list.add("BIG_COLL_" + i);
+    }
+
+    TypedJson typedJson = new TypedJson(RESULT, list);
+
+    checkResult(typedJson);
+  }
+
+  @Test
+  public void testEnumContainer() throws Exception {
+    EnumContainer enumContainer = new EnumContainer(Currency.DIME);
+
+    TypedJson typedJson = new TypedJson(RESULT, enumContainer);
+
+    checkResult(typedJson);
+  }
+
+  @Test
+  public void testEnum() throws Exception {
+    TypedJson typedJson = new TypedJson(RESULT, Currency.DIME);
+
+    checkResult(typedJson);
+  }
+
+  @Test
+  public void testEnumList() throws Exception {
+    List<Currency> list = new ArrayList();
+    list.add(Currency.DIME);
+    list.add(Currency.NICKLE);
+    list.add(Currency.QUARTER);
+    list.add(Currency.NICKLE);
+
+    TypedJson typedJson = new TypedJson(RESULT, list);
+
+    checkResult(typedJson);
+  }
+
+  @Test
+  public void testMap() throws Exception {
+    Map<String, String> map = new HashMap<>();
+    map.put("1", "ONE");
+    map.put("2", "TWO");
+    map.put("3", "THREE");
+    map.put("4", "FOUR");
+
+    TypedJson typedJson = new TypedJson(RESULT, map);
+
+    checkResult(typedJson);
+  }
+
+  @Test
+  public void testBigDecimal() throws Exception {
+    BigDecimal dc = new BigDecimal(20);
+
+    TypedJson typedJson = new TypedJson(RESULT, dc);
+
+    checkResult(typedJson);
+  }
+
+  @Test
+  public void testObjects() throws Exception {
+    Object object = new Object();
+
+    TypedJson typedJson = new TypedJson(RESULT, object);
+
+    checkResult(typedJson);
+  }
+
+  private void checkResult(final TypedJson typedJson) throws GfJsonException {
+    GfJsonObject gfJsonObject = new GfJsonObject(typedJson.toString());
+    System.out.println(gfJsonObject);
+    assertThat(gfJsonObject.get(RESULT)).isNotNull();
+  }
+
+  private enum Currency {
+    PENNY, NICKLE, DIME, QUARTER
+  };
+
+  private static class EnumContainer {
+
+    private final Currency currency;
+
+    EnumContainer(final Currency currency) {
+      this.currency = currency;
+    }
+  }
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@geode.apache.org" <commits@geode.apache.org>.

Reply via email to