1111import jakarta .persistence .OneToOne ;
1212import jakarta .persistence .Table ;
1313import jakarta .persistence .UniqueConstraint ;
14-
1514import org .hibernate .boot .model .relational .Namespace ;
15+ import org .hibernate .boot .spi .MetadataImplementor ;
1616import org .hibernate .mapping .Column ;
1717import org .hibernate .mapping .ForeignKey ;
1818import org .hibernate .mapping .UniqueKey ;
19-
19+ import org . hibernate . testing . orm . junit . DomainModel ;
2020import org .hibernate .testing .orm .junit .JiraKey ;
21- import org .hibernate .testing .junit4 .BaseNonConfigCoreFunctionalTestCase ;
22- import org .junit .Test ;
21+ import org .hibernate .testing .orm .junit .SessionFactory ;
22+ import org .hibernate .testing .orm .junit .SessionFactoryScope ;
23+ import org .junit .jupiter .api .Test ;
2324
24- import static org .junit .Assert .assertEquals ;
25- import static org .junit .Assert .assertFalse ;
26- import static org .junit .Assert .assertTrue ;
25+ import static org .assertj .core .api .Assertions .assertThat ;
2726
2827/**
2928 * @author Brett Meyer
3029 */
31- public class ConstraintTest extends BaseNonConfigCoreFunctionalTestCase {
30+ @ DomainModel (
31+ annotatedClasses = {
32+ ConstraintTest .DataPoint .class ,
33+ ConstraintTest .DataPoint2 .class
34+ }
35+ )
36+ @ SessionFactory
37+ public class ConstraintTest {
3238
3339 private static final int MAX_NAME_LENGTH = 30 ;
3440
@@ -38,91 +44,91 @@ public class ConstraintTest extends BaseNonConfigCoreFunctionalTestCase {
3844
3945 private static final String EXPLICIT_UK_NAME = "uk_explicit" ;
4046
41- @ Override
42- protected Class <?>[] getAnnotatedClasses () {
43- return new Class <?>[] { DataPoint .class , DataPoint2 .class };
44- }
45-
4647 @ Test
47- @ JiraKey ( value = "HHH-7797" )
48- public void testUniqueConstraints () {
49- Column column = (Column ) metadata ().getEntityBinding ( DataPoint .class .getName () )
48+ @ JiraKey (value = "HHH-7797" )
49+ public void testUniqueConstraints (SessionFactoryScope scope ) {
50+ MetadataImplementor metadata = scope .getMetadataImplementor ();
51+ Column column = (Column ) metadata .getEntityBinding ( DataPoint .class .getName () )
5052 .getProperty ( "foo1" ).getSelectables ().get ( 0 );
51- assertFalse ( column .isNullable () );
52- assertTrue ( column .isUnique () );
53+ assertThat ( column .isNullable () ). isFalse ( );
54+ assertThat ( column .isUnique () ). isTrue ( );
5355
54- column = (Column ) metadata () .getEntityBinding ( DataPoint .class .getName () )
56+ column = (Column ) metadata .getEntityBinding ( DataPoint .class .getName () )
5557 .getProperty ( "foo2" ).getSelectables ().get ( 0 );
56- assertTrue ( column .isNullable () );
57- assertTrue ( column .isUnique () );
58+ assertThat ( column .isNullable () ). isTrue ( );
59+ assertThat ( column .isUnique () ). isTrue ( );
5860
59- column = (Column ) metadata () .getEntityBinding ( DataPoint .class .getName () )
61+ column = (Column ) metadata .getEntityBinding ( DataPoint .class .getName () )
6062 .getProperty ( "id" ).getSelectables ().get ( 0 );
61- assertFalse ( column .isNullable () );
62- assertTrue ( column .isUnique () );
63+ assertThat ( column .isNullable () ). isFalse ( );
64+ assertThat ( column .isUnique () ). isTrue ( );
6365 }
6466
6567 @ Test
66- @ JiraKey ( value = "HHH-1904" )
67- public void testConstraintNameLength () {
68+ @ JiraKey (value = "HHH-1904" )
69+ public void testConstraintNameLength (SessionFactoryScope scope ) {
70+ MetadataImplementor metadata = scope .getMetadataImplementor ();
71+
6872 int foundCount = 0 ;
69- for ( Namespace namespace : metadata () .getDatabase ().getNamespaces () ) {
73+ for ( Namespace namespace : metadata .getDatabase ().getNamespaces () ) {
7074 for ( org .hibernate .mapping .Table table : namespace .getTables () ) {
7175 for ( ForeignKey fk : table .getForeignKeyCollection () ) {
72- assertTrue ( fk .getName ().length () <= MAX_NAME_LENGTH );
76+ assertThat ( fk .getName ().length () ). isLessThanOrEqualTo ( MAX_NAME_LENGTH );
7377
7478 // ensure the randomly generated constraint name doesn't
7579 // happen if explicitly given
7680 Column column = fk .getColumn ( 0 );
7781 if ( column .getName ().equals ( "explicit_native" ) ) {
7882 foundCount ++;
79- assertEquals ( EXPLICIT_FK_NAME_NATIVE , fk .getName () );
83+ assertThat ( fk .getName () ). isEqualTo ( EXPLICIT_FK_NAME_NATIVE );
8084 }
8185 else if ( column .getName ().equals ( "explicit_jpa" ) ) {
8286 foundCount ++;
83- assertEquals ( EXPLICIT_FK_NAME_JPA , fk .getName () );
87+ assertThat ( fk .getName () ). isEqualTo ( EXPLICIT_FK_NAME_JPA );
8488 }
8589 }
8690
8791 for ( UniqueKey uk : table .getUniqueKeys ().values () ) {
88- assertTrue ( uk .getName ().length () <= MAX_NAME_LENGTH );
92+ assertThat ( uk .getName ().length () ). isLessThanOrEqualTo ( MAX_NAME_LENGTH );
8993
9094 // ensure the randomly generated constraint name doesn't
9195 // happen if explicitly given
9296 Column column = uk .getColumn ( 0 );
9397 if ( column .getName ().equals ( "explicit" ) ) {
9498 foundCount ++;
95- assertEquals ( EXPLICIT_UK_NAME , uk .getName () );
99+ assertThat ( uk .getName () ). isEqualTo ( EXPLICIT_UK_NAME );
96100 }
97101 }
98102 }
99103
100104 }
101105
102- assertEquals ("Could not find the necessary columns." , 3 , foundCount );
106+ assertThat ( foundCount )
107+ .describedAs ( "Could not find the necessary columns." )
108+ .isEqualTo ( 3 );
103109 }
104110
105111 @ Entity
106- @ Table ( name = "DataPoint" , uniqueConstraints = {
107- @ UniqueConstraint ( name = EXPLICIT_UK_NAME , columnNames = { "explicit" } )
108- } )
112+ @ Table (name = "DataPoint" , uniqueConstraints = {
113+ @ UniqueConstraint (name = EXPLICIT_UK_NAME , columnNames = {"explicit" } )
114+ })
109115 public static class DataPoint {
110116 @ Id
111117 @ GeneratedValue
112- @ jakarta .persistence .Column ( nullable = false , unique = true )
118+ @ jakarta .persistence .Column (nullable = false , unique = true )
113119 public long id ;
114120
115- @ jakarta .persistence .Column ( nullable = false , unique = true )
121+ @ jakarta .persistence .Column (nullable = false , unique = true )
116122 public String foo1 ;
117123
118- @ jakarta .persistence .Column ( nullable = true , unique = true )
124+ @ jakarta .persistence .Column (unique = true )
119125 public String foo2 ;
120126
121127 public String explicit ;
122128 }
123129
124130 @ Entity
125- @ Table ( name = "DataPoint2" )
131+ @ Table (name = "DataPoint2" )
126132 public static class DataPoint2 {
127133 @ Id
128134 @ GeneratedValue
0 commit comments