use of dev.morphia.test.query.TestLegacyQuery.Pic in project morphia by mongodb.
the class TestQueriesOnReferences method testQueryOverReference.
@Test
public void testQueryOverReference() {
final ContainsPic cpk = new ContainsPic();
final Pic p = new Pic();
getDs().save(p);
cpk.setPic(p);
getDs().save(cpk);
final Query<ContainsPic> query = getDs().find(ContainsPic.class);
final ContainsPic object = query.filter(eq("pic", p)).iterator(new FindOptions().limit(1)).tryNext();
assertNotNull(object);
}
use of dev.morphia.test.query.TestLegacyQuery.Pic in project morphia by mongodb.
the class TestQueriesOnReferences method testQueryOverLazyReference.
@Test
public void testQueryOverLazyReference() {
final ContainsPic cpk = new ContainsPic();
final Pic p = new Pic();
getDs().save(p);
final PicWithObjectId withObjectId = new PicWithObjectId();
getDs().save(withObjectId);
cpk.setLazyPic(p);
cpk.setLazyObjectIdPic(withObjectId);
getDs().save(cpk);
Query<ContainsPic> query = getDs().find(ContainsPic.class);
assertNotNull(query.filter(eq("lazyPic", p)).iterator(new FindOptions().limit(1)).tryNext());
query = getDs().find(ContainsPic.class);
assertNotNull(query.filter(eq("lazyObjectIdPic", withObjectId)).iterator(new FindOptions().limit(1)).tryNext());
}
use of dev.morphia.test.query.TestLegacyQuery.Pic in project morphia by mongodb.
the class TestQueriesOnReferences method testMissingReferences.
@Test(expectedExceptions = ReferenceException.class)
public void testMissingReferences() {
final ContainsPic cpk = new ContainsPic();
final Pic p = new Pic();
cpk.setPic(p);
getDs().save(p);
getDs().save(cpk);
getDs().delete(p);
getDs().find(ContainsPic.class).iterator().toList();
}
use of dev.morphia.test.query.TestLegacyQuery.Pic in project morphia by mongodb.
the class TestQueriesOnReferences method testKeyExists.
@Test
public void testKeyExists() {
final ContainsPic cpk = new ContainsPic();
final Pic p = new Pic();
cpk.setPic(p);
getDs().save(p);
getDs().save(cpk);
assertNotNull(getDs().find(ContainsPic.class).filter(exists("pic")).iterator(new FindOptions().projection().include("pic").limit(1)).tryNext());
assertNull(getDs().find(ContainsPic.class).filter(exists("pic").not()).iterator(new FindOptions().projection().include("pic").limit(1)).tryNext());
}
use of dev.morphia.test.query.TestLegacyQuery.Pic in project morphia by mongodb.
the class TestQueriesOnReferences method testWithKeyQuery.
@Test
public void testWithKeyQuery() {
final ContainsPic cpk = new ContainsPic();
final Pic p = new Pic();
cpk.setPic(p);
getDs().save(p);
getDs().save(cpk);
Query<ContainsPic> query = getDs().find(ContainsPic.class).filter(eq("pic", new Key<>(Pic.class, "pic", p.getId())));
assertEquals(query.first(new FindOptions().logQuery().limit(1)).getId(), cpk.getId(), query.getLoggedQuery());
}
Aggregations