summaryrefslogtreecommitdiffstats
path: root/src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy')
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy82
1 files changed, 66 insertions, 16 deletions
diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy
index 4411971a..2ce870ab 100644
--- a/src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy
+++ b/src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2021 Nordix Foundation
+ * Modifications Copyright (C) 2021 Bell Canada
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,12 +21,16 @@
package org.onap.cps.ncmp.dmi.service.operation
+import org.onap.cps.ncmp.dmi.TestUtils
import org.onap.cps.ncmp.dmi.config.DmiConfiguration
+import org.onap.cps.ncmp.dmi.exception.SdncException
import org.onap.cps.ncmp.dmi.service.client.SdncRestconfClient
import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.http.HttpHeaders
+import org.springframework.http.HttpStatus
+import org.springframework.http.ResponseEntity
import org.springframework.test.context.ContextConfiguration
import spock.lang.Specification
@@ -39,14 +44,59 @@ class SdncOperationsSpec extends Specification {
@Autowired
SdncOperations objectUnderTest
- def 'call get modules from node to SDNC.'() {
+ def 'get modules from node.'() {
given: 'node id and url'
def nodeId = 'node1'
def expectedUrl = '/rests/data/network-topology:network-topology/topology=test-topology/node=node1/yang-ext:mount/ietf-netconf-monitoring:netconf-state/schemas'
- when: 'called get modules from node'
- objectUnderTest.getModulesFromNode(nodeId)
- then: 'the get operation is executed with the correct URL'
- 1 * mockSdncRestClient.getOperation(expectedUrl)
+ and: 'sdnc returns one module in response'
+ mockSdncRestClient.getOperation(expectedUrl) >>
+ ResponseEntity.ok(TestUtils.getResourceFileContent('ModuleSchema.json'))
+ when: 'get modules from node is called'
+ def moduleSchemas = objectUnderTest.getModuleSchemasFromNode(nodeId)
+ then: 'one module is found'
+ moduleSchemas.size() == 1
+ and: 'module schema has expected values'
+ with(moduleSchemas[0]) {
+ it.getIdentifier() == "example-identifier"
+ it.getNamespace() == "example:namespace"
+ it.getVersion() == "example-version"
+ it.getFormat() == "example-format"
+ it.getLocation() == ["example-location"]
+ }
+ }
+
+ def 'No modules from Node: SDNC Response - #scenario .'() {
+ given: 'node id and url'
+ def nodeId = 'node1'
+ def expectedUrl = '/rests/data/network-topology:network-topology/topology=test-topology/node=node1/yang-ext:mount/ietf-netconf-monitoring:netconf-state/schemas'
+ and: 'sdnc operation returns #scenario'
+ mockSdncRestClient.getOperation(expectedUrl) >> ResponseEntity.ok(responseBody)
+ when: 'modules from node is called'
+ def moduleSchemas = objectUnderTest.getModuleSchemasFromNode(nodeId)
+ then: 'no modules are returned'
+ moduleSchemas.size() == 0
+ where:
+ scenario | responseBody
+ 'empty response body ' | ''
+ 'no module schema' | '{ "ietf-netconf-monitoring:schemas" : { "schema" : [] } } '
+ }
+
+ def 'Error handling - modules from node: #scenario'() {
+ given: 'node id and url'
+ def nodeId = 'node1'
+ def expectedUrl = '/rests/data/network-topology:network-topology/topology=test-topology/node=node1/yang-ext:mount/ietf-netconf-monitoring:netconf-state/schemas'
+ and: 'sdnc operation returns configured response'
+ mockSdncRestClient.getOperation(expectedUrl) >> new ResponseEntity<>(sdncResponseBody, sdncHttpStatus)
+ when: 'modules for node are fetched'
+ objectUnderTest.getModuleSchemasFromNode(nodeId)
+ then: 'SDNCException is thrown'
+ def thrownException = thrown(SdncException)
+ thrownException.getDetails().contains(expectedExceptionDetails)
+ where:
+ scenario | sdncHttpStatus | sdncResponseBody || expectedExceptionDetails
+ 'failed response from SDNC' | HttpStatus.BAD_REQUEST | '{ "errorMessage" : "incorrect input"}' || '{ "errorMessage" : "incorrect input"}'
+ 'invalid json response' | HttpStatus.OK | 'invalid-json' || 'SDNC response is not in the expected format'
+ 'response in unexpected json schema' | HttpStatus.OK | '{ "format" : "incorrect" }' || 'SDNC response is not in the expected format'
}
def 'Get module resources from SDNC.'() {
@@ -64,7 +114,7 @@ class SdncOperationsSpec extends Specification {
def expectedUrl = '/rests/data/network-topology:network-topology/topology=test-topology/node=node1/yang-ext:mount/testResourceId?a=1&b=2&content=testContent'
when: 'called get modules from node'
objectUnderTest.getResouceDataForOperationalAndRunning('node1', 'testResourceId',
- '(a=1,b=2)', 'testAcceptParam', 'content=testContent')
+ '(a=1,b=2)', 'testAcceptParam', 'content=testContent')
then: 'the get operation is executed with the correct URL'
1 * mockSdncRestClient.getOperation(expectedUrl, _ as HttpHeaders)
}
@@ -73,30 +123,30 @@ class SdncOperationsSpec extends Specification {
given: 'expected url, topology-id, sdncOperation object'
def expectedUrl = '/rests/data/network-topology:network-topology/topology=test-topology/node=node1/yang-ext:mount/testResourceId'
when: 'write resource data for pass through running is called'
- objectUnderTest.writeResourceDataPassthroughRunning('node1','testResourceId','application/json','requestData')
+ objectUnderTest.writeResourceDataPassthroughRunning('node1', 'testResourceId', 'application/json', 'requestData')
then: 'the post operation is executed with the correct URL and data'
1 * mockSdncRestClient.postOperationWithJsonData(expectedUrl, 'requestData', _ as HttpHeaders)
}
def 'build query param list for SDNC where options contains a #scenario'() {
when: 'build query param list is called with #scenario'
- def result = objectUnderTest.buildQueryParamList(optionsParamInQuery,'d=4')
+ def result = objectUnderTest.buildQueryParamList(optionsParamInQuery, 'd=4')
then: 'result equals to expected result'
result == expectedResult
where: 'following parameters are used'
- scenario | optionsParamInQuery || expectedResult
- 'single key-value pair' | '(a=x)' || ['a=x','d=4']
- 'multiple key-value pairs'| '(a=x,b=y,c=z)' || ['a=x','b=y','c=z','d=4']
- '/ as special char' | '(a=x,b=y,c=t/z)' || ['a=x','b=y','c=t/z','d=4']
- '" as special char' | '(a=x,b=y,c="z")' || ['a=x','b=y','c="z"','d=4']
- '[] as special char' | '(a=x,b=y,c=[z])' || ['a=x','b=y','c=[z]','d=4']
- '= in value' | '(a=(x=y),b=x=y)' || ['a=(x=y)','b=x=y','d=4']
+ scenario | optionsParamInQuery || expectedResult
+ 'single key-value pair' | '(a=x)' || ['a=x', 'd=4']
+ 'multiple key-value pairs' | '(a=x,b=y,c=z)' || ['a=x', 'b=y', 'c=z', 'd=4']
+ '/ as special char' | '(a=x,b=y,c=t/z)' || ['a=x', 'b=y', 'c=t/z', 'd=4']
+ '" as special char' | '(a=x,b=y,c="z")' || ['a=x', 'b=y', 'c="z"', 'd=4']
+ '[] as special char' | '(a=x,b=y,c=[z])' || ['a=x', 'b=y', 'c=[z]', 'd=4']
+ '= in value' | '(a=(x=y),b=x=y)' || ['a=(x=y)', 'b=x=y', 'd=4']
}
def 'options parameters contains a comma #scenario'() {
// https://jira.onap.org/browse/CPS-719
when: 'build query param list is called with #scenario'
- def result = objectUnderTest.buildQueryParamList(optionsParamInQuery,'d=4')
+ def result = objectUnderTest.buildQueryParamList(optionsParamInQuery, 'd=4')
then: 'expect 2 elements from options +1 from content query param (2+1) = 3 elements'
def expectedNoOfElements = 3
and: 'results contains more elements than expected'