import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.MODEL;
import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
if (newModuleReferences.isEmpty()) {
return Collections.emptyMap();
}
- final String jsonWithDataAndDmiProperties = getRequestBodyToFetchYangResources(
- newModuleReferences, yangModelCmHandle.getDmiProperties());
+ final String jsonWithDataAndDmiProperties = getRequestBodyToFetchYangResources(newModuleReferences,
+ yangModelCmHandle.getDmiProperties(), yangModelCmHandle.getModuleSetTag());
final ResponseEntity<Object> responseEntity = getResourceFromDmiWithJsonData(
yangModelCmHandle.resolveDmiServiceName(MODEL),
jsonWithDataAndDmiProperties,
}
private static String getRequestBodyToFetchYangResources(final Collection<ModuleReference> newModuleReferences,
- final List<YangModelCmHandle.Property> dmiProperties) {
+ final List<YangModelCmHandle.Property> dmiProperties,
+ final String moduleSetTag) {
final JsonArray moduleReferencesAsJson = getModuleReferencesAsJson(newModuleReferences);
final JsonObject data = new JsonObject();
data.add("modules", moduleReferencesAsJson);
final JsonObject jsonRequestObject = new JsonObject();
+ if (!moduleSetTag.isEmpty()) {
+ final JsonElement moduleSetTagAsJson = JsonParser.parseString(moduleSetTag);
+ jsonRequestObject.add("moduleSetTag", moduleSetTagAsJson);
+ }
jsonRequestObject.add("data", data);
jsonRequestObject.add("cmHandleProperties", toJsonObject(dmiProperties));
return jsonRequestObject.toString();
def moduleReferencesAsLisOfMaps = [[moduleName: 'mod1', revision: 'A'], [moduleName: 'mod2', revision: 'X']]
def expectedUrl = "${dmiServiceName}/dmi/v1/ch/${cmHandleId}/modules"
def responseFromDmi = new ResponseEntity([schemas: moduleReferencesAsLisOfMaps], HttpStatus.OK)
- mockDmiRestClient.postOperationWithJsonData(expectedUrl, '{"cmHandleProperties":{},"moduleSetTag":"tag1"}', READ, NO_AUTH_HEADER)
+ mockDmiRestClient.postOperationWithJsonData(expectedUrl, '{"cmHandleProperties":{},"moduleSetTag":""}', READ, NO_AUTH_HEADER)
>> responseFromDmi
when: 'get module references is called'
def result = objectUnderTest.getModuleReferences(yangModelCmHandle)
and: 'a positive response from DMI service when it is called with tha expected parameters'
def responseFromDmi = new ResponseEntity<String>(HttpStatus.OK)
mockDmiRestClient.postOperationWithJsonData("${dmiServiceName}/dmi/v1/ch/${cmHandleId}/modules",
- '{"cmHandleProperties":' + expectedAdditionalPropertiesInRequest + ',"moduleSetTag":"tag1"}', READ, NO_AUTH_HEADER) >> responseFromDmi
+ '{"cmHandleProperties":' + expectedAdditionalPropertiesInRequest + ',"moduleSetTag":""}', READ, NO_AUTH_HEADER) >> responseFromDmi
when: 'a get module references is called'
def result = objectUnderTest.getModuleReferences(yangModelCmHandle)
then: 'the result is the response from DMI service'
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'
+ and: 'a positive response from DMI service when it is called with the expected moduleSetTag, modules and properties'
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 + '}',
'without properties' | [] || '{}'
}
+ def 'Retrieving yang resources #scenario'() {
+ given: 'a cm handle'
+ mockYangModelCmHandleRetrieval([], moduleSetTag)
+ and: 'a positive response from DMI service when it is called with the expected moduleSetTag'
+ def responseFromDmi = new ResponseEntity<>([[moduleName: 'mod1', revision: 'A', yangSource: 'some yang source']], HttpStatus.OK)
+ mockDmiRestClient.postOperationWithJsonData("${dmiServiceName}/dmi/v1/ch/${cmHandleId}/moduleResources",
+ '{' + expectedModuleSetTagInRequest + '"data":{"modules":[{"name":"mod1","revision":"A"},{"name":"mod2","revision":"X"}]},"cmHandleProperties":{}}',
+ 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 Module Set Tags are used'
+ scenario | moduleSetTag || expectedModuleSetTagInRequest
+ 'Without module set tag' | '' || ''
+ 'With module set tag' | 'moduleSetTag1' || '"moduleSetTag":"moduleSetTag1",'
+ }
+
def 'Retrieving yang resources from DMI with no module references.'() {
given: 'a cm handle'
mockYangModelCmHandleRetrieval([])
def static resourceIdentifier = 'parent/child'
def mockYangModelCmHandleRetrieval(dmiProperties) {
- populateYangModelCmHandle(dmiProperties)
+ populateYangModelCmHandle(dmiProperties, '')
+ mockInventoryPersistence.getYangModelCmHandle(cmHandleId) >> yangModelCmHandle
+ }
+
+ def mockYangModelCmHandleRetrieval(dmiProperties, moduleSetTag) {
+ populateYangModelCmHandle(dmiProperties, moduleSetTag)
mockInventoryPersistence.getYangModelCmHandle(cmHandleId) >> yangModelCmHandle
}
def mockYangModelCmHandleCollectionRetrieval(dmiProperties) {
- populateYangModelCmHandle(dmiProperties)
+ populateYangModelCmHandle(dmiProperties, "")
mockInventoryPersistence.getYangModelCmHandles(_) >> [yangModelCmHandle]
}
- def populateYangModelCmHandle(dmiProperties) {
+ def populateYangModelCmHandle(dmiProperties, moduleSetTag) {
yangModelCmHandle.dmiDataServiceName = dmiServiceName
yangModelCmHandle.dmiServiceName = dmiServiceName
yangModelCmHandle.dmiProperties = dmiProperties
yangModelCmHandle.id = cmHandleId
yangModelCmHandle.compositeState = new CompositeState()
yangModelCmHandle.compositeState.cmHandleState = CmHandleState.READY
- yangModelCmHandle.moduleSetTag = 'tag1'
+ yangModelCmHandle.moduleSetTag = moduleSetTag
}
}