From 17c5fab50e9a1c90a96a01498b8c95b1646194cc Mon Sep 17 00:00:00 2001 From: Vlad Mihalcea Date: Fri, 21 Feb 2020 10:11:12 +0200 Subject: [PATCH] HHH-12338 - Incorrect metamodel for basic collections --- .../MetaAttributeGenerationVisitor.java | 17 ++++ .../CollectionAsBasicTypeTest.java | 89 +++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/collectionbasictype/CollectionAsBasicTypeTest.java diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/MetaAttributeGenerationVisitor.java b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/MetaAttributeGenerationVisitor.java index 5a1117b850..58226681d7 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/MetaAttributeGenerationVisitor.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/MetaAttributeGenerationVisitor.java @@ -138,6 +138,23 @@ public class MetaAttributeGenerationVisitor extends SimpleTypeVisitor6. + */ +package org.hibernate.jpamodelgen.test.collectionbasictype; + +import org.hibernate.jpamodelgen.test.util.CompilationTest; +import org.hibernate.jpamodelgen.test.util.TestForIssue; +import org.hibernate.jpamodelgen.test.util.WithClasses; + +import org.junit.Test; + +import static org.hibernate.jpamodelgen.test.util.TestUtil.assertAttributeTypeInMetaModelFor; +import static org.hibernate.jpamodelgen.test.util.TestUtil.assertListAttributeTypeInMetaModelFor; +import static org.hibernate.jpamodelgen.test.util.TestUtil.assertMetamodelClassGeneratedFor; + +/** + * @author helloztt + */ +public class CollectionAsBasicTypeTest extends CompilationTest { + + @Test + @TestForIssue(jiraKey = "HHH-12338") + @WithClasses({Goods.class, Product.class}) + public void testConvert() throws ClassNotFoundException, NoSuchFieldException { + assertMetamodelClassGeneratedFor(Product.class); + assertMetamodelClassGeneratedFor(Goods.class); + assertListAttributeTypeInMetaModelFor( + Goods.class, + "productList", + Product.class, + "ListAttribute generic type should be Product" + ); + assertAttributeTypeInMetaModelFor( + Goods.class, + "tags", + Goods.class.getDeclaredField("tags").getGenericType(), + "Wrong meta model type" + ); + + } + + @Test + @TestForIssue(jiraKey = "HHH-12338") + @WithClasses({Person.class}) + public void testListType() throws ClassNotFoundException, NoSuchFieldException { + assertMetamodelClassGeneratedFor(Person.class); + + assertAttributeTypeInMetaModelFor( + Person.class, + "phones", + Person.class.getDeclaredField("phones").getGenericType(), + "Wrong meta model type" + ); + + } + + @Test + @TestForIssue(jiraKey = "HHH-12338") + @WithClasses({PersonPhone.class}) + public void testListTypeWithImport() throws ClassNotFoundException, NoSuchFieldException { + assertMetamodelClassGeneratedFor(PersonPhone.class); + + assertAttributeTypeInMetaModelFor( + PersonPhone.class, + "phones", + PersonPhone.class.getDeclaredField("phones").getGenericType(), + "Wrong meta model type" + ); + + } + + @Test + @TestForIssue(jiraKey = "HHH-12338") + @WithClasses({PhoneBook.class}) + public void testMapType() throws ClassNotFoundException, NoSuchFieldException { + assertMetamodelClassGeneratedFor(PhoneBook.class); + + assertAttributeTypeInMetaModelFor( + PhoneBook.class, + "phones", + PhoneBook.class.getDeclaredField("phones").getGenericType(), + "Wrong meta model type" + ); + + } +}