diff options
Diffstat (limited to 'ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/JsonMatcher.kt')
-rw-r--r-- | ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/JsonMatcher.kt | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/JsonMatcher.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/JsonMatcher.kt new file mode 100644 index 000000000..995b19c41 --- /dev/null +++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/JsonMatcher.kt @@ -0,0 +1,26 @@ +package org.onap.ccsdk.cds.blueprintsprocessor.uat.utils + +import org.mockito.ArgumentMatcher +import org.skyscreamer.jsonassert.JSONAssert +import org.skyscreamer.jsonassert.JSONCompareMode + +class JsonMatcher(val expectedJson: String?) : ArgumentMatcher<String> { + + override fun matches(actualJson: String?): Boolean { + if (expectedJson == null) { + return actualJson == null + } else if (actualJson.isNullOrEmpty() && (expectedJson.isEmpty() || expectedJson.equals("null"))) { + // null, "" and "null" means the same here + return true + } else if (!actualJson.isNullOrEmpty() && expectedJson.isNotEmpty()) { + return try { + JSONAssert.assertEquals("", expectedJson, actualJson, JSONCompareMode.LENIENT) + true + } catch (e: AssertionError) { + false + } + } else { + return false + } + } +} |