112113114115116117118119120121122
assertTrue(lc.isNew()); lc.addFail = false; lc.addedFail = true; try { lc.save(); assertFalse(true); } catch (Exception e) { // ignore } assertFalse(lc.isNew());
123124125126127128129130131132133
lc.addedFail = false; lc.bar = "yy"; lc.updateFail = true; try { lc.save(); } catch (Exception e) { // ignore } LifeCycle lc1 = LifeCycle.q("foo", "bar").get(); assertFalse(lc1.bar.equals(lc.bar));
185186187188189190191192193194195
@Test public void testExceptionsinBatchLifeCycleMethods() { LifeCycle lc0 = new LifeCycle(); lc0.foo = "bar"; lc0.bar = "order"; lc0.save(); LifeCycle lc1 = new LifeCycle(); lc1.foo = "foo"; lc1.bar = "order"; lc1.save();
190191192193194195196197198199200
lc0.save(); LifeCycle lc1 = new LifeCycle(); lc1.foo = "foo"; lc1.bar = "order"; lc1.save(); MorphiaQuery q = LifeCycle.q("bar", "order"); LifeCycle.batchDeleteFail = true; try { q.delete();
3233343536373839404142
public void testLifeCycle() { LifeCycle lc = new LifeCycle(); lc.foo = "bar"; lc.bar = "xx"; lc.save(); t("bar", OnAdd.class, 1); t("bar", Added.class, 1); t("bar2", OnAdd.class, 1); t("bar", Object.class, 2);
4041424344454647484950
t("bar", Added.class, 1); t("bar2", OnAdd.class, 1); t("bar", Object.class, 2); lc.bar = "yy"; lc.save(); t("bar", OnAdd.class, 1); t("bar", OnUpdate.class, 1); t("bar", Updated.class, 1); t("bar2", OnUpdate.class, 1);
4950515253545556575859
t("bar", Updated.class, 1); t("bar2", OnUpdate.class, 1); t("bar", Object.class, 4); lc.bar = "zz"; lc.save(); t("bar", OnAdd.class, 1); t("bar", OnUpdate.class, 2); t("bar", Updated.class, 2); t("bar2", OnUpdate.class, 2);
8283848586878889909192
@Test public void testBatchDelete() { LifeCycle lc0 = new LifeCycle(); lc0.foo = "bar"; lc0.bar = "order"; lc0.save(); LifeCycle lc1 = new LifeCycle(); lc1.foo = "foo"; lc1.bar = "order"; lc1.save();
8788899091929394959697
lc0.save(); LifeCycle lc1 = new LifeCycle(); lc1.foo = "foo"; lc1.bar = "order"; lc1.save(); LifeCycle.q("bar", "order").delete(); t("foobar", OnBatchDelete.class, 2); t("foobar", BatchDeleted.class, 2);
103104105106107108109110111112113
lc.foo = "bar"; lc.bar = "xx"; lc.addFail = true; try { lc.save(); } catch (Exception e) { // ignore } assertTrue(lc.isNew()); lc.addFail = false;