Restconf 8040 should return 204 for delete and put 05/68905/1
authorTom Pantelis <tompantelis@gmail.com>
Wed, 28 Feb 2018 19:13:38 +0000 (14:13 -0500)
committerTom Pantelis <tompantelis@gmail.com>
Wed, 28 Feb 2018 19:19:39 +0000 (14:19 -0500)
restconf was returning 200 Ok but according to RCF8040, for put,
"If an existing resource is modified, a "204 No Content"
status-line is returned."" and for delete, "If the DELETE request
succeeds, a "204 No Content" status-line is returned.".

Change-Id: I7133cdd747c1869d6b640c873bbcdccd437e8900
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtil.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PutDataTransactionUtil.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImplTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtilTest.java

index 94945a33e16e102a4ac0244020044f0ff2364b94..dd293479a95fb2a3005e9a0d813b3841033176fe 100644 (file)
@@ -38,7 +38,7 @@ public final class DeleteDataTransactionUtil {
         final CheckedFuture<Void, TransactionCommitFailedException> future = submitData(
                 transactionNode.getTransactionChain(), transactionNode.getTransactionChain().newReadWriteTransaction(),
                 transactionNode.getInstanceIdentifier().getInstanceIdentifier());
-        final ResponseFactory response = new ResponseFactory(Status.OK);
+        final ResponseFactory response = new ResponseFactory(Status.NO_CONTENT);
         FutureCallbackTx.addCallback(future, RestconfDataServiceConstant.DeleteData.DELETE_TX_TYPE, response);
         return response.build();
     }
index a9cff57b020f8c229f858fc39d4d2a0d700467c0..9e3130cb67118671e97adbb05bbf935517bd1e13 100644 (file)
@@ -170,7 +170,8 @@ public final class PutDataTransactionUtil {
         final FutureDataFactory<Boolean> existsResponse = new FutureDataFactory<>();
         FutureCallbackTx.addCallback(existsFuture, RestconfDataServiceConstant.PutData.PUT_TX_TYPE, existsResponse);
 
-        final ResponseFactory responseFactory = new ResponseFactory(existsResponse.result ? Status.OK : Status.CREATED);
+        final ResponseFactory responseFactory =
+                new ResponseFactory(existsResponse.result ? Status.NO_CONTENT : Status.CREATED);
         final CheckedFuture<Void, TransactionCommitFailedException> submitData = submitData(path, schemaContext,
                 transactionNode.getTransactionChain(), readWriteTransaction, payload.getData(), insert, point);
         FutureCallbackTx.addCallback(submitData, RestconfDataServiceConstant.PutData.PUT_TX_TYPE, responseFactory);
index 085a8a36974d33fb2971ed971009a83f473be395..acde252103c406d2f08a8065078439921093048a 100644 (file)
@@ -328,7 +328,7 @@ public class RestconfDataServiceImplTest {
         doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
         final Response response = this.dataService.putData(null, payload, this.uriInfo);
         assertNotNull(response);
-        assertEquals(200, response.getStatus());
+        assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
     }
 
     @Test
@@ -347,7 +347,7 @@ public class RestconfDataServiceImplTest {
         doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
         final Response response = this.dataService.putData(null, payload, this.uriInfo);
         assertNotNull(response);
-        assertEquals(200, response.getStatus());
+        assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
     }
 
     @Test
@@ -403,7 +403,7 @@ public class RestconfDataServiceImplTest {
                 .when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
         final Response response = this.dataService.deleteData("example-jukebox:jukebox");
         assertNotNull(response);
-        assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
+        assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
     }
 
     /**
@@ -418,7 +418,7 @@ public class RestconfDataServiceImplTest {
         final Response response =
                 this.dataService.deleteData("example-jukebox:jukebox/yang-ext:mount/example-jukebox:jukebox");
         assertNotNull(response);
-        assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
+        assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
     }
 
     @Test
index f64f6e8d06028cc4b9979e708577f9fd6a2b9cb5..e71982a3a0c19268539165ad0efce3809c5f84b5 100644 (file)
@@ -92,7 +92,7 @@ public class DeleteDataTransactionUtilTest {
                 new TransactionVarsWrapper(this.context, null, this.transactionChain));
 
         // assert success
-        assertEquals("Not expected response received", Status.OK.getStatusCode(), response.getStatus());
+        assertEquals("Not expected response received", Status.NO_CONTENT.getStatusCode(), response.getStatus());
     }
 
     /**
@@ -115,4 +115,4 @@ public class DeleteDataTransactionUtilTest {
             assertEquals(404, e.getErrors().get(0).getErrorTag().getStatusCode());
         }
     }
-}
\ No newline at end of file
+}