diff options
author | 2023-07-13 10:15:28 +0000 | |
---|---|---|
committer | 2023-07-13 10:15:28 +0000 | |
commit | 46d25a52084252a7bb34f084e75bcdd100e7c9ab (patch) | |
tree | 9ccf7e63875631519a4bf673cbdc4d334ddaec43 /cps-ncmp-service/src/test | |
parent | db2db56f3358fa8dcccc864e04b490b307877c33 (diff) | |
parent | 7be880243ff54cfb17d00f062815c4952aa4d16c (diff) |
Merge "Improved code coverage for record filter strategies"
Diffstat (limited to 'cps-ncmp-service/src/test')
-rw-r--r-- | cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/async/RecordFilterStrategiesSpec.groovy | 41 |
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 000000000..4189a8b38 --- /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 + } + +} |