summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/common
diff options
context:
space:
mode:
authorKAPIL SINGAL <ks220y@att.com>2020-08-31 12:50:44 +0000
committerGerrit Code Review <gerrit@onap.org>2020-08-31 12:50:44 +0000
commite76a3d93363d72d1f5c98f6f8f16d0d6c2992b91 (patch)
tree4f864d3c4e49029197b2f2926192aaf0dc131039 /sdnr/wt/common
parenta4ceb7aa23cab5d291d0784095492b001709981f (diff)
parent4cd4c471e9b56494b7ae1e4917e88fa9513082b9 (diff)
Merge "add data-provider v2 for openroadm"
Diffstat (limited to 'sdnr/wt/common')
-rw-r--r--sdnr/wt/common/src/main/java/org/onap/ccsdk/features/sdnr/wt/common/test/JSONAssert.java57
1 files changed, 55 insertions, 2 deletions
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 {
}
}
+
+
}