From 4cd4c471e9b56494b7ae1e4917e88fa9513082b9 Mon Sep 17 00:00:00 2001 From: Michael Dürre Date: Mon, 31 Aug 2020 10:36:42 +0200 Subject: add data-provider v2 for openroadm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit extend db service for writing data for v2 Issue-ID: CCSDK-2582 Signed-off-by: Michael Dürre Change-Id: Ib47919a7f45a4954cd76514097a0b073c605fec3 Signed-off-by: Michael Dürre --- .../features/sdnr/wt/common/test/JSONAssert.java | 57 +++++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) (limited to 'sdnr/wt/common') diff --git a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/JSONAssert.java b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/JSONAssert.java index f95dfe0b2..8b651cbe9 100644 --- a/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/JSONAssert.java +++ b/sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/JSONAssert.java @@ -60,7 +60,7 @@ public class JSONAssert { } else if ((o1 instanceof String) && (o2 instanceof String)) { - return ((String) o1).equals(((String) o2)) ? 0 : -1; + return ((String) o1).equals((o2)) ? 0 : -1; } else if ((o1 instanceof JSONObject) && (o2 instanceof JSONObject)) { if (((JSONObject) o1).length() != ((JSONObject) o2).length()) { return ((JSONObject) o1).length() - ((JSONObject) o2).length() < 0 ? -1 : 1; @@ -137,7 +137,7 @@ public class JSONAssert { } else if ((o1 instanceof String) && (o2 instanceof String)) { - return ((String) o1).equals(((String) o2)) ? 0 : -1; + return ((String) o1).equals((o2)) ? 0 : -1; } else if ((o1 instanceof JSONObject) && (o2 instanceof JSONObject)) { if (((JSONObject) o1).length() == 0 && ((JSONObject) o2).length() == 0) { return 0; @@ -181,6 +181,56 @@ public class JSONAssert { } } + + public static void assertContainsOnlyKey(JSONObject o, String key) { + if(o==null) { + throw new AssertionError("object is null"); + } + if(key==null) { + throw new AssertionError("key is null"); + } + + Object[] keys= o.keySet().toArray(); + if(keys.length>1) { + throw new AssertionError("more than one key found"); + } + if(keys.length==0) { + throw new AssertionError("no key found"); + } + if(!key.equals(keys[0])) { + throw new AssertionError("different key found "+key+" <=> "+ keys[0]); + } + } + + + public static void assertContainsExactKeys(JSONObject o, String[] keys) { + if(o==null) { + throw new AssertionError("object is null"); + } + if(keys==null) { + throw new AssertionError("keys is null"); + } + Object[] okeys= o.keySet().toArray(); + if(okeys.length!=keys.length) { + throw new AssertionError("found different amount of keys"); + } + for(String k:keys) { + if(!o.keySet().contains(k)) { + throw new AssertionError("key "+ k+ " not found"); + } + } + } + public static void assertContainsNoKeys(JSONObject o) { + if(o==null) { + throw new AssertionError("object is null"); + } + + Object[] okeys= o.keySet().toArray(); + if(okeys.length!=0) { + throw new AssertionError("found keys"); + } + } + private static void assertEqualsNonStrict(String message, String def, String toTest) throws JSONException { JSONObject d1 = new JSONObject(def); @@ -188,6 +238,7 @@ public class JSONAssert { if (nonStrictComarator.compare(d1, d2) != 0) { throw new AssertionError(message); } + } private static void assertEqualsStrict(String message, String def, String toTest) throws JSONException { @@ -198,4 +249,6 @@ public class JSONAssert { } } + + } -- cgit 1.2.3-korg