1 package org.hibernate.test.hql; 3 4 import junit.framework.Test; 5 import junit.framework.TestSuite; 6 7 12 public class ASTQueryTranslatorTest extends QueryTranslatorTestCase { 13 14 public ASTQueryTranslatorTest(String x) { 15 super( x ); 16 } 17 18 public static Test suite() { 19 return new TestSuite( ASTQueryTranslatorTest.class ); 20 } 21 22 protected boolean dropAfterFailure() { 23 return false; 24 } 25 26 28 public void testSelectManyToOne() { 29 assertTranslation("select distinct a.zoo from Animal a where a.zoo is not null"); 30 assertTranslation("select a.zoo from Animal a"); 31 } 32 33 public void testSelectExpression() { 34 assertTranslation("select a.bodyWeight + m.bodyWeight from Animal a join a.mother m"); 36 } 37 38 public void testFetchProperties() { 39 assertTranslation("from Animal a fetch all properties join a.offspring o fetch all properties"); 41 } 42 43 public void testOldSyntax() { 44 assertTranslation("from a in class Animal, o in elements(a.offspring), h in class Human"); 46 } 47 48 public void testImplicitJoinInsideOutsideSubselect() { 49 assertTranslation( "from Simple s where s = some( from Simple sim where sim.other.count=s.other.count ) and s.other.count > 0" ); 80 assertTranslation( "from Simple s where s.other.count > 0 and s = some( from Simple sim where sim.other.count=s.other.count )" ); 81 } 82 83 public void testNakedPropertyRef() { 84 assertTranslation( "from Animal where bodyWeight = bodyWeight" ); 88 assertTranslation( "select bodyWeight from Animal" ); 89 assertTranslation( "select max(bodyWeight) from Animal" ); 90 } 91 92 public void testNakedComponentPropertyRef() { 93 assertTranslation( "from Human where name.first = 'Gavin'" ); 97 assertTranslation( "select name from Human" ); 98 assertTranslation( "select upper(h.name.first) from Human as h" ); 99 assertTranslation( "select upper(name.first) from Human" ); 100 } 101 102 public void testNakedMapIndex() throws Exception { 103 assertTranslation( "from Zoo where mammals['dog'].description like '%black%'" ); 104 } 105 106 public void testDuplicateImplicitJoinInWhere() { 107 assertTranslation("from Human h where h.mother.bodyWeight>10 and h.mother.bodyWeight<10"); 109 } 110 111 public void testWhereExpressions() { 112 assertTranslation("from User u where u.userName='gavin' and u.human.name.first='Gavin'"); 113 assertTranslation("from User u where u.human.name.last='King' and u.human.name.first='Gavin'"); 115 assertTranslation("from Bar bar where bar.baz.name='josh'"); 116 assertTranslation("from Bar bar where bar.baz.name='josh' and not bar.baz.name='gavin'"); 117 } 118 119 public void testImplicitJoinInSelect() { 120 assertTranslation("select foo.long, foo.foo from Foo foo"); 122 } 123 124 public void testSelectStandardFunctions() throws Exception { 125 assertTranslation( "select current_date(), current_time(), current_timestamp() from Animal" ); 127 } 128 129 public void testSelectClauseImplicitJoin() throws Exception { 130 assertTranslation( "select d.owner.mother from Dog d" ); 132 } 133 134 public void testComplexWhereExpression() throws Exception { 135 assertTranslation( "select distinct s from Simple s\n" + 137 "where ( ( s.other.count + 3 ) = (15*2)/2 and s.count = 69) or ( ( s.other.count + 2 ) / 7 ) = 2" ); 138 } 139 140 public void testDuplicateImplicitJoin() throws Exception { 141 assertTranslation( "from Animal an where an.mother.bodyWeight > 10 and an.mother.bodyWeight < 20" ); 143 } 144 145 public void testKeywordClassNameAndAlias() throws Exception { 146 assertTranslation( "from Order order" ); 148 } 149 150 public void testComponent3() throws Exception { 151 assertTranslation( "from Dog dog where dog.owner.name.first = 'Gavin' and dog.owner.name.last='King' and dog.owner.bodyWeight<70" ); 153 } 154 155 public void testUncorrelatedSubselectWithJoin() throws Exception { 156 assertTranslation( "from Animal a where a in (select mam from Zoo zoo join zoo.mammals mam)" ); 159 } 160 161 public void testFetch() throws Exception { 162 assertTranslation("from Customer cust left join fetch cust.billingAddress where cust.customerId='abc123'"); 164 } 165 166 public void testImplicitJoin() throws Exception { 167 assertTranslation( "from Animal an where an.offspring.mother.bodyWeight > 10" ); 170 } 171 172 } 173 | Popular Tags |