- '{"data":{"modules":[' + expectedModuleReferencesInRequest + ']},"cmHandleProperties":'+expectedAdditionalPropertiesInRequest+'}',
- [:]) >> responseFromDmi
- when: 'get new yang resources from dmi service'
- def result = objectUnderTest.getNewYangResourcesFromDmi(persistenceCmHandle, unknownModuleReferences)
- then: 'the result is the response from dmi service'
- assert result == responseFromDmi
- where:
- scenario | additionalPropertiesObject | unknownModuleReferences || expectedAdditionalPropertiesInRequest | expectedModuleReferencesInRequest
- 'with module references and properties' | [sampleAdditionalProperty] | newModuleReferences || '{"prop1":"val1"}' | '{"name":"mod1","revision":"A"},{"name":"mod2","revision":"X"}'
- 'without module references' | [sampleAdditionalProperty] | [] || '{"prop1":"val1"}' | ''
- 'without properties' | [] | newModuleReferences || '{}' | '{"name":"mod1","revision":"A"},{"name":"mod2","revision":"X"}'
+ '{"data":{"modules":[' + expectedModuleReferencesInRequest + ']},"cmHandleProperties":{}}', READ, NO_AUTH_HEADER) >> responseFromDmi
+ when: 'get new yang resources from DMI service'
+ def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, newModuleReferences)
+ then: 'the result has the 2 expected yang (re)sources (order is not guaranteed)'
+ assert result.size() == 2
+ assert result.get('mod1') == 'some yang source'
+ assert result.get('mod2') == 'other yang source'
+ }
+
+ def 'Retrieving yang resources, edge case: scenario.'() {
+ given: 'a cm handle'
+ mockYangModelCmHandleRetrieval([])
+ and: 'a positive response from DMI service when it is called with tha expected parameters'
+ // TODO (toine): production code ignores any error code from DMI, this should be improved in future
+ def responseFromDmi = new ResponseEntity(responseFromDmiBody, HttpStatus.NO_CONTENT)
+ mockDmiRestClient.postOperationWithJsonData(*_) >> responseFromDmi
+ when: 'get new yang resources from DMI service'
+ def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, newModuleReferences)
+ then: 'the result is empty'
+ assert result == [:]
+ where: 'the DMI response body has the following content'
+ scenario | responseFromDmiBody
+ 'empty array' | []
+ 'null array' | null
+ }
+
+ def 'Retrieving yang resources, DMI property handling #scenario.'() {
+ given: 'a cm handle'
+ mockYangModelCmHandleRetrieval(dmiProperties)
+ and: 'a positive response from DMI service when it is called with the expected parameters'
+ def responseFromDmi = new ResponseEntity<>([[moduleName: 'mod1', revision: 'A', yangSource: 'some yang source']], HttpStatus.OK)
+ mockDmiRestClient.postOperationWithJsonData("${dmiServiceName}/dmi/v1/ch/${cmHandleId}/moduleResources",
+ '{"data":{"modules":[{"name":"mod1","revision":"A"},{"name":"mod2","revision":"X"}]},"cmHandleProperties":' + expectedAdditionalPropertiesInRequest + '}',
+ READ, NO_AUTH_HEADER) >> responseFromDmi
+ when: 'get new yang resources from DMI service'
+ def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, newModuleReferences)
+ then: 'the result is the response from DMI service'
+ assert result == [mod1:'some yang source']
+ where: 'the following DMI properties are used'
+ scenario | dmiProperties || expectedAdditionalPropertiesInRequest
+ 'with module references and properties' | [yangModelCmHandleProperty] || '{"prop1":"val1"}'
+ 'without properties' | [] || '{}'
+ }
+
+ def 'Retrieving yang resources from DMI with no module references.'() {
+ given: 'a cm handle'
+ mockYangModelCmHandleRetrieval([])
+ when: 'a get new yang resources from DMI is called with no module references'
+ def result = objectUnderTest.getNewYangResourcesFromDmi(yangModelCmHandle, [])
+ then: 'no resources are returned'
+ assert result == [:]
+ and: 'no request is sent to DMI'
+ 0 * mockDmiRestClient.postOperationWithJsonData(*_)