Skip to content

Commit

Permalink
GEODE-6743: Remove GFJsonObject and GFJsonArray classes (apache#3555)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeppe-pivotal authored May 7, 2019
1 parent 6b34a5f commit 6defb1b
Show file tree
Hide file tree
Showing 25 changed files with 188 additions and 1,503 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

import javax.management.ObjectName;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -61,8 +63,6 @@
import org.apache.geode.management.internal.SystemManagementService;
import org.apache.geode.management.internal.beans.BeanUtilFuncs;
import org.apache.geode.management.internal.beans.QueryDataFunction;
import org.apache.geode.management.internal.cli.json.GfJsonArray;
import org.apache.geode.management.internal.cli.json.GfJsonObject;
import org.apache.geode.pdx.PdxInstance;
import org.apache.geode.pdx.PdxInstanceFactory;
import org.apache.geode.pdx.internal.PdxInstanceFactoryImpl;
Expand Down Expand Up @@ -245,16 +245,12 @@ public void testLimitForQuery() throws Exception {
assertThat(jsonString).contains("result").doesNotContain("No Data Found");
assertThat(jsonString).contains(BIG_COLLECTION_ELEMENT_);

GfJsonObject jsonObject = new GfJsonObject(jsonString);
GfJsonArray jsonArray = jsonObject.getJSONArray("result");
assertThat(jsonArray.length()).isEqualTo(DEFAULT_QUERY_LIMIT);

// Get the first element
GfJsonArray jsonArray1 = jsonArray.getJSONArray(0);
assertThat(jsonArray1).isNotNull();
JsonNode jsonObject = new ObjectMapper().readTree(jsonString);
JsonNode jsonArray = jsonObject.get("result");
assertThat(jsonArray.size()).isEqualTo(DEFAULT_QUERY_LIMIT);

// Get the ObjectValue
GfJsonObject collectionObject = jsonArray1.getJsonObject(1);
JsonNode collectionObject = jsonArray.get(0).get(1);
assertThat(collectionObject.size()).isEqualTo(100);

// Query With Override Values
Expand All @@ -274,17 +270,14 @@ public void testLimitForQuery() throws Exception {
verifyJsonIsValid(jsonString);
assertThat(jsonString).contains("result").doesNotContain("No Data Found");

jsonObject = new GfJsonObject(jsonString);
jsonObject = new ObjectMapper().readTree(jsonString);
assertThat(jsonString).contains(BIG_COLLECTION_ELEMENT_);

jsonArray = jsonObject.getJSONArray("result");
assertThat(jsonArray.length()).isEqualTo(newQueryResultSetLimit);

// Get the first element
jsonArray1 = jsonArray.getJSONArray(0);
jsonArray = jsonObject.get("result");
assertThat(jsonArray.size()).isEqualTo(newQueryResultSetLimit);

// Get the ObjectValue
collectionObject = jsonArray1.getJsonObject(1);
collectionObject = jsonArray.get(0).get(1);
assertThat(collectionObject.size()).isEqualTo(newQueryCollectionDepth);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -26,7 +24,6 @@
import org.apache.geode.distributed.internal.InternalConfigurationPersistenceService;
import org.apache.geode.internal.cache.wan.MyAsyncEventListener;
import org.apache.geode.management.internal.cli.i18n.CliStrings;
import org.apache.geode.management.internal.cli.json.GfJsonException;
import org.apache.geode.management.internal.configuration.domain.Configuration;
import org.apache.geode.test.dunit.rules.ClusterStartupRule;
import org.apache.geode.test.dunit.rules.MemberVM;
Expand Down Expand Up @@ -162,8 +159,7 @@ public void destroyAeqOnGroupThatDoesNotExisit_returnsError() {
}

@Test
public void destroyAeq_selectsQueuesOnGroup_showsErrorForServersNotInGroup()
throws GfJsonException {
public void destroyAeq_selectsQueuesOnGroup_showsErrorForServersNotInGroup() {
gfsh.executeAndAssertThat("create async-event-queue --id=queue1 --group=group1 --listener="
+ MyAsyncEventListener.class.getName()).statusIsSuccess();

Expand All @@ -181,7 +177,7 @@ public void destroyAeq_selectsQueuesOnGroup_showsErrorForServersNotInGroup()
}

@Test
public void destroyAeq_selectsQueuesByGroup_returnsSuccess() throws GfJsonException, IOException {
public void destroyAeq_selectsQueuesByGroup_returnsSuccess() {
server3 = lsRule.startServerVM(3, "group3", locator.getPort());

gfsh.executeAndAssertThat("create async-event-queue --id=queue1 --group=group1 --listener="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.text.SimpleDateFormat;
import java.util.Properties;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
Expand All @@ -44,7 +43,6 @@
import org.apache.geode.internal.Assert;
import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.internal.cache.GemFireCacheImpl;
import org.apache.geode.management.internal.cli.json.GfJsonException;
import org.apache.geode.pdx.internal.json.PdxToJSON;
import org.apache.geode.test.dunit.Host;
import org.apache.geode.test.dunit.NetworkUtils;
Expand Down Expand Up @@ -185,7 +183,7 @@ public Object call() throws Exception {
});
}

public void VerifyPdxInstanceAndJsonConversion() throws JsonProcessingException, GfJsonException {
public void VerifyPdxInstanceAndJsonConversion() throws Exception {
Region region = getRootRegion("testSimplePdx");

// Create Object and initialize its members.
Expand Down Expand Up @@ -215,7 +213,7 @@ public void VerifyPdxInstanceAndJsonConversion() throws JsonProcessingException,
}

private void validateReceivedJSON(Region region, TestObjectForJSONFormatter actualTestObject,
ObjectMapper objectMapper) throws JsonProcessingException, GfJsonException {
ObjectMapper objectMapper) throws Exception {
// 1. get the json from the object using Jackson Object Mapper
String json = objectMapper.writeValueAsString(actualTestObject);
String jsonWithClassType = actualTestObject.addClassTypeToJson(json);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
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.GfJsonException;
import org.apache.geode.management.internal.cli.json.GfJsonObject;
import org.apache.geode.management.internal.cli.json.QueryResultFormatter;
import org.apache.geode.management.internal.cli.json.QueryResultFormatterPdxIntegrationTest;
import org.apache.geode.test.junit.categories.OQLQueryTest;
Expand Down Expand Up @@ -96,9 +98,9 @@ private Portfolio[] createPortfoliosAndPositions(final int count) {
return portfolios;
}

private void checkResult(final QueryResultFormatter queryResultFormatter) throws GfJsonException {
GfJsonObject gfJsonObject = new GfJsonObject(queryResultFormatter.toString());
System.out.println(gfJsonObject);
assertThat(gfJsonObject.get(RESULT)).isNotNull();
private void checkResult(final QueryResultFormatter queryResultFormatter) throws IOException {
JsonNode jsonObject = new ObjectMapper().readTree(queryResultFormatter.toString());
System.out.println(jsonObject.toString());
assertThat(jsonObject.get(RESULT)).isNotNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.Collection;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -32,7 +33,6 @@
import org.apache.geode.management.internal.SystemManagementService;
import org.apache.geode.management.internal.beans.DataQueryEngine;
import org.apache.geode.management.internal.beans.QueryDataFunction;
import org.apache.geode.management.internal.cli.json.GfJsonObject;
import org.apache.geode.management.model.EmptyObject;
import org.apache.geode.management.model.Item;
import org.apache.geode.management.model.Order;
Expand Down Expand Up @@ -105,7 +105,7 @@ public void testCyclicWithNestedObjectReference() throws Exception {

assertThat(queryResult).isEqualToIgnoringWhitespace(expectedResult);
// If not correct JSON format this will throw a JSONException
new GfJsonObject(queryResult);
new ObjectMapper().readTree(queryResult);
}

/**
Expand Down Expand Up @@ -135,7 +135,7 @@ public void testCyclicWithNestedClasses() throws Exception {
assertThat(queryResult).isEqualToIgnoringWhitespace(expectedResult);

// If not correct JSON format this will throw a JSONException
new GfJsonObject(queryResult);
new ObjectMapper().readTree(queryResult);
}

/**
Expand Down Expand Up @@ -165,7 +165,7 @@ public void testCyclicWithNestedRefernce2ndLayer() throws Exception {
assertThat(queryResult).isEqualToIgnoringWhitespace(expectedResult);

// If not correct JSON format this will throw a JSONException
new GfJsonObject(queryResult);
new ObjectMapper().readTree(queryResult);
}

@Test
Expand All @@ -189,7 +189,7 @@ public void testCyclicWithCollection1stLayer() throws Exception {
System.out.println("Query Result: " + queryResult);

// If not correct JSON format this will throw a JSONException
new GfJsonObject(queryResult);
new ObjectMapper().readTree(queryResult);
}

@Test
Expand All @@ -215,7 +215,7 @@ public void testCyclicCollectionWithMultipleObjects() throws Exception {
System.out.println("Query Result: " + queryResult);

// If not correct JSON format this will throw a JSONException
new GfJsonObject(queryResult);
new ObjectMapper().readTree(queryResult);
}

@Test
Expand All @@ -241,7 +241,7 @@ public void testCyclicArrayMultipleObjects() throws Exception {
System.out.println("Query Result: " + queryResult);

// If not correct JSON format this will throw a JSONException
new GfJsonObject(queryResult);
new ObjectMapper().readTree(queryResult);

}

Expand All @@ -254,7 +254,7 @@ public void testCyclicArrayMultipleObjectsMemberWise() throws Exception {
System.out.println(queryResult);

// If not correct JSON format this will throw a JSONException
new GfJsonObject(queryResult);
new ObjectMapper().readTree(queryResult);
}

@Test
Expand All @@ -267,7 +267,7 @@ public void testEmptyObject() throws Exception {
assertThat(queryResult).isEqualToIgnoringWhitespace(expectedResult);

// If not correct JSON format this will throw a JSONException
new GfJsonObject(queryResult);
new ObjectMapper().readTree(queryResult);
}

@Test
Expand All @@ -281,7 +281,7 @@ public void testSubClassOverridingMethods() throws Exception {
assertThat(queryResult).isEqualToIgnoringWhitespace(expectedResult);

// If not correct JSON format this will throw a JSONException
new GfJsonObject(queryResult);
new ObjectMapper().readTree(queryResult);
}

@Test
Expand All @@ -304,7 +304,7 @@ public void testNestedPDXObject() throws Exception {
assertThat(queryResult).isEqualToIgnoringWhitespace(expectedResult);

// If not correct JSON format this will throw a JSONException
new GfJsonObject(queryResult);
new ObjectMapper().readTree(queryResult);
}

@Test
Expand All @@ -322,7 +322,7 @@ public void testArrayWithNullValues() throws Exception {
assertThat(queryResult).isEqualToIgnoringWhitespace(expectedResult);

// If not correct JSON format this will throw a JSONException
new GfJsonObject(queryResult);
new ObjectMapper().readTree(queryResult);
}

@Test
Expand All @@ -340,7 +340,14 @@ public void testWithSqlDate() throws Exception {
assertThat(queryResult).isEqualToIgnoringWhitespace(expectedResult);

// If not correct JSON format this will throw a JSONException
new GfJsonObject(queryResult);
new ObjectMapper().readTree(queryResult);
}

@Test
public void testWithUnknownRegion() throws Exception {
String queryResult = queryEngine.queryForJsonResult("select * from /unknonwn", 1, 1, 1);
assertThat(queryResult)
.isEqualTo("{\"message\":\"Cannot find regions /unknonwn in any of the members\"}");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
import java.io.Serializable;
import java.util.Properties;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -90,10 +93,10 @@ public void supportsObjectContainingPdxInstance() throws Exception {
checkResult(queryResultFormatter);
}

private void checkResult(QueryResultFormatter queryResultFormatter) throws GfJsonException {
GfJsonObject gfJsonObject = new GfJsonObject(queryResultFormatter.toString());
System.out.println(gfJsonObject);
assertThat(gfJsonObject.get(RESULT)).isNotNull();
private void checkResult(QueryResultFormatter queryResultFormatter) throws IOException {
JsonNode jsonObject = new ObjectMapper().readTree(queryResultFormatter.toString());
System.out.println(jsonObject.toString());
assertThat(jsonObject.get(RESULT)).isNotNull();
}

private static class SerializableObject implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.text.SimpleDateFormat;
import java.util.List;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.After;
Expand All @@ -33,7 +32,6 @@
import org.apache.geode.cache.CacheFactory;
import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.Region;
import org.apache.geode.management.internal.cli.json.GfJsonException;
import org.apache.geode.pdx.internal.PdxInstanceImpl;
import org.apache.geode.pdx.internal.PeerTypeRegistration;
import org.apache.geode.test.junit.categories.SerializationTest;
Expand All @@ -58,7 +56,7 @@ public void tearDown() {
}

@Test
public void ValidatePdxInstanceToJsonConversion() throws GfJsonException {
public void ValidatePdxInstanceToJsonConversion() throws Exception {
TestObjectForJSONFormatter actualTestObject = new TestObjectForJSONFormatter();
actualTestObject.defaultInitialization();

Expand All @@ -78,7 +76,7 @@ public void ValidatePdxInstanceToJsonConversion() throws GfJsonException {
}

@Test
public void verifyJsonToPdxInstanceConversion() throws JsonProcessingException, GfJsonException {
public void verifyJsonToPdxInstanceConversion() throws Exception {
TestObjectForJSONFormatter expectedTestObject = new TestObjectForJSONFormatter();
expectedTestObject.defaultInitialization();

Expand Down Expand Up @@ -113,7 +111,7 @@ public void verifyJsonToPdxInstanceConversion() throws JsonProcessingException,
}

@Test
public void verifyJsonToPdxInstanceConversionWithJSONFormatter() throws GfJsonException {
public void verifyJsonToPdxInstanceConversionWithJSONFormatter() throws Exception {
TestObjectForJSONFormatter expectedTestObject = new TestObjectForJSONFormatter();
expectedTestObject.defaultInitialization();

Expand Down
Loading

0 comments on commit 6defb1b

Please sign in to comment.