1111import java .util .concurrent .CompletionStage ;
1212import java .util .concurrent .TimeUnit ;
1313import java .util .function .Supplier ;
14+
15+ import io .vertx .junit5 .VertxTestContext ;
1416import jakarta .persistence .criteria .CriteriaQuery ;
1517
1618import org .hibernate .SessionFactory ;
2224import org .hibernate .reactive .provider .Settings ;
2325import org .hibernate .reactive .stage .Stage ;
2426
25- import org .junit .After ;
26- import org .junit .AfterClass ;
27- import org .junit .Before ;
28- import org .junit .ClassRule ;
29- import org .junit .runner .RunWith ;
27+ import org .junit .jupiter .api .AfterAll ;
28+ import org .junit .jupiter .api .AfterEach ;
29+ import org .junit .jupiter .api .BeforeEach ;
30+ import org .junit .jupiter .api .TestInstance ;
31+ import org .junit .jupiter .api .extension .ExtendWith ;
32+ import org .junit .jupiter .api .extension .RegisterExtension ;
3033
3134import io .smallrye .mutiny .Uni ;
3235import io .vertx .core .Promise ;
33- import io .vertx .core .Vertx ;
3436import io .vertx .core .VertxOptions ;
35- import io .vertx .ext .unit .Async ;
36- import io .vertx .ext .unit .TestContext ;
37- import io .vertx .ext .unit .junit .RunTestOnContext ;
38- import io .vertx .ext .unit .junit .Timeout ;
39- import io .vertx .ext .unit .junit .VertxUnitRunner ;
37+ import io .vertx .junit5 .RunTestOnContext ;
38+ import io .vertx .junit5 .Timeout ;
39+ import io .vertx .junit5 .VertxExtension ;
4040import org .testcontainers .containers .PostgreSQLContainer ;
4141import org .testcontainers .utility .DockerImageName ;
4242
4747 * Similar to BaseReactiveTest in the hibernate-reactive-core.
4848 * Hopefully, one day we will reorganize the code better.
4949 */
50- @ RunWith (VertxUnitRunner .class )
50+ @ ExtendWith (VertxExtension .class )
51+ @ TestInstance (TestInstance .Lifecycle .PER_METHOD )
52+ @ Timeout (value = 600 , timeUnit = TimeUnit .SECONDS )
5153public abstract class BaseReactiveIT {
5254
5355 // These properties are in DatabaseConfiguration in core
@@ -67,17 +69,20 @@ public abstract class BaseReactiveIT {
6769 .withDatabaseName ( DB_NAME )
6870 .withReuse ( true );
6971
70- @ ClassRule
71- public static final Timeout rule = Timeout .seconds ( 10 * 60 );
7272
7373 private static SessionFactory ormSessionFactory ;
74- @ ClassRule
75- public static final RunTestOnContext vertxContextRule = new RunTestOnContext ( () -> {
76- VertxOptions options = new VertxOptions ();
77- options .setBlockedThreadCheckInterval ( 5 );
78- options .setBlockedThreadCheckIntervalUnit ( TimeUnit .MINUTES );
79- return Vertx .vertx ( options );
80- } );
74+
75+ /**
76+ * Configure Vertx JUnit5 test context
77+ */
78+ @ RegisterExtension
79+ static RunTestOnContext testOnContext = new RunTestOnContext ( vertxOptions () );
80+
81+ private static VertxOptions vertxOptions () {
82+ return new VertxOptions ()
83+ .setBlockedThreadCheckInterval ( 5 )
84+ .setBlockedThreadCheckIntervalUnit ( TimeUnit .MINUTES );
85+ }
8186
8287 /**
8388 * Configure properties defined in {@link Settings}.
@@ -113,10 +118,6 @@ private static String dbConnectionUrl(boolean enableDocker) {
113118 return "postgres://localhost:5432/" + DB_NAME ;
114119 }
115120
116- protected static void test (TestContext context , CompletionStage <?> work ) {
117- test ( context .async (), context , work );
118- }
119-
120121 /**
121122 * These entities will be added to the configuration of the factory and
122123 * the rows in the mapping tables deleted after each test.
@@ -135,29 +136,19 @@ protected Collection<String> mappings() {
135136 return List .of ();
136137 }
137138
138- /**
139- * For when we need to create the {@link Async} in advance
140- */
141- protected static void test (Async async , TestContext context , CompletionStage <?> work ) {
139+ public static void test (VertxTestContext context , CompletionStage <?> work ) {
142140 work .whenComplete ( (res , err ) -> {
143141 if ( err != null ) {
144- context .fail ( err );
142+ context .failNow ( err );
145143 }
146144 else {
147- async . complete ();
145+ context . completeNow ();
148146 }
149147 } );
150148 }
151149
152- protected static void test (TestContext context , Uni <?> uni ) {
153- test ( context .async (), context , uni );
154- }
155-
156- /**
157- * For when we need to create the {@link Async} in advance
158- */
159- public static void test (Async async , TestContext context , Uni <?> uni ) {
160- uni .subscribe ().with ( res -> async .complete (), context ::fail );
150+ public static void test (VertxTestContext context , Uni <?> uni ) {
151+ uni .subscribe ().with ( res -> context .completeNow (), context ::failNow );
161152 }
162153
163154 protected Configuration constructConfiguration () {
@@ -193,8 +184,8 @@ private <T> CriteriaQuery<T> queryForDelete(Class<T> entityClass) {
193184 return query ;
194185 }
195186
196- @ Before
197- public void before (TestContext context ) {
187+ @ BeforeEach
188+ public void before (VertxTestContext context ) {
198189 test ( context , setupSessionFactory ( this ::constructConfiguration ) );
199190 }
200191
@@ -212,9 +203,9 @@ protected CompletionStage<Void> setupSessionFactory(Configuration configuration)
212203 * @param confSupplier supplies the configuration for the factory
213204 * @return a {@link CompletionStage} void that succeeds when the factory is ready.
214205 */
215- protected CompletionStage <Void > setupSessionFactory (Supplier <Configuration > confSupplier ) {
206+ protected static CompletionStage <Void > setupSessionFactory (Supplier <Configuration > confSupplier ) {
216207 CompletableFuture <Void > future = new CompletableFuture <>();
217- vertxContextRule .vertx ()
208+ testOnContext .vertx ()
218209 .executeBlocking (
219210 // schema generation is a blocking operation and so it causes an
220211 // exception when run on the Vert.x event loop. So call it using
@@ -232,7 +223,7 @@ protected CompletionStage<Void> setupSessionFactory(Supplier<Configuration> conf
232223 return future ;
233224 }
234225
235- private void startFactoryManager (Promise <Object > p , Supplier <Configuration > confSupplier ) {
226+ private static void startFactoryManager (Promise <Object > p , Supplier <Configuration > confSupplier ) {
236227 try {
237228 ormSessionFactory = createHibernateSessionFactory ( confSupplier .get () );
238229 p .complete ();
@@ -242,7 +233,7 @@ private void startFactoryManager(Promise<Object> p, Supplier<Configuration> conf
242233 }
243234 }
244235
245- private SessionFactory createHibernateSessionFactory (Configuration configuration ) {
236+ private static SessionFactory createHibernateSessionFactory (Configuration configuration ) {
246237 StandardServiceRegistryBuilder builder = new ReactiveServiceRegistryBuilder ()
247238 .applySettings ( configuration .getProperties () );
248239 addServices ( builder );
@@ -251,13 +242,13 @@ private SessionFactory createHibernateSessionFactory(Configuration configuration
251242 return configuration .buildSessionFactory ( registry );
252243 }
253244
254- protected void addServices (StandardServiceRegistryBuilder builder ) {}
245+ protected static void addServices (StandardServiceRegistryBuilder builder ) {}
255246
256- protected void configureServices (StandardServiceRegistry registry ) {
247+ protected static void configureServices (StandardServiceRegistry registry ) {
257248 }
258249
259- @ After
260- public void after (TestContext context ) {
250+ @ AfterEach
251+ public void after (VertxTestContext context ) {
261252 test ( context , cleanDb () );
262253 }
263254
@@ -271,8 +262,8 @@ protected CompletionStage<Void> cleanDb() {
271262 : deleteEntities ( classes .toArray ( new Class <?>[0 ] ) );
272263 }
273264
274- @ AfterClass
275- public static void closeFactory (TestContext context ) {
265+ @ AfterAll
266+ public static void closeFactory () {
276267 if ( ormSessionFactory != null && ormSessionFactory .isOpen () ) {
277268 ormSessionFactory .close ();
278269 }
0 commit comments