-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configure separate source directories for HR and ORM Quarkus Panache …
…tests
- Loading branch information
Showing
12 changed files
with
389 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...kusHrPanache/java/org/hibernate/jpamodelgen/test/hrPanache/BookRepositoryWithSession.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.hibernate.jpamodelgen.test.hrPanache; | ||
|
||
import java.util.List; | ||
|
||
import org.hibernate.annotations.processing.Find; | ||
import org.hibernate.reactive.mutiny.Mutiny; | ||
|
||
import io.quarkus.hibernate.reactive.panache.common.runtime.SessionOperations; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
public interface BookRepositoryWithSession { | ||
|
||
public default Uni<Mutiny.Session> mySession() { | ||
return SessionOperations.getSession(); | ||
} | ||
|
||
@Find | ||
public Uni<List<PanacheBook>> findBook(String isbn); | ||
} |
28 changes: 28 additions & 0 deletions
28
...rator/src/quarkusHrPanache/java/org/hibernate/jpamodelgen/test/hrPanache/PanacheBook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.hibernate.jpamodelgen.test.hrPanache; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
|
||
import java.util.List; | ||
|
||
import org.hibernate.annotations.NaturalId; | ||
import org.hibernate.annotations.processing.Find; | ||
import org.hibernate.annotations.processing.HQL; | ||
|
||
import io.quarkus.hibernate.reactive.panache.PanacheEntity; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
@Entity | ||
public class PanacheBook extends PanacheEntity { | ||
public @Id String isbn; | ||
public @NaturalId String title; | ||
public @NaturalId String author; | ||
public String text; | ||
public int pages; | ||
|
||
@Find | ||
public static native Uni<List<PanacheBook>> findBook(String isbn); | ||
|
||
@HQL("WHERE isbn = :isbn") | ||
public static native Uni<List<PanacheBook>> hqlBook(String isbn); | ||
} |
19 changes: 19 additions & 0 deletions
19
...quarkusHrPanache/java/org/hibernate/jpamodelgen/test/hrPanache/PanacheBookRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.hibernate.jpamodelgen.test.hrPanache; | ||
|
||
import java.util.List; | ||
|
||
import org.hibernate.annotations.processing.Find; | ||
import org.hibernate.annotations.processing.HQL; | ||
|
||
import io.quarkus.hibernate.reactive.panache.PanacheRepository; | ||
import io.smallrye.mutiny.Uni; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class PanacheBookRepository implements PanacheRepository<PanacheBook> { | ||
@Find | ||
public native Uni<List<PanacheBook>> findBook(String isbn); | ||
|
||
@HQL("WHERE isbn = :isbn") | ||
public native Uni<List<PanacheBook>> hqlBook(String isbn); | ||
} |
22 changes: 22 additions & 0 deletions
22
...quarkusHrPanache/java/org/hibernate/jpamodelgen/test/hrPanache/QuarkusBookRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.hibernate.jpamodelgen.test.hrPanache; | ||
|
||
import java.util.List; | ||
|
||
import org.hibernate.annotations.processing.Find; | ||
import org.hibernate.annotations.processing.HQL; | ||
|
||
import io.smallrye.mutiny.Uni; | ||
|
||
public interface QuarkusBookRepository { | ||
@Find | ||
public Uni<List<PanacheBook>> findBook(String isbn); | ||
|
||
@HQL("WHERE isbn = :isbn") | ||
public Uni<List<PanacheBook>> hqlBook(String isbn); | ||
|
||
@HQL("DELETE FROM PanacheBook") | ||
public Uni<Void> deleteAllBooksVoid(); | ||
|
||
@HQL("DELETE FROM PanacheBook") | ||
public Uni<Integer> deleteAllBooksInt(); | ||
} |
151 changes: 151 additions & 0 deletions
151
.../quarkusHrPanache/java/org/hibernate/jpamodelgen/test/hrPanache/QuarkusHrPanacheTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/* | ||
* 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.hrPanache; | ||
|
||
import org.hibernate.jpamodelgen.test.util.CompilationTest; | ||
import org.hibernate.jpamodelgen.test.util.TestUtil; | ||
import org.hibernate.jpamodelgen.test.util.WithClasses; | ||
import org.junit.Test; | ||
import org.junit.jupiter.api.Assertions; | ||
|
||
import io.smallrye.mutiny.Uni; | ||
import jakarta.inject.Inject; | ||
import jakarta.persistence.EntityManager; | ||
|
||
import static org.hibernate.jpamodelgen.test.util.TestUtil.getMetamodelClassFor; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Modifier; | ||
|
||
/** | ||
* @author Gavin King | ||
*/ | ||
public class QuarkusHrPanacheTest extends CompilationTest { | ||
@Test | ||
@WithClasses({ PanacheBook.class }) | ||
public void testPanacheEntityMetamodel() throws Exception { | ||
// Panache entity | ||
System.out.println( TestUtil.getMetaModelSourceAsString( PanacheBook.class ) ); | ||
Class<?> entityClass = getMetamodelClassFor( PanacheBook.class ); | ||
Assertions.assertNotNull( entityClass ); | ||
|
||
// Make sure it has the proper supertype | ||
Class<?> superclass = entityClass.getSuperclass(); | ||
if ( superclass != null ) { | ||
Assertions.assertEquals( "io.quarkus.hibernate.reactive.panache.PanacheEntity_", superclass.getName() ); | ||
} | ||
|
||
// Panache static native method generates a static method | ||
Method method = entityClass.getDeclaredMethod( "hqlBook", Uni.class, String.class ); | ||
Assertions.assertNotNull( method ); | ||
checkUni(method); | ||
Assertions.assertTrue( Modifier.isStatic( method.getModifiers()) ); | ||
|
||
// Panache static native method generates a static method | ||
method = entityClass.getDeclaredMethod( "findBook", Uni.class, String.class ); | ||
Assertions.assertNotNull( method ); | ||
checkUni(method); | ||
Assertions.assertTrue( Modifier.isStatic( method.getModifiers() ) ); | ||
} | ||
|
||
@Test | ||
@WithClasses({ PanacheBook.class, PanacheBookRepository.class }) | ||
public void testPanacheRepositoryMetamodel() throws Exception { | ||
// Panache repository | ||
System.out.println( TestUtil.getMetaModelSourceAsString( PanacheBookRepository.class ) ); | ||
Class<?> repositoryClass = getMetamodelClassFor( PanacheBookRepository.class ); | ||
Assertions.assertNotNull( repositoryClass ); | ||
|
||
// Make sure it has the proper supertype | ||
Class<?> superclass = repositoryClass.getSuperclass(); | ||
if ( superclass != null ) { | ||
Assertions.assertEquals( "java.lang.Object", superclass.getName() ); | ||
} | ||
|
||
// Panache native method generates a static method | ||
Method method = repositoryClass.getDeclaredMethod( "hqlBook", Uni.class, String.class ); | ||
Assertions.assertNotNull( method ); | ||
checkUni(method); | ||
Assertions.assertTrue( Modifier.isStatic(method.getModifiers()) ); | ||
|
||
// Panache native method generates a static method | ||
method = repositoryClass.getDeclaredMethod( "findBook", Uni.class, String.class ); | ||
Assertions.assertNotNull( method ); | ||
checkUni(method); | ||
Assertions.assertTrue( Modifier.isStatic( method.getModifiers() ) ); | ||
} | ||
|
||
private void checkUni(Method method) { | ||
Assertions.assertEquals("io.smallrye.mutiny.Uni<org.hibernate.reactive.mutiny.Mutiny$Session>", method.getGenericParameterTypes()[0].toString()); | ||
} | ||
|
||
@Test | ||
@WithClasses({ PanacheBook.class, QuarkusBookRepository.class }) | ||
public void testQuarkusRepositoryMetamodel() throws Exception { | ||
// Regular repository | ||
System.out.println( TestUtil.getMetaModelSourceAsString( QuarkusBookRepository.class ) ); | ||
Class<?> repositoryClass = getMetamodelClassFor( QuarkusBookRepository.class ); | ||
Assertions.assertNotNull( repositoryClass ); | ||
|
||
// Make sure it has the proper supertype | ||
Class<?> superclass = repositoryClass.getSuperclass(); | ||
if ( superclass != null ) { | ||
Assertions.assertEquals( "java.lang.Object", superclass.getName() ); | ||
} | ||
Class<?>[] interfaces = repositoryClass.getInterfaces(); | ||
Assertions.assertEquals( 1, interfaces.length ); | ||
Assertions.assertEquals( QuarkusBookRepository.class.getName(), interfaces[0].getName() ); | ||
|
||
// Annotated method generates an instance method | ||
Method method = repositoryClass.getDeclaredMethod( "hqlBook", String.class ); | ||
Assertions.assertNotNull( method ); | ||
Assertions.assertFalse( Modifier.isStatic( method.getModifiers() ) ); | ||
|
||
// Annotated method generates an instance method | ||
method = repositoryClass.getDeclaredMethod( "findBook", String.class ); | ||
Assertions.assertNotNull( method ); | ||
Assertions.assertFalse( Modifier.isStatic( method.getModifiers() ) ); | ||
|
||
// Make sure we have only the default constructor | ||
Constructor<?>[] constructors = repositoryClass.getDeclaredConstructors(); | ||
Assertions.assertNotNull( constructors ); | ||
Assertions.assertEquals( 1, constructors.length ); | ||
Assertions.assertNotNull( repositoryClass.getDeclaredConstructor() ); | ||
|
||
// Proper return type | ||
method = repositoryClass.getDeclaredMethod( "deleteAllBooksVoid" ); | ||
Assertions.assertNotNull( method ); | ||
Assertions.assertEquals("io.smallrye.mutiny.Uni<java.lang.Void>", method.getGenericReturnType().toString()); | ||
Assertions.assertFalse( Modifier.isStatic( method.getModifiers() ) ); | ||
|
||
// Proper return type | ||
method = repositoryClass.getDeclaredMethod( "deleteAllBooksInt" ); | ||
Assertions.assertNotNull( method ); | ||
Assertions.assertEquals("io.smallrye.mutiny.Uni<java.lang.Integer>", method.getGenericReturnType().toString()); | ||
Assertions.assertFalse( Modifier.isStatic( method.getModifiers() ) ); | ||
} | ||
|
||
@Test | ||
@WithClasses({ PanacheBook.class, BookRepositoryWithSession.class }) | ||
public void testBookRepositoryWithSessionMetamodel() throws Exception { | ||
// Regular repository with default session method | ||
System.out.println( TestUtil.getMetaModelSourceAsString( BookRepositoryWithSession.class ) ); | ||
Class<?> repositoryClass = getMetamodelClassFor( BookRepositoryWithSession.class ); | ||
Assertions.assertNotNull( repositoryClass ); | ||
|
||
// Make sure we have only the default constructor | ||
Constructor<?>[] constructors = repositoryClass.getDeclaredConstructors(); | ||
Assertions.assertNotNull( constructors ); | ||
Assertions.assertEquals( 1, constructors.length ); | ||
Assertions.assertNotNull( repositoryClass.getDeclaredConstructor() ); | ||
|
||
// Make sure we do not override the default session method | ||
Assertions.assertThrows( NoSuchMethodException.class, () -> repositoryClass.getDeclaredMethod( "mySession" ) ); | ||
} | ||
} | ||
|
14 changes: 14 additions & 0 deletions
14
...arkusOrmPanache/java/org/hibernate/jpamodelgen/test/ormPanache/QuarkusBookRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.hibernate.jpamodelgen.test.ormPanache; | ||
|
||
import java.util.List; | ||
|
||
import org.hibernate.annotations.processing.Find; | ||
import org.hibernate.annotations.processing.HQL; | ||
|
||
public interface QuarkusBookRepository { | ||
@Find | ||
public List<PanacheBook> findBook(String isbn); | ||
|
||
@HQL("WHERE isbn = :isbn") | ||
public List<PanacheBook> hqlBook(String isbn); | ||
} |
Oops, something went wrong.