use of dev.morphia.test.query.TestQuery.ContainsPic in project morphia by mongodb.
the class TestUpdateOperations method testInsertWithRef.
@Test
public void testInsertWithRef() {
final Pic pic = new Pic();
pic.setName("fist");
final ObjectId picKey = getDs().save(pic).getId();
Query<ContainsPic> query = getDs().find(ContainsPic.class).filter(eq("name", "first"), eq("pic", picKey));
assertInserted(query.update(set("name", "A")).execute(new UpdateOptions().upsert(true)));
MatcherAssert.assertThat(getDs().find(ContainsPic.class).count(), is(1L));
getDs().find(ContainsPic.class).delete(new DeleteOptions().multi(true));
query = getDs().find(ContainsPic.class).filter(eq("name", "first"), eq("pic", pic));
assertInserted(query.update(set("name", "second")).execute(new UpdateOptions().upsert(true)));
MatcherAssert.assertThat(getDs().find(ContainsPic.class).count(), is(1L));
// test reading the object.
final ContainsPic cp = getDs().find(ContainsPic.class).iterator(new FindOptions().limit(1)).next();
assertThat(cp, is(notNullValue()));
MatcherAssert.assertThat(cp.getName(), is("second"));
MatcherAssert.assertThat(cp.getPic(), is(notNullValue()));
MatcherAssert.assertThat(cp.getPic().getName(), is(notNullValue()));
MatcherAssert.assertThat(cp.getPic().getName(), is("fist"));
}
use of dev.morphia.test.query.TestQuery.ContainsPic in project morphia by mongodb.
the class TestUpdateOperations method createContainsPic.
private void createContainsPic(int size) {
final ContainsPic containsPic = new ContainsPic();
containsPic.setSize(size);
getDs().save(containsPic);
}
use of dev.morphia.test.query.TestQuery.ContainsPic in project morphia by mongodb.
the class TestUpdateOperations method testUpdateRef.
@Test
public void testUpdateRef() {
final ContainsPic cp = new ContainsPic();
cp.setName("cp one");
getDs().save(cp);
final Pic pic = new Pic();
pic.setName("fist");
getDs().save(pic);
Query<ContainsPic> query = getDs().find(ContainsPic.class).filter(eq("name", cp.getName()));
UpdateResult result = query.update(set("pic", pic)).execute();
Assert.assertEquals(result.getModifiedCount(), 1);
// test reading the object.
final ContainsPic cp2 = getDs().find(ContainsPic.class).iterator(new FindOptions().limit(1)).next();
assertThat(cp2, is(notNullValue()));
MatcherAssert.assertThat(cp.getName(), CoreMatchers.is(cp2.getName()));
MatcherAssert.assertThat(cp2.getPic(), is(notNullValue()));
MatcherAssert.assertThat(cp2.getPic().getName(), is(notNullValue()));
MatcherAssert.assertThat(pic.getName(), CoreMatchers.is(cp2.getPic().getName()));
// test reading the object.
final ContainsPic cp3 = getDs().find(ContainsPic.class).iterator(new FindOptions().limit(1)).next();
assertThat(cp3, is(notNullValue()));
MatcherAssert.assertThat(cp.getName(), CoreMatchers.is(cp3.getName()));
MatcherAssert.assertThat(cp3.getPic(), is(notNullValue()));
MatcherAssert.assertThat(cp3.getPic().getName(), is(notNullValue()));
MatcherAssert.assertThat(pic.getName(), CoreMatchers.is(cp3.getPic().getName()));
}
Aggregations