diff options
Diffstat (limited to 'integration-test/src')
5 files changed, 152 insertions, 42 deletions
diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy index 5020dceef6..51b02387ed 100644 --- a/integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy +++ b/integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy @@ -21,6 +21,7 @@ package org.onap.cps.integration.base import java.time.OffsetDateTime +import java.time.format.DateTimeFormatter import org.onap.cps.api.CpsAnchorService import org.onap.cps.api.CpsDataService import org.onap.cps.api.CpsDataspaceService @@ -39,6 +40,7 @@ import org.onap.cps.spi.exceptions.DataspaceNotFoundException import org.onap.cps.spi.model.DataNode import org.onap.cps.spi.repository.DataspaceRepository import org.onap.cps.spi.utils.SessionManager +import org.onap.cps.utils.JsonObjectMapper import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.autoconfigure.EnableAutoConfiguration import org.springframework.boot.autoconfigure.domain.EntityScan @@ -48,6 +50,7 @@ import org.springframework.context.annotation.ComponentScan import org.springframework.data.jpa.repository.config.EnableJpaRepositories import org.springframework.http.HttpStatus import org.springframework.http.MediaType +import org.springframework.test.web.client.ExpectedCount import org.springframework.test.web.client.MockRestServiceServer import org.springframework.test.web.servlet.MockMvc import org.springframework.web.client.RestTemplate @@ -56,13 +59,11 @@ import spock.lang.Shared import spock.lang.Specification import spock.util.concurrent.PollingConditions -import java.time.format.DateTimeFormatter - -import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo -import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT +import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo +import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK, classes = [CpsDataspaceService]) @Testcontainers @@ -77,10 +78,10 @@ abstract class CpsIntegrationSpecBase extends Specification { DatabaseTestContainer databaseTestContainer = DatabaseTestContainer.getInstance() @Shared - KafkaTestContainer kafkaTestContainer = KafkaTestContainer.getInstance(); + KafkaTestContainer kafkaTestContainer = KafkaTestContainer.getInstance() @Autowired - MockMvc mvc; + MockMvc mvc @Autowired CpsDataspaceService cpsDataspaceService @@ -115,12 +116,15 @@ abstract class CpsIntegrationSpecBase extends Specification { @Autowired ModuleSyncWatchdog moduleSyncWatchdog - MockRestServiceServer mockDmiServer = null + @Autowired + JsonObjectMapper jsonObjectMapper - static final DMI_URL = 'http://mock-dmi-server' + MockRestServiceServer mockDmiServer = null - def static GENERAL_TEST_DATASPACE = 'generalTestDataspace' - def static BOOKSTORE_SCHEMA_SET = 'bookstoreSchemaSet' + static DMI_URL = 'http://mock-dmi-server' + static NO_MODULE_SET_TAG = '' + static GENERAL_TEST_DATASPACE = 'generalTestDataspace' + static BOOKSTORE_SCHEMA_SET = 'bookstoreSchemaSet' def static initialized = false def now = OffsetDateTime.now() @@ -134,10 +138,6 @@ abstract class CpsIntegrationSpecBase extends Specification { mockDmiServer = MockRestServiceServer.bindTo(restTemplate).ignoreExpectOrder(true).build() } - def cleanup() { - mockDmiServer.reset() - } - def static readResourceDataFile(filename) { return new File('src/test/resources/data/' + filename).text } @@ -200,15 +200,13 @@ abstract class CpsIntegrationSpecBase extends Specification { // *** NCMP Integration Test Utilities *** - def registerCmHandle(dmiPlugin, cmHandleId, moduleSetTag, dmiModuleReferencesResponse, dmiModuleResourcesResponse) { + def registerCmHandle(dmiPlugin, cmHandleId, moduleSetTag) { def cmHandleToCreate = new NcmpServiceCmHandle(cmHandleId: cmHandleId, moduleSetTag: moduleSetTag) networkCmProxyDataService.updateDmiRegistrationAndSyncModule(new DmiPluginRegistration(dmiPlugin: dmiPlugin, createdCmHandles: [cmHandleToCreate])) - mockDmiResponsesForModuleSync(dmiPlugin, cmHandleId, dmiModuleReferencesResponse, dmiModuleResourcesResponse) moduleSyncWatchdog.moduleSyncAdvisedCmHandles() new PollingConditions().within(3, () -> { CmHandleState.READY == networkCmProxyDataService.getCmHandleCompositeState(cmHandleId).cmHandleState }) - mockDmiServer.reset() } def deregisterCmHandle(dmiPlugin, cmHandleId) { @@ -231,6 +229,11 @@ abstract class CpsIntegrationSpecBase extends Specification { .andRespond(withStatus(HttpStatus.SERVICE_UNAVAILABLE)) } + def mockDmiWillRespondToHealthChecks(dmiPlugin) { + mockDmiServer.expect(ExpectedCount.between(0, Integer.MAX_VALUE), requestTo("${dmiPlugin}/actuator/health")) + .andRespond(withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON).body('{"status":"UP"}')) + } + def overrideCmHandleLastUpdateTime(cmHandleId, newUpdateTime) { String ISO_TIMESTAMP_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; DateTimeFormatter ISO_TIMESTAMP_FORMATTER = DateTimeFormatter.ofPattern(ISO_TIMESTAMP_PATTERN); 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 0dabbf30a4..28c4280468 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 @@ -40,12 +40,15 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. class NcmpBearerTokenPassthroughSpec extends CpsIntegrationSpecBase { - static final NO_MODULE_SET_TAG = '' static final MODULE_REFERENCES_RESPONSE = readResourceDataFile('mock-dmi-responses/bookStoreAWithModules_M1_M2_Response.json') static final MODULE_RESOURCES_RESPONSE = readResourceDataFile('mock-dmi-responses/bookStoreAWithModules_M1_M2_ResourcesResponse.json') def setup() { - registerCmHandle(DMI_URL, 'ch-1', NO_MODULE_SET_TAG, MODULE_REFERENCES_RESPONSE, MODULE_RESOURCES_RESPONSE) + mockDmiWillRespondToHealthChecks(DMI_URL) + mockDmiResponsesForModuleSync(DMI_URL, 'ch-1', MODULE_REFERENCES_RESPONSE, MODULE_RESOURCES_RESPONSE) + registerCmHandle(DMI_URL, 'ch-1', NO_MODULE_SET_TAG) + mockDmiServer.reset() + mockDmiWillRespondToHealthChecks(DMI_URL) } def cleanup() { diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpCmHandleCreateSpec.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpCmHandleCreateSpec.groovy index d20ac337bf..a6b516cd74 100644 --- a/integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpCmHandleCreateSpec.groovy +++ b/integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpCmHandleCreateSpec.groovy @@ -20,7 +20,8 @@ package org.onap.cps.integration.functional - +import java.time.Duration +import java.time.OffsetDateTime import org.apache.kafka.common.TopicPartition import org.apache.kafka.common.serialization.StringDeserializer import org.onap.cps.integration.KafkaTestContainer @@ -31,16 +32,14 @@ import org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse import org.onap.cps.ncmp.api.models.DmiPluginRegistration import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle +import org.onap.cps.ncmp.events.lcm.v1.LcmEvent import spock.util.concurrent.PollingConditions -import java.time.Duration -import java.time.OffsetDateTime - class NcmpCmHandleCreateSpec extends CpsIntegrationSpecBase { NetworkCmProxyDataService objectUnderTest - def kafkaConsumer = KafkaTestContainer.getConsumer("ncmp-group", StringDeserializer.class); + def kafkaConsumer = KafkaTestContainer.getConsumer('ncmp-group', StringDeserializer.class) static final MODULE_REFERENCES_RESPONSE_A = readResourceDataFile('mock-dmi-responses/bookStoreAWithModules_M1_M2_Response.json') static final MODULE_RESOURCES_RESPONSE_A = readResourceDataFile('mock-dmi-responses/bookStoreAWithModules_M1_M2_ResourcesResponse.json') @@ -49,6 +48,7 @@ class NcmpCmHandleCreateSpec extends CpsIntegrationSpecBase { def setup() { objectUnderTest = networkCmProxyDataService + mockDmiWillRespondToHealthChecks(DMI_URL) } def 'CM Handle registration is successful.'() { @@ -82,7 +82,8 @@ class NcmpCmHandleCreateSpec extends CpsIntegrationSpecBase { def records = message.records(new TopicPartition('ncmp-events', 0)) and: 'the newest lcm event notification is received with READY state' - assert records.last().value().toString().contains('"cmHandleState":"READY"') + def notificationMessage = jsonObjectMapper.convertJsonString(records.last().value().toString(), LcmEvent) + assert notificationMessage.event.newValues.cmHandleState.value() == 'READY' and: 'the CM-handle has expected modules' assert ['M1', 'M2'] == objectUnderTest.getYangResourcesModuleReferences('ch-1').moduleName.sort() @@ -122,8 +123,10 @@ class NcmpCmHandleCreateSpec extends CpsIntegrationSpecBase { def 'Create a CM-handle with existing moduleSetTag.'() { given: 'existing CM-handles cm-1 with moduleSetTag "A", and cm-2 with moduleSetTag "B"' - registerCmHandle(DMI_URL, 'ch-1', 'A', MODULE_REFERENCES_RESPONSE_A, MODULE_RESOURCES_RESPONSE_A) - registerCmHandle(DMI_URL, 'ch-2', 'B', MODULE_REFERENCES_RESPONSE_B, MODULE_RESOURCES_RESPONSE_B) + mockDmiResponsesForModuleSync(DMI_URL, 'ch-1', MODULE_REFERENCES_RESPONSE_A, MODULE_RESOURCES_RESPONSE_A) + mockDmiResponsesForModuleSync(DMI_URL, 'ch-2', MODULE_REFERENCES_RESPONSE_B, MODULE_RESOURCES_RESPONSE_B) + registerCmHandle(DMI_URL, 'ch-1', 'A') + registerCmHandle(DMI_URL, 'ch-2', 'B') assert ['M1', 'M2'] == objectUnderTest.getYangResourcesModuleReferences('ch-1').moduleName.sort() assert ['M1', 'M3'] == objectUnderTest.getYangResourcesModuleReferences('ch-2').moduleName.sort() diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpCmHandleUpgradeSpec.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpCmHandleUpgradeSpec.groovy index c5c59e05ca..5421ad3237 100644 --- a/integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpCmHandleUpgradeSpec.groovy +++ b/integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpCmHandleUpgradeSpec.groovy @@ -41,23 +41,24 @@ class NcmpCmHandleUpgradeSpec extends CpsIntegrationSpecBase { static final INITIAL_MODULE_RESOURCES_RESPONSE = readResourceDataFile('mock-dmi-responses/bookStoreAWithModules_M1_M2_ResourcesResponse.json') static final UPDATED_MODULE_REFERENCES_RESPONSE = readResourceDataFile('mock-dmi-responses/bookStoreBWithModules_M1_M3_Response.json') static final UPDATED_MODULE_RESOURCES_RESPONSE = readResourceDataFile('mock-dmi-responses/bookStoreBWithModules_M1_M3_ResourcesResponse.json') - static final NO_MODULE_SET_TAG = '' static final CM_HANDLE_ID = 'ch-1' static final CM_HANDLE_ID_WITH_EXISTING_MODULE_SET_TAG = 'ch-2' def setup() { objectUnderTest = networkCmProxyDataService + mockDmiWillRespondToHealthChecks(DMI_URL) } def 'Upgrade CM-handle with new moduleSetTag or no moduleSetTag.'() { - given: 'an existing CM-handle with expected initial modules: M1 and M2' - registerCmHandle(DMI_URL, CM_HANDLE_ID, initialModuleSetTag, INITIAL_MODULE_REFERENCES_RESPONSE, INITIAL_MODULE_RESOURCES_RESPONSE) - assert ['M1', 'M2'] == objectUnderTest.getYangResourcesModuleReferences(CM_HANDLE_ID).moduleName.sort() - + given: 'DMI will return modules for initial registration' + mockDmiResponsesForModuleSync(DMI_URL, CM_HANDLE_ID, INITIAL_MODULE_REFERENCES_RESPONSE, INITIAL_MODULE_RESOURCES_RESPONSE) and: 'DMI returns different modules for upgrade' mockDmiResponsesForModuleSync(DMI_URL, CM_HANDLE_ID, UPDATED_MODULE_REFERENCES_RESPONSE, UPDATED_MODULE_RESOURCES_RESPONSE) - when: "CM-handle is upgraded with given moduleSetTag '${updatedModuleSetTag}'" + when: 'a CM-handle is created with expected initial modules: M1 and M2' + registerCmHandle(DMI_URL, CM_HANDLE_ID, initialModuleSetTag) + assert ['M1', 'M2'] == objectUnderTest.getYangResourcesModuleReferences(CM_HANDLE_ID).moduleName.sort() + and: "the CM-handle is upgraded with given moduleSetTag '${updatedModuleSetTag}'" def cmHandlesToUpgrade = new UpgradedCmHandles(cmHandles: [CM_HANDLE_ID], moduleSetTag: updatedModuleSetTag) def dmiPluginRegistrationResponse = networkCmProxyDataService.updateDmiRegistrationAndSyncModule( new DmiPluginRegistration(dmiPlugin: DMI_URL, upgradedCmHandles: cmHandlesToUpgrade)) @@ -101,11 +102,14 @@ class NcmpCmHandleUpgradeSpec extends CpsIntegrationSpecBase { } def 'Upgrade CM-handle with existing moduleSetTag.'() { - given: "an existing CM-handle handle with moduleSetTag '${updatedModuleSetTag}'" - registerCmHandle(DMI_URL, CM_HANDLE_ID_WITH_EXISTING_MODULE_SET_TAG, updatedModuleSetTag, UPDATED_MODULE_REFERENCES_RESPONSE, UPDATED_MODULE_RESOURCES_RESPONSE) + given: 'DMI will return modules for registration' + mockDmiResponsesForModuleSync(DMI_URL, CM_HANDLE_ID, INITIAL_MODULE_REFERENCES_RESPONSE, INITIAL_MODULE_RESOURCES_RESPONSE) + mockDmiResponsesForModuleSync(DMI_URL, CM_HANDLE_ID_WITH_EXISTING_MODULE_SET_TAG, UPDATED_MODULE_REFERENCES_RESPONSE, UPDATED_MODULE_RESOURCES_RESPONSE) + and: "an existing CM-handle handle with moduleSetTag '${updatedModuleSetTag}'" + registerCmHandle(DMI_URL, CM_HANDLE_ID_WITH_EXISTING_MODULE_SET_TAG, updatedModuleSetTag) assert ['M1', 'M3'] == objectUnderTest.getYangResourcesModuleReferences(CM_HANDLE_ID_WITH_EXISTING_MODULE_SET_TAG).moduleName.sort() and: "a CM-handle with moduleSetTag '${initialModuleSetTag}' which will be upgraded" - registerCmHandle(DMI_URL, CM_HANDLE_ID, initialModuleSetTag, INITIAL_MODULE_REFERENCES_RESPONSE, INITIAL_MODULE_RESOURCES_RESPONSE) + registerCmHandle(DMI_URL, CM_HANDLE_ID, initialModuleSetTag) assert ['M1', 'M2'] == objectUnderTest.getYangResourcesModuleReferences(CM_HANDLE_ID).moduleName.sort() when: "CM-handle is upgraded to moduleSetTag '${updatedModuleSetTag}'" @@ -142,7 +146,8 @@ class NcmpCmHandleUpgradeSpec extends CpsIntegrationSpecBase { def 'Skip upgrade of CM-handle with same moduleSetTag as before.'() { given: 'an existing CM-handle with expected initial modules: M1 and M2' - registerCmHandle(DMI_URL, CM_HANDLE_ID, 'same', INITIAL_MODULE_REFERENCES_RESPONSE, INITIAL_MODULE_RESOURCES_RESPONSE) + mockDmiResponsesForModuleSync(DMI_URL, CM_HANDLE_ID, INITIAL_MODULE_REFERENCES_RESPONSE, INITIAL_MODULE_RESOURCES_RESPONSE) + registerCmHandle(DMI_URL, CM_HANDLE_ID, 'same') assert ['M1', 'M2'] == objectUnderTest.getYangResourcesModuleReferences(CM_HANDLE_ID).moduleName.sort() when: 'CM-handle is upgraded with the same moduleSetTag' @@ -164,13 +169,14 @@ class NcmpCmHandleUpgradeSpec extends CpsIntegrationSpecBase { } def 'Upgrade of CM-handle fails due to DMI error.'() { - given: 'an existing CM-handle' - registerCmHandle(DMI_URL, CM_HANDLE_ID, 'oldTag', INITIAL_MODULE_REFERENCES_RESPONSE, INITIAL_MODULE_RESOURCES_RESPONSE) - - and: 'DMI returns error code' + given: 'DMI will return modules for initial registration' + mockDmiResponsesForModuleSync(DMI_URL, CM_HANDLE_ID, INITIAL_MODULE_REFERENCES_RESPONSE, INITIAL_MODULE_RESOURCES_RESPONSE) + and: 'DMI returns error code for upgrade' mockDmiServer.expect(anything()).andRespond(withStatus(HttpStatus.SERVICE_UNAVAILABLE)) - when: "CM-handle is upgraded" + when: 'a CM-handle is created' + registerCmHandle(DMI_URL, CM_HANDLE_ID, 'oldTag') + and: 'the CM-handle is upgraded' def cmHandlesToUpgrade = new UpgradedCmHandles(cmHandles: [CM_HANDLE_ID], moduleSetTag: 'newTag') networkCmProxyDataService.updateDmiRegistrationAndSyncModule( new DmiPluginRegistration(dmiPlugin: DMI_URL, upgradedCmHandles: cmHandlesToUpgrade)) diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpRestApiSpec.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpRestApiSpec.groovy new file mode 100644 index 0000000000..d7f8771e18 --- /dev/null +++ b/integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpRestApiSpec.groovy @@ -0,0 +1,95 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2024 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.integration.functional + +import org.onap.cps.integration.base.CpsIntegrationSpecBase +import org.springframework.http.MediaType +import spock.util.concurrent.PollingConditions +import static org.hamcrest.Matchers.containsInAnyOrder +import static org.hamcrest.Matchers.hasSize +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status + +class NcmpRestApiSpec extends CpsIntegrationSpecBase { + + static final MODULE_REFERENCES_RESPONSE_A = readResourceDataFile('mock-dmi-responses/bookStoreAWithModules_M1_M2_Response.json') + static final MODULE_RESOURCES_RESPONSE_A = readResourceDataFile('mock-dmi-responses/bookStoreAWithModules_M1_M2_ResourcesResponse.json') + static final MODULE_REFERENCES_RESPONSE_B = readResourceDataFile('mock-dmi-responses/bookStoreBWithModules_M1_M3_Response.json') + static final MODULE_RESOURCES_RESPONSE_B = readResourceDataFile('mock-dmi-responses/bookStoreBWithModules_M1_M3_ResourcesResponse.json') + + def setup() { + mockDmiWillRespondToHealthChecks(DMI_URL) + } + + def 'Register CM Handles using REST API.'() { + given: 'DMI will return modules' + mockDmiResponsesForModuleSync(DMI_URL, 'ch-1', MODULE_REFERENCES_RESPONSE_A, MODULE_RESOURCES_RESPONSE_A) + mockDmiResponsesForModuleSync(DMI_URL, 'ch-2', MODULE_REFERENCES_RESPONSE_A, MODULE_RESOURCES_RESPONSE_A) + mockDmiResponsesForModuleSync(DMI_URL, 'ch-3', MODULE_REFERENCES_RESPONSE_B, MODULE_RESOURCES_RESPONSE_B) + and: 'a POST request is made to register the CM Handles' + def requestBody = '{"dmiPlugin":"'+DMI_URL+'","createdCmHandles":[{"cmHandle":"ch-1"},{"cmHandle":"ch-2"},{"cmHandle":"ch-3"}]}' + mvc.perform(post('/ncmpInventory/v1/ch').contentType(MediaType.APPLICATION_JSON).content(requestBody)) + .andExpect(status().is2xxSuccessful()) + when: 'module sync runs' + moduleSyncWatchdog.moduleSyncAdvisedCmHandles() + then: 'CM-handles go to READY state' + new PollingConditions(timeout: 3, delay: 0.5).eventually { + mvc.perform(get('/ncmp/v1/ch/ch-1')) + .andExpect(status().isOk()) + .andExpect(jsonPath('$.state.cmHandleState').value('READY')) + } + } + + def 'Search for CM Handles by module using REST API.'() { + given: 'a JSON request body containing search parameter' + def requestBodyWithModuleCondition = """{ + "cmHandleQueryParameters": [ + { + "conditionName": "hasAllModules", + "conditionParameters": [ {"moduleName": "%s"} ] + } + ] + }""".formatted(moduleName) + expect: "a search for module ${moduleName} returns expected CM handles" + mvc.perform(post(DMI_URL+'/ncmp/v1/ch/id-searches').contentType(MediaType.APPLICATION_JSON).content(requestBodyWithModuleCondition)) + .andExpect(status().is2xxSuccessful()) + .andExpect(jsonPath('$[*]', containsInAnyOrder(expectedCmHandles.toArray()))) + .andExpect(jsonPath('$', hasSize(expectedCmHandles.size()))); + where: + moduleName || expectedCmHandles + 'M1' || ['ch-1', 'ch-2', 'ch-3'] + 'M2' || ['ch-1', 'ch-2'] + 'M3' || ['ch-3'] + } + + def 'De-register CM handles using REST API.'() { + when: 'a POST request is made to deregister the CM Handle' + def requestBody = '{"dmiPlugin":"'+DMI_URL+'", "removedCmHandles": ["ch-1", "ch-2", "ch-3"]}' + mvc.perform(post('/ncmpInventory/v1/ch').contentType(MediaType.APPLICATION_JSON).content(requestBody)) + .andExpect(status().is2xxSuccessful()) + then: 'the CM handles are not found using GET' + (1..3).each { + mvc.perform(get('/ncmp/v1/ch/ch-'+it)).andExpect(status().is4xxClientError()) + } + } +} |