Fix for get cm handle identifiers response body 76/125676/2
authorniamhcore <niamh.core@est.tech>
Wed, 10 Nov 2021 12:13:51 +0000 (12:13 +0000)
committerniamhcore <niamh.core@est.tech>
Wed, 10 Nov 2021 12:28:40 +0000 (12:28 +0000)
Issue-ID: CPS-636
Signed-off-by: niamhcore <niamh.core@est.tech>
Change-Id: I35dabf8e5839c56a9ae1851495cc9bf15e633c21

cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy

index 19b9a09..075b451 100755 (executable)
@@ -217,8 +217,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
         final List<ConditionProperties> conditionProperties =
             conditions.getConditions().stream().collect(Collectors.toList());
         final CmHandles cmHandles = new CmHandles();
-        final Collection<String> cmHandleIdentifiers = processConditions(conditionProperties);
-        cmHandleIdentifiers.forEach(cmHandle -> cmHandles.setCmHandles(toCmHandleProperties(cmHandle)));
+        cmHandles.setCmHandles(toCmHandleProperties(processConditions(conditionProperties)));
         return ResponseEntity.ok(cmHandles);
     }
 
@@ -254,11 +253,13 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
         return moduleNames;
     }
 
-    private CmHandleProperties toCmHandleProperties(final String cmHandleId) {
+    private CmHandleProperties toCmHandleProperties(final Collection<String> cmHandleIdentifiers) {
         final CmHandleProperties cmHandleProperties = new CmHandleProperties();
-        final CmHandleProperty cmHandleProperty = new CmHandleProperty();
-        cmHandleProperty.setCmHandleId(cmHandleId);
-        cmHandleProperties.add(cmHandleProperty);
+        for (final String cmHandleIdentifier : cmHandleIdentifiers) {
+            final CmHandleProperty cmHandleProperty = new CmHandleProperty();
+            cmHandleProperty.setCmHandleId(cmHandleIdentifier);
+            cmHandleProperties.add(cmHandleProperty);
+        }
         return cmHandleProperties;
     }
 
index 4066fd3..cca62b9 100644 (file)
@@ -258,8 +258,8 @@ class NetworkCmProxyControllerSpec extends Specification {
         given: 'an endpoint and json data'
             def searchesEndpoint = "$ncmpBasePathV1/ch/searches"
             String jsonData = TestUtils.getResourceFileContent('cmhandle-search.json')
-        and: 'the service method is invoked with module names and returns a cm handle id'
-            mockNetworkCmProxyDataService.executeCmHandleHasAllModulesSearch(['module1', 'module2']) >> ['some-cmhandle-id']
+        and: 'the service method is invoked with module names and returns two cm handle ids'
+            mockNetworkCmProxyDataService.executeCmHandleHasAllModulesSearch(['module1', 'module2']) >> ['some-cmhandle-id1', 'some-cmhandle-id2']
         when: 'the searches api is invoked'
             def response = mvc.perform(post(searchesEndpoint)
                     .contentType(MediaType.APPLICATION_JSON)
@@ -267,7 +267,7 @@ class NetworkCmProxyControllerSpec extends Specification {
         then: 'response status returns OK'
             response.status == HttpStatus.OK.value()
         and: 'the expected response content is returned'
-            response.contentAsString == '{"cmHandles":[{"cmHandleId":"some-cmhandle-id"}]}'
+            response.contentAsString == '{"cmHandles":[{"cmHandleId":"some-cmhandle-id1"},{"cmHandleId":"some-cmhandle-id2"}]}'
     }
 
     def 'Call execute cm handle searches with unrecognized condition name.'() {
@@ -279,7 +279,7 @@ class NetworkCmProxyControllerSpec extends Specification {
                     .contentType(MediaType.APPLICATION_JSON)
                     .content(jsonData)).andReturn().response
         then: 'an empty cm handle identifier is returned'
-            response.contentAsString == '{"cmHandles":null}'
+            response.contentAsString == '{"cmHandles":[]}'
     }
 
     def 'Update resource data in passthrough-running datastore.' () {