diff options
Diffstat (limited to 'cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/mapper/CloudEventMapperSpec.groovy')
-rw-r--r-- | cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/mapper/CloudEventMapperSpec.groovy | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/mapper/CloudEventMapperSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/mapper/CloudEventMapperSpec.groovy index 380aea405..e6d383128 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/mapper/CloudEventMapperSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/mapper/CloudEventMapperSpec.groovy @@ -34,17 +34,30 @@ class CloudEventMapperSpec extends Specification { @Autowired JsonObjectMapper jsonObjectMapper - def 'Cloud event to Target event type when it is #scenario'() { - expect: 'Events mapped correctly' - assert mappedCloudEvent == (CloudEventMapper.toTargetEvent(testCloudEvent(), targetClass) != null) + def 'Cloud event to target event type'() { + given: 'a cloud event with valid payload' + def cloudEvent = testCloudEvent(new CmSubscriptionNcmpInEvent()) + when: 'the cloud event mapped to target event' + def result = CloudEventMapper.toTargetEvent((cloudEvent), CmSubscriptionNcmpInEvent.class) + then: 'the cloud event is mapped' + assert result instanceof CmSubscriptionNcmpInEvent + } + + def 'Cloud event to target event type when it is #scenario'() { + given: 'a cloud event with invalid payload' + def cloudEvent = testCloudEvent(payload) + when: 'the cloud event mapped to target event' + def result = CloudEventMapper.toTargetEvent(cloudEvent, CmSubscriptionNcmpInEvent.class) + then: 'result is null' + assert result == null where: 'below are the scenarios' - scenario | targetClass || mappedCloudEvent - 'valid concrete type' | CmSubscriptionNcmpInEvent.class || true - 'invalid concrete type' | ArrayList.class || false + scenario | payload + 'invalid payload type' | ArrayList.class + 'without payload' | null } - def testCloudEvent() { - return CloudEventBuilder.v1().withData(jsonObjectMapper.asJsonBytes(new CmSubscriptionNcmpInEvent())) + def testCloudEvent(payload) { + return CloudEventBuilder.v1().withData(jsonObjectMapper.asJsonBytes(payload)) .withId("cmhandle1") .withSource(URI.create('test-source')) .withDataSchema(URI.create('test')) |