aboutsummaryrefslogtreecommitdiffstats
path: root/ms
diff options
context:
space:
mode:
authorFrank Kimmlingen <frank.kimmlingen@telekom.de>2022-10-25 13:22:59 +0200
committerFrank Kimmlingen <frank.kimmlingen@telekom.de>2022-10-25 13:38:34 +0200
commit3920536083e753e84faafab9887e4a3f5f36af3d (patch)
tree2bc9128392d3153cd4f36ee18e597124ea9b7e21 /ms
parentfe6da442cfdf37a4f47d9e7be65c797ae261e91f (diff)
UatExecutor does not support complex test scenarios
Issue-ID: CCSDK-3793 Signed-off-by: Frank Kimmlingen <frank.kimmlingen@telekom.de> Change-Id: I6bb03a8e03a37aa9e87d381075bc5de8cadcc7f2
Diffstat (limited to 'ms')
-rw-r--r--ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/JsonMatcher.kt26
-rw-r--r--ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatExecutor.kt11
-rw-r--r--ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/JsonMatcherTest.kt74
3 files changed, 107 insertions, 4 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
+ }
+ }
+}
diff --git a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatExecutor.kt b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatExecutor.kt
index b97dbf7bb..45677fac1 100644
--- a/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatExecutor.kt
+++ b/ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatExecutor.kt
@@ -154,7 +154,7 @@ open class UatExecutor(
verify(mockClient, evalVerificationMode(expectation.times)).exchangeResource(
eq(request.method),
eq(request.path),
- argThat { assertJsonEquals(request.body, this) },
+ any(),
argThat(RequiredMapEntriesMatcher(request.headers))
)
}
@@ -202,7 +202,7 @@ open class UatExecutor(
restClient.exchangeResource(
eq(expectation.request.method),
eq(expectation.request.path),
- any(),
+ argThat(JsonMatcher(expectation.request.body.toString())),
any()
)
)
@@ -324,8 +324,11 @@ open class UatExecutor(
override fun getInstance(selector: String, service: BlueprintWebClientService): BlueprintWebClientService {
var spiedService = spies[selector]
- if (spiedService != null)
+ if (spiedService != null) {
+ // inject the service here as realService: needed for "stateful services" (e.g. holding a session token)
+ spiedService.realService = service
return spiedService
+ }
spiedService = SpyService(mapper, selector, service)
spies[selector] = spiedService
@@ -339,7 +342,7 @@ open class UatExecutor(
open class SpyService(
private val mapper: ObjectMapper,
val selector: String,
- private val realService: BlueprintWebClientService
+ var realService: BlueprintWebClientService
) :
BlueprintWebClientService by realService {
diff --git a/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/JsonMatcherTest.kt b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/JsonMatcherTest.kt
new file mode 100644
index 000000000..9179176f9
--- /dev/null
+++ b/ms/blueprintsprocessor/application/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/JsonMatcherTest.kt
@@ -0,0 +1,74 @@
+package org.onap.ccsdk.cds.blueprintsprocessor.uat.utils
+
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertTrue
+import org.junit.Test
+
+class JsonMatcherTest {
+ @Test
+ fun `matches easy case`() {
+ val expected = """
+ {
+ "a": "b"
+ }
+ """.trimIndent()
+ val actual = """
+ {
+ "a": "b"
+ }
+ """.trimIndent()
+ assertTrue(JsonMatcher(expected).matches(actual))
+ }
+
+ @Test
+ fun `matches fails easy case`() {
+ val expected = """
+ {
+ "a": "b"
+ }
+ """.trimIndent()
+ val actual = """
+ {
+ "a": "c"
+ }
+ """.trimIndent()
+ assertFalse(JsonMatcher(expected).matches(actual))
+ }
+
+ @Test
+ fun `matches easy case (actual is lenient aka Extensible)`() {
+ val expected = """
+ {
+ "a": "b"
+ }
+ """.trimIndent()
+ val actual = """
+ {
+ "a": "b",
+ "c": "d"
+ }
+ """.trimIndent()
+ assertTrue(JsonMatcher(expected).matches(actual))
+
+ assertFalse(JsonMatcher(actual).matches(expected))
+ }
+
+ @Test
+ fun `matches null`() {
+ assertTrue(JsonMatcher(null).matches(null))
+ }
+
+ @Test
+ fun `matches null and "null"`() {
+ val expected: String? = null
+ val actual: String? = null
+ assertTrue(JsonMatcher("null").matches(null))
+ }
+
+ @Test
+ fun `matches ""`() {
+ val expected: String? = null
+ val actual: String? = null
+ assertTrue(JsonMatcher("").matches(""))
+ }
+}