Reputation: 541
I am trying to learn Spring web flux with r2dbc. I am trying to execute a test case as follows:
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 :(
Upvotes: -1
Views: 234
Reputation: 541
Thanks to Martin,
After calling the saveAll
method of the repository, I was not blocking the saveAll
method and was immediately going for fetching the data with APIs. I blocked it with saveAll(items).blockLast()
. So the correct code should be:
@Test
void searchItem() {
// Arrange
itemRepository.saveAll(TestHelper.createItemEntitiesToInsert()).blockLast();
// Act
final var responseBody = get("/api/v1/items/search?name=ite")
.returnResult(ItemResource.class)
.getResponseBody();
// Assert
StepVerifier.create(responseBody)
.expectNextCount(2)
.expectComplete()
.verify();
}
Upvotes: 0