summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-rest/src
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-rest/src')
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapper.java7
-rwxr-xr-xcps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java12
-rw-r--r--cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapperSpec.groovy21
-rw-r--r--cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy29
4 files changed, 67 insertions, 2 deletions
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapper.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapper.java
index 118fa45263..eb48754b4f 100644
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapper.java
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapper.java
@@ -25,8 +25,10 @@ import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.NullValuePropertyMappingStrategy;
+import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
+import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters;
import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration;
import org.onap.cps.ncmp.rest.model.RestInputCmHandle;
import org.onap.cps.ncmp.rest.model.RestModuleDefinition;
@@ -59,4 +61,7 @@ public interface NcmpRestInputMapper {
@InheritConfiguration(name = "toRestModuleReference")
RestModuleDefinition toRestModuleDefinition(
final ModuleDefinition moduleDefinition);
-} \ No newline at end of file
+
+ CmHandleQueryServiceParameters toCmHandleQueryServiceParameters(
+ final CmHandleQueryParameters cmHandleQueryParameters);
+}
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java
index 0c428e4423..98da15093c 100755
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java
@@ -27,10 +27,12 @@ import java.util.stream.Collectors;
import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
+import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse;
import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.Status;
import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse;
import org.onap.cps.ncmp.rest.api.NetworkCmProxyInventoryApi;
+import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters;
import org.onap.cps.ncmp.rest.model.CmHandlerRegistrationErrorResponse;
import org.onap.cps.ncmp.rest.model.DmiPluginRegistrationErrorResponse;
import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration;
@@ -47,6 +49,16 @@ public class NetworkCmProxyInventoryController implements NetworkCmProxyInventor
private final NetworkCmProxyDataService networkCmProxyDataService;
private final NcmpRestInputMapper ncmpRestInputMapper;
+ @Override
+ public ResponseEntity<List<String>> searchCmHandleIds(final CmHandleQueryParameters cmHandleQueryParameters) {
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = ncmpRestInputMapper
+ .toCmHandleQueryServiceParameters(cmHandleQueryParameters);
+
+ final Set<String> cmHandleIds = networkCmProxyDataService
+ .executeCmHandleIdSearchForInventory(cmHandleQueryServiceParameters);
+ return ResponseEntity.ok(List.copyOf(cmHandleIds));
+ }
+
/**
* Get all cm-handle IDs under a registered DMI plugin.
*
diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapperSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapperSpec.groovy
index cd3770eb84..dfe7bf3853 100644
--- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapperSpec.groovy
+++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NcmpRestInputMapperSpec.groovy
@@ -22,10 +22,13 @@ package org.onap.cps.ncmp.rest.controller
import org.mapstruct.factory.Mappers
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
+import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters
+import org.onap.cps.ncmp.rest.model.ConditionProperties
import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration
import org.onap.cps.ncmp.rest.model.RestInputCmHandle
import org.onap.cps.ncmp.rest.model.RestModuleDefinition
import org.onap.cps.ncmp.rest.model.RestModuleReference
+import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters
import org.onap.cps.spi.model.ModuleDefinition
import org.onap.cps.spi.model.ModuleReference
import spock.lang.Specification
@@ -104,4 +107,22 @@ class NcmpRestInputMapperSpec extends Specification {
' content: content\n' +
'}'
}
+
+ def 'Convert a CmHandle REST query to CmHandle query service parameters.'() {
+ given: 'a CmHandle REST query with two conditions'
+ def conditionParameter1 = new ConditionProperties(conditionName: 'some condition', conditionParameters: [[p1:1]] )
+ def conditionParameter2 = new ConditionProperties(conditionName: 'other condition', conditionParameters: [[p2:2]] )
+ def cmHandleQuery = new CmHandleQueryParameters()
+ cmHandleQuery.cmHandleQueryParameters = [conditionParameter1, conditionParameter2]
+ when: 'it is converted into CmHandle query service parameters'
+ def result = objectUnderTest.toCmHandleQueryServiceParameters(cmHandleQuery)
+ then: 'the result is of the correct class'
+ assert result instanceof CmHandleQueryServiceParameters
+ and: 'the result has the same conditions'
+ assert result.cmHandleQueryParameters.size() == 2
+ assert result.cmHandleQueryParameters[0].conditionName == 'some condition'
+ assert result.cmHandleQueryParameters[0].conditionParameters == [[p1:1]]
+ assert result.cmHandleQueryParameters[1].conditionName == 'other condition'
+ assert result.cmHandleQueryParameters[1].conditionParameters == [[p2:2]]
+ }
}
diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy
index b5a089bba3..88f496a188 100644
--- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy
+++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy
@@ -27,10 +27,11 @@ import org.onap.cps.ncmp.api.NetworkCmProxyDataService
import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse
import org.onap.cps.ncmp.api.models.DmiPluginRegistration
import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse
-import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
+import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters
import org.onap.cps.ncmp.rest.model.CmHandlerRegistrationErrorResponse
import org.onap.cps.ncmp.rest.model.DmiPluginRegistrationErrorResponse
import org.onap.cps.ncmp.rest.model.RestDmiPluginRegistration
+import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters
import org.onap.cps.utils.JsonObjectMapper
import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
@@ -60,6 +61,9 @@ class NetworkCmProxyInventoryControllerSpec extends Specification {
DmiPluginRegistration mockDmiPluginRegistration = Mock()
+ CmHandleQueryServiceParameters cmHandleQueryServiceParameters = Mock()
+
+ @SpringBean
JsonObjectMapper jsonObjectMapper = new JsonObjectMapper(new ObjectMapper())
@Value('${rest.api.ncmp-inventory-base-path}/v1')
@@ -102,6 +106,29 @@ class NetworkCmProxyInventoryControllerSpec extends Specification {
response.status == HttpStatus.BAD_REQUEST.value()
}
+ def 'CmHandle search endpoint test #scenario.'() {
+ given: 'a query object'
+ def cmHandleQueryParameters = jsonObjectMapper.asJsonString(new CmHandleQueryParameters())
+ and: 'the mapper service returns a converted object'
+ ncmpRestInputMapper.toCmHandleQueryServiceParameters(_) >> cmHandleQueryServiceParameters
+ and: 'the service returns the desired results'
+ mockNetworkCmProxyDataService.executeCmHandleIdSearchForInventory(cmHandleQueryServiceParameters) >> serviceMockResponse
+ when: 'post request is performed & search is called with the given request parameters'
+ def response = mvc.perform(
+ post("$ncmpBasePathV1/ch/searches")
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(cmHandleQueryParameters)
+ ).andReturn().response
+ then: 'response status is OK'
+ assert response.status == HttpStatus.OK.value()
+ and: 'the response data matches the service response.'
+ jsonObjectMapper.convertJsonString(response.getContentAsString(), List) == serviceMockResponse
+ where: 'the service respond with'
+ scenario | serviceMockResponse
+ 'empty response' | []
+ 'populates response' | ['cmHandle1', 'cmHandle2']
+ }
+
def 'DMI Registration: All cm-handles operations processed successfully.'() {
given: 'a dmi plugin registration'
def dmiRegistrationRequest = '{}'