HHH-16887 smoke test HQL validation
This commit is contained in:
parent
28b1670d18
commit
a2defad7a4
|
@ -1,8 +1,7 @@
|
|||
package org.hibernate.jpamodelgen.test.querymethod;
|
||||
package org.hibernate.jpamodelgen.test.hqlsql;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.NamedEntityGraph;
|
||||
|
||||
@Entity
|
||||
public class Book {
|
|
@ -1,4 +1,4 @@
|
|||
package org.hibernate.jpamodelgen.test.querymethod;
|
||||
package org.hibernate.jpamodelgen.test.hqlsql;
|
||||
|
||||
import jakarta.persistence.TypedQuery;
|
||||
import org.hibernate.annotations.processing.HQL;
|
|
@ -4,7 +4,7 @@
|
|||
* 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.querymethod;
|
||||
package org.hibernate.jpamodelgen.test.hqlsql;
|
||||
|
||||
import org.hibernate.jpamodelgen.test.util.CompilationTest;
|
||||
import org.hibernate.jpamodelgen.test.util.TestUtil;
|
|
@ -0,0 +1,11 @@
|
|||
package org.hibernate.jpamodelgen.test.hqlvalidation;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class Book {
|
||||
@Id String isbn;
|
||||
String title;
|
||||
String text;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package org.hibernate.jpamodelgen.test.hqlvalidation;
|
||||
|
||||
import jakarta.persistence.TypedQuery;
|
||||
import org.hibernate.annotations.processing.HQL;
|
||||
import org.hibernate.annotations.processing.SQL;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Dao1 {
|
||||
@HQL("from Book where title like ?1")
|
||||
TypedQuery<Book> findByTitle(String title);
|
||||
|
||||
@HQL("from Book where title like ?1 order by title fetch first ?2 rows only")
|
||||
List<Book> findFirstNByTitle(String title, int N);
|
||||
|
||||
@HQL("from Boook where isbn = :isbn")
|
||||
Book findByIsbn(String isbn);
|
||||
|
||||
@SQL("select * from Book where isbn = :isbn")
|
||||
Book findByIsbnNative(String isbn);
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package org.hibernate.jpamodelgen.test.hqlvalidation;
|
||||
|
||||
import jakarta.persistence.TypedQuery;
|
||||
import org.hibernate.annotations.processing.HQL;
|
||||
import org.hibernate.annotations.processing.SQL;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Dao2 {
|
||||
@HQL("from Book where tile like ?1")
|
||||
TypedQuery<Book> findByTitle(String title);
|
||||
|
||||
@HQL("from Book where title like ?1 order by title fetch first ?2 rows only")
|
||||
List<Book> findFirstNByTitle(String title, int N);
|
||||
|
||||
@HQL("from Book where isbn = :isbn")
|
||||
Book findByIsbn(String isbn);
|
||||
|
||||
@SQL("select * from Book where isbn = :isbn")
|
||||
Book findByIsbnNative(String isbn);
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* 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.hqlvalidation;
|
||||
|
||||
import org.hibernate.jpamodelgen.test.util.CompilationTest;
|
||||
import org.hibernate.jpamodelgen.test.util.IgnoreCompilationErrors;
|
||||
import org.hibernate.jpamodelgen.test.util.TestUtil;
|
||||
import org.hibernate.jpamodelgen.test.util.WithClasses;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertNoMetamodelClassGeneratedFor;
|
||||
|
||||
/**
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class ValidationTest extends CompilationTest {
|
||||
@Test @IgnoreCompilationErrors
|
||||
@WithClasses({ Book.class, Dao1.class })
|
||||
public void testError1() {
|
||||
System.out.println( TestUtil.getMetaModelSourceAsString( Dao1.class ) );
|
||||
assertNoMetamodelClassGeneratedFor( Book.class );
|
||||
assertNoMetamodelClassGeneratedFor( Dao1.class );
|
||||
}
|
||||
|
||||
@Test @IgnoreCompilationErrors
|
||||
@WithClasses({ Book.class, Dao2.class })
|
||||
public void testError2() {
|
||||
System.out.println( TestUtil.getMetaModelSourceAsString( Dao2.class ) );
|
||||
assertNoMetamodelClassGeneratedFor( Book.class );
|
||||
assertNoMetamodelClassGeneratedFor( Dao2.class );
|
||||
}
|
||||
}
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
package org.hibernate.jpamodelgen.test.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
@ -35,10 +34,10 @@ public class CompilationRunner extends BlockJUnit4ClassRunner {
|
|||
|
||||
public CompilationRunner(Class<?> clazz) throws InitializationError {
|
||||
super( clazz );
|
||||
this.testEntities = new ArrayList<Class<?>>();
|
||||
this.preCompileEntities = new ArrayList<Class<?>>();
|
||||
this.mappingFiles = new ArrayList<String>();
|
||||
this.processorOptions = new HashMap<String, String>();
|
||||
this.testEntities = new ArrayList<>();
|
||||
this.preCompileEntities = new ArrayList<>();
|
||||
this.mappingFiles = new ArrayList<>();
|
||||
this.processorOptions = new HashMap<>();
|
||||
Package pkg = clazz.getPackage();
|
||||
this.packageName = pkg != null ? pkg.getName() : null;
|
||||
|
||||
|
|
|
@ -24,11 +24,7 @@ import javax.tools.Diagnostic;
|
|||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Hardy Ferentschik
|
||||
|
@ -165,6 +161,14 @@ public class TestUtil {
|
|||
assertNotNull( getMetamodelClassFor( clazz ) );
|
||||
}
|
||||
|
||||
public static void assertNoMetamodelClassGeneratedFor(Class<?> clazz) {
|
||||
try {
|
||||
getMetamodelClassFor( clazz );
|
||||
fail();
|
||||
}
|
||||
catch (AssertionError ae) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes recursively all files found in the output directory for the annotation processor.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue