mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-27 21:01:15 +08:00
Add test #686
This commit is contained in:
parent
9b709c2bfd
commit
7628e64e8e
@ -28,6 +28,7 @@ import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.mysema.query.mongodb.domain.*;
|
||||
import org.bson.types.ObjectId;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -41,15 +42,10 @@ import com.mongodb.MongoException;
|
||||
import com.mongodb.ReadPreference;
|
||||
import com.mysema.query.NonUniqueResultException;
|
||||
import com.mysema.query.SearchResults;
|
||||
import com.mysema.query.mongodb.domain.Address;
|
||||
import com.mysema.query.mongodb.domain.City;
|
||||
import com.mysema.query.mongodb.domain.Item;
|
||||
import com.mysema.query.mongodb.domain.MapEntity;
|
||||
import com.mysema.query.mongodb.domain.QAddress;
|
||||
import com.mysema.query.mongodb.domain.QItem;
|
||||
import com.mysema.query.mongodb.domain.QMapEntity;
|
||||
import com.mysema.query.mongodb.domain.QUser;
|
||||
import com.mysema.query.mongodb.domain.User;
|
||||
import com.mysema.query.mongodb.domain.User.Gender;
|
||||
import com.mysema.query.mongodb.morphia.MorphiaQuery;
|
||||
import com.mysema.query.types.EntityPath;
|
||||
@ -70,6 +66,7 @@ public class MongodbQueryTest {
|
||||
private final QItem item = QItem.item;
|
||||
private final QAddress address = QAddress.address;
|
||||
private final QMapEntity mapEntity = QMapEntity.mapEntity;
|
||||
private final QDates dates = QDates.dates;
|
||||
|
||||
List<User> users = Lists.newArrayList();
|
||||
User u1, u2, u3, u4;
|
||||
@ -77,7 +74,7 @@ public class MongodbQueryTest {
|
||||
|
||||
public MongodbQueryTest() throws UnknownHostException, MongoException {
|
||||
mongo = new Mongo();
|
||||
morphia = new Morphia().map(User.class).map(Item.class).map(MapEntity.class);
|
||||
morphia = new Morphia().map(User.class).map(Item.class).map(MapEntity.class).map(Dates.class);
|
||||
ds = morphia.createDatastore(mongo, dbname);
|
||||
}
|
||||
|
||||
@ -209,6 +206,18 @@ public class MongodbQueryTest {
|
||||
assertEquals(0, query().where(user.addresses.any().street.eq("akatu")).count());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Dates() {
|
||||
Date start = new Date();
|
||||
ds.delete(ds.createQuery(Dates.class));
|
||||
Dates d = new Dates();
|
||||
d.setDate(new Date());
|
||||
ds.save(d);
|
||||
Date end = new Date();
|
||||
|
||||
assertEquals(d, query(dates).where(dates.date.between(start, end)).singleResult());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ElemMatch() {
|
||||
// { "addresses" : { "$elemMatch" : { "street" : "Aakatu1"}}}
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
package com.mysema.query.mongodb.domain;
|
||||
|
||||
import org.bson.types.ObjectId;
|
||||
import org.mongodb.morphia.annotations.Entity;
|
||||
import org.mongodb.morphia.annotations.Id;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Entity
|
||||
public class Dates {
|
||||
|
||||
private @Id ObjectId id;
|
||||
|
||||
private Date date;
|
||||
|
||||
public ObjectId getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(ObjectId id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user