summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/test
diff options
context:
space:
mode:
authorJosephKeenan <joseph.keenan@est.tech>2021-09-07 10:31:37 +0100
committerJosephKeenan <joseph.keenan@est.tech>2021-09-10 09:43:57 +0100
commitd469924472af98ce13c2bcb3d8b053d45322e806 (patch)
treeec9abdf036df29ab23064d80c6ae64dc361ced4c /cps-ncmp-service/src/test
parent2d67cfd62ad847dfbb1c286dd4e6c3f028a99685 (diff)
CPS-635 - Module Resource call does not include body
Issue-ID: CPS-635 Change-Id: Ie7a783ec1cd5107cef19a128439532bb520e3e89 Signed-off-by: JosephKeenan <joseph.keenan@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/test')
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/JsonUtilsSpec.groovy44
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy12
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy14
4 files changed, 65 insertions, 7 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/JsonUtilsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/JsonUtilsSpec.groovy
new file mode 100644
index 0000000000..2b3d998645
--- /dev/null
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/JsonUtilsSpec.groovy
@@ -0,0 +1,44 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.api.impl
+
+import spock.lang.Specification
+
+class JsonUtilsSpec extends Specification {
+ def 'Remove redundant escape characters.'() {
+ expect: 'removing redundant escape characters returns the correct output for #scenario'
+ JsonUtils.removeRedundantEscapeCharacters(input) == expectedOutput
+ where: 'the following input is used'
+ scenario | input || expectedOutput
+ 'two lines' | 'line1\\nline2' || 'line1\nline2'
+ 'a string inside quotes' | 'a \\"word in quotes\\"' || 'a "word in quotes"'
+ 'quotes inside quotes (double escape)' | '\\"quotes \\\\\\"inside\\\\\\" quotes\\"' || '"quotes \\"inside\\" quotes"' // human readable: "quotes \"inside\" quotes"
+ }
+ def 'Remove wrapping tokens.'() {
+ expect: 'removing wrapping tokens returns the correct output for #scenario'
+ JsonUtils.removeWrappingTokens(input) == expectedOutput
+ where: 'the following input is used'
+ scenario | input || expectedOutput
+ 'a string in quotes' | '"abc"' || 'abc'
+ 'a string in apostrophes' | "'abc'" || 'abc'
+ 'a string inside any other tokens' | 'abcde' || 'bcd'
+ }
+}
+
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
index 795eeefa31..98a3aaed1c 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
@@ -34,6 +34,7 @@ import org.onap.cps.ncmp.api.impl.operation.DmiOperations
import org.onap.cps.ncmp.api.models.CmHandle
import org.onap.cps.ncmp.api.models.DmiPluginRegistration
import org.onap.cps.ncmp.api.models.PersistenceCmHandle
+import org.onap.cps.ncmp.api.models.PersistenceCmHandlesList
import org.onap.cps.ncmp.utils.TestUtils
import org.onap.cps.spi.FetchDescendantsOption
import org.onap.cps.spi.model.DataNode
@@ -65,7 +66,6 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
def cmHandleXPath = "/dmi-registry/cm-handles[@id='testCmHandle']"
def cmHandleForModelSync = new PersistenceCmHandle(id:'some cm handle', dmiServiceName: 'some service name')
def expectedDataspaceNameForModleSync = 'NCMP-Admin'
- def NO_NAMESPACE = null
def expectedDataspaceName = 'NFP-Operational'
def 'Query data nodes by cps path with #fetchDescendantsOption.'() {
@@ -333,7 +333,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
'testCmHandle',
'testResourceId',
'{"operation":"create","dataType":"application/json","data":"{some-json}","cmHandleProperties":{"testName":"testValue"}}')
- >> { new ResponseEntity<>(HttpStatus.CREATED) }
+ >> { new ResponseEntity<>(HttpStatus.OK) }
}
def 'Write resource data for pass-through running from dmi using POST "not found" response (from DMI).'() {
@@ -362,7 +362,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
mockCpsModuleService.getYangResourceModuleReferences(_) >> [knownModule1, knownOtherModule]
and: 'DMI-Plugin returns resource(s) for "new" module(s)'
def moduleResources = new ResponseEntity<String>(sdncReponseBody, HttpStatus.OK)
- mockDmiOperations.getResourceFromDmi(_, cmHandleForModelSync.getId(), 'moduleResources') >> moduleResources
+ mockDmiOperations.getResourceFromDmiWithJsonData(_, _, _, 'moduleResources') >> moduleResources
when: 'module Sync is triggered'
objectUnderTest.createAnchorAndSyncModel(cmHandleForModelSync)
then: 'the CPS module service is called once with the correct parameters'
@@ -370,9 +370,9 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
and: 'admin service create anchor method has been called with correct parameters'
1 * mockCpsAdminService.createAnchor(expectedDataspaceNameForModleSync, cmHandleForModelSync.getId(), cmHandleForModelSync.getId())
where: 'the following responses are recieved from SDNC'
- scenario | sdncReponseBody || expectedYangResourceToContentMap
- 'one unknown module' | '[{"moduleName" : "someModule", "revision" : "1","yangSource": "someResource"}]' || [someModule: 'someResource']
- 'no unknown module' | '[]' || [:]
+ scenario | sdncReponseBody || expectedYangResourceToContentMap
+ 'one unknown module' | '[{"moduleName" : "someModule", "revision" : "1","yangSource": "[some yang source]"}]' || [someModule: 'some yang source']
+ 'no unknown module' | '[]' || [:]
}
def getModulesForCmHandle() {
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy
index 879c73c27e..809c48a619 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy
@@ -55,7 +55,7 @@ class DmiRestClientSpec extends Specification {
setupTestConfigurationData()
and: 'the rest template returns a valid response entity'
def mockResponseEntity = Mock(ResponseEntity)
- mockRestTemplate.postForEntity(getResourceDataUrl, _ as HttpEntity, Void.class) >> mockResponseEntity
+ mockRestTemplate.postForEntity(getResourceDataUrl, _ as HttpEntity, String.class) >> mockResponseEntity
when: 'POST operation is invoked'
def result = objectUnderTest.postOperationWithJsonData(getResourceDataUrl, 'json-data', new HttpHeaders())
then: 'the output of the method is equal to the output from the test template'
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy
index 987ab2bca1..6a1ce1a18b 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy
@@ -92,4 +92,18 @@ class DmiOperationsSpec extends Specification {
then: 'the post operation is executed with the correct URL'
1 * mockDmiRestClient.postOperation(expectedUrl, _ as HttpHeaders)
}
+
+ def 'Call get resource from dmi with json data.'() {
+ given: 'expected url & json data'
+ def requestBody = 'some json'
+ def expectedUrl = 'testDmiBasePath/dmi/v1/ch/testCmHandle/modules'
+ def expectedHttpHeaders = new HttpHeaders()
+ when: 'get resource data is called to dmi'
+ objectUnderTest.getResourceFromDmiWithJsonData('testDmiBasePath',
+ requestBody,
+ 'testCmHandle',
+ 'modules')
+ then: 'the post operation is executed with the correct URL and json data'
+ 1 * mockDmiRestClient.postOperationWithJsonData(expectedUrl, requestBody, expectedHttpHeaders)
+ }
} \ No newline at end of file