|
| 1 | +/* Hibernate, Relational Persistence for Idiomatic Java |
| 2 | + * |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + * Copyright: Red Hat Inc. and Hibernate Authors |
| 5 | + */ |
| 6 | +package org.hibernate.reactive.annotations.tests; |
| 7 | + |
| 8 | +import java.util.Set; |
| 9 | +import java.util.concurrent.CompletionStage; |
| 10 | + |
| 11 | +import org.hibernate.reactive.BaseReactiveTest; |
| 12 | +import org.hibernate.reactive.annotations.RunDBType; |
| 13 | +import org.hibernate.reactive.annotations.RunDBTypes; |
| 14 | + |
| 15 | +import org.junit.jupiter.api.Test; |
| 16 | + |
| 17 | +import io.vertx.junit5.VertxTestContext; |
| 18 | + |
| 19 | +import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2; |
| 20 | +import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MYSQL; |
| 21 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 22 | + |
| 23 | +@RunDBTypes(value = { |
| 24 | + @RunDBType(value = MYSQL), |
| 25 | + @RunDBType(value = DB2) |
| 26 | +}) |
| 27 | +public class RunDBTypesClassTest extends BaseReactiveTest { |
| 28 | + |
| 29 | + @Override |
| 30 | + protected Set<Class<?>> annotatedEntities() { |
| 31 | + return Set.of( GuineaPig.class ); |
| 32 | + } |
| 33 | + |
| 34 | + private CompletionStage<Void> populateDB() { |
| 35 | + return getSessionFactory() |
| 36 | + .withTransaction( s -> s.persist( new GuineaPig( 5, "Aloi" ) ) ); |
| 37 | + } |
| 38 | + |
| 39 | + private CompletionStage<String> selectNameFromId(Integer id) { |
| 40 | + return openSession() |
| 41 | + .thenCompose( session -> session |
| 42 | + .find( GuineaPig.class, id ) |
| 43 | + .thenCompose( pig -> session.close() |
| 44 | + .thenApply( v -> pig == null ? null : pig.getName() ) ) |
| 45 | + ); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + public void testFind_RunDB2andMYSQL_Class(VertxTestContext context) { |
| 50 | + final GuineaPig expectedPig = new GuineaPig( 5, "Aloi" ); |
| 51 | + test( |
| 52 | + context, |
| 53 | + populateDB() |
| 54 | + .thenCompose( v -> openSession() ) |
| 55 | + .thenCompose( session -> session.find( GuineaPig.class, expectedPig.getId() ) |
| 56 | + .thenAccept( actualPig -> assertEquals( 5, actualPig.getId() ) ) |
| 57 | + ) |
| 58 | + ); |
| 59 | + } |
| 60 | +} |
0 commit comments