summaryrefslogtreecommitdiffstats
path: root/testutil
diff options
context:
space:
mode:
authorHåkon Hallingstad <hakon@verizonmedia.com>2019-02-08 10:56:32 +0100
committerHåkon Hallingstad <hakon@verizonmedia.com>2019-02-08 10:56:32 +0100
commit2b269b2cc7407759ed1ff2a90270a74932c4a454 (patch)
tree4b02b08ce6f6fef162a2378939576d64931e08d6 /testutil
parentca7cd96750fdab9fc54a633ac1557730737cf23f (diff)
Patching and retrieving node reports in host admin
- A report can be patched to the node repository by using NodeAttributes and NodeRepository.updateNodeAttributes(). - A report can be retrieved as a Jackson class from NodeSpec and its NodeReports.
Diffstat (limited to 'testutil')
-rw-r--r--testutil/pom.xml5
-rw-r--r--testutil/src/main/java/com/yahoo/test/json/JsonTestHelper.java31
2 files changed, 33 insertions, 3 deletions
diff --git a/testutil/pom.xml b/testutil/pom.xml
index 503754e9aa2..543a0fbf5eb 100644
--- a/testutil/pom.xml
+++ b/testutil/pom.xml
@@ -51,6 +51,11 @@
<artifactId>jimfs</artifactId>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <scope>compile</scope>
+ </dependency>
</dependencies>
<build>
<plugins>
diff --git a/testutil/src/main/java/com/yahoo/test/json/JsonTestHelper.java b/testutil/src/main/java/com/yahoo/test/json/JsonTestHelper.java
index 8a86b922377..e7496b759cc 100644
--- a/testutil/src/main/java/com/yahoo/test/json/JsonTestHelper.java
+++ b/testutil/src/main/java/com/yahoo/test/json/JsonTestHelper.java
@@ -1,15 +1,21 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.test.json;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Joiner;
import org.hamcrest.MatcherAssert;
+import java.io.UncheckedIOException;
+
import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs;
/**
* @author Vegard Sjonfjell
*/
public class JsonTestHelper {
+ private static final ObjectMapper mapper = new ObjectMapper();
/**
* Convenience method to input JSON without escaping double quotes and newlines
@@ -20,10 +26,29 @@ public class JsonTestHelper {
return Joiner.on("\n").join(lines).replaceAll("'", "\"");
}
- /**
- * Structurally compare two JSON encoded strings
- */
+ /** Structurally compare two JSON encoded strings */
public static void assertJsonEquals(String inputJson, String expectedJson) {
MatcherAssert.assertThat(inputJson, sameJSONAs(expectedJson));
}
+
+ /** Structurally compare a {@link JsonNode} and a JSON string. */
+ public static void assertJsonEquals(JsonNode left, String rightJson) {
+ try {
+ String leftJson = mapper.writeValueAsString(left);
+ assertJsonEquals(leftJson, rightJson);
+ } catch (JsonProcessingException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+
+ /** Structurally compare two {@link JsonNode}s. */
+ public static void assertJsonEquals(JsonNode left, JsonNode right) {
+ try {
+ String leftJson = mapper.writeValueAsString(left);
+ String rightJson = mapper.writeValueAsString(right);
+ assertJsonEquals(leftJson, rightJson);
+ } catch (JsonProcessingException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
}