HHH-8960 Formatting and fixing order of expected and actual values in some assertEquals statements

This commit is contained in:
Hardy Ferentschik 2014-02-11 15:35:23 +01:00
parent 284e219fd3
commit c46dbebc5b
2 changed files with 41 additions and 26 deletions

View File

@ -23,75 +23,86 @@
*/ */
package org.hibernate.test.annotations.beanvalidation; package org.hibernate.test.annotations.beanvalidation;
import org.hibernate.cfg.Configuration; import org.junit.Test;
import org.hibernate.metamodel.spi.relational.PrimaryKey;
import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.cfg.Configuration;
import org.hibernate.metamodel.spi.relational.Column;
import org.hibernate.metamodel.spi.relational.PrimaryKey;
import org.hibernate.test.util.SchemaUtil;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.test.util.SchemaUtil;
import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
/** /**
* Test verifying that DDL constraints get applied when Bean Validation / Hibernate Validator are enabled. * Test verifying that DDL constraints get applied when Bean Validation / Hibernate Validator is enabled.
* *
* @author Emmanuel Bernard * @author Emmanuel Bernard
* @author Hardy Ferentschik * @author Hardy Ferentschik
*/ */
public class DDLTest extends BaseCoreFunctionalTestCase { public class DDLTest extends BaseCoreFunctionalTestCase {
@Test @Test
@FailureExpectedWithNewMetamodel
public void testBasicDDL() { public void testBasicDDL() {
org.hibernate.metamodel.spi.relational.Column stateColumn = SchemaUtil.getColumn( Address.class, "state", metadata() ); Column stateColumn = SchemaUtil.getColumn(
assertEquals( stateColumn.getSize().getLength(), 3 ); Address.class,
org.hibernate.metamodel.spi.relational.Column zipColumn = SchemaUtil.getColumn( Address.class, "zip", metadata() ); "state",
assertEquals( zipColumn.getSize().getLength(), 5 ); metadata()
);
assertEquals( 3, stateColumn.getSize().getLength() );
Column zipColumn = SchemaUtil.getColumn(
Address.class,
"zip",
metadata()
);
assertEquals( 5, zipColumn.getSize().getLength() );
assertFalse( zipColumn.isNullable() ); assertFalse( zipColumn.isNullable() );
} }
@Test @Test
@FailureExpectedWithNewMetamodel
public void testApplyOnIdColumn() throws Exception { public void testApplyOnIdColumn() throws Exception {
PrimaryKey id = SchemaUtil.getPrimaryKey( Tv.class, metadata() ); PrimaryKey id = SchemaUtil.getPrimaryKey( Tv.class, metadata() );
assertEquals( "Validator annotation not applied on ids", 2, id.getColumns().get( 0 ).getSize().getLength() ); assertEquals( "Validator annotation not applied on ids", 2, id.getColumns().get( 0 ).getSize().getLength() );
} }
@Test @Test
@TestForIssue( jiraKey = "HHH-5281" ) @TestForIssue(jiraKey = "HHH-5281")
@FailureExpectedWithNewMetamodel
public void testLengthConstraint() throws Exception { public void testLengthConstraint() throws Exception {
org.hibernate.metamodel.spi.relational.Column column = SchemaUtil.getColumn( Tv.class, "model", metadata() ); Column column = SchemaUtil.getColumn( Tv.class, "model", metadata() );
assertEquals( column.getSize().getLength(), 5 ); assertEquals( 5, column.getSize().getLength() );
} }
@Test @Test
@FailureExpectedWithNewMetamodel
public void testApplyOnManyToOne() throws Exception { public void testApplyOnManyToOne() throws Exception {
org.hibernate.metamodel.spi.relational.Column column = SchemaUtil.getColumn( TvOwner.class, "tv_serial", metadata() ); org.hibernate.metamodel.spi.relational.Column column = SchemaUtil.getColumn(
assertEquals( "Validator annotations not applied on associations", false, column.isNullable() ); TvOwner.class,
"tv_serial",
metadata()
);
assertFalse( "@NotNull on @ManyToOne should be applied", column.isNullable() );
} }
@Test @Test
public void testSingleTableAvoidNotNull() throws Exception { public void testSingleTableAvoidNotNull() throws Exception {
org.hibernate.metamodel.spi.relational.Column column = SchemaUtil.getColumn( Rock.class, "bit", metadata() ); Column column = SchemaUtil.getColumn( Rock.class, "bit", metadata() );
assertTrue( "Notnull should not be applied on single tables", column.isNullable() ); assertTrue( "Notnull should not be applied on single tables", column.isNullable() );
} }
@Test @Test
@FailureExpectedWithNewMetamodel
public void testNotNullOnlyAppliedIfEmbeddedIsNotNullItself() throws Exception { public void testNotNullOnlyAppliedIfEmbeddedIsNotNullItself() throws Exception {
org.hibernate.metamodel.spi.relational.Column column = SchemaUtil.getColumn( Tv.class, "frequency", metadata() ); Column column = SchemaUtil.getColumn(
assertEquals( Tv.class,
"Validator annotations are applied on tuner as it is @NotNull", false, column.isNullable() "frequency",
metadata()
);
assertFalse(
"Validator annotations are applied on tuner as it is @NotNull", column.isNullable()
); );
column = SchemaUtil.getColumn( Tv.class, "`time`", metadata() ); column = SchemaUtil.getColumn( Tv.class, "`time`", metadata() );
assertEquals( assertTrue(
"Validator annotations were not applied on recorder", true, column.isNullable() "Validator annotations were not applied on recorder", column.isNullable()
); );
} }

View File

@ -23,13 +23,17 @@
*/ */
package org.hibernate.test.annotations.beanvalidation; package org.hibernate.test.annotations.beanvalidation;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
@Entity @Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class Music { public class Music {
@Id @Id
public String name; public String name;