*/
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;
@BeforeEach
void beforeEach() {
- lenient().doReturn(CommitInfo.emptyFluentFuture()).when(tx).commit();
doReturn(tx).when(dataBroker).newReadWriteTransaction();
}
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("""
}
@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("""
}
@Test
- public void testPostExistingData() {
+ void testPostExistingData() {
doReturn(new MultivaluedHashMap<>()).when(uriInfo).getQueryParameters();
doReturn(immediateTrueFluentFuture())
.when(tx).exists(LogicalDatastoreType.CONFIGURATION, JUKEBOX_IID);
}
@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);
}
@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"));
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(
}
@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"));
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(
}
@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"));
.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(
}
@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"));
.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(