diff options
author | Håkon Hallingstad <hakon@verizonmedia.com> | 2019-02-08 10:56:32 +0100 |
---|---|---|
committer | Håkon Hallingstad <hakon@verizonmedia.com> | 2019-02-08 10:56:32 +0100 |
commit | 2b269b2cc7407759ed1ff2a90270a74932c4a454 (patch) | |
tree | 4b02b08ce6f6fef162a2378939576d64931e08d6 /testutil/src | |
parent | ca7cd96750fdab9fc54a633ac1557730737cf23f (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/src')
-rw-r--r-- | testutil/src/main/java/com/yahoo/test/json/JsonTestHelper.java | 31 |
1 files changed, 28 insertions, 3 deletions
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); + } + } } |