summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/test/groovy/org/onap
diff options
context:
space:
mode:
authorwaqas.ikram <waqas.ikram@est.tech>2023-10-04 10:05:09 +0100
committerwaqas.ikram <waqas.ikram@est.tech>2023-10-16 12:11:37 +0100
commitad6021f2d7317b866ca983e355337a740d769c2f (patch)
treeac0a64bc6f16201bede8fbf703f70ec2c270b56f /cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/test/groovy/org/onap
parent74eed2c34d86f9c55ba4200f040fbe861879f254 (diff)
Adding NCMP Stubs documentation
Issue-ID: CPS-1858 Change-Id: I90017d9d9c6e937292e9de45c0e8228357414e16 Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
Diffstat (limited to 'cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/test/groovy/org/onap')
-rw-r--r--cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/test/groovy/org/onap/cps/ncmp/rest/stub/SampleCpsNcmpClientSpec.groovy82
-rw-r--r--cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/test/groovy/org/onap/cps/ncmp/rest/stub/TestApplication.groovy28
2 files changed, 110 insertions, 0 deletions
diff --git a/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/test/groovy/org/onap/cps/ncmp/rest/stub/SampleCpsNcmpClientSpec.groovy b/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/test/groovy/org/onap/cps/ncmp/rest/stub/SampleCpsNcmpClientSpec.groovy
new file mode 100644
index 000000000..b36e25ada
--- /dev/null
+++ b/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/test/groovy/org/onap/cps/ncmp/rest/stub/SampleCpsNcmpClientSpec.groovy
@@ -0,0 +1,82 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 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.ncmp.rest.stub
+
+import org.onap.cps.ncmp.api.impl.operations.DatastoreType
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.beans.factory.annotation.Value
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration
+import org.springframework.boot.test.context.SpringBootContextLoader
+import org.springframework.boot.test.context.SpringBootTest
+import org.springframework.boot.test.web.client.TestRestTemplate
+import org.springframework.boot.test.web.server.LocalServerPort
+import org.springframework.http.HttpStatus
+import org.springframework.test.context.ActiveProfiles
+import org.springframework.test.context.ContextConfiguration
+
+import com.fasterxml.jackson.core.JsonProcessingException
+import com.fasterxml.jackson.core.type.TypeReference
+import com.fasterxml.jackson.databind.JsonMappingException
+import com.fasterxml.jackson.databind.ObjectMapper
+
+import spock.lang.Shared
+import spock.lang.Specification
+
+@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@ActiveProfiles("test")
+class SampleCpsNcmpClientSpec extends Specification {
+
+ static final String CM_HANDLE = "anything"
+
+ static final String DATA_STORE_NAME = DatastoreType.PASSTHROUGH_OPERATIONAL.getDatastoreName()
+
+ @LocalServerPort
+ def port
+
+ final def testRestTemplate = new TestRestTemplate()
+
+ @Value('${rest.api.ncmp-stub-base-path}')
+ def stubBasePath
+
+ @Autowired
+ ObjectMapper objectMapper
+
+ def 'Test the invocation of the stub API' () throws JsonMappingException, JsonProcessingException {
+
+ when: 'Get resource data for cm handle URL is invoked'
+ def url = "${getBaseUrl()}/v1/ch/${CM_HANDLE}/data/ds/${DATA_STORE_NAME}?resourceIdentifier=parent&options=(a=1,b=2)"
+ def response = testRestTemplate.getForEntity(url, String.class)
+ then: 'Response is OK'
+ response.getStatusCode() == HttpStatus.OK
+
+ and: 'Response body contains customized stub response that contains correct bookstore category code'
+ def typeRef = new TypeReference<HashMap<String, Object>>() {}
+ def map = objectMapper.readValue(response.getBody(), typeRef)
+ def obj1 = (Map<String, Object>) map.get("stores:bookstore")
+ def obj2 = (List<Object>) obj1.get("categories")
+ def obj3 = (Map<String, Object>) obj2.iterator().next()
+
+ assert obj3.get("code") == "02"
+ }
+
+ def String getBaseUrl() {
+ return "http://localhost:" + port + stubBasePath
+ }
+}
diff --git a/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/test/groovy/org/onap/cps/ncmp/rest/stub/TestApplication.groovy b/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/test/groovy/org/onap/cps/ncmp/rest/stub/TestApplication.groovy
new file mode 100644
index 000000000..79384239a
--- /dev/null
+++ b/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/test/groovy/org/onap/cps/ncmp/rest/stub/TestApplication.groovy
@@ -0,0 +1,28 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 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.ncmp.rest.stub
+
+import org.springframework.boot.autoconfigure.SpringBootApplication
+import org.springframework.context.annotation.ComponentScan
+
+@SpringBootApplication
+@ComponentScan(basePackages = ["org.onap.cps.ncmp.rest.stub", "org.onap.cps.ncmp.rest.stub.controller", "org.onap.cps.ncmp.rest.api"])
+class TestApplication {
+}