Start of tests
This commit is contained in:
parent
b32296ff32
commit
7c453fb6b6
|
@ -18,6 +18,28 @@ ext {
|
|||
xsdDir = file( "${projectDir}/src/main/xsd" )
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
quarkusOrmPanache {
|
||||
compileClasspath += sourceSets.main.output
|
||||
compileClasspath += sourceSets.test.output
|
||||
runtimeClasspath += sourceSets.main.output
|
||||
runtimeClasspath += sourceSets.test.output
|
||||
}
|
||||
quarkusHrPanache {
|
||||
compileClasspath += sourceSets.main.output
|
||||
compileClasspath += sourceSets.test.output
|
||||
runtimeClasspath += sourceSets.main.output
|
||||
runtimeClasspath += sourceSets.test.output
|
||||
}
|
||||
}
|
||||
|
||||
configurations {
|
||||
quarkusOrmPanacheImplementation.extendsFrom testImplementation
|
||||
quarkusOrmPanacheRuntimeOnly.extendsFrom runtimeOnly
|
||||
quarkusHrPanacheImplementation.extendsFrom testImplementation
|
||||
quarkusHrPanacheRuntimeOnly.extendsFrom runtimeOnly
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// api - ewww... but Maven needs them this way
|
||||
api project( ':hibernate-core' )
|
||||
|
@ -31,8 +53,51 @@ dependencies {
|
|||
xjc jakartaLibs.xjc
|
||||
xjc jakartaLibs.jaxb
|
||||
xjc rootProject.fileTree(dir: 'patched-libs/jaxb2-basics', include: '*.jar')
|
||||
|
||||
quarkusOrmPanacheImplementation "io.quarkus:quarkus-hibernate-orm-panache:3.6.2"
|
||||
quarkusOrmPanacheImplementation project( ":hibernate-testing" )
|
||||
quarkusOrmPanacheImplementation 'org.checkerframework:checker-qual:3.4.0'
|
||||
|
||||
quarkusHrPanacheImplementation "io.quarkus:quarkus-hibernate-hr-panache:3.6.2"
|
||||
quarkusHrPanacheImplementation project( ":hibernate-testing" )
|
||||
quarkusHrPanacheImplementation 'org.checkerframework:checker-qual:3.4.0'
|
||||
}
|
||||
|
||||
def quarkusOrmPanacheTestTask = tasks.register( 'quarkusOrmPanacheTest', Test ) {
|
||||
description = 'Runs the Quarkus ORM Panache tests.'
|
||||
group = 'verification'
|
||||
|
||||
testClassesDirs = sourceSets.quarkusOrmPanache.output.classesDirs
|
||||
classpath = sourceSets.quarkusOrmPanache.runtimeClasspath
|
||||
shouldRunAfter test
|
||||
dependsOn test
|
||||
|
||||
useJUnitPlatform()
|
||||
|
||||
testLogging {
|
||||
events "passed"
|
||||
}
|
||||
}
|
||||
|
||||
def quarkusHrPanacheTestTask = tasks.register( 'quarkusHrPanacheTest', Test ) {
|
||||
description = 'Runs the Quarkus HR Panache tests.'
|
||||
group = 'verification'
|
||||
|
||||
testClassesDirs = sourceSets.quarkusHrPanache.output.classesDirs
|
||||
classpath = sourceSets.quarkusHrPanache.runtimeClasspath
|
||||
shouldRunAfter test
|
||||
dependsOn test
|
||||
|
||||
useJUnitPlatform()
|
||||
|
||||
testLogging {
|
||||
events "passed"
|
||||
}
|
||||
}
|
||||
|
||||
check.dependsOn quarkusHrPanacheTestTask
|
||||
check.dependsOn quarkusOrmPanacheTestTask
|
||||
|
||||
sourceSets.main {
|
||||
java.srcDir xjcTargetDir
|
||||
resources.srcDir xsdDir
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package org.hibernate.jpamodelgen.test.ormPanache;
|
||||
|
||||
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.orm.panache.PanacheEntity;
|
||||
|
||||
@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 List<PanacheBook> findBook(String isbn);
|
||||
|
||||
@HQL("WHERE isbn = :isbn")
|
||||
public static native List<PanacheBook> hqlBook(String isbn);
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package org.hibernate.jpamodelgen.test.ormPanache;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.annotations.processing.Find;
|
||||
import org.hibernate.annotations.processing.HQL;
|
||||
|
||||
import io.quarkus.hibernate.orm.panache.PanacheRepository;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
|
||||
@ApplicationScoped
|
||||
public class PanacheBookRepository implements PanacheRepository<PanacheBook> {
|
||||
@Find
|
||||
public native List<PanacheBook> findBook(String isbn);
|
||||
|
||||
@HQL("WHERE isbn = :isbn")
|
||||
public native List<PanacheBook> hqlBook(String isbn);
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* 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.ormPanache;
|
||||
|
||||
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 jakarta.persistence.EntityManager;
|
||||
|
||||
import static org.hibernate.jpamodelgen.test.util.TestUtil.getMetamodelClassFor;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class QuarkusOrmPanacheTest 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.orm.panache.PanacheEntity_", superclass.getName());
|
||||
}
|
||||
|
||||
// Panache static native method generates a static method
|
||||
Method method = entityClass.getDeclaredMethod("hqlBook", EntityManager.class, String.class);
|
||||
Assertions.assertNotNull(method);
|
||||
Assertions.assertTrue(Modifier.isStatic(method.getModifiers()));
|
||||
|
||||
// Panache static native method generates a static method
|
||||
method = entityClass.getDeclaredMethod("findBook", EntityManager.class, String.class);
|
||||
Assertions.assertNotNull(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", EntityManager.class, String.class);
|
||||
Assertions.assertNotNull(method);
|
||||
Assertions.assertTrue(Modifier.isStatic(method.getModifiers()));
|
||||
|
||||
// Panache native method generates a static method
|
||||
method = repositoryClass.getDeclaredMethod("findBook", EntityManager.class, String.class);
|
||||
Assertions.assertNotNull(method);
|
||||
Assertions.assertTrue(Modifier.isStatic(method.getModifiers()));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue