+ @Test
+ public void testXmlToCompositeNode400() throws UnsupportedEncodingException, URISyntaxException {
+ String uri = createUri("/datastore/", "simple-nodes:user/name");
+
+ when(brokerFacade.readOperationalData(any(InstanceIdentifier.class))).thenReturn(null);
+
+ Response response = target(uri).request(Draft01.MediaTypes.DATA + RestconfService.XML).get();
+ assertEquals(400, response.getStatus());
+ }
+
+ @Test
+ public void testRpcResultCommitedToStatusCodes() throws UnsupportedEncodingException {
+ InputStream xmlStream = RestconfImplTest.class.getResourceAsStream("/parts/ietf-interfaces_interfaces.xml");
+ String xml = TestUtils.getDocumentInPrintableForm(TestUtils.loadDocumentFrom(xmlStream));
+ Entity<String> entity = Entity.entity(xml, MEDIA_TYPE_DRAFT02);
+ RpcResult<TransactionStatus> rpcResult = new DummyRpcResult.Builder<TransactionStatus>().result(
+ TransactionStatus.COMMITED).build();
+ Future<RpcResult<TransactionStatus>> dummyFuture = DummyFuture.builder().rpcResult(rpcResult).build();
+ when(brokerFacade.commitOperationalDataPut(any(InstanceIdentifier.class), any(CompositeNode.class)))
+ .thenReturn(dummyFuture);
+ when(brokerFacade.commitConfigurationDataPut(any(InstanceIdentifier.class), any(CompositeNode.class)))
+ .thenReturn(dummyFuture);
+
+ String uri = createUri("/config/", "ietf-interfaces:interfaces/interface/eth0");
+ Response response = target(uri).request(MEDIA_TYPE_DRAFT02).put(entity);
+ assertEquals(200, response.getStatus());
+ response = target(uri).request(MEDIA_TYPE_DRAFT02).post(entity);
+ assertEquals(204, response.getStatus());
+
+ uri = createUri("/config/", "ietf-interfaces:interfaces/interface/eth0");
+ response = target(uri).request(MEDIA_TYPE_DRAFT02).put(entity);
+ assertEquals(200, response.getStatus());
+ response = target(uri).request(MEDIA_TYPE_DRAFT02).post(entity);
+ assertEquals(204, response.getStatus());
+
+ uri = createUri("/datastore/", "ietf-interfaces:interfaces/interface/eth0");
+ response = target(uri).request(MEDIA_TYPE).put(entity);
+ assertEquals(200, response.getStatus());
+ response = target(uri).request(MEDIA_TYPE).post(entity);
+ assertEquals(204, response.getStatus());
+ }
+
+ @Test
+ public void testRpcResultOtherToStatusCodes() throws UnsupportedEncodingException {
+ InputStream xmlStream = RestconfImplTest.class.getResourceAsStream("/parts/ietf-interfaces_interfaces.xml");
+ String xml = TestUtils.getDocumentInPrintableForm(TestUtils.loadDocumentFrom(xmlStream));
+ Entity<String> entity = Entity.entity(xml, MEDIA_TYPE_DRAFT02);
+ RpcResult<TransactionStatus> rpcResult = new DummyRpcResult.Builder<TransactionStatus>().result(
+ TransactionStatus.FAILED).build();
+ Future<RpcResult<TransactionStatus>> dummyFuture = DummyFuture.builder().rpcResult(rpcResult).build();
+ when(brokerFacade.commitOperationalDataPut(any(InstanceIdentifier.class), any(CompositeNode.class)))
+ .thenReturn(dummyFuture);
+ when(brokerFacade.commitConfigurationDataPut(any(InstanceIdentifier.class), any(CompositeNode.class)))
+ .thenReturn(dummyFuture);
+
+ String uri = createUri("/config/", "ietf-interfaces:interfaces/interface/eth0");
+ Response response = target(uri).request(MEDIA_TYPE_DRAFT02).put(entity);
+ assertEquals(500, response.getStatus());
+ response = target(uri).request(MEDIA_TYPE_DRAFT02).post(entity);
+ assertEquals(500, response.getStatus());
+
+ uri = createUri("/config/", "ietf-interfaces:interfaces/interface/eth0");
+ response = target(uri).request(MEDIA_TYPE_DRAFT02).put(entity);
+ assertEquals(500, response.getStatus());
+ response = target(uri).request(MEDIA_TYPE_DRAFT02).post(entity);
+ assertEquals(500, response.getStatus());
+
+ uri = createUri("/datastore/", "ietf-interfaces:interfaces/interface/eth0");
+ response = target(uri).request(MEDIA_TYPE).put(entity);
+ assertEquals(500, response.getStatus());
+ response = target(uri).request(MEDIA_TYPE).post(entity);
+ assertEquals(500, response.getStatus());
+ }
+
+ private String createUri(String prefix, String encodedPart) throws UnsupportedEncodingException {
+ return URI.create(prefix + URLEncoder.encode(encodedPart, Charsets.US_ASCII.name()).toString()).toASCIIString();
+ }
+