summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service
diff options
context:
space:
mode:
authorToineSiebelink <toine.siebelink@est.tech>2023-07-12 17:05:41 +0100
committerToine Siebelink <toine.siebelink@est.tech>2023-07-12 16:45:24 +0000
commit7be880243ff54cfb17d00f062815c4952aa4d16c (patch)
tree81af8b034d2d685afb55957554bbad5124235285 /cps-ncmp-service
parenta904a7d59e7f278bf93e2f58bb129e2ec7a03d20 (diff)
Improved code coverage for record filter strategies
(the semi-integration test dont cover all scenarios) Issue-ID: CPS-475 Signed-off-by: ToineSiebelink <toine.siebelink@est.tech> Change-Id: I717946cddec315a1e69ca8d104b07f91691c1b63
Diffstat (limited to 'cps-ncmp-service')
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/async/RecordFilterStrategiesSpec.groovy41
1 files changed, 41 insertions, 0 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/async/RecordFilterStrategiesSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/async/RecordFilterStrategiesSpec.groovy
new file mode 100644
index 0000000000..4189a8b381
--- /dev/null
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/async/RecordFilterStrategiesSpec.groovy
@@ -0,0 +1,41 @@
+package org.onap.cps.ncmp.api.impl.async
+
+import spock.lang.Specification
+import org.apache.kafka.common.header.Header
+import org.apache.kafka.common.header.Headers
+
+import java.nio.charset.Charset
+
+class RecordFilterStrategiesSpec extends Specification {
+
+ def objectUnderTest = new RecordFilterStrategies()
+
+ def headers = Mock(Headers)
+ def header = Mock(Header)
+
+ def 'Determining cloud event using ce_type header for a #scenario.'() {
+ given: 'headers contain a header for key: #key'
+ headers.lastHeader(key) >> header
+ expect: 'the check for cloud events returns #expectedResult'
+ assert objectUnderTest.isCloudEvent(headers) == expectedResult
+ where: 'the following headers (keys) are defined'
+ scenario | key || expectedResult
+ 'cloud event' | 'ce_type' || true
+ 'non-cloud event' | 'other' || false
+ }
+
+ def 'Excluding cloud event of given type only with #scenario.'() {
+ given: 'headers contain a header for key: #key and value: #value'
+ header.value() >> value.getBytes(Charset.defaultCharset())
+ headers.lastHeader(key) >> header
+ expect: 'the event would (not) be excluded: #expectedToBeExcluded'
+ assert objectUnderTest.isNotCloudEventOfType(headers,'requiredType') == expectedToBeExcluded
+ where: 'the following headers are defined'
+ scenario | key | value || expectedToBeExcluded
+ 'required type' | 'ce_type' | 'requiredType' || false
+ 'contains requiredType' | 'ce_type' | 'Contains requiredType and more' || false
+ 'other type' | 'ce_type' | 'other' || true
+ 'no ce_type header' | 'other' | 'irrelevant' || true
+ }
+
+}