aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/JsonMatcher.kt
blob: 995b19c4143e274aa1ead142ddced3e9522cefde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
        }
    }
}