Migrate restconf/restconf-nb tests to JUnit5
[netconf.git] / restconf / restconf-nb / src / test / java / org / opendaylight / restconf / nb / jaxrs / RestconfDataPostTest.java
index bb8f4a42dc6ff8d9f0be35f336ec1fb730c88e7b..4ad69bc8fe7dfef34391236e686973b8dd3de53c 100644 (file)
@@ -7,13 +7,12 @@
  */
 package org.opendaylight.restconf.nb.jaxrs;
 
-import static org.junit.Assert.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.lenient;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFalseFluentFuture;
@@ -58,7 +57,6 @@ class RestconfDataPostTest extends AbstractRestconfTest {
 
     @BeforeEach
     void beforeEach() {
-        lenient().doReturn(CommitInfo.emptyFluentFuture()).when(tx).commit();
         doReturn(tx).when(dataBroker).newReadWriteTransaction();
     }
 
@@ -69,6 +67,7 @@ class RestconfDataPostTest extends AbstractRestconfTest {
         doNothing().when(tx).put(LogicalDatastoreType.CONFIGURATION, JUKEBOX_IID,
             ImmutableNodes.newContainerBuilder().withNodeIdentifier(new NodeIdentifier(JUKEBOX_QNAME)).build());
         doReturn(UriBuilder.fromUri(BASE_URI)).when(uriInfo).getBaseUriBuilder();
+        doReturn(CommitInfo.emptyFluentFuture()).when(tx).commit();
 
         assertEquals(URI.create("http://localhost:8181/rests/data/example-jukebox:jukebox"),
             assertResponse(201, ar -> restconf.postDataJSON(stringInputStream("""
@@ -79,12 +78,13 @@ class RestconfDataPostTest extends AbstractRestconfTest {
     }
 
     @Test
-    public void testPostMapEntryData() {
+    void testPostMapEntryData() {
         doReturn(new MultivaluedHashMap<>()).when(uriInfo).getQueryParameters();
         final var node = PLAYLIST_IID.node(BAND_ENTRY.name());
         doReturn(immediateFalseFluentFuture()).when(tx).exists(LogicalDatastoreType.CONFIGURATION, node);
         doNothing().when(tx).put(LogicalDatastoreType.CONFIGURATION, node, BAND_ENTRY);
         doReturn(UriBuilder.fromUri(BASE_URI)).when(uriInfo).getBaseUriBuilder();
+        doReturn(CommitInfo.emptyFluentFuture()).when(tx).commit();
 
         assertEquals(URI.create("http://localhost:8181/rests/data/example-jukebox:jukebox/playlist=name%20of%20band"),
             assertResponse(201, ar -> restconf.postDataJSON(JUKEBOX_API_PATH, stringInputStream("""
@@ -97,7 +97,7 @@ class RestconfDataPostTest extends AbstractRestconfTest {
     }
 
     @Test
-    public void testPostExistingData() {
+    void testPostExistingData() {
         doReturn(new MultivaluedHashMap<>()).when(uriInfo).getQueryParameters();
         doReturn(immediateTrueFluentFuture())
             .when(tx).exists(LogicalDatastoreType.CONFIGURATION, JUKEBOX_IID);
@@ -116,7 +116,7 @@ class RestconfDataPostTest extends AbstractRestconfTest {
     }
 
     @Test
-    public void testPostExistingListsDataErrorPath() {
+    void testPostExistingListsDataErrorPath() {
         doReturn(new MultivaluedHashMap<>()).when(uriInfo).getQueryParameters();
         final var node = PLAYLIST_IID.node(BAND_ENTRY.name());
         doReturn(immediateTrueFluentFuture()).when(tx).exists(LogicalDatastoreType.CONFIGURATION, node);
@@ -139,7 +139,7 @@ class RestconfDataPostTest extends AbstractRestconfTest {
     }
 
     @Test
-    public void testPostDataWithInsertLast() {
+    void testPostDataWithInsertLast() {
         // Mocking the query parameters to include 'insert=last'
         final var queryParams = new MultivaluedHashMap<String, String>();
         queryParams.put(INSERT, List.of("last"));
@@ -151,6 +151,7 @@ class RestconfDataPostTest extends AbstractRestconfTest {
         doNothing().when(tx).put(eq(LogicalDatastoreType.CONFIGURATION), any(YangInstanceIdentifier.class),
             any(NormalizedNode.class));
         doReturn(UriBuilder.fromUri(BASE_URI)).when(uriInfo).getBaseUriBuilder();
+        doReturn(CommitInfo.emptyFluentFuture()).when(tx).commit();
 
         assertEquals(URI.create("http://localhost:8181/rests/data/example-jukebox:jukebox/playlist=0/song=3"),
             assertResponse(201, ar -> restconf.postDataJSON(
@@ -166,7 +167,7 @@ class RestconfDataPostTest extends AbstractRestconfTest {
     }
 
     @Test
-    public void testPostDataWithInsertFirst() {
+    void testPostDataWithInsertFirst() {
         // Mocking the query parameters to include 'insert=first'
         final var queryParams = new MultivaluedHashMap<String, String>();
         queryParams.put(INSERT, List.of("first"));
@@ -182,6 +183,7 @@ class RestconfDataPostTest extends AbstractRestconfTest {
         doNothing().when(tx).put(eq(LogicalDatastoreType.CONFIGURATION), any(YangInstanceIdentifier.class),
                 any(NormalizedNode.class));
         doReturn(UriBuilder.fromUri(BASE_URI)).when(uriInfo).getBaseUriBuilder();
+        doReturn(CommitInfo.emptyFluentFuture()).when(tx).commit();
 
         assertEquals(URI.create("http://localhost:8181/rests/data/example-jukebox:jukebox/playlist=0/song=3"),
             assertResponse(201, ar -> restconf.postDataJSON(
@@ -197,7 +199,7 @@ class RestconfDataPostTest extends AbstractRestconfTest {
     }
 
     @Test
-    public void testPostDataWithInsertBefore() {
+    void testPostDataWithInsertBefore() {
         // Mocking the query parameters to include 'insert=before' and 'point=example-jukebox:jukebox/playlist=0/song=2'
         final var queryParams = new MultivaluedHashMap<String, String>();
         queryParams.put(INSERT, List.of("before"));
@@ -212,6 +214,7 @@ class RestconfDataPostTest extends AbstractRestconfTest {
             .read(eq(LogicalDatastoreType.CONFIGURATION), any(YangInstanceIdentifier.class));
 
         doReturn(UriBuilder.fromUri(BASE_URI)).when(uriInfo).getBaseUriBuilder();
+        doReturn(CommitInfo.emptyFluentFuture()).when(tx).commit();
 
         assertEquals(URI.create("http://localhost:8181/rests/data/example-jukebox:jukebox/playlist=0/song=3"),
             assertResponse(201, ar -> restconf.postDataJSON(
@@ -229,7 +232,7 @@ class RestconfDataPostTest extends AbstractRestconfTest {
     }
 
     @Test
-    public void testPostDataWithInsertAfter() {
+    void testPostDataWithInsertAfter() {
         // Mocking the query parameters to include 'insert=after' and 'point=example-jukebox:jukebox/playlist=0/song=1'
         final var queryParams = new MultivaluedHashMap<String, String>();
         queryParams.put(INSERT, List.of("after"));
@@ -243,6 +246,7 @@ class RestconfDataPostTest extends AbstractRestconfTest {
             .read(eq(LogicalDatastoreType.CONFIGURATION), any(YangInstanceIdentifier.class));
 
         doReturn(UriBuilder.fromUri(BASE_URI)).when(uriInfo).getBaseUriBuilder();
+        doReturn(CommitInfo.emptyFluentFuture()).when(tx).commit();
 
         assertEquals(URI.create("http://localhost:8181/rests/data/example-jukebox:jukebox/playlist=0/song=3"),
             assertResponse(201, ar -> restconf.postDataJSON(