From 4bd5c8a730367b515c6b3ed94b44b25e0eb13ff3 Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Tue, 28 Feb 2017 00:15:55 -0500 Subject: [PATCH] HHH-11568 - Added test case. --- .../java/org/hibernate/test/hql/HQLTest.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/HQLTest.java b/hibernate-core/src/test/java/org/hibernate/test/hql/HQLTest.java index 54dccf240b..1eaa14a619 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/HQLTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/HQLTest.java @@ -15,6 +15,7 @@ import java.util.Map; import org.hibernate.QueryException; +import org.hibernate.Session; import org.hibernate.dialect.AbstractHANADialect; import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.H2Dialect; @@ -63,11 +64,13 @@ import antlr.RecognitionException; import antlr.collections.AST; +import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * Tests cases where the AST based query translator and the 'classic' query translator generate identical SQL. @@ -107,6 +110,38 @@ protected void cleanupTest() throws Exception { super.cleanupTest(); } + @Test + @TestForIssue(jiraKey = "HHH-2187") + public void testBogusQuery() { + try { + QueryTranslatorImpl translator = createNewQueryTranslator( "bogus" ); + fail( "This should have failed with a QueryException" ); + } + catch ( Throwable t ) { + assertTyping( QueryException.class, t ); + } + } + + @Test + @TestForIssue(jiraKey = "HHH-2187") + public void testBogusCreateQuery() { + Session session = openSession(); + try { + session.beginTransaction(); + session.createQuery( "Bogus" ); + fail( "This should have failed with an IllegalArgumentException" ); + } + catch ( IllegalArgumentException e ) { + if ( session.getTransaction().isActive() ) { + session.getTransaction().rollback(); + } + assertTyping( QueryException.class, e.getCause() ); + } + finally { + session.close(); + } + } + @Test public void testModulo() { assertTranslation( "from Animal a where a.bodyWeight % 2 = 0" ); @@ -133,6 +168,7 @@ public void testRowValueConstructorSyntaxInInList2() { PostgreSQL81Dialect.class, MySQLDialect.class } ) + public void testRowValueConstructorSyntaxInInListBeingTranslated() { QueryTranslatorImpl translator = createNewQueryTranslator("from LineItem l where l.id in (?)"); assertInExist("'in' should be translated to 'and'", false, translator);