1) Problem Description:
- I am using a Spring-Data-Mongo-Reactive, Testcontainers and JUnit 05;
- I have a Test-Class with simple-test and ‘Nested-Test-Class’(which has a simple test, as well);
- When, JUnit tests the NestedClass, the MongoDb Connection is closed, and the test 'Test's NestedClass' fail;
My Goal is:
- Keep the Reactive-MongoDB-Connection opened, in order to test, the ‘Nested-Test-Class’;
Below is the code for the above situation:
1.1) Code:
Current working status: not working;
Current behaviour:
- The Reactive-MongoDB connection is closing, when the ‘Nested-Test-Class’ is being tested, even though the first test is tested normally. .
@Import(ServiceCrudRepoCfg.class)
@TestcontainerAnn
@TestsMongoConfigAnn
@TestsGlobalAnn
public class Lab {
final private String enabledTest = "true";
@Autowired
IService serviceCrudRepo;
@Test
@DisplayName("Save")
@EnabledIf(expression = enabledTest, loadContext = true)
public void save() {
Person localPerson = personWithIdAndName().create();
StepVerifier
.create(serviceCrudRepo.save(localPerson))
.expectSubscription()
.expectNext(localPerson)
.verifyComplete();
}
@Nested
@DisplayName("Nested Class")
@Execution(SAME_THREAD)
class NestedClass {
@Test
@DisplayName("findAll")
@EnabledIf(expression = enabledTest, loadContext = true)
public void findAll() {
StepVerifier
.create(serviceCrudRepo.findAll()
.log())
.expectSubscription()
.expectNextCount(1L)
.verifyComplete();
}
}
}
2) Current Problematic Log / Error:
java.lang.AssertionError: expectation "expectNextCount(1)" failed (expected: count = 1; actual: counted = 0; signal: onError(org.springframework.data.mongodb.ClientSessionException: state should be: server session pool is open; nested exception is java.lang.IllegalStateException: state should be: server session pool is open))
Caused by: java.lang.IllegalStateException: state should be: server session pool is open
3) Question:
- How Can I Keep the Reactive-MongoDB-Connection opened, in order to test the ‘Nested-Test-Class’ as well?
Thanks a lot for any help