HHH-12011 - Added test case.

This commit is contained in:
Chris Cranford 2018-05-04 14:56:43 -04:00
parent 9b98e61e7f
commit 7162bf26ec
2 changed files with 111 additions and 0 deletions

View File

@ -0,0 +1,49 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpamodelgen.test.arraytype;
import org.hibernate.jpamodelgen.test.util.CompilationTest;
import org.hibernate.jpamodelgen.test.util.IgnoreCompilationErrors;
import org.hibernate.jpamodelgen.test.util.TestForIssue;
import org.hibernate.jpamodelgen.test.util.TestUtil;
import org.hibernate.jpamodelgen.test.util.WithClasses;
import org.junit.Test;
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertAttributeTypeInMetaModelFor;
/**
* @author Chris Cranford
*/
public class ArrayTestWithTypeUseTest extends CompilationTest {
@Test
@TestForIssue(jiraKey = "HHH-12011")
@WithClasses(TestEntity.class)
@IgnoreCompilationErrors
public void testArrayWithBeanValidation() {
System.out.println( TestUtil.getMetaModelSourceAsString( TestEntity.class ) );
// Primitive Arrays
assertAttributeTypeInMetaModelFor( TestEntity.class, "primitiveAnnotatedArray", byte[].class, "Wrong type for field." );
assertAttributeTypeInMetaModelFor( TestEntity.class, "primitiveArray", byte[].class, "Wrong type for field." );
// Primitive non-array
assertAttributeTypeInMetaModelFor( TestEntity.class, "primitiveAnnotated", Byte.class, "Wrong type for field." );
assertAttributeTypeInMetaModelFor( TestEntity.class, "primitive", Byte.class, "Wrong type for field." );
// Non-primitive Arrays
assertAttributeTypeInMetaModelFor( TestEntity.class, "nonPrimitiveAnnotatedArray", Byte[].class, "Wrong type for field." );
assertAttributeTypeInMetaModelFor( TestEntity.class, "nonPrimitiveArray", Byte[].class, "Wrong type for field." );
// Non-primitive non-array
assertAttributeTypeInMetaModelFor( TestEntity.class, "nonPrimitiveAnnotated", Byte.class, "Wrong type for field." );
assertAttributeTypeInMetaModelFor( TestEntity.class, "nonPrimitive", Byte.class, "Wrong type for field." );
// Custom class type array
assertAttributeTypeInMetaModelFor( TestEntity.class, "customAnnotatedArray", TestEntity.CustomType[].class, "Wrong type for field." );
assertAttributeTypeInMetaModelFor( TestEntity.class, "customArray", TestEntity.CustomType[].class, "Wrong type for field." );
}
}

View File

@ -0,0 +1,62 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpamodelgen.test.arraytype;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.persistence.Entity;
import javax.persistence.Id;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.TYPE_USE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* @author Chris Cranford
*/
@Entity
public class TestEntity {
@Id
private Integer id;
// Primitive array test
@MySize
private byte[] primitiveAnnotatedArray;
private byte[] primitiveArray;
// Primitive non-array test
@MySize
private byte primitiveAnnotated;
private byte primitive;
// Non-primitive array test
@MySize
private Byte[] nonPrimitiveAnnotatedArray;
private Byte[] nonPrimitiveArray;
// Non-primitive non-array test
@MySize
private Byte nonPrimitiveAnnotated;
private Byte nonPrimitive;
// Custom array test
@MySize
private CustomType[] customAnnotatedArray;
private CustomType[] customArray;
@Target({FIELD, TYPE_USE})
@Retention(RUNTIME)
public @interface MySize {
}
// some custom type
public static class CustomType {
private Integer id;
}
}