-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transaction not rollbacked by using Rest Assured with transactionMode = SINGLE_TRANSACTION #975
Comments
I have the same issue in version 4.3.6
|
when you are making real HTTP client requests these are sent to the running server which runs a separate transaction in a completely different thread from the test. Currently it is not possible to use the same transaction in the test method and the server running a completely different thread in the controller. For this case you need to implement manual rollback. |
to implement manual rollback you typically, annotate with the test with package example.micronaut;
import io.micronaut.core.type.Argument;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.HttpStatus;
import io.micronaut.http.client.BlockingHttpClient;
import io.micronaut.http.client.HttpClient;
import io.micronaut.http.client.annotation.Client;
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
@MicronautTest(transactional = false)
class FruitControllerTest {
@Test
void itIsPossibleToNavigateWithCursoredPage(@Client("/") HttpClient httpClient,
FruitRepository repository) {
List<Fruit> data = List.of(
new Fruit(null, "apple"),
new Fruit(null, "banana"),
new Fruit(null, "cherry"),
new Fruit(null, "date"),
new Fruit(null, "elderberry"),
new Fruit(null, "fig"),
new Fruit(null, "grape"),
new Fruit(null, "honeydew"),
new Fruit(null, "kiwi"),
new Fruit(null, "lemon")
);
repository.saveAll(data);
int numberOfFruits = data.size();
assertEquals(numberOfFruits, repository.count());
BlockingHttpClient client = httpClient.toBlocking();
HttpResponse<List<Fruit>> response = assertDoesNotThrow(() ->
client.exchange(HttpRequest.GET("/fruits"), (Argument.listOf(Fruit.class))));
assertEquals(HttpStatus.OK, response.getStatus());
List<Fruit> fruits = response.body();
assertEquals(numberOfFruits, fruits.size());
// manual rollback
repository.deleteAll();
}
} |
Thanks for the answer. |
Expected Behavior
I'd expect the data to be rolled back if a Micronaut test is annotated like @MicronautTest(transactionMode = TransactionMode.SINGLE_TRANSACTION). Even we are using rest assured to test the endpoint.
Actual Behaviour
The data is not rolled back. And probably would be polluted in the next test scenario.
Steps To Reproduce
BookController.java
BookControllerTest.java
Environment Information
micronaut 3.9.4
micronaut-test-rest-assured:3.9.4
Example Application
No response
Version
3.9.4
The text was updated successfully, but these errors were encountered: