mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-30 21:08:30 +08:00
This commit is contained in:
parent
e1a25373ec
commit
f9aede527e
@ -4,7 +4,10 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.mysema.query.jdoql.testdomain.Book;
|
||||
import com.mysema.query.jdoql.testdomain.Department;
|
||||
import com.mysema.query.jdoql.testdomain.QBook;
|
||||
import com.mysema.query.jdoql.testdomain.QCompany;
|
||||
import com.mysema.query.jdoql.testdomain.QProduct;
|
||||
import com.mysema.query.types.expr.Expr;
|
||||
|
||||
@ -14,6 +17,13 @@ public class JDOQLSerializerTest {
|
||||
|
||||
private QProduct product = QProduct.product;
|
||||
|
||||
private QCompany company = QCompany.company;
|
||||
|
||||
@Test
|
||||
public void instanceOf(){
|
||||
assertEquals("product instanceof com.mysema.query.jdoql.testdomain.Book", serialize(product.instanceOf(Book.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandle() {
|
||||
assertEquals("this.name == product.name", serialize(book.name.eq(product.name)));
|
||||
@ -29,14 +39,20 @@ public class JDOQLSerializerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void collectionTests(){
|
||||
public void collectionTests(){
|
||||
Department dep = new Department();
|
||||
// collection
|
||||
// TODO contains
|
||||
// TODO get
|
||||
assertEquals("company.departments.contains(a1)", serialize(company.departments.contains(dep)));
|
||||
assertEquals("company.departments.get(0) == a1", serialize(company.departments.get(0).eq(dep)));
|
||||
assertEquals("company.departments.isEmpty()", serialize(company.departments.empty()));
|
||||
assertEquals("!company.departments.isEmpty()", serialize( company.departments.notEmpty()));
|
||||
assertEquals("company.departments.size() == a1", serialize(company.departments.size().eq(1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapTests(){
|
||||
// TODO containsKey
|
||||
// TODO containsValue
|
||||
// TODO isEmpty
|
||||
// TODO size
|
||||
// TODO containsValue
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -2,17 +2,45 @@ package com.mysema.query.jdoql;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
// TODO : FIXME
|
||||
import com.mysema.query.jdoql.testdomain.Book;
|
||||
|
||||
public class JDOQueryTest extends AbstractJDOTest{
|
||||
|
||||
@Test
|
||||
public void basicTests() {
|
||||
@Ignore
|
||||
public void countTests(){
|
||||
// FIXME
|
||||
assertEquals("count", 2, query().from(product).count()); // returns 1, why?
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void searchResults(){
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testOrder(){
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Test
|
||||
public void projectionTests(){
|
||||
assertEquals("Sony Discman", query().from(product)
|
||||
.where(product.name.eq("Sony Discman"))
|
||||
.uniqueResult(product.name));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basicTests() {
|
||||
assertEquals("list", 2, query().from(product).list(product).size());
|
||||
assertEquals("list", 1, query().from(book).list(book).size());
|
||||
assertEquals("eq", 1, query(product, product.name.eq("Sony Discman")).size());
|
||||
// FIXME assertEquals("instanceof ", 1, query(product, product.typeOf(Book.class)).size());
|
||||
assertEquals("instanceof ", 1, query(product, product.instanceOf(Book.class)).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@ -5,12 +5,15 @@
|
||||
*/
|
||||
package com.mysema.query.jdoql.testdomain;
|
||||
|
||||
import javax.jdo.annotations.Inheritance;
|
||||
import javax.jdo.annotations.InheritanceStrategy;
|
||||
import javax.jdo.annotations.PersistenceCapable;
|
||||
|
||||
/**
|
||||
* Definition of a Book. Extends basic Product class.
|
||||
*/
|
||||
@PersistenceCapable
|
||||
@Inheritance(strategy=InheritanceStrategy.NEW_TABLE)
|
||||
public class Book extends Product {
|
||||
private String author = null;
|
||||
|
||||
|
||||
@ -0,0 +1,69 @@
|
||||
package com.mysema.query.jdoql.testdomain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.jdo.annotations.PersistenceCapable;
|
||||
import javax.jdo.annotations.PrimaryKey;
|
||||
|
||||
/**
|
||||
* The Class Company.
|
||||
*/
|
||||
@PersistenceCapable
|
||||
// TODO : finish annotations
|
||||
public class Company {
|
||||
private @PrimaryKey
|
||||
int id;
|
||||
// @ManyToOne
|
||||
private Employee ceo;
|
||||
// @OneToMany(mappedBy="company")
|
||||
private List<Department> departments;
|
||||
private String name;
|
||||
|
||||
public Company() {
|
||||
}
|
||||
|
||||
public Company(int id) {
|
||||
setId(id);
|
||||
}
|
||||
|
||||
public void addDepartment(Department department) {
|
||||
if (departments == null) {
|
||||
departments = new ArrayList<Department>();
|
||||
}
|
||||
departments.add(department);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Employee getCeo() {
|
||||
return ceo;
|
||||
}
|
||||
|
||||
public void setCeo(Employee ceo) {
|
||||
this.ceo = ceo;
|
||||
}
|
||||
|
||||
public List<Department> getDepartments() {
|
||||
return departments;
|
||||
}
|
||||
|
||||
public void setDepartments(List<Department> departments) {
|
||||
this.departments = departments;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,73 @@
|
||||
package com.mysema.query.jdoql.testdomain;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.jdo.annotations.PersistenceCapable;
|
||||
import javax.jdo.annotations.PrimaryKey;
|
||||
|
||||
/**
|
||||
* The Class Department.
|
||||
*/
|
||||
@PersistenceCapable
|
||||
// TODO : finish annotations
|
||||
public class Department {
|
||||
private @PrimaryKey
|
||||
int id;
|
||||
// @ManyToOne
|
||||
private Company company;
|
||||
// @OneToMany(mappedBy="department")
|
||||
private Set<Employee> employees;
|
||||
private String name;
|
||||
// @ManyToOne
|
||||
private Department parent;
|
||||
|
||||
public Department() {
|
||||
}
|
||||
|
||||
public Department(int id, Company c) {
|
||||
setId(id);
|
||||
setCompany(c);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Company getCompany() {
|
||||
return company;
|
||||
}
|
||||
|
||||
public void setCompany(Company company) {
|
||||
this.company = company;
|
||||
company.addDepartment(this);
|
||||
}
|
||||
|
||||
public Set<Employee> getEmployees() {
|
||||
return employees;
|
||||
}
|
||||
|
||||
public void setEmployees(Set<Employee> employees) {
|
||||
this.employees = employees;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Department getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(Department parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
package com.mysema.query.jdoql.testdomain;
|
||||
|
||||
import javax.jdo.annotations.PersistenceCapable;
|
||||
|
||||
/**
|
||||
* The Class Employee.
|
||||
*/
|
||||
@PersistenceCapable
|
||||
// TODO : finish annotations
|
||||
public class Employee extends Person {
|
||||
// @ManyToOne
|
||||
private Company company;
|
||||
// @ManyToOne
|
||||
private Department department;
|
||||
// @ManyToOne
|
||||
private Employee superior;
|
||||
|
||||
public Employee() {
|
||||
}
|
||||
|
||||
public Employee(int i) {
|
||||
setId(i);
|
||||
}
|
||||
|
||||
public Employee(int i, Employee superior) {
|
||||
setId(i);
|
||||
setSuperior(superior);
|
||||
}
|
||||
|
||||
public Company getCompany() {
|
||||
return company;
|
||||
}
|
||||
|
||||
public void setCompany(Company company) {
|
||||
this.company = company;
|
||||
}
|
||||
|
||||
public Department getDepartment() {
|
||||
return department;
|
||||
}
|
||||
|
||||
public void setDepartment(Department department) {
|
||||
this.department = department;
|
||||
}
|
||||
|
||||
public Employee getSuperior() {
|
||||
return superior;
|
||||
}
|
||||
|
||||
public void setSuperior(Employee superior) {
|
||||
this.superior = superior;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.mysema.query.jdoql.testdomain;
|
||||
|
||||
import javax.jdo.annotations.PersistenceCapable;
|
||||
import javax.jdo.annotations.PrimaryKey;
|
||||
|
||||
/**
|
||||
* Person provides
|
||||
*
|
||||
* @author tiwe
|
||||
* @version $Id$
|
||||
*/
|
||||
@PersistenceCapable
|
||||
// TODO : finish annotations
|
||||
public class Person {
|
||||
private String firstName, lastName, email;
|
||||
private @PrimaryKey
|
||||
Integer id;
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
||||
@ -5,12 +5,15 @@
|
||||
*/
|
||||
package com.mysema.query.jdoql.testdomain;
|
||||
|
||||
import javax.jdo.annotations.Inheritance;
|
||||
import javax.jdo.annotations.InheritanceStrategy;
|
||||
import javax.jdo.annotations.PersistenceCapable;
|
||||
|
||||
/**
|
||||
* Definition of a Product Represents a product, and contains the key aspects of the item.
|
||||
*/
|
||||
@PersistenceCapable
|
||||
@Inheritance(strategy=InheritanceStrategy.NEW_TABLE)
|
||||
public class Product {
|
||||
private String name = null;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user