1616import org .hibernate .boot .registry .StandardServiceRegistry ;
1717import org .hibernate .boot .registry .StandardServiceRegistryBuilder ;
1818import org .hibernate .boot .spi .MetadataImplementor ;
19+ import org .hibernate .community .dialect .InformixDialect ;
1920import org .hibernate .dialect .Dialect ;
2021import org .hibernate .engine .jdbc .env .spi .IdentifierHelper ;
2122import org .hibernate .engine .jdbc .env .spi .JdbcEnvironment ;
23+ import org .hibernate .testing .orm .junit .SkipForDialect ;
2224import org .hibernate .tool .hbm2ddl .SchemaExport ;
2325import org .hibernate .tool .schema .TargetType ;
2426
2931import org .junit .Before ;
3032import org .junit .Test ;
3133
34+ import static org .hamcrest .MatcherAssert .assertThat ;
3235import static org .hamcrest .Matchers .containsString ;
3336import static org .hamcrest .Matchers .hasItem ;
34- import static org .junit .Assert .assertThat ;
3537
3638/**
3739 * @author Andrea Boriero
3840 */
39-
41+ @ SkipForDialect (dialectClass = InformixDialect .class ,
42+ reason = "Informix has a strange syntax for 'alter table add constraint'" )
4043public class ForeignKeyGenerationTest extends BaseUnitTestCase {
4144 private File output ;
4245 private StandardServiceRegistry ssr ;
43- private MetadataImplementor metadata ;
4446
4547 @ Before
4648 public void setUp () throws IOException {
@@ -150,13 +152,13 @@ alter table EMPLOYEE_PROJECT add constraint FK_PROJECT foreign key (PROJECT_ID)
150152 ) );
151153 }
152154
153- private void createSchema (Class [] annotatedClasses ) {
155+ private void createSchema (Class <?> [] annotatedClasses ) {
154156 final MetadataSources metadataSources = new MetadataSources ( ssr );
155157
156- for ( Class c : annotatedClasses ) {
158+ for ( Class <?> c : annotatedClasses ) {
157159 metadataSources .addAnnotatedClass ( c );
158160 }
159- metadata = (MetadataImplementor ) metadataSources .buildMetadata ();
161+ final MetadataImplementor metadata = (MetadataImplementor ) metadataSources .buildMetadata ();
160162 metadata .orderColumns ( false );
161163 metadata .validate ();
162164 new SchemaExport ()
@@ -171,7 +173,8 @@ private void checkAlterTableStatement(AlterTableStatement alterTableStatement)
171173 final String expectedAlterTableStatement = alterTableStatement .toSQL ();
172174 final List <String > sqlLines = Files .readAllLines ( output .toPath (), Charset .defaultCharset () );
173175
174- assertThat ( "Expected alter table statement not found" , sqlLines , hasItem ( containsString ( expectedAlterTableStatement ) ) );
176+ assertThat ( "Expected alter table statement not found" , sqlLines ,
177+ hasItem ( containsString ( expectedAlterTableStatement ) ) );
175178 }
176179
177180 private static class AlterTableStatement {
@@ -195,7 +198,7 @@ public AlterTableStatement(
195198 }
196199
197200 public String toSQL () {
198- JdbcEnvironment jdbcEnvironment = ssr .getService ( JdbcEnvironment .class );
201+ JdbcEnvironment jdbcEnvironment = ssr .requireService ( JdbcEnvironment .class );
199202 Dialect dialect = jdbcEnvironment .getDialect ();
200203 IdentifierHelper identifierHelper = jdbcEnvironment .getIdentifierHelper ();
201204 UnaryOperator <String > asIdentifier = identifier -> identifierHelper .toIdentifier ( identifier ).render ( dialect );
0 commit comments