UatExecutor does not support complex test scenarios
[ccsdk/cds.git] / ms / blueprintsprocessor / application / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / uat / utils / JsonMatcher.kt
1 package org.onap.ccsdk.cds.blueprintsprocessor.uat.utils
2
3 import org.mockito.ArgumentMatcher
4 import org.skyscreamer.jsonassert.JSONAssert
5 import org.skyscreamer.jsonassert.JSONCompareMode
6
7 class JsonMatcher(val expectedJson: String?) : ArgumentMatcher<String> {
8
9     override fun matches(actualJson: String?): Boolean {
10         if (expectedJson == null) {
11             return actualJson == null
12         } else if (actualJson.isNullOrEmpty() && (expectedJson.isEmpty() || expectedJson.equals("null"))) {
13             // null, "" and "null" means the same here
14             return true
15         } else if (!actualJson.isNullOrEmpty() && expectedJson.isNotEmpty()) {
16             return try {
17                 JSONAssert.assertEquals("", expectedJson, actualJson, JSONCompareMode.LENIENT)
18                 true
19             } catch (e: AssertionError) {
20                 false
21             }
22         } else {
23             return false
24         }
25     }
26 }