summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java30
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy20
2 files changed, 29 insertions, 21 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
index 291b0bf330..2395fb5db4 100755
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
@@ -59,7 +59,6 @@ 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;
-import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
@@ -349,13 +348,13 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
cmHandleJsonData, NO_TIMESTAMP);
for (final PersistenceCmHandle persistenceCmHandle : persistenceCmHandlesList.getPersistenceCmHandles()) {
- createAnchorAndSyncModel(persistenceCmHandle);
+ syncModulesAndCreateAnchor(persistenceCmHandle);
}
}
- protected void createAnchorAndSyncModel(final PersistenceCmHandle persistenceCmHandle) {
- createAnchor(persistenceCmHandle);
+ protected void syncModulesAndCreateAnchor(final PersistenceCmHandle persistenceCmHandle) {
fetchAndSyncModules(persistenceCmHandle);
+ createAnchor(persistenceCmHandle);
}
private static PersistenceCmHandle toPersistenceCmHandle(final String dmiPluginService,
@@ -417,14 +416,13 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
private List<ModuleReference> fetchModuleReferencesFromDmi(final PersistenceCmHandle persistenceCmHandle,
final Map<String, String> cmHandlePropertiesAsMap) {
- final GenericRequestBody requestBodyObject = GenericRequestBody.builder()
- .operation(GenericRequestBody.OperationEnum.READ)
+ final GenericRequestBody genericRequestBody = GenericRequestBody.builder()
.cmHandleProperties(cmHandlePropertiesAsMap)
.build();
- final String jsonBody = prepareOperationBody(requestBodyObject);
+ final String jsonBodyWithOnlyCmHandleProperties = prepareOperationBody(genericRequestBody);
final ResponseEntity<String> dmiFetchModulesResponseEntity =
dmiOperations.getResourceFromDmiWithJsonData(persistenceCmHandle.getDmiServiceName(),
- jsonBody, persistenceCmHandle.getId(), "modules");
+ jsonBodyWithOnlyCmHandleProperties, persistenceCmHandle.getId(), "modules");
return toModuleReferences(dmiFetchModulesResponseEntity);
}
@@ -437,13 +435,11 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
final JsonArray moduleReferencesAsJson = getModuleReferencesAsJson(unknownModuleReferences);
final JsonObject data = new JsonObject();
data.add("modules", moduleReferencesAsJson);
- final GenericRequestBody dmiRequestBodyObject = GenericRequestBody.builder()
- .operation(GenericRequestBody.OperationEnum.READ)
- .dataType(MediaType.APPLICATION_JSON_VALUE)
- .data(data.toString())
- .cmHandleProperties(cmHandlePropertiesAsMap)
- .build();
- return prepareOperationBody(dmiRequestBodyObject);
+ final JsonObject jsonRequestObject = new JsonObject();
+ jsonRequestObject.add("data", data);
+ final Gson gson = new Gson();
+ jsonRequestObject.add("cmHandleProperties", gson.toJsonTree(cmHandlePropertiesAsMap));
+ return jsonRequestObject.toString();
}
private static JsonArray getModuleReferencesAsJson(final List<ModuleReference> unknownModuleReferences) {
@@ -461,12 +457,12 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
private Map<String, String> getNewYangResourcesFromDmi(final PersistenceCmHandle persistenceCmHandle,
final List<ModuleReference> unknownModuleReferences,
final Map<String, String> cmHandlePropertiesAsMap) {
- final String jsonData = getRequestBodyToFetchYangResourceFromDmi(
+ final String jsonDataWithDataAndCmHandleProperties = getRequestBodyToFetchYangResourceFromDmi(
unknownModuleReferences, cmHandlePropertiesAsMap);
final ResponseEntity<String> moduleResourcesAsJsonString = dmiOperations.getResourceFromDmiWithJsonData(
persistenceCmHandle.getDmiServiceName(),
- jsonData,
+ jsonDataWithDataAndCmHandleProperties,
persistenceCmHandle.getId(),
"moduleResources");
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 2b376e97bf..e38386fdd2 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
@@ -419,7 +419,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
}
and: 'dmi operations returns some module references'
def jsonData = TestUtils.getResourceFileContent('cmHandleModules.json')
- def expectedJsonBody = '{"operation":"read","cmHandleProperties":' + expectedJsonForAdditionalProperties + '}'
+ def expectedJsonBody = '{"cmHandleProperties":' + expectedJsonForAdditionalProperties + '}'
mockDmiProperties.getAuthUsername() >> 'someUser'
mockDmiProperties.getAuthPassword() >> 'somePassword'
def moduleReferencesFromCmHandleAsJson = new ResponseEntity<String>(jsonData, HttpStatus.OK)
@@ -428,10 +428,10 @@ 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)
- def jsonDataToFetchYangResource = '{"operation":"read","dataType":"application/json","data":"{\\"modules\\":[{\\"name\\":\\"module2\\",\\"revision\\":\\"1\\"}]}","cmHandleProperties":' + expectedJsonForAdditionalProperties + '}'
+ def jsonDataToFetchYangResource = '{"data":{"modules":[{"name":"module2","revision":"1"}]},"cmHandleProperties":' + expectedJsonForAdditionalProperties + '}'
mockDmiOperations.getResourceFromDmiWithJsonData('some service name', jsonDataToFetchYangResource, 'some cm handle', 'moduleResources') >> moduleResources
when: 'module Sync is triggered'
- objectUnderTest.createAnchorAndSyncModel(cmHandleForModelSync)
+ objectUnderTest.syncModulesAndCreateAnchor(cmHandleForModelSync)
then: 'the CPS module service is called once with the correct parameters'
1 * mockCpsModuleService.createSchemaSetFromModules(expectedDataspaceName, cmHandleForModelSync.getId(), expectedYangResourceToContentMap, [knownModule1])
and: 'admin service create anchor method has been called with correct parameters'
@@ -451,10 +451,22 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
1 * mockCpsModuleService.getYangResourcesModuleReferences('NFP-Operational','some cm handle')
}
+ def 'Create the request body to get yang resources from DMI.'() {
+ given: 'the expected json request'
+ def expectedRequestBody = '{"data":{"modules":[{"name":"module1","revision":"1"},{"name":"module2","revision":"2"}]},"cmHandleProperties":{"name1":"value1"}}'
+ and: 'module references and cm handle properties'
+ def moduleReferences = [new ModuleReference('module1', '1'),new ModuleReference('module2', '2')]
+ def cmHandleProperties = ['name1':'value1']
+ when: 'get request body to fetch yang resources from DMI is called'
+ def result = objectUnderTest.getRequestBodyToFetchYangResourceFromDmi(moduleReferences, cmHandleProperties)
+ then: 'the result is the same as the expected request body'
+ result == expectedRequestBody
+ }
+
def getObjectUnderTestWithModelSyncDisabled() {
def objectUnderTest = Spy(new NetworkCmProxyDataServiceImpl(mockDmiOperations, mockCpsModuleService,
mockCpsDataService, mockCpsQueryService, mockCpsAdminService, spyObjectMapper))
- objectUnderTest.createAnchorAndSyncModel(_) >> null
+ objectUnderTest.syncModulesAndCreateAnchor(_) >> null
return objectUnderTest
}