properties:
operation:
type: string
- enum: [ read, create, update, delete ]
+ enum: [ read, create, update, patch, delete ]
example: read
dataType:
type: string
<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>
<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>
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;
@Configuration
public class DmiConfiguration {
+ private static final int TIMEOUT = 5000;
+
@Getter
@Component
public static class CpsProperties {
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
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;
dataAccessRequest.getOperation(),
cmHandle,
resourceIdentifier,
- MediaType.APPLICATION_JSON_VALUE,
+ dataAccessRequest.getDataType(),
dataAccessRequest.getData());
}
return new ResponseEntity<>(sdncResponse, getHttpStatus(dataAccessRequest));
break;
case READ:
case UPDATE:
+ case PATCH:
httpStatus = HttpStatus.OK;
break;
case DELETE:
case CREATE:
httpMethod = HttpMethod.POST;
break;
+ case PATCH:
+ httpMethod = HttpMethod.PATCH;
+ break;
case UPDATE:
httpMethod = HttpMethod.PUT;
break;
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'
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
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(
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.'(){
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
'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'() {
--- /dev/null
+{
+ "operation": "patch",
+ "dataType": "application/yang.patch+json",
+ "data": "normal request body",
+ "cmHandleProperties": {
+ "some-property": "some-property-value"
+ }
+}
\ No newline at end of file