summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-service/src/test')
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/JsonUtilsSpec.groovy51
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy136
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy28
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/NcmpConfigurationSpec.groovy52
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy14
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/PersistenceCmHandleSpec.groovy42
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/moduleReferenceSpec.groovy25
-rw-r--r--cps-ncmp-service/src/test/resources/application.yml23
8 files changed, 309 insertions, 62 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 000000000..be27dfad5
--- /dev/null
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/JsonUtilsSpec.groovy
@@ -0,0 +1,51 @@
+/*
+ * ============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'
+ }
+
+ def 'Cannot use constructor.'() {
+ when: 'attempt to construct object'
+ new JsonUtils()
+ then: 'an exception is thrown'
+ thrown(IllegalStateException)
+ }
+}
+
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 b42db5723..8739355c8 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
@@ -36,6 +36,8 @@ import org.onap.cps.ncmp.api.models.DmiPluginRegistration
import org.onap.cps.ncmp.api.models.PersistenceCmHandle
import org.onap.cps.ncmp.utils.TestUtils
import org.onap.cps.spi.FetchDescendantsOption
+import org.onap.cps.spi.exceptions.DataNodeNotFoundException
+import org.onap.cps.spi.exceptions.DataValidationException
import org.onap.cps.spi.model.DataNode
import org.onap.cps.spi.model.ModuleReference
import org.springframework.http.HttpStatus
@@ -56,16 +58,15 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
def mockCpsModuleService = Mock(CpsModuleService)
def mockCpsAdminService = Mock(CpsAdminService)
def mockDmiProperties = Mock(NcmpConfiguration.DmiProperties)
+ def spyObjectMapper = Spy(ObjectMapper)
def objectUnderTest = new NetworkCmProxyDataServiceImpl(mockDmiOperations, mockCpsModuleService,
- mockCpsDataService, mockCpsQueryService, mockCpsAdminService, new ObjectMapper())
+ mockCpsDataService, mockCpsQueryService, mockCpsAdminService, spyObjectMapper)
def cmHandle = 'some handle'
def noTimestamp = null
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.'() {
@@ -156,12 +157,12 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
'ncmp-dmi-registry', "/dmi-registry/cm-handles[@id='cmHandle001']", noTimestamp)
where:
- scenario | createdCmHandles | updatedCmHandles | removedCmHandles || expectedCallsToSaveNode | expectedCallsToUpdateNode | expectedCallsToDeleteListDataNode
- 'create' | [persistenceCmHandle ] | [] | [] || 1 | 0 | 0
- 'update' | [] | [persistenceCmHandle ] | [] || 0 | 1 | 0
- 'delete' | [] | [] | cmHandlesArray || 0 | 0 | 1
- 'create, update and delete' | [persistenceCmHandle ] | [persistenceCmHandle ] | cmHandlesArray || 1 | 1 | 1
-
+ scenario | createdCmHandles | updatedCmHandles | removedCmHandles || expectedCallsToSaveNode | expectedCallsToUpdateNode | expectedCallsToDeleteListDataNode
+ 'create' | [persistenceCmHandle] | [] | [] || 1 | 0 | 0
+ 'update' | [] | [persistenceCmHandle] | [] || 0 | 1 | 0
+ 'delete' | [] | [] | cmHandlesArray || 0 | 0 | 1
+ 'create, update and delete' | [persistenceCmHandle] | [persistenceCmHandle] | cmHandlesArray || 1 | 1 | 1
+ 'no valid data' | null | null | null || 0 | 0 | 0
}
def 'Register a DMI Plugin for the given cmHandle without additional properties.'() {
@@ -171,7 +172,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
dmiPluginRegistration.dmiPlugin = 'my-server'
persistenceCmHandle.cmHandleID = '123'
persistenceCmHandle.cmHandleProperties = null
- dmiPluginRegistration.createdCmHandles = [persistenceCmHandle ]
+ dmiPluginRegistration.createdCmHandles = [persistenceCmHandle]
def expectedJsonData = '{"cm-handles":[{"id":"123","dmi-service-name":"my-server","additional-properties":[]}]}'
when: 'registration is updated'
objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
@@ -180,28 +181,58 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
'/dmi-registry', expectedJsonData, noTimestamp)
}
+ def 'Register a DMI Plugin with JSON processing errors during #scenario.'() {
+ given: 'a registration without cmHandle properties '
+ NetworkCmProxyDataServiceImpl objectUnderTest = getObjectUnderTestWithModelSyncDisabled()
+ def dmiPluginRegistration = new DmiPluginRegistration()
+ dmiPluginRegistration.createdCmHandles = createdCmHandles
+ dmiPluginRegistration.updatedCmHandles = updatedCmHandles
+ and: 'an JSON processing exception occurs'
+ spyObjectMapper.writeValueAsString(_) >> { throw (new JsonProcessingException('')) }
+ when: 'registration is updated'
+ objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
+ then: 'a data validation exception is thrown'
+ thrown(DataValidationException)
+ where:
+ scenario | createdCmHandles | updatedCmHandles
+ 'create' | [persistenceCmHandle] | []
+ 'update' | [] | [persistenceCmHandle]
+ }
+
+ def 'Register a DMI Plugin with no data found during delete.'() {
+ given: 'a registration without cmHandle properties '
+ NetworkCmProxyDataServiceImpl objectUnderTest = getObjectUnderTestWithModelSyncDisabled()
+ def dmiPluginRegistration = new DmiPluginRegistration()
+ dmiPluginRegistration.removedCmHandles = ['some cm handle']
+ and: 'an JSON processing exception occurs'
+ mockCpsDataService.deleteListNodeData(*_) >> { throw (new DataNodeNotFoundException('','')) }
+ when: 'registration is updated'
+ objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
+ then: 'no exception is thrown'
+ noExceptionThrown()
+ }
+
def 'Get resource data for pass-through operational from dmi.'() {
given: 'data node representing cmHandle and its properties'
def cmHandleDataNode = getCmHandleDataNodeForTest()
+ and: 'data node is got from data service'
+ mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
+ cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> cmHandleDataNode
+ and: 'resource data is got from DMI'
+ mockDmiOperations.getResourceDataOperationalFromDmi('testDmiService',
+ 'testCmHandle',
+ 'testResourceId',
+ 'testFieldQuery',
+ 5,
+ 'testAcceptParam',
+ '{"operation":"read","cmHandleProperties":{"testName":"testValue"}}') >> new ResponseEntity<>('result-json', HttpStatus.OK)
when: 'get resource data is called'
def response = objectUnderTest.getResourceDataOperationalForCmHandle('testCmHandle',
'testResourceId',
'testAcceptParam',
'testFieldQuery',
5)
- then: 'cps data service is being called once to get data node'
- 1 * mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
- cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> cmHandleDataNode
- and: 'dmi operation is being called to get resource data'
- 1 * mockDmiOperations.getResourceDataOperationalFromDmi('testDmiService',
- 'testCmHandle',
- 'testResourceId',
- 'testFieldQuery',
- 5,
- 'testAcceptParam',
- '{"operation":"read","cmHandleProperties":{"testName":"testValue"}}') >>
- new ResponseEntity<>('result-json', HttpStatus.OK)
- and: 'dmi returns ok response'
+ then: 'dmi returns ok response'
response == 'result-json'
}
@@ -214,15 +245,16 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
and: 'objectMapper not able to parse object'
def mockObjectMapper = Mock(ObjectMapper)
objectUnderTest.objectMapper = mockObjectMapper
- mockObjectMapper.writeValueAsString(_) >> { throw new JsonProcessingException("testException") }
+ mockObjectMapper.writeValueAsString(_) >> { throw new JsonProcessingException('testException') }
when: 'get resource data is called'
def response = objectUnderTest.getResourceDataOperationalForCmHandle('testCmHandle',
'testResourceId',
'testAcceptParam',
'testFieldQuery',
5)
- then: 'exception is thrown'
- thrown(NcmpException.class)
+ then: 'exception is thrown with the expected details'
+ def exceptionThrown = thrown(NcmpException.class)
+ exceptionThrown.details == 'testException'
}
def 'Get resource data for pass-through operational from dmi return NOK response.'() {
@@ -247,7 +279,9 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
'testFieldQuery',
5)
then: 'exception is thrown'
- thrown(NcmpException.class)
+ def exceptionThrown = thrown(NcmpException.class)
+ and: 'details contains the original response'
+ exceptionThrown.details.contains('NOK-json')
}
def 'Get resource data for pass-through running from dmi.'() {
@@ -283,15 +317,16 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
and: 'objectMapper not able to parse object'
def mockObjectMapper = Mock(ObjectMapper)
objectUnderTest.objectMapper = mockObjectMapper
- mockObjectMapper.writeValueAsString(_) >> { throw new JsonProcessingException("testException") }
+ mockObjectMapper.writeValueAsString(_) >> { throw new JsonProcessingException('testException') }
when: 'get resource data is called'
def response = objectUnderTest.getResourceDataPassThroughRunningForCmHandle('testCmHandle',
'testResourceId',
'testAcceptParam',
'testFieldQuery',
5)
- then: 'exception is thrown'
- thrown(NcmpException.class)
+ then: 'exception is thrown with the expected details'
+ def exceptionThrown = thrown(NcmpException.class)
+ exceptionThrown.details == 'testException'
}
def 'Get resource data for pass-through running from dmi return NOK response.'() {
@@ -316,13 +351,15 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
'testFieldQuery',
5)
then: 'exception is thrown'
- thrown(NcmpException.class)
+ def exceptionThrown = thrown(NcmpException.class)
+ and: 'details contains the original response'
+ exceptionThrown.details.contains('NOK-json')
}
def 'Write resource data for pass-through running from dmi using POST.'() {
given: 'data node representing cmHandle and its properties'
def cmHandleDataNode = getCmHandleDataNodeForTest()
- and: 'cpsDataService returns valid dataNode'
+ and: 'cpsDataService returns valid cm-handle datanode'
mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> cmHandleDataNode
when: 'get resource data is called'
@@ -334,7 +371,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).'() {
@@ -344,36 +381,45 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
cmHandleXPath, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> cmHandleDataNode
and: 'dmi throws exception'
- 1 * mockDmiOperations.createResourceDataPassThroughRunningFromDmi(_ as String, _ as String, _ as String, _ as String)
+ mockDmiOperations.createResourceDataPassThroughRunningFromDmi(_ as String, _ as String, _ as String, _ as String)
>> { new ResponseEntity<>(HttpStatus.NOT_FOUND) }
when: 'get resource data is called'
objectUnderTest.createResourceDataPassThroughRunningForCmHandle('testCmHandle',
'testResourceId',
'{some-json}', 'application/json')
then: 'exception is thrown'
- thrown(NcmpException.class)
+ def exceptionThrown = thrown(NcmpException.class)
+ and: 'details contains (not found) error code: 404'
+ exceptionThrown.details.contains('404')
}
def 'Sync model for a (new) cm handle with #scenario'() {
given: 'DMI PLug-in returns a list of module references'
getModulesForCmHandle()
- def knownModule1 = new ModuleReference('module1', NO_NAMESPACE, '1')
- def knownOtherModule = new ModuleReference('some other module', NO_NAMESPACE, 'some revision')
+ def knownModule1 = new ModuleReference('module1', '1')
+ def knownOtherModule = new ModuleReference('some other module', 'some revision')
and: 'CPS-Core returns list of known modules'
- mockCpsModuleService.getAllYangResourcesModuleReferences() >> [knownModule1, knownOtherModule]
+ 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'
- 1 * mockCpsModuleService.createSchemaSetFromModules(expectedDataspaceNameForModleSync, cmHandleForModelSync.getId(), expectedYangResourceToContentMap , [knownModule1])
+ 1 * mockCpsModuleService.createSchemaSetFromModules(expectedDataspaceName, cmHandleForModelSync.getId(), expectedYangResourceToContentMap, [knownModule1])
and: 'admin service create anchor method has been called with correct parameters'
- 1 * mockCpsAdminService.createAnchor(expectedDataspaceNameForModleSync, cmHandleForModelSync.getId(), cmHandleForModelSync.getId())
+ 1 * mockCpsAdminService.createAnchor(expectedDataspaceName, 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 'Getting Yang Resources.'() {
+ when: 'yang resources is called'
+ objectUnderTest.getYangResourcesModuleReferences('some cm handle')
+ then: 'CPS module services is invoked for the correct dataspace and cm handle'
+ 1 * mockCpsModuleService.getYangResourcesModuleReferences('NFP-Operational','some cm handle')
}
def getModulesForCmHandle() {
@@ -387,7 +433,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
def getObjectUnderTestWithModelSyncDisabled() {
def objectUnderTest = Spy(new NetworkCmProxyDataServiceImpl(mockDmiOperations, mockCpsModuleService,
- mockCpsDataService, mockCpsQueryService, mockCpsAdminService, new ObjectMapper()))
+ mockCpsDataService, mockCpsQueryService, mockCpsAdminService, spyObjectMapper))
objectUnderTest.createAnchorAndSyncModel(_) >> null
return objectUnderTest
}
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 879c73c27..bf6179ba1 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
@@ -21,24 +21,30 @@
package org.onap.cps.ncmp.api.impl.client
import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration
+import org.spockframework.spring.SpringBean
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.boot.test.context.SpringBootTest
import org.springframework.http.HttpEntity
import org.springframework.http.HttpHeaders
+import org.springframework.http.HttpMethod
import org.springframework.http.ResponseEntity
+import org.springframework.test.context.ContextConfiguration
import org.springframework.web.client.RestTemplate
import spock.lang.Specification
-import org.springframework.http.HttpMethod
+@SpringBootTest
+@ContextConfiguration(classes = [NcmpConfiguration.DmiProperties, DmiRestClient])
class DmiRestClientSpec extends Specification {
- def mockDmiProperties = Mock(NcmpConfiguration.DmiProperties)
- def mockRestTemplate = Mock(RestTemplate)
- def objectUnderTest = new DmiRestClient(mockRestTemplate, mockDmiProperties)
+ @SpringBean
+ RestTemplate mockRestTemplate = Mock(RestTemplate)
+
+ @Autowired
+ DmiRestClient objectUnderTest
def 'DMI PUT operation.'() {
given: 'a PUT url'
def getResourceDataUrl = 'http://some-uri/getResourceDataUrl'
- and: 'dmi properties'
- setupTestConfigurationData()
and: 'the rest template returns a valid response entity'
def mockResponseEntity = Mock(ResponseEntity)
mockRestTemplate.exchange(getResourceDataUrl, HttpMethod.PUT, _ as HttpEntity, Object.class) >> mockResponseEntity
@@ -51,19 +57,13 @@ class DmiRestClientSpec extends Specification {
def 'DMI POST operation.'() {
given: 'a POST url'
def getResourceDataUrl = 'http://some-uri/createResourceDataUrl'
- and: 'dmi properties'
- 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'
result == mockResponseEntity
}
- def setupTestConfigurationData() {
- mockDmiProperties.authUsername >> 'some-username'
- mockDmiProperties.authPassword >> 'some-password'
- }
-} \ No newline at end of file
+}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/NcmpConfigurationSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/NcmpConfigurationSpec.groovy
new file mode 100644
index 000000000..dd4c1375b
--- /dev/null
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/NcmpConfigurationSpec.groovy
@@ -0,0 +1,52 @@
+/*
+ * ============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.config
+
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.boot.test.context.SpringBootTest
+import org.springframework.boot.web.client.RestTemplateBuilder
+import org.springframework.test.context.ContextConfiguration
+import org.springframework.web.client.RestTemplate
+import spock.lang.Specification
+
+@SpringBootTest
+@ContextConfiguration(classes = [NcmpConfiguration.DmiProperties])
+class NcmpConfigurationSpec extends Specification{
+
+ @Autowired
+ NcmpConfiguration.DmiProperties dmiProperties
+
+ def 'DMI Properties.'() {
+ expect: 'properties are set to values in test configuration yaml file'
+ dmiProperties.authUsername == 'some-user'
+ dmiProperties.authPassword == 'some-password'
+ }
+
+ def 'Rest Template creation.'() {
+ given: 'a rest template builder'
+ def mockRestTemplateBuilder = Mock(RestTemplateBuilder)
+ def expectedRestTemplate = Mock(RestTemplate)
+ mockRestTemplateBuilder.build() >> expectedRestTemplate
+ when: 'a rest template is created'
+ def result = NcmpConfiguration.restTemplate(mockRestTemplateBuilder)
+ then: 'the rest template from the builder is returned'
+ assert result == expectedRestTemplate
+ }
+}
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 987ab2bca..6a1ce1a18 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
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/PersistenceCmHandleSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/PersistenceCmHandleSpec.groovy
new file mode 100644
index 000000000..bfed795f7
--- /dev/null
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/PersistenceCmHandleSpec.groovy
@@ -0,0 +1,42 @@
+/*
+ * ============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.models
+
+import spock.lang.Specification
+
+class PersistenceCmHandleSpec extends Specification {
+
+ def objectUnderTest = new PersistenceCmHandle()
+
+ def 'Setting and getting additional properties.'() {
+ given: 'a map of one property is added'
+ objectUnderTest.setAdditionalProperties([myProperty: 'some value'])
+ when: 'the additional properties are retrieved'
+ def result = objectUnderTest.getAdditionalProperties()
+ then: 'the result has the right size'
+ assert result.size() == 1
+ and: 'the property in the result has the correct name and value'
+ def actualAdditionalProperty = result.get(0)
+ def expectedAdditionalProperty = new PersistenceCmHandle.AdditionalProperty('myProperty','some value')
+ assert actualAdditionalProperty.name == expectedAdditionalProperty.name
+ assert actualAdditionalProperty.value == expectedAdditionalProperty.value
+ }
+
+}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/moduleReferenceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/moduleReferenceSpec.groovy
index d6cb4635d..444a25804 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/moduleReferenceSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/moduleReferenceSpec.groovy
@@ -1,14 +1,33 @@
+/*
+ * ============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.models
-import org.onap.cps.spi.model.ModuleReference
+import org.onap.cps.spi.model.ExtendedModuleReference
import spock.lang.Specification
class moduleReferenceSpec extends Specification {
def 'lombok data annotation correctly implements toString() and hashCode() methods'() {
given: 'two moduleReference objects'
- def moduleReference1 = new ModuleReference('module1', "some namespace", '1')
- def moduleReference2 = new ModuleReference('module1', "some namespace", '1')
+ def moduleReference1 = new ExtendedModuleReference('module1', "some namespace", '1')
+ def moduleReference2 = new ExtendedModuleReference('module1', "some namespace", '1')
when: 'lombok generated methods are called'
then: 'the methods exist and behaviour is accurate'
assert moduleReference1.toString() == moduleReference2.toString()
diff --git a/cps-ncmp-service/src/test/resources/application.yml b/cps-ncmp-service/src/test/resources/application.yml
new file mode 100644
index 000000000..71ac2c9a0
--- /dev/null
+++ b/cps-ncmp-service/src/test/resources/application.yml
@@ -0,0 +1,23 @@
+# ============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=========================================================
+
+dmi:
+ auth:
+ username: some-user
+ password: some-password
+