summaryrefslogtreecommitdiffstats
path: root/container-search/src/test/java/com/yahoo/search/rendering/JsonRendererTestCase.java
diff options
context:
space:
mode:
Diffstat (limited to 'container-search/src/test/java/com/yahoo/search/rendering/JsonRendererTestCase.java')
-rw-r--r--container-search/src/test/java/com/yahoo/search/rendering/JsonRendererTestCase.java42
1 files changed, 12 insertions, 30 deletions
diff --git a/container-search/src/test/java/com/yahoo/search/rendering/JsonRendererTestCase.java b/container-search/src/test/java/com/yahoo/search/rendering/JsonRendererTestCase.java
index c4d49c11f5e..48003f6586f 100644
--- a/container-search/src/test/java/com/yahoo/search/rendering/JsonRendererTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/rendering/JsonRendererTestCase.java
@@ -1,7 +1,6 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.rendering;
-import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.util.concurrent.ListenableFuture;
@@ -56,9 +55,6 @@ import com.yahoo.tensor.TensorType;
import com.yahoo.tensor.serialization.TypedBinaryFormat;
import com.yahoo.text.Utf8;
import com.yahoo.yolean.trace.TraceNode;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
@@ -67,7 +63,6 @@ import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
@@ -83,6 +78,8 @@ import static org.junit.Assert.assertTrue;
*/
public class JsonRendererTestCase {
+ private static final ObjectMapper jsonMapper = new ObjectMapper();
+
private JsonRenderer originalRenderer;
private JsonRenderer renderer;
@@ -959,7 +956,7 @@ public class JsonRendererTestCase {
}
@Test
- public void testJsonObjects() throws InterruptedException, ExecutionException, IOException, JSONException {
+ public void testJsonObjects() throws InterruptedException, ExecutionException, IOException {
String expected = "{"
+ " \"root\": {"
+ " \"children\": ["
@@ -973,14 +970,6 @@ public class JsonRendererTestCase {
+ " },"
+ " \"json producer\": {"
+ " \"long in structured\": 7809531904"
- + " },"
- + " \"org.json array\": ["
- + " true,"
- + " true,"
- + " false"
- + " ],"
- + " \"org.json object\": {"
- + " \"forty-two\": 42"
+ " }"
+ " },"
+ " \"id\": \"json objects\","
@@ -996,26 +985,17 @@ public class JsonRendererTestCase {
+ "}";
Result r = newEmptyResult();
Hit h = new Hit("json objects");
- JSONObject o = new JSONObject();
- JSONArray a = new JSONArray();
- ObjectMapper mapper = new ObjectMapper();
- JsonNode j = mapper.createObjectNode();
+ ObjectNode j = jsonMapper.createObjectNode();
JSONString s = new JSONString("{\"a\": \"b\"}");
Slime slime = new Slime();
Cursor c = slime.setObject();
c.setLong("long in structured", 7809531904L);
SlimeAdapter slimeInit = new SlimeAdapter(slime.get());
StructuredData struct = new StructuredData(slimeInit);
- ((ObjectNode) j).put("Nineteen-eighty-four", 1984);
- o.put("forty-two", 42);
- a.put(true);
- a.put(true);
- a.put(false);
+ j.put("Nineteen-eighty-four", 1984);
h.setField("inspectable", s);
h.setField("jackson", j);
h.setField("json producer", struct);
- h.setField("org.json array", a);
- h.setField("org.json object", o);
r.hits().add(h);
String summary = render(r);
assertEqualJson(expected, summary);
@@ -1236,11 +1216,13 @@ public class JsonRendererTestCase {
public void testThatTheJsonValidatorCanCatchErrors() {
String json = "{"
+ " \"root\": {"
- + " \"duplicate\": 1,"
- + " \"duplicate\": 2"
+ + " \"invalidvalue\": 1adsf,"
+ " }"
+ "}";
- assertEquals("Duplicate key \"duplicate\"", validateJSON(json));
+ assertEquals(
+ "Unexpected character ('a' (code 97)): was expecting comma to separate Object entries\n" +
+ " at [Source: { \"root\": { \"invalidvalue\": 1adsf, }}; line: 1, column: 41]",
+ validateJSON(json));
}
@Test
@@ -1316,9 +1298,9 @@ public class JsonRendererTestCase {
private String validateJSON(String presumablyValidJson) {
try {
- new JSONObject(presumablyValidJson);
+ jsonMapper.readTree(presumablyValidJson);
return "";
- } catch (JSONException e) {
+ } catch (IOException e) {
return e.getMessage();
}
}