mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#831 - EQL query language parser needs to throw exception on invalid query ... "find ..." - remove unhelpful tests
This commit is contained in:
@@ -1,72 +0,0 @@
|
||||
package com.avaje.tests.model.basic;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
@Entity
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "findOverlappingSlots",
|
||||
// query = "where slotState != 4 and oid != :thisOID and swimlaneOid = :thisSwimlaneOID and :thisPlannedBegin < plannedEnd and plannedBegin < :thisPlannedEnd") // See JODA AbstractInterval
|
||||
// query = "where slotState != 4 and oid != :thisOID and swimlaneOid = :thisSwimlaneOID and :thisPlannedBegin < plannedEnd")
|
||||
query = "where :thisPlannedBegin < plannedEnd") // Doesn't work
|
||||
// query = "where plannedEnd < :thisPlannedBegin") // Works
|
||||
})
|
||||
public class Slot {
|
||||
|
||||
@Id
|
||||
private long oid;
|
||||
|
||||
private long slotState;
|
||||
|
||||
private long swimlaneOid;
|
||||
|
||||
public long getSwimlaneOid() {
|
||||
return swimlaneOid;
|
||||
}
|
||||
|
||||
public void setSwimlaneOid(long swimlaneOid) {
|
||||
this.swimlaneOid = swimlaneOid;
|
||||
}
|
||||
|
||||
private DateTime plannedBegin;
|
||||
|
||||
/** The planned end. */
|
||||
private DateTime plannedEnd;
|
||||
|
||||
|
||||
public long getOid() {
|
||||
return oid;
|
||||
}
|
||||
|
||||
public void setOid(long oid) {
|
||||
this.oid = oid;
|
||||
}
|
||||
|
||||
public long getSlotState() {
|
||||
return slotState;
|
||||
}
|
||||
|
||||
public void setSlotState(long slotState) {
|
||||
this.slotState = slotState;
|
||||
}
|
||||
|
||||
public DateTime getPlannedBegin() {
|
||||
return plannedBegin;
|
||||
}
|
||||
|
||||
public void setPlannedBegin(DateTime plannedBegin) {
|
||||
this.plannedBegin = plannedBegin;
|
||||
}
|
||||
|
||||
public DateTime getPlannedEnd() {
|
||||
return plannedEnd;
|
||||
}
|
||||
|
||||
public void setPlannedEnd(DateTime plannedEnd) {
|
||||
this.plannedEnd = plannedEnd;
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package com.avaje.tests.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Article;
|
||||
import com.avaje.tests.model.basic.Section;
|
||||
import com.avaje.tests.model.basic.Slot;
|
||||
|
||||
public class TestNamedQueryWithNamedParam extends BaseTestCase {
|
||||
|
||||
|
||||
@Test
|
||||
public void testInvalidEQL() {
|
||||
Section s0 = new Section("some content");
|
||||
String author1 = "auth1";
|
||||
Article a0 = new Article("art1", author1);
|
||||
a0.addSection(s0);
|
||||
|
||||
Ebean.save(a0);
|
||||
|
||||
Section s1 = new Section("some content");
|
||||
String author2 = "auth2";
|
||||
Article a1 = new Article("art2", author2);
|
||||
a1.addSection(s1);
|
||||
|
||||
Ebean.save(a1);
|
||||
|
||||
List<Article> list = Ebean.find(Article.class).where().eq("author", author1).findList();
|
||||
|
||||
Assert.assertTrue(list.size() ==1); //<<<<<<<<<<<<< Works fine
|
||||
|
||||
Query<Article> query = Ebean.createQuery(Article.class, "find Article where name = :p0"); // Should throw an exception
|
||||
query.setParameter("p0", author1);
|
||||
list = query.findList();
|
||||
|
||||
Assert.assertTrue("Shouldn't get this far as the query is syntactically incorrect", list.size() ==1); // <<<<<<<<<<<<< fails
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamedQuery() {
|
||||
final Query<Slot> query =
|
||||
Ebean.createNamedQuery(Slot.class, "findOverlappingSlots");
|
||||
|
||||
// query.setParameter("thisOID", 1);
|
||||
// query.setParameter("swimlaneOid", 1);
|
||||
query.setParameter("thisPlannedBegin", new DateTime());
|
||||
// query.setParameter("thisPlannedEnd", new DateTime());
|
||||
//
|
||||
query.findList();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user