I am trying to learn Spring web flux with r2dbc. I am trying to execute a test case as follows:
- Save the data by calling the save method directly via a repository bean.
- Fetch the saved data by invoking the API using the webflux test client.
Step two does not return any data while the two records were getting inserted successfully.
@Test
void searchItem() {
// Arrange
itemRepository.saveAll(createItemEntitiesToInsert());
// Act
final var responseBody = get("/api/v1/items/search?name=ite")
.returnResult(ItemResource.class)
.getResponseBody();
// Assert
StepVerifier.create(responseBody)
.expectNextCount(2)
.expectComplete()
.verify();
}
Looks like some context-related issue but not sure what is happening :(
Thanks to Martin,
After calling the
saveAll
method of the repository, I was not blocking thesaveAll
method and was immediately going for fetching the data with APIs. I blocked it withsaveAll(items).blockLast()
. So the correct code should be: