Skip to content

Commit 8108936

Browse files
committed
tests to verify new annotations
1 parent 8fd405d commit 8108936

File tree

7 files changed

+414
-0
lines changed

7 files changed

+414
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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.Objects;
9+
10+
import jakarta.persistence.Entity;
11+
import jakarta.persistence.Id;
12+
import jakarta.persistence.Table;
13+
14+
@Entity(name = "GuineaPig")
15+
@Table(name = "pig")
16+
public class GuineaPig {
17+
@Id
18+
private Integer id;
19+
private String name;
20+
21+
public GuineaPig() {
22+
}
23+
24+
public GuineaPig(Integer id, String name) {
25+
this.id = id;
26+
this.name = name;
27+
}
28+
29+
public Integer getId() {
30+
return id;
31+
}
32+
33+
public void setId(Integer id) {
34+
this.id = id;
35+
}
36+
37+
public String getName() {
38+
return name;
39+
}
40+
41+
public void setName(String name) {
42+
this.name = name;
43+
}
44+
45+
@Override
46+
public String toString() {
47+
return id + ": " + name;
48+
}
49+
50+
@Override
51+
public boolean equals(Object o) {
52+
if ( this == o ) {
53+
return true;
54+
}
55+
if ( o == null || getClass() != o.getClass() ) {
56+
return false;
57+
}
58+
GuineaPig guineaPig = (GuineaPig) o;
59+
return Objects.equals( name, guineaPig.name );
60+
}
61+
62+
@Override
63+
public int hashCode() {
64+
return Objects.hash( name );
65+
}
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
14+
import org.junit.jupiter.api.Test;
15+
16+
import io.vertx.junit5.VertxTestContext;
17+
18+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
19+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MYSQL;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
22+
@RunDBType(value = MYSQL)
23+
@RunDBType(value = DB2)
24+
public class RunDBTypeClassTest extends BaseReactiveTest {
25+
26+
@Override
27+
protected Set<Class<?>> annotatedEntities() {
28+
return Set.of( GuineaPig.class );
29+
}
30+
31+
private CompletionStage<Void> populateDB() {
32+
return getSessionFactory()
33+
.withTransaction( s -> s.persist( new GuineaPig( 5, "Aloi" ) ) );
34+
}
35+
36+
private CompletionStage<String> selectNameFromId(Integer id) {
37+
return openSession()
38+
.thenCompose( session -> session
39+
.find( GuineaPig.class, id )
40+
.thenCompose( pig -> session.close()
41+
.thenApply( v -> pig == null ? null : pig.getName() ) )
42+
);
43+
}
44+
45+
@Test
46+
public void testFind_RunDB2andMYSQL_Class(VertxTestContext context) {
47+
final GuineaPig expectedPig = new GuineaPig( 5, "Aloi" );
48+
test(
49+
context,
50+
populateDB()
51+
.thenCompose( v -> openSession() )
52+
.thenCompose( session -> session.find( GuineaPig.class, expectedPig.getId() )
53+
.thenAccept( actualPig -> assertEquals( 5, actualPig.getId() ) )
54+
)
55+
);
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
14+
import org.junit.jupiter.api.Test;
15+
16+
import io.vertx.junit5.VertxTestContext;
17+
18+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
19+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MYSQL;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
22+
public class RunDBTypeMethodTest extends BaseReactiveTest {
23+
24+
@Override
25+
protected Set<Class<?>> annotatedEntities() {
26+
return Set.of( GuineaPig.class );
27+
}
28+
29+
private CompletionStage<Void> populateDB() {
30+
return getSessionFactory()
31+
.withTransaction( s -> s.persist( new GuineaPig( 5, "Aloi" ) ) );
32+
}
33+
34+
private CompletionStage<String> selectNameFromId(Integer id) {
35+
return openSession()
36+
.thenCompose( session -> session
37+
.find( GuineaPig.class, id )
38+
.thenCompose( pig -> session.close()
39+
.thenApply( v -> pig == null ? null : pig.getName() ) )
40+
);
41+
}
42+
43+
@Test
44+
@RunDBType(value = DB2)
45+
@RunDBType(value = MYSQL)
46+
public void testFind_RunDB2andMYSQL_Method(VertxTestContext context) {
47+
final GuineaPig expectedPig = new GuineaPig( 5, "Aloi" );
48+
test(
49+
context,
50+
populateDB()
51+
.thenCompose( v -> openSession() )
52+
.thenCompose( session -> session.find( GuineaPig.class, expectedPig.getId() )
53+
.thenAccept( actualPig -> assertEquals( 5, actualPig.getId() ) )
54+
)
55+
);
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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.SkipDBType;
13+
14+
import org.junit.jupiter.api.Test;
15+
16+
import io.vertx.junit5.VertxTestContext;
17+
18+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
19+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MYSQL;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
22+
@SkipDBType( value = MYSQL, reason = "Reason #1")
23+
@SkipDBType( value = DB2, reason = "Reason #2")
24+
public class SkipDBTypeClassTest extends BaseReactiveTest {
25+
26+
@Override
27+
protected Set<Class<?>> annotatedEntities() {
28+
return Set.of( GuineaPig.class );
29+
}
30+
31+
private CompletionStage<Void> populateDB() {
32+
return getSessionFactory()
33+
.withTransaction( s -> s.persist( new GuineaPig( 5, "Aloi" ) ) );
34+
}
35+
36+
private CompletionStage<String> selectNameFromId(Integer id) {
37+
return openSession()
38+
.thenCompose( session -> session
39+
.find( GuineaPig.class, id )
40+
.thenCompose( pig -> session.close()
41+
.thenApply( v -> pig == null ? null : pig.getName() ) )
42+
);
43+
}
44+
45+
@Test
46+
public void testFind_SkipDB2andMYSQL_Class(VertxTestContext context) {
47+
final GuineaPig expectedPig = new GuineaPig( 5, "Aloi" );
48+
test(
49+
context,
50+
populateDB()
51+
.thenCompose( v -> openSession() )
52+
.thenCompose( session -> session.find( GuineaPig.class, expectedPig.getId() )
53+
.thenAccept( actualPig -> assertEquals( 5, actualPig.getId() ) )
54+
)
55+
);
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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.SkipDBType;
13+
14+
import org.junit.jupiter.api.Test;
15+
16+
import io.vertx.junit5.VertxTestContext;
17+
18+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
19+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MYSQL;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
22+
public class SkipDBTypeMethodTest extends BaseReactiveTest {
23+
24+
@Override
25+
protected Set<Class<?>> annotatedEntities() {
26+
return Set.of( GuineaPig.class );
27+
}
28+
29+
private CompletionStage<Void> populateDB() {
30+
return getSessionFactory()
31+
.withTransaction( s -> s.persist( new GuineaPig( 5, "Aloi" ) ) );
32+
}
33+
34+
private CompletionStage<String> selectNameFromId(Integer id) {
35+
return openSession()
36+
.thenCompose( session -> session
37+
.find( GuineaPig.class, id )
38+
.thenCompose( pig -> session.close()
39+
.thenApply( v -> pig == null ? null : pig.getName() ) )
40+
);
41+
}
42+
43+
@SkipDBType( value = MYSQL, reason = "Reason #1")
44+
@SkipDBType( value = DB2, reason = "Reason #2")
45+
@Test
46+
public void testFind_SkipDB2andMYSQL_Class(VertxTestContext context) {
47+
final GuineaPig expectedPig = new GuineaPig( 5, "Aloi" );
48+
test(
49+
context,
50+
populateDB()
51+
.thenCompose( v -> openSession() )
52+
.thenCompose( session -> session.find( GuineaPig.class, expectedPig.getId() )
53+
.thenAccept( actualPig -> assertEquals( 5, actualPig.getId() ) )
54+
)
55+
);
56+
}
57+
}

0 commit comments

Comments
 (0)