aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-rest/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-rest/src/test')
-rw-r--r--cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy29
-rw-r--r--cps-ncmp-rest/src/test/resources/cmhandle-search.json15
-rw-r--r--cps-ncmp-rest/src/test/resources/invalid-cmhandle-search.json7
3 files changed, 51 insertions, 0 deletions
diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
index 342f41b26..a609cfacb 100644
--- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
+++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
@@ -22,6 +22,7 @@
package org.onap.cps.ncmp.rest.controller
+import org.onap.cps.TestUtils
import org.onap.cps.spi.model.ModuleReference
import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
@@ -252,5 +253,33 @@ class NetworkCmProxyControllerSpec extends Specification {
and: 'response returns an OK http code'
response.status == HttpStatus.OK.value()
}
+
+ def 'Retrieve cm handles.'() {
+ given: 'an endpoint and json data'
+ def searchesEndpoint = "$ncmpBasePathV1/ch/searches"
+ String jsonData = TestUtils.getResourceFileContent('cmhandle-search.json')
+ and: 'the service method is invoked with module names and returns a cm handle id'
+ mockNetworkCmProxyDataService.executeCmHandleHasAllModulesSearch(['module1', 'module2']) >> ['some-cmhandle-id']
+ when: 'the searches api is invoked'
+ def response = mvc.perform(post(searchesEndpoint)
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(jsonData)).andReturn().response
+ then: 'response status returns OK'
+ response.status == HttpStatus.OK.value()
+ and: 'the expected response content is returned'
+ response.contentAsString == '{"cmHandles":[{"cmHandleId":"some-cmhandle-id"}]}'
+ }
+
+ def 'Call execute cm handle searches with unrecognized condition name.'() {
+ given: 'an endpoint and json data'
+ def searchesEndpoint = "$ncmpBasePathV1/ch/searches"
+ String jsonData = TestUtils.getResourceFileContent('invalid-cmhandle-search.json')
+ when: 'the searches api is invoked'
+ def response = mvc.perform(post(searchesEndpoint)
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(jsonData)).andReturn().response
+ then: 'an empty cm handle identifier is returned'
+ response.contentAsString == '{"cmHandles":null}'
+ }
}
diff --git a/cps-ncmp-rest/src/test/resources/cmhandle-search.json b/cps-ncmp-rest/src/test/resources/cmhandle-search.json
new file mode 100644
index 000000000..e3c721bfd
--- /dev/null
+++ b/cps-ncmp-rest/src/test/resources/cmhandle-search.json
@@ -0,0 +1,15 @@
+{
+ "conditions": [
+ {
+ "name": "hasAllModules",
+ "conditionParameters": [
+ {
+ "moduleName": "module1"
+ },
+ {
+ "moduleName": "module2"
+ }
+ ]
+ }
+ ]
+} \ No newline at end of file
diff --git a/cps-ncmp-rest/src/test/resources/invalid-cmhandle-search.json b/cps-ncmp-rest/src/test/resources/invalid-cmhandle-search.json
new file mode 100644
index 000000000..838c9481b
--- /dev/null
+++ b/cps-ncmp-rest/src/test/resources/invalid-cmhandle-search.json
@@ -0,0 +1,7 @@
+{
+ "conditions": [
+ {
+ "name": "does-not-exist"
+ }
+ ]
+} \ No newline at end of file