mirror of https://github.com/apache/openjpa.git
OPENJPA-1143: further clean up test cases
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@795265 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8b98816386
commit
0adf13872e
|
@ -252,14 +252,39 @@ public abstract class CriteriaTest extends TestCase {
|
|||
|
||||
for (int i = 0; i < jSQL.size(); i++) {
|
||||
if (!jSQL.get(i).equals(expectedSQL)) {
|
||||
printSQL("SQL for JPQL", jSQL);
|
||||
printSQL("Expected SQL", cSQL);
|
||||
printSQL("SQL for JPQL", jSQL.get(i));
|
||||
printSQL("Expected SQL", cSQL.get(i));
|
||||
assertEquals(i + "-th Expected SQL and SQL for JPQL: " + jpql + " are different",
|
||||
expectedSQL, jSQL.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void executeAndCompareSQL(Query jQ, String expectedSQL) {
|
||||
List<String> jSQL = null;
|
||||
try {
|
||||
jSQL = executeQueryAndCollectSQL(jQ);
|
||||
} catch (Exception e) {
|
||||
StringWriter w = new StringWriter();
|
||||
e.printStackTrace(new PrintWriter(w));
|
||||
}
|
||||
|
||||
printSQL("Expected SQL", expectedSQL);
|
||||
String jSql = jSQL.get(0).trim();
|
||||
if (jSql.indexOf("optimize for 1 row") != -1)
|
||||
jSql = jSql.substring(0, jSql.indexOf("optimize for 1 row")).trim();
|
||||
|
||||
if (!jSql.equals(expectedSQL)) {
|
||||
printSQL("SQL for JPQL", jSql);
|
||||
assertEquals(expectedSQL, jSql);
|
||||
}
|
||||
}
|
||||
|
||||
void printSQL(String header, String sql) {
|
||||
System.err.println(header);
|
||||
System.err.println(sql);
|
||||
}
|
||||
|
||||
void printSQL(String header, List<String> sqls) {
|
||||
System.err.println(header);
|
||||
for (int i = 0; sqls != null && i < sqls.size(); i++) {
|
||||
|
|
|
@ -21,14 +21,14 @@ package org.apache.openjpa.persistence.criteria;
|
|||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Parameter;
|
||||
import javax.persistence.Query;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Expression;
|
||||
import javax.persistence.criteria.Join;
|
||||
import javax.persistence.criteria.JoinType;
|
||||
import javax.persistence.criteria.ListJoin;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
import javax.persistence.criteria.SetJoin;
|
||||
import javax.persistence.criteria.Subquery;
|
||||
|
@ -1230,7 +1230,8 @@ public class TestJPQLSubquery extends CriteriaTest {
|
|||
assertEquivalence(q, jpql);
|
||||
}
|
||||
|
||||
public void xtestSubquery18() {
|
||||
@AllowFailure(message="can not compare timestamp")
|
||||
public void testSubquery18() {
|
||||
String jpql = "select o.id from Order o where o.orderTs >"
|
||||
+ " (select CURRENT_TIMESTAMP from o.lineItems i)";
|
||||
|
||||
|
@ -1471,11 +1472,7 @@ public class TestJPQLSubquery extends CriteriaTest {
|
|||
assertEquivalence(q, jpql);
|
||||
}
|
||||
|
||||
/**
|
||||
* this test scenario must use Dependent.java and DependentId.java in
|
||||
* org.apache.openjpa.persistence.query package.
|
||||
*/
|
||||
@AllowFailure(message="")
|
||||
@AllowFailure(message="can not compare timestamp")
|
||||
public void testSubSelectMaxDateRange() {
|
||||
String jpql = "SELECT e,d from Employee e, Dependent d "
|
||||
+ "WHERE e.empId = :empid "
|
||||
|
@ -1493,7 +1490,27 @@ public class TestJPQLSubquery extends CriteriaTest {
|
|||
jQ.setParameter("minDate", new Date(100));
|
||||
jQ.setParameter("maxDate", new Date(100000));
|
||||
|
||||
List jList = jQ.getResultList();
|
||||
executeAndCompareSQL(jQ, expectedSQL);
|
||||
|
||||
CriteriaQuery<?> q = cb.createQuery();
|
||||
Root<Employee> e = q.from(Employee.class);
|
||||
Root<Dependent> d = q.from(Dependent.class);
|
||||
q.multiselect(e, d);
|
||||
Parameter<Integer> empid = cb.parameter(Integer.class, "empid");
|
||||
Parameter<Date> minDate = cb.parameter(Date.class, "minDate");
|
||||
Parameter<Date> maxDate = cb.parameter(Date.class, "maxDate");
|
||||
|
||||
Subquery<Integer> sq = q.subquery(Integer.class);
|
||||
Root<Employee> e2 = sq.from(Employee.class);
|
||||
sq.select(cb.max(e2.get(Employee_.empId)));
|
||||
Predicate p1 = cb.equal(e.get(Employee_.empId), empid);
|
||||
Predicate p2 = cb.equal(d.get(Dependent_.id).get(DependentId_.empid), sq);
|
||||
//Predicate p3 = cb.gt(d.get(Dependent_.id).get(DependentId_.effDate), minDate);
|
||||
//Predicate p4 = cb.lt(d.get(Dependent_.id).get(DependentId_.effDate), maxDate);
|
||||
|
||||
//q.where(cb.and(cb.and(cb.and(p1, p2), p3), p4));
|
||||
assertEquivalence(q, jpql);
|
||||
|
||||
}
|
||||
|
||||
public void testCorrelatedNestedSubquery1() {
|
||||
|
|
|
@ -30,6 +30,8 @@ import javax.persistence.criteria.Root;
|
|||
import javax.persistence.criteria.SetJoin;
|
||||
import javax.persistence.criteria.Subquery;
|
||||
|
||||
import org.apache.openjpa.persistence.test.AllowFailure;
|
||||
|
||||
public class TestSubqueries extends CriteriaTest {
|
||||
|
||||
public void testExist() {
|
||||
|
@ -448,8 +450,8 @@ public class TestSubqueries extends CriteriaTest {
|
|||
assertEquivalence(q, query);
|
||||
}
|
||||
|
||||
|
||||
public void xtestSubquery18() {
|
||||
@AllowFailure(message="can not compare timestamp")
|
||||
public void testSubquery18() {
|
||||
String query = "select o.id from Order o where o.orderTs >"
|
||||
+ " (select CURRENT_TIMESTAMP from o.lineItems i)";
|
||||
|
||||
|
@ -587,22 +589,4 @@ public class TestSubqueries extends CriteriaTest {
|
|||
Customer.CreditRating.POOR))));
|
||||
assertEquivalence(q, query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify a sub query can contain MAX and additional date comparisons
|
||||
* without losing the correct alias information. This sort of query
|
||||
* originally caused problems for DBDictionaries which used DATABASE syntax.
|
||||
*/
|
||||
// Not sure how to do Cartesian join when Employee can not
|
||||
// navigate to Dependent
|
||||
|
||||
public void testSubSelectMaxDateRange() {
|
||||
String query = "SELECT e,d from Employee e, Dependent d "
|
||||
+ "WHERE e.empId = :empid "
|
||||
+ "AND d.id.empid = (SELECT MAX (e2.empId) FROM Employee e2) "
|
||||
+ "AND d.id.effDate > :minDate "
|
||||
+ "AND d.id.effDate < :maxDate ";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -192,19 +192,15 @@ public class TestTypeSafeCondExpression extends CriteriaTest {
|
|||
assertEquivalence(cq, query);
|
||||
}
|
||||
|
||||
@AllowFailure(message = "SQL generation is slightly different")
|
||||
|
||||
public void testIsEmptyExprUsingCriteria() {
|
||||
String query = "SELECT o.name FROM CompUser o WHERE o.nicknames IS NOT EMPTY";
|
||||
|
||||
CriteriaQuery<String> cq = cb.createQuery(String.class);
|
||||
Root<CompUser> o = cq.from(CompUser.class);
|
||||
cq.select(o.get(CompUser_.name));
|
||||
cq.where(cb.isNotEmpty(o.get(CompUser_.nicknames)));
|
||||
cq.where(cb.isEmpty(o.get(CompUser_.nicknames)).negate());
|
||||
assertEquivalence(cq, query);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void testConstructorExprUsingCriteria() {
|
||||
String query = "SELECT NEW org.apache.openjpa.persistence.criteria.MaleUser(" +
|
||||
|
@ -397,7 +393,7 @@ public class TestTypeSafeCondExpression extends CriteriaTest {
|
|||
assertEquivalence(q, query);
|
||||
}
|
||||
|
||||
@AllowFailure
|
||||
@AllowFailure(message="can not parameterize the literial in math function")
|
||||
public void testArithmFunc3() {
|
||||
String query = "select MOD(e.age, 4) From CompUser e WHERE e.name='Seetha'";
|
||||
|
||||
|
@ -525,14 +521,13 @@ public class TestTypeSafeCondExpression extends CriteriaTest {
|
|||
assertEquivalence(q, query, new String[]{"t"}, new Class[]{MaleUser.class});
|
||||
}
|
||||
|
||||
@AllowFailure(message="cross join is not implemented")
|
||||
public void testTypeExpression3() {
|
||||
String query = "SELECT e, FemaleUser, a FROM Address a, FemaleUser e where e.address IS NOT NULL";
|
||||
|
||||
CriteriaQuery<Tuple> q = cb.createTupleQuery();
|
||||
Root<Address> a = q.from(Address.class);
|
||||
Root<FemaleUser> e = q.from(FemaleUser.class);
|
||||
q.multiselect(e, cb.literal(FemaleUser.class), e.get(CompUser_.address));
|
||||
q.multiselect(e, cb.literal(FemaleUser.class), a);
|
||||
q.where(e.get(FemaleUser_.address).isNotNull());
|
||||
|
||||
assertEquivalence(q, query);
|
||||
|
|
|
@ -541,7 +541,6 @@ public class TestTypesafeCriteria extends CriteriaTest {
|
|||
new Object[] { 1, "test" });
|
||||
}
|
||||
|
||||
@AllowFailure(message="collection valued parameter does not work in in()")
|
||||
public void testParameters5() {
|
||||
String jpql = "SELECT c FROM Customer c Where c.status IN (:coll)";
|
||||
|
||||
|
@ -759,7 +758,6 @@ public class TestTypesafeCriteria extends CriteriaTest {
|
|||
assertEquivalence(q, jpql);
|
||||
}
|
||||
|
||||
@AllowFailure(message="incorrect SQL generated by criteria API")
|
||||
public void testOrdering3() {
|
||||
String jpql = "SELECT o.quantity, o.totalCost * 1.08 AS taxedCost, "
|
||||
+ "a.zipCode FROM Customer c JOIN c.orders o JOIN c.address a "
|
||||
|
|
Loading…
Reference in New Issue