use of dev.morphia.test.models.CustomId in project morphia by mongodb.
the class TestQuery method testQBE.
@Test
public void testQBE() {
final CustomId cId = new CustomId();
cId.setId(new ObjectId());
cId.setType("banker");
final UsesCustomIdObject object = new UsesCustomIdObject();
object.setId(cId);
object.setText("hllo");
getDs().save(object);
final UsesCustomIdObject loaded;
// Add back if/when query by example for embedded fields is supported (require dotting each field).
// CustomId exId = new CustomId();
// exId.type = cId.type;
// loaded = getDs().find(UsesCustomIdObject.class, "_id", exId).get();
// assertNotNull(loaded);
final UsesCustomIdObject ex = new UsesCustomIdObject();
ex.setText(object.getText());
loaded = getDs().queryByExample(ex).iterator(new FindOptions().limit(1)).next();
assertNotNull(loaded);
}
use of dev.morphia.test.models.CustomId in project morphia by mongodb.
the class TestQuery method testComplexIdQueryWithRenamedField.
@Test
public void testComplexIdQueryWithRenamedField() {
final CustomId cId = new CustomId();
cId.setId(new ObjectId());
cId.setType("banker");
final UsesCustomIdObject object = new UsesCustomIdObject();
object.setId(cId);
object.setText("hllo");
getDs().save(object);
assertNotNull(getDs().find(UsesCustomIdObject.class).filter(eq("_id.t", "banker")).iterator(new FindOptions().limit(1)).tryNext());
}
use of dev.morphia.test.models.CustomId in project morphia by mongodb.
the class TestQuery method testKeys.
@Test
public void testKeys() {
PhotoWithKeywords pwk1 = new PhotoWithKeywords("california", "nevada", "arizona");
PhotoWithKeywords pwk2 = new PhotoWithKeywords("Joe", "Sarah");
PhotoWithKeywords pwk3 = new PhotoWithKeywords("MongoDB", "World");
getDs().save(asList(pwk1, pwk2, pwk3));
MongoCursor<Key<PhotoWithKeywords>> keys = getDs().find(PhotoWithKeywords.class).keys();
assertTrue(keys.hasNext());
assertEquals(pwk1.id, keys.next().getId());
assertEquals(pwk2.id, keys.next().getId());
assertEquals(pwk3.id, keys.next().getId());
List<UsesCustomIdObject> list = asList(new UsesCustomIdObject(new CustomId("Turk"), "Turk"), new UsesCustomIdObject(new CustomId("JD"), "Dorian"), new UsesCustomIdObject(new CustomId("Carla"), "Espinosa"));
getDs().save(list);
Iterator<Key<UsesCustomIdObject>> complexKeys = getDs().find(UsesCustomIdObject.class).keys();
assertTrue(complexKeys.hasNext());
assertEquals(list.get(0).getId(), complexKeys.next().getId());
assertEquals(list.get(1).getId(), complexKeys.next().getId());
assertEquals(list.get(2).getId(), complexKeys.next().getId());
assertFalse(complexKeys.hasNext());
}
use of dev.morphia.test.models.CustomId in project morphia by mongodb.
the class TestQuery method testComplexIdQuery.
@Test
public void testComplexIdQuery() {
final CustomId cId = new CustomId();
cId.setId(new ObjectId());
cId.setType("banker");
final UsesCustomIdObject object = new UsesCustomIdObject();
object.setId(cId);
object.setText("hllo");
getDs().save(object);
assertNotNull(getDs().find(UsesCustomIdObject.class).filter(eq("_id.type", "banker")).iterator(new FindOptions().limit(1)).tryNext());
assertNotNull(getDs().find(UsesCustomIdObject.class).filter(in("_id", singletonList(cId))).iterator(new FindOptions().limit(1)).tryNext());
}
Aggregations