- @Test
- public void postDatastoreDataViaUrlTest202() throws UnsupportedEncodingException {
- controllerContext.setSchemas(schemaContextYangsIetf);
- mockCommitConfigurationDataPostMethod(null);
- String urlPath = "ietf-interfaces:interfaces";
- postDataViaUrlTest("/datastore/", urlPath, Draft01.MediaTypes.DATA + JSON, jsonData, 202);
- postDataViaUrlTest("/datastore/", urlPath, Draft01.MediaTypes.DATA + XML, xmlData, 202);
- postDataViaUrlTest("/datastore/", urlPath, MediaType.APPLICATION_JSON, jsonData, 202);
- postDataViaUrlTest("/datastore/", urlPath, MediaType.APPLICATION_XML, xmlData, 202);
- postDataViaUrlTest("/datastore/", urlPath, MediaType.TEXT_XML, xmlData, 202);
- }
-
- @Test
- public void postDatastoreDataViaUrlTest500() throws UnsupportedEncodingException {
- controllerContext.setSchemas(schemaContextYangsIetf);
- mockCommitConfigurationDataPostMethod(TransactionStatus.FAILED);
- String urlPath = "ietf-interfaces:interfaces";
- postDataViaUrlTest("/datastore/", urlPath, Draft01.MediaTypes.DATA + JSON, jsonData, 500);
- postDataViaUrlTest("/datastore/", urlPath, Draft01.MediaTypes.DATA + XML, xmlData, 500);
- postDataViaUrlTest("/datastore/", urlPath, MediaType.APPLICATION_JSON, jsonData, 500);
- postDataViaUrlTest("/datastore/", urlPath, MediaType.APPLICATION_XML, xmlData, 500);
- postDataViaUrlTest("/datastore/", urlPath, MediaType.TEXT_XML, xmlData, 500);
- }
-
- @Test
- public void postDataViaUrlMountPoint() throws UnsupportedEncodingException {
- controllerContext.setSchemas(schemaContextYangsIetf);
- mockCommitConfigurationDataPostMethod(TransactionStatus.COMMITED);
-
- MountService mockMountService = mock(MountService.class);
- SchemaContext otherSchemaContext = schemaContextTestModule;
- when(mockMountService.getMountPoint(any(InstanceIdentifier.class))).thenReturn(
- new DummyMountInstanceImpl.Builder().setSchemaContext(otherSchemaContext).build());
-
- ControllerContext.getInstance().setMountService(mockMountService);
-
- String uri = createUri("/config/", "ietf-interfaces:interfaces/interface/0/test-module:cont/cont1");
- Response response = target(uri).request(Draft02.MediaTypes.DATA + XML).post(
- entity(xmlData2, Draft02.MediaTypes.DATA + XML));
- // 204 code is returned when COMMITED transaction status is put as input
- // to mock method
- assertEquals(204, response.getStatus());
- }
-
- private void postDataViaUrlTest(String urlPrefix, String urlPath, String mediaType, String data, int responseStatus)
- throws UnsupportedEncodingException {
- String url = createUri(urlPrefix, urlPath);
- Response response = target(url).request(mediaType).post(entity(data, mediaType));
- assertEquals(responseStatus, response.getStatus());
- }
-
- private void mockCommitConfigurationDataPostMethod(TransactionStatus statusName) {
- RpcResult<TransactionStatus> rpcResult = new DummyRpcResult.Builder<TransactionStatus>().result(statusName)
- .build();
- Future<RpcResult<TransactionStatus>> dummyFuture = null;
- if (statusName != null) {
- dummyFuture = DummyFuture.builder().rpcResult(rpcResult).build();
- } else {
- dummyFuture = DummyFuture.builder().build();
- }
-
- when(brokerFacade.commitConfigurationDataPost(any(InstanceIdentifier.class), any(CompositeNode.class)))
- .thenReturn(dummyFuture);
- }
-
- private static CompositeNodeWrapper prepareCnSnRpcOutput() throws URISyntaxException {
- CompositeNodeWrapper cnSnDataOutput = new CompositeNodeWrapper(new URI("test:module"), "output");
- CompositeNodeWrapper cont = new CompositeNodeWrapper(new URI("test:module"), "cont-output");
- cnSnDataOutput.addValue(cont);
- cnSnDataOutput.unwrap();
- return cnSnDataOutput;