|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 | + * Copyright Red Hat Inc. and Hibernate Authors |
| 4 | + */ |
| 5 | +package org.hibernate.processor.test.data.innerclass; |
| 6 | + |
| 7 | +import jakarta.persistence.Entity; |
| 8 | +import jakarta.persistence.EntityManager; |
| 9 | +import jakarta.persistence.Id; |
| 10 | +import jakarta.persistence.NamedQuery; |
| 11 | +import org.hibernate.processor.test.data.innerclass.InnerClassTest.One.Two; |
| 12 | +import org.hibernate.processor.test.util.CompilationTest; |
| 13 | +import org.hibernate.processor.test.util.WithClasses; |
| 14 | +import org.junit.Test; |
| 15 | + |
| 16 | +import static org.hibernate.processor.test.util.TestUtil.assertMetamodelClassGeneratedFor; |
| 17 | +import static org.hibernate.processor.test.util.TestUtil.assertNoMetamodelClassGeneratedFor; |
| 18 | +import static org.hibernate.processor.test.util.TestUtil.assertPresenceOfFieldInMetamodelFor; |
| 19 | +import static org.hibernate.processor.test.util.TestUtil.assertPresenceOfMethodInMetamodelFor; |
| 20 | +import static org.hibernate.processor.test.util.TestUtil.getMetaModelSourceAsString; |
| 21 | +import static org.junit.Assert.assertEquals; |
| 22 | + |
| 23 | +public class InnerClassTest extends CompilationTest { |
| 24 | + |
| 25 | + @WithClasses({Person.class, Dummy.class, Inner.class, Two.class}) |
| 26 | + @Test |
| 27 | + public void test() { |
| 28 | + System.out.println( getMetaModelSourceAsString( InnerClassTest.class ) ); |
| 29 | + System.out.println( getMetaModelSourceAsString( Dummy.class ) ); |
| 30 | + System.out.println( getMetaModelSourceAsString( Person.class ) ); |
| 31 | + System.out.println( getMetaModelSourceAsString( InnerClassTest.class, true ) ); |
| 32 | + System.out.println( getMetaModelSourceAsString( Dummy.class, true ) ); |
| 33 | + System.out.println( getMetaModelSourceAsString( Person.class, true ) ); |
| 34 | + assertEquals( |
| 35 | + getMetaModelSourceAsString( Inner.class ), |
| 36 | + getMetaModelSourceAsString( Two.class ) |
| 37 | + ); |
| 38 | + assertEquals( |
| 39 | + getMetaModelSourceAsString( Inner.class, true ), |
| 40 | + getMetaModelSourceAsString( Two.class, true ) |
| 41 | + ); |
| 42 | + assertMetamodelClassGeneratedFor( Inner.class ); |
| 43 | + assertMetamodelClassGeneratedFor( Inner.class, true ); |
| 44 | + assertMetamodelClassGeneratedFor( Two.class ); |
| 45 | + assertMetamodelClassGeneratedFor( Two.class, true ); |
| 46 | + assertMetamodelClassGeneratedFor( Dummy.Inner.class ); |
| 47 | + assertMetamodelClassGeneratedFor( Dummy.Inner.class, true ); |
| 48 | + assertMetamodelClassGeneratedFor( Person.class ); |
| 49 | + assertMetamodelClassGeneratedFor( Person.class, true ); |
| 50 | + assertMetamodelClassGeneratedFor( Person.PersonId.class ); |
| 51 | + assertNoMetamodelClassGeneratedFor( Dummy.class ); |
| 52 | + assertMetamodelClassGeneratedFor( Dummy.DummyEmbeddable.class ); |
| 53 | + assertMetamodelClassGeneratedFor( Dummy.ThePerson.class ); |
| 54 | + assertMetamodelClassGeneratedFor( Dummy.ThePerson.class, true ); |
| 55 | + /*assertNoMetamodelClassGeneratedFor( Dummy.class );*/ |
| 56 | + assertPresenceOfFieldInMetamodelFor( Dummy.ThePerson.class, "QUERY_SELECT_THE_PERSON_NAME" ); |
| 57 | + assertPresenceOfMethodInMetamodelFor( Dummy.ThePerson.class, "selectThePersonName", EntityManager.class ); |
| 58 | + } |
| 59 | + |
| 60 | + @Entity(name = "Inner") |
| 61 | + @NamedQuery(name = "allInner", query = "from Inner") |
| 62 | + public static class Inner { |
| 63 | + @Id |
| 64 | + Integer id; |
| 65 | + |
| 66 | + String address; |
| 67 | + |
| 68 | + public Integer getId() { |
| 69 | + return id; |
| 70 | + } |
| 71 | + |
| 72 | + public void setId(Integer id) { |
| 73 | + this.id = id; |
| 74 | + } |
| 75 | + |
| 76 | + public String getAddress() { |
| 77 | + return address; |
| 78 | + } |
| 79 | + |
| 80 | + public void setAddress(String address) { |
| 81 | + this.address = address; |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + static class One { |
| 86 | + @Entity |
| 87 | + static class Two { |
| 88 | + @Id |
| 89 | + Integer id; |
| 90 | + String value; |
| 91 | + } |
| 92 | + } |
| 93 | +} |
0 commit comments