|
| 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.namedentity; |
| 6 | + |
| 7 | +import jakarta.persistence.TypedQueryReference; |
| 8 | +import org.hibernate.processor.test.util.CompilationTest; |
| 9 | +import org.hibernate.processor.test.util.WithClasses; |
| 10 | +import org.junit.Test; |
| 11 | + |
| 12 | +import java.lang.reflect.Field; |
| 13 | +import java.lang.reflect.ParameterizedType; |
| 14 | +import java.lang.reflect.Type; |
| 15 | + |
| 16 | +import static org.hibernate.processor.test.util.TestUtil.assertMetamodelClassGeneratedFor; |
| 17 | +import static org.hibernate.processor.test.util.TestUtil.assertPresenceOfFieldInMetamodelFor; |
| 18 | +import static org.hibernate.processor.test.util.TestUtil.getFieldFromMetamodelFor; |
| 19 | +import static org.hibernate.processor.test.util.TestUtil.getMetaModelSourceAsString; |
| 20 | +import static org.junit.Assert.assertEquals; |
| 21 | +import static org.junit.Assert.assertTrue; |
| 22 | + |
| 23 | +public class NamedEntityTest extends CompilationTest { |
| 24 | + |
| 25 | + @Test |
| 26 | + @WithClasses(Book.class) |
| 27 | + public void test() { |
| 28 | + System.out.println( getMetaModelSourceAsString( Book.class ) ); |
| 29 | + |
| 30 | + assertMetamodelClassGeneratedFor( Book.class ); |
| 31 | + |
| 32 | + assertPresenceOfFieldInMetamodelFor( Book.class, "QUERY_FIND_ALL_BOOKS" ); |
| 33 | + final Field field = getFieldFromMetamodelFor( Book.class, "_findAllBooks_" ); |
| 34 | + assertEquals( TypedQueryReference.class, field.getType() ); |
| 35 | + final Type genericType = field.getGenericType(); |
| 36 | + assertTrue( genericType instanceof ParameterizedType ); |
| 37 | + final ParameterizedType parameterizedType = (ParameterizedType) genericType; |
| 38 | + assertEquals( Book.class, parameterizedType.getActualTypeArguments()[0] ); |
| 39 | + } |
| 40 | +} |
0 commit comments