diff options
Diffstat (limited to 'integration-test/src')
3 files changed, 54 insertions, 59 deletions
diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/base/DmiDispatcher.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/base/DmiDispatcher.groovy index 6676cb74c2..e77815f5ec 100644 --- a/integration-test/src/test/groovy/org/onap/cps/integration/base/DmiDispatcher.groovy +++ b/integration-test/src/test/groovy/org/onap/cps/integration/base/DmiDispatcher.groovy @@ -22,11 +22,11 @@ package org.onap.cps.integration.base import static org.onap.cps.integration.base.CpsIntegrationSpecBase.readResourceDataFile -import org.springframework.http.HttpHeaders import java.util.regex.Matcher import okhttp3.mockwebserver.Dispatcher import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.RecordedRequest +import org.springframework.http.HttpHeaders import org.springframework.http.HttpStatus import org.springframework.http.MediaType @@ -53,25 +53,40 @@ class DmiDispatcher extends Dispatcher { static final MODULE_RESOURCES_RESPONSE_TEMPLATE = readResourceDataFile('mock-dmi-responses/moduleResourcesTemplate.json') def isAvailable = true - Map<String, List<String>> moduleNamesPerCmHandleId = [:] + def lastAuthHeaderReceived @Override MockResponse dispatch(RecordedRequest request) { if (!isAvailable) { - return new MockResponse().setResponseCode(HttpStatus.SERVICE_UNAVAILABLE.value()) + return mockResponse(HttpStatus.SERVICE_UNAVAILABLE) } + if (request.path == '/actuator/health') { + return mockResponseWithBody(HttpStatus.OK, '{"status":"UP"}') + } + + lastAuthHeaderReceived = request.getHeader('Authorization') switch (request.path) { - case ~/^\/dmi\/v1\/ch\/(.*)\/modules$/: + // get module references for a CM-handle + case ~'^/dmi/v1/ch/(.*)/modules$': def cmHandleId = Matcher.lastMatcher[0][1] return getModuleReferencesResponse(cmHandleId) - case ~/^\/dmi\/v1\/ch\/(.*)\/moduleResources$/: + // get module resources for a CM-handle + case ~'^/dmi/v1/ch/(.*)/moduleResources$': def cmHandleId = Matcher.lastMatcher[0][1] return getModuleResourcesResponse(cmHandleId) + // pass-through data operation for a CM-handle + case ~'^/dmi/v1/ch/(.*)/data/ds/(.*)$': + return mockResponseWithBody(HttpStatus.OK, '{}') + + // legacy pass-through batch data operation + case ~'^/dmi/v1/data$': + return mockResponseWithBody(HttpStatus.ACCEPTED, '{}') + default: - throw new IllegalArgumentException('Mock DMI does not handle path ' + request.path) + throw new IllegalArgumentException('Mock DMI does not implement endpoint ' + request.path) } } @@ -79,14 +94,14 @@ class DmiDispatcher extends Dispatcher { def moduleReferences = '{"schemas":[' + getModuleNamesForCmHandle(cmHandleId).collect { MODULE_REFERENCES_RESPONSE_TEMPLATE.replaceAll("<MODULE_NAME>", it) }.join(',') + ']}' - return mockOkResponseWithBody(moduleReferences) + return mockResponseWithBody(HttpStatus.OK, moduleReferences) } private getModuleResourcesResponse(cmHandleId) { def moduleResources = '[' + getModuleNamesForCmHandle(cmHandleId).collect { MODULE_RESOURCES_RESPONSE_TEMPLATE.replaceAll("<MODULE_NAME>", it) }.join(',') + ']' - return mockOkResponseWithBody(moduleResources) + return mockResponseWithBody(HttpStatus.OK, moduleResources) } private getModuleNamesForCmHandle(cmHandleId) { @@ -96,9 +111,13 @@ class DmiDispatcher extends Dispatcher { return moduleNamesPerCmHandleId.get(cmHandleId) } - private static mockOkResponseWithBody(responseBody) { + private static mockResponse(status) { + return new MockResponse().setResponseCode(status.value()) + } + + private static mockResponseWithBody(status, responseBody) { return new MockResponse() - .setResponseCode(HttpStatus.OK.value()) + .setResponseCode(status.value()) .addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .setBody(responseBody) } diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpBearerTokenPassthroughSpec.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpBearerTokenPassthroughSpec.groovy index 2a35313f74..664fca82e5 100644 --- a/integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpBearerTokenPassthroughSpec.groovy +++ b/integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpBearerTokenPassthroughSpec.groovy @@ -20,13 +20,8 @@ package org.onap.cps.integration.functional -import okhttp3.mockwebserver.Dispatcher -import okhttp3.mockwebserver.MockResponse -import okhttp3.mockwebserver.RecordedRequest -import org.jetbrains.annotations.NotNull import org.onap.cps.integration.base.CpsIntegrationSpecBase import org.springframework.http.HttpHeaders -import org.springframework.http.HttpStatus import org.springframework.http.MediaType import spock.util.concurrent.PollingConditions @@ -40,25 +35,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. class NcmpBearerTokenPassthroughSpec extends CpsIntegrationSpecBase { - def lastAuthHeaderReceived = null - def setup() { dmiDispatcher.moduleNamesPerCmHandleId['ch-1'] = ['M1', 'M2'] registerCmHandle(DMI_URL, 'ch-1', NO_MODULE_SET_TAG) - - mockDmiServer.setDispatcher(new Dispatcher() { - @Override - MockResponse dispatch(@NotNull RecordedRequest request) throws InterruptedException { - if (request.path == '/actuator/health') { - return new MockResponse() - .addHeader("Content-Type", MediaType.APPLICATION_JSON).setBody('{"status":"UP"}') - .setResponseCode(HttpStatus.OK.value()) - } else { - lastAuthHeaderReceived = request.getHeader('Authorization') - return new MockResponse().setResponseCode(HttpStatus.OK.value()) - } - } - }) } def cleanup() { @@ -75,7 +54,7 @@ class NcmpBearerTokenPassthroughSpec extends CpsIntegrationSpecBase { .andExpect(status().is2xxSuccessful()) then: 'DMI has received request with bearer token' - lastAuthHeaderReceived == 'Bearer some-bearer-token' + assert dmiDispatcher.lastAuthHeaderReceived == 'Bearer some-bearer-token' where: 'all HTTP operations are applied' httpMethod << [GET, POST, PUT, PATCH, DELETE] @@ -91,7 +70,7 @@ class NcmpBearerTokenPassthroughSpec extends CpsIntegrationSpecBase { .andExpect(status().is2xxSuccessful()) then: 'DMI has received request with no authorization header' - lastAuthHeaderReceived == null + assert dmiDispatcher.lastAuthHeaderReceived == null where: 'all HTTP operations are applied' httpMethod << [GET, POST, PUT, PATCH, DELETE] @@ -115,7 +94,7 @@ class NcmpBearerTokenPassthroughSpec extends CpsIntegrationSpecBase { then: 'DMI will receive the async request with bearer token' new PollingConditions().within(3, () -> { - assert lastAuthHeaderReceived == 'Bearer some-bearer-token' + assert dmiDispatcher.lastAuthHeaderReceived == 'Bearer some-bearer-token' }) } diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpCmNotificationSubscriptionSpec.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpCmNotificationSubscriptionSpec.groovy index c2768f1942..49a4b4d60b 100644 --- a/integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpCmNotificationSubscriptionSpec.groovy +++ b/integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpCmNotificationSubscriptionSpec.groovy @@ -21,7 +21,7 @@ package org.onap.cps.integration.functional import org.onap.cps.integration.base.CpsIntegrationSpecBase -import org.onap.cps.ncmp.api.impl.events.cmsubscription.service.CmNotificationSubscriptionPersistenceService +import org.onap.cps.ncmp.impl.cmnotificationsubscription.utils.CmSubscriptionPersistenceService import org.springframework.beans.factory.annotation.Autowired import static org.onap.cps.ncmp.api.data.models.DatastoreType.PASSTHROUGH_RUNNING @@ -29,23 +29,22 @@ import static org.onap.cps.ncmp.api.data.models.DatastoreType.PASSTHROUGH_RUNNIN class NcmpCmNotificationSubscriptionSpec extends CpsIntegrationSpecBase { @Autowired - CmNotificationSubscriptionPersistenceService cmNotificationSubscriptionPersistenceService; + CmSubscriptionPersistenceService cmSubscriptionPersistenceService def 'Adding a new cm notification subscription'() { given: 'there is no ongoing cm subscription for the following' def datastoreType = PASSTHROUGH_RUNNING def cmHandleId = 'ch-1' def xpath = '/x/y' - assert cmNotificationSubscriptionPersistenceService. - getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath).size() == 0 + assert cmSubscriptionPersistenceService. + getOngoingCmSubscriptionIds(datastoreType, cmHandleId, xpath).size() == 0 when: 'we add a new cm notification subscription' - cmNotificationSubscriptionPersistenceService.addCmNotificationSubscription(datastoreType,cmHandleId,xpath, + cmSubscriptionPersistenceService.addCmSubscription(datastoreType, cmHandleId, xpath, 'subId-1') then: 'there is an ongoing cm subscription for that CM handle and xpath' - assert cmNotificationSubscriptionPersistenceService.isOngoingCmNotificationSubscription(datastoreType,cmHandleId,xpath) + assert cmSubscriptionPersistenceService.isOngoingCmSubscription(datastoreType, cmHandleId, xpath) and: 'only one subscription id is related to now ongoing cm subscription' - assert cmNotificationSubscriptionPersistenceService. - getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath).size() == 1 + assert cmSubscriptionPersistenceService.getOngoingCmSubscriptionIds(datastoreType, cmHandleId, xpath).size() == 1 } def 'Adding a cm notification subscription to the already existing cm handle but non existing xpath'() { @@ -53,18 +52,17 @@ class NcmpCmNotificationSubscriptionSpec extends CpsIntegrationSpecBase { def datastoreType = PASSTHROUGH_RUNNING def cmHandleId = 'ch-1' def existingXpath = '/x/y' - assert cmNotificationSubscriptionPersistenceService.isOngoingCmNotificationSubscription(datastoreType,cmHandleId,existingXpath) + assert cmSubscriptionPersistenceService.isOngoingCmSubscription(datastoreType, cmHandleId, existingXpath) and: 'a non existing cm subscription with same datastore name and cm handle but different xpath' def nonExistingXpath = '/x2/y2' - assert !cmNotificationSubscriptionPersistenceService.isOngoingCmNotificationSubscription(datastoreType,cmHandleId,nonExistingXpath) + assert !cmSubscriptionPersistenceService.isOngoingCmSubscription(datastoreType, cmHandleId, nonExistingXpath) when: 'a new cm notification subscription is made for the existing cm handle and non existing xpath' - cmNotificationSubscriptionPersistenceService.addCmNotificationSubscription(datastoreType,cmHandleId, nonExistingXpath, + cmSubscriptionPersistenceService.addCmSubscription(datastoreType, cmHandleId, nonExistingXpath, 'subId-2') then: 'there is an ongoing cm subscription for that CM handle and xpath' - assert cmNotificationSubscriptionPersistenceService.isOngoingCmNotificationSubscription(datastoreType,cmHandleId,nonExistingXpath) + assert cmSubscriptionPersistenceService.isOngoingCmSubscription(datastoreType, cmHandleId, nonExistingXpath) and: 'only one subscription id is related to now ongoing cm subscription' - assert cmNotificationSubscriptionPersistenceService. - getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,nonExistingXpath).size() == 1 + assert cmSubscriptionPersistenceService.getOngoingCmSubscriptionIds(datastoreType, cmHandleId, nonExistingXpath).size() == 1 } def 'Adding a cm notification subscription to the already existing cm handle and xpath'() { @@ -73,10 +71,10 @@ class NcmpCmNotificationSubscriptionSpec extends CpsIntegrationSpecBase { def cmHandleId = 'ch-1' def xpath = '/x/y' when: 'a new cm notification subscription is made for the SAME CM handle and xpath' - cmNotificationSubscriptionPersistenceService.addCmNotificationSubscription(datastoreType,cmHandleId,xpath, + cmSubscriptionPersistenceService.addCmSubscription(datastoreType, cmHandleId, xpath, 'subId-3') then: 'it is added to the ongoing list of subscription ids' - def subscriptionIds = cmNotificationSubscriptionPersistenceService.getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath) + def subscriptionIds = cmSubscriptionPersistenceService.getOngoingCmSubscriptionIds(datastoreType, cmHandleId, xpath) assert subscriptionIds.size() == 2 and: 'both subscription ids exists for the CM handle and xpath' assert subscriptionIds.contains("subId-1") && subscriptionIds.contains("subId-3") @@ -89,13 +87,12 @@ class NcmpCmNotificationSubscriptionSpec extends CpsIntegrationSpecBase { def xpath = '/x/y' and: 'the number of subscribers is as follows' def originalNumberOfSubscribers = - cmNotificationSubscriptionPersistenceService.getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath).size() + cmSubscriptionPersistenceService.getOngoingCmSubscriptionIds(datastoreType, cmHandleId, xpath).size() when: 'a subscriber is removed' - cmNotificationSubscriptionPersistenceService.removeCmNotificationSubscription(datastoreType,cmHandleId,xpath,'subId-3') + cmSubscriptionPersistenceService.removeCmSubscription(datastoreType, cmHandleId, xpath, 'subId-3') then: 'the number of subscribers is reduced by 1' - def updatedNumberOfSubscribers = - cmNotificationSubscriptionPersistenceService.getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath).size() - assert updatedNumberOfSubscribers == originalNumberOfSubscribers-1 + def updatedNumberOfSubscribers = cmSubscriptionPersistenceService.getOngoingCmSubscriptionIds(datastoreType, cmHandleId, xpath).size() + assert updatedNumberOfSubscribers == originalNumberOfSubscribers - 1 } def 'Removing the LAST cm notification subscriber for a given cm handle, datastore and xpath'() { @@ -104,12 +101,12 @@ class NcmpCmNotificationSubscriptionSpec extends CpsIntegrationSpecBase { def cmHandleId = 'ch-1' def xpath = '/x/y' and: 'there is only one subscriber' - assert cmNotificationSubscriptionPersistenceService - .getOngoingCmNotificationSubscriptionIds(datastoreType,cmHandleId,xpath).size() == 1 + assert cmSubscriptionPersistenceService + .getOngoingCmSubscriptionIds(datastoreType, cmHandleId, xpath).size() == 1 when: 'only subscriber is removed' - cmNotificationSubscriptionPersistenceService.removeCmNotificationSubscription(datastoreType,cmHandleId,xpath,'subId-1') + cmSubscriptionPersistenceService.removeCmSubscription(datastoreType, cmHandleId, xpath, 'subId-1') then: 'there are no longer any subscriptions for the cm handle, datastore and xpath' - assert !cmNotificationSubscriptionPersistenceService.isOngoingCmNotificationSubscription(datastoreType, cmHandleId, xpath) + assert !cmSubscriptionPersistenceService.isOngoingCmSubscription(datastoreType, cmHandleId, xpath) } } |