Skip to content

Commit 10d90c1

Browse files
blafondDavideD
authored andcommitted
[hibernate#1827] Test @EnabledFor and @DisabledFor annotations
1 parent 6104b21 commit 10d90c1

File tree

2 files changed

+184
-0
lines changed

2 files changed

+184
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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 org.hibernate.reactive.annotations.DisableFor;
9+
import org.hibernate.reactive.annotations.DisableForGroup;
10+
import org.hibernate.reactive.annotations.EnableFor;
11+
import org.hibernate.reactive.annotations.EnableForGroup;
12+
13+
import org.junit.jupiter.api.Nested;
14+
import org.junit.jupiter.api.Test;
15+
16+
import static org.assertj.core.api.Assertions.assertThat;
17+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
18+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MYSQL;
19+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.POSTGRESQL;
20+
import static org.hibernate.reactive.containers.DatabaseConfiguration.dbType;
21+
22+
public class FilterByDbTypeOnClassTest {
23+
24+
@Nested
25+
@DisableFor(value = POSTGRESQL, reason = "some reason")
26+
class DisableForOneDbType {
27+
@Test
28+
public void test() {
29+
assertThat( dbType() ).isNotIn( POSTGRESQL );
30+
}
31+
}
32+
33+
@Nested
34+
@DisableFor({POSTGRESQL, MYSQL, DB2})
35+
class DisableForMultipleDbType {
36+
@Test
37+
public void test() {
38+
assertThat( dbType() ).isNotIn( POSTGRESQL, MYSQL, DB2 );
39+
}
40+
}
41+
42+
@Nested
43+
@DisableFor(value = MYSQL, reason = "some reason")
44+
@DisableFor(value = POSTGRESQL, reason = "some reason")
45+
class DisabledForRepeatableTest {
46+
@Test
47+
public void testDisabledRepeatable() {
48+
assertThat( dbType() ).isNotIn( POSTGRESQL, MYSQL );
49+
}
50+
}
51+
52+
@Nested
53+
@DisableForGroup({
54+
@DisableFor(MYSQL),
55+
@DisableFor(POSTGRESQL)
56+
})
57+
class DisabledForGroupTest {
58+
@Test
59+
public void testDisabledRepeatable() {
60+
assertThat( dbType() ).isNotIn( POSTGRESQL, MYSQL );
61+
}
62+
}
63+
64+
@Nested
65+
@EnableFor(POSTGRESQL)
66+
class EnableForOneDbTypeTest {
67+
@Test
68+
public void test() {
69+
assertThat( dbType() ).isEqualTo( POSTGRESQL );
70+
}
71+
}
72+
73+
@Nested
74+
@EnableFor(value = {POSTGRESQL, MYSQL, DB2}, reason = "some reason")
75+
class EnableForMultipleDbTypeTest {
76+
@Test
77+
public void test() {
78+
assertThat( dbType() ).isIn( POSTGRESQL, MYSQL, DB2 );
79+
}
80+
}
81+
82+
@Nested
83+
@EnableFor(value = {POSTGRESQL, MYSQL, DB2}, reason = "some reason")
84+
class EnableRepeatableDbTypeTest {
85+
@Test
86+
public void test() {
87+
assertThat( dbType() ).isIn( POSTGRESQL, MYSQL );
88+
}
89+
}
90+
91+
@Nested
92+
@EnableForGroup({
93+
@EnableFor(MYSQL),
94+
@EnableFor(POSTGRESQL)
95+
})
96+
class EnableForGroupTest {
97+
@Test
98+
public void test() {
99+
assertThat( dbType() ).isIn( POSTGRESQL, MYSQL );
100+
}
101+
}
102+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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 org.hibernate.reactive.annotations.DisableFor;
9+
import org.hibernate.reactive.annotations.DisableForGroup;
10+
import org.hibernate.reactive.annotations.EnableFor;
11+
import org.hibernate.reactive.annotations.EnableForGroup;
12+
13+
import org.junit.jupiter.api.Test;
14+
15+
import static org.assertj.core.api.Assertions.assertThat;
16+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
17+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MYSQL;
18+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.POSTGRESQL;
19+
import static org.hibernate.reactive.containers.DatabaseConfiguration.dbType;
20+
21+
public class FilterByDbTypeOnMethodTest {
22+
23+
@Test
24+
@DisableFor(POSTGRESQL)
25+
public void testDisableOneDb() {
26+
// Throw exception if this test is run with POSTGRESQL database
27+
assertThat( dbType() ).isNotEqualTo( POSTGRESQL );
28+
}
29+
30+
@Test
31+
@DisableFor(value = {POSTGRESQL, MYSQL, DB2}, reason = "some reason")
32+
public void testDisableMultipleDbs() {
33+
// Throw exception if this test is run with POSTGRESQL database
34+
assertThat( dbType() ).isNotIn( POSTGRESQL, MYSQL, DB2 );
35+
}
36+
37+
@Test
38+
@DisableFor(value = MYSQL, reason = "some reason")
39+
@DisableFor(value = POSTGRESQL, reason = "some reason")
40+
public void testDisabledRepeatable() {
41+
// Throw exception if this test is run with POSTGRESQL or MYSQL database
42+
assertThat( dbType() ).isNotIn( POSTGRESQL, MYSQL );
43+
}
44+
45+
@Test
46+
@DisableForGroup({
47+
@DisableFor(MYSQL),
48+
@DisableFor(POSTGRESQL)
49+
})
50+
public void testDisabledForGroup() {
51+
// Throw exception if this test is run with POSTGRESQL or MYSQL database
52+
assertThat( dbType() ).isNotIn( POSTGRESQL, MYSQL );
53+
}
54+
55+
@Test
56+
@EnableFor(POSTGRESQL)
57+
public void testEnableForOneDb() {
58+
assertThat( dbType() ).isEqualTo( POSTGRESQL );
59+
}
60+
61+
@Test
62+
@EnableFor(value = {POSTGRESQL, MYSQL, DB2}, reason = "some reason")
63+
public void testEnableMultipleDbs() {
64+
assertThat( dbType() ).isIn( POSTGRESQL, MYSQL, DB2 );
65+
}
66+
67+
@Test
68+
@EnableFor(value = MYSQL, reason = "some reason")
69+
@EnableFor(value = POSTGRESQL, reason = "some reason")
70+
public void testEnableRepeatable() {
71+
assertThat( dbType() ).isIn( POSTGRESQL, MYSQL );
72+
}
73+
74+
@Test
75+
@EnableForGroup({
76+
@EnableFor(MYSQL),
77+
@EnableFor(POSTGRESQL)
78+
})
79+
public void testEnableForGroup() {
80+
assertThat( dbType() ).isIn( POSTGRESQL, MYSQL );
81+
}
82+
}

0 commit comments

Comments
 (0)