diff options
9 files changed, 51 insertions, 12 deletions
diff --git a/openapi/components.yml b/openapi/components.yml index aa0827a5..bf271bb4 100644 --- a/openapi/components.yml +++ b/openapi/components.yml @@ -87,7 +87,7 @@ components: properties: operation: type: string - enum: [ read, create, update, delete ] + enum: [ read, create, update, patch, delete ] example: read dataType: type: string @@ -45,6 +45,7 @@ <jacoco.minimum.coverage>0.98</jacoco.minimum.coverage> <maven.build.timestamp.format>yyyyMMdd'T'HHmmss'Z'</maven.build.timestamp.format> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <httpclient.version>4.4.1</httpclient.version> </properties> <dependencyManagement> <dependencies> @@ -156,6 +157,11 @@ <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <version>${httpclient.version}</version> + </dependency> </dependencies> <build> <resources> diff --git a/src/main/java/org/onap/cps/ncmp/dmi/config/DmiConfiguration.java b/src/main/java/org/onap/cps/ncmp/dmi/config/DmiConfiguration.java index 9b8b05b2..18b22dbe 100644 --- a/src/main/java/org/onap/cps/ncmp/dmi/config/DmiConfiguration.java +++ b/src/main/java/org/onap/cps/ncmp/dmi/config/DmiConfiguration.java @@ -25,6 +25,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; @@ -34,6 +35,8 @@ import org.springframework.web.client.RestTemplate; @Configuration public class DmiConfiguration { + private static final int TIMEOUT = 5000; + @Getter @Component public static class CpsProperties { @@ -62,8 +65,23 @@ public class DmiConfiguration { public String topologyId; } + /** + * Returns restTemplate bean for the spring context. + * + * @param restTemplateBuilder restTemplate builder + * @return {@code RestTemplate} rest template + */ @Bean public RestTemplate restTemplate(final RestTemplateBuilder restTemplateBuilder) { - return restTemplateBuilder.build(); + final RestTemplate restTemplate = restTemplateBuilder.build(); + setCustomRequestFactoryToSupportPatch(restTemplate); + return restTemplate; + } + + private void setCustomRequestFactoryToSupportPatch(final RestTemplate restTemplate) { + final HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(); + requestFactory.setConnectTimeout(TIMEOUT); + requestFactory.setReadTimeout(TIMEOUT); + restTemplate.setRequestFactory(requestFactory); } }
\ No newline at end of file diff --git a/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java b/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java index 97848c3e..077c4ab4 100644 --- a/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java +++ b/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java @@ -36,7 +36,6 @@ import org.onap.cps.ncmp.dmi.rest.api.DmiPluginInternalApi; import org.onap.cps.ncmp.dmi.service.DmiService; import org.onap.cps.ncmp.dmi.service.model.ModuleReference; import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -135,7 +134,7 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi { dataAccessRequest.getOperation(), cmHandle, resourceIdentifier, - MediaType.APPLICATION_JSON_VALUE, + dataAccessRequest.getDataType(), dataAccessRequest.getData()); } return new ResponseEntity<>(sdncResponse, getHttpStatus(dataAccessRequest)); @@ -157,6 +156,7 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi { break; case READ: case UPDATE: + case PATCH: httpStatus = HttpStatus.OK; break; case DELETE: diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/operation/SdncOperations.java b/src/main/java/org/onap/cps/ncmp/dmi/service/operation/SdncOperations.java index ced9b061..5903eacf 100644 --- a/src/main/java/org/onap/cps/ncmp/dmi/service/operation/SdncOperations.java +++ b/src/main/java/org/onap/cps/ncmp/dmi/service/operation/SdncOperations.java @@ -248,6 +248,9 @@ public class SdncOperations { case CREATE: httpMethod = HttpMethod.POST; break; + case PATCH: + httpMethod = HttpMethod.PATCH; + break; case UPDATE: httpMethod = HttpMethod.PUT; break; diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/config/DmiConfigurationSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/config/DmiConfigurationSpec.groovy index 1798c9f2..9d80b71f 100644 --- a/src/test/groovy/org/onap/cps/ncmp/dmi/config/DmiConfigurationSpec.groovy +++ b/src/test/groovy/org/onap/cps/ncmp/dmi/config/DmiConfigurationSpec.groovy @@ -56,7 +56,7 @@ class DmiConfigurationSpec extends Specification { given: 'a DMI configuration' DmiConfiguration objectUnderTest = new DmiConfiguration() and: 'a rest template builder' - RestTemplateBuilder mockRestTemplateBuilder = Mock(RestTemplateBuilder) + RestTemplateBuilder mockRestTemplateBuilder = Spy(RestTemplateBuilder) when: 'rest template method is invoked' objectUnderTest.restTemplate(mockRestTemplateBuilder) then: 'DMI configuration uses the build method on the template builder' diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy index 221603c2..ac632bb2 100644 --- a/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy +++ b/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy @@ -44,6 +44,7 @@ import org.springframework.test.web.servlet.MockMvc import spock.lang.Specification import static org.onap.cps.ncmp.dmi.model.DataAccessRequest.OperationEnum.DELETE +import static org.onap.cps.ncmp.dmi.model.DataAccessRequest.OperationEnum.PATCH import static org.onap.cps.ncmp.dmi.model.DataAccessRequest.OperationEnum.READ import static org.springframework.http.HttpStatus.BAD_REQUEST import static org.springframework.http.HttpStatus.NO_CONTENT @@ -211,14 +212,14 @@ class DmiRestControllerSpec extends Specification { 0 * mockDmiService.getResourceData(*_) } - def 'write data with #scenario operation using passthrough running.'() { + def 'data with #scenario operation using passthrough running.'() { given: 'write data for passthrough running url and jsonData' def writeDataForPassthroughRunning = "${basePathV1}/ch/some-cmHandle/data/ds/ncmp-datastore:passthrough-running" + "?resourceIdentifier=some-resourceIdentifier" def jsonData = TestUtils.getResourceFileContent(requestBodyFile) and: 'dmi service is called' mockDmiService.writeData(operationEnum, 'some-cmHandle', - 'some-resourceIdentifier', 'application/json', + 'some-resourceIdentifier', dataType, 'normal request body' ) >> '{some-json}' when: 'write data for passthrough running post api is invoked with json data' def response = mvc.perform( @@ -230,11 +231,12 @@ class DmiRestControllerSpec extends Specification { and: 'the data in the request body is as expected' response.getContentAsString() == expectedJsonResponse where: 'given request body and data' - scenario | requestBodyFile | operationEnum || expectedResponseStatus | expectedJsonResponse - 'Create' | 'createDataWithNormalChar.json' | CREATE || CREATED.value() | '{some-json}' - 'Update' | 'updateData.json' | UPDATE || OK.value() | '{some-json}' - 'Delete' | 'deleteData.json' | DELETE || NO_CONTENT.value() | '{some-json}' - 'Read' | 'readData.json' | READ || OK.value() | '' + scenario | requestBodyFile | operationEnum | dataType || expectedResponseStatus | expectedJsonResponse + 'Create' | 'createDataWithNormalChar.json' | CREATE | 'application/json' || CREATED.value() | '{some-json}' + 'Update' | 'updateData.json' | UPDATE | 'application/json' || OK.value() | '{some-json}' + 'Delete' | 'deleteData.json' | DELETE | 'application/json' || NO_CONTENT.value() | '{some-json}' + 'Read' | 'readData.json' | READ | 'application/json' || OK.value() | '' + 'Patch' | 'patchData.json' | PATCH | 'application/yang.patch+json' || OK.value() | '{some-json}' } def 'Create data using passthrough for special characters.'(){ diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy index 5079ada7..49cdc205 100644 --- a/src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy +++ b/src/test/groovy/org/onap/cps/ncmp/dmi/service/operation/SdncOperationsSpec.groovy @@ -37,6 +37,7 @@ import spock.lang.Specification import static org.onap.cps.ncmp.dmi.model.DataAccessRequest.OperationEnum.CREATE import static org.onap.cps.ncmp.dmi.model.DataAccessRequest.OperationEnum.DELETE +import static org.onap.cps.ncmp.dmi.model.DataAccessRequest.OperationEnum.PATCH import static org.onap.cps.ncmp.dmi.model.DataAccessRequest.OperationEnum.UPDATE import static org.onap.cps.ncmp.dmi.model.DataAccessRequest.OperationEnum.READ @@ -138,6 +139,7 @@ class SdncOperationsSpec extends Specification { 'Update' | UPDATE || HttpMethod.PUT 'Read' | READ || HttpMethod.GET 'Delete' | DELETE || HttpMethod.DELETE + 'Patch' | PATCH || HttpMethod.PATCH } def 'build query param list for SDNC where options contains a #scenario'() { diff --git a/src/test/resources/patchData.json b/src/test/resources/patchData.json new file mode 100644 index 00000000..e5466eaf --- /dev/null +++ b/src/test/resources/patchData.json @@ -0,0 +1,8 @@ +{ + "operation": "patch", + "dataType": "application/yang.patch+json", + "data": "normal request body", + "cmHandleProperties": { + "some-property": "some-property-value" + } +}
\ No newline at end of file |