Skip to content

Commit 4bd5c8a

Browse files
committed
HHH-11568 - Added test case.
1 parent 9ae3914 commit 4bd5c8a

File tree

1 file changed

+36
-0
lines changed
  • hibernate-core/src/test/java/org/hibernate/test/hql

1 file changed

+36
-0
lines changed

hibernate-core/src/test/java/org/hibernate/test/hql/HQLTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.Map;
1616

1717
import org.hibernate.QueryException;
18+
import org.hibernate.Session;
1819
import org.hibernate.dialect.AbstractHANADialect;
1920
import org.hibernate.dialect.DB2Dialect;
2021
import org.hibernate.dialect.H2Dialect;
@@ -63,11 +64,13 @@
6364
import antlr.RecognitionException;
6465
import antlr.collections.AST;
6566

67+
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
6668
import static org.junit.Assert.assertEquals;
6769
import static org.junit.Assert.assertFalse;
6870
import static org.junit.Assert.assertNotNull;
6971
import static org.junit.Assert.assertNull;
7072
import static org.junit.Assert.assertTrue;
73+
import static org.junit.Assert.fail;
7174

7275
/**
7376
* 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 {
107110
super.cleanupTest();
108111
}
109112

113+
@Test
114+
@TestForIssue(jiraKey = "HHH-2187")
115+
public void testBogusQuery() {
116+
try {
117+
QueryTranslatorImpl translator = createNewQueryTranslator( "bogus" );
118+
fail( "This should have failed with a QueryException" );
119+
}
120+
catch ( Throwable t ) {
121+
assertTyping( QueryException.class, t );
122+
}
123+
}
124+
125+
@Test
126+
@TestForIssue(jiraKey = "HHH-2187")
127+
public void testBogusCreateQuery() {
128+
Session session = openSession();
129+
try {
130+
session.beginTransaction();
131+
session.createQuery( "Bogus" );
132+
fail( "This should have failed with an IllegalArgumentException" );
133+
}
134+
catch ( IllegalArgumentException e ) {
135+
if ( session.getTransaction().isActive() ) {
136+
session.getTransaction().rollback();
137+
}
138+
assertTyping( QueryException.class, e.getCause() );
139+
}
140+
finally {
141+
session.close();
142+
}
143+
}
144+
110145
@Test
111146
public void testModulo() {
112147
assertTranslation( "from Animal a where a.bodyWeight % 2 = 0" );
@@ -133,6 +168,7 @@ public void testRowValueConstructorSyntaxInInList2() {
133168
PostgreSQL81Dialect.class,
134169
MySQLDialect.class
135170
} )
171+
136172
public void testRowValueConstructorSyntaxInInListBeingTranslated() {
137173
QueryTranslatorImpl translator = createNewQueryTranslator("from LineItem l where l.id in (?)");
138174
assertInExist("'in' should be translated to 'and'", false, translator);

0 commit comments

Comments
 (0)