@Test public void shouldNotStoreObjectOnRollback() throws Exception { final DOMAIN domain = createNewDomainObject(); rollback(Void.class, new Store(domain)); DOMAIN stored = commit(getDomainClass(), new Get(domain.getId())); Assert.assertNull("Object should not be stored when transaction is rolled back", stored); }
@Test public void shouldStoreObjectOnCommit() throws Exception { final DOMAIN domain = createNewDomainObject(); commit(Void.class, new Store(domain)); DOMAIN stored = commit(new Get(domain.getId())); Assert.assertNotNull("Object should be stored when transaction is committed", stored); }
@Test public void shouldUpdateObjectOnCommit() throws Exception { final DOMAIN domain = createNewDomainObject(); commit(Void.class, new Store(domain)); DOMAIN stored = commit(new Get(domain.getId())); updateDomainObject(stored); commit(Void.class, new Store(stored)); DOMAIN updated = commit(new Get(domain.getId())); validateUpdatedDomainObject(updated); }
@Test public void shouldSetCreatedDate() throws Exception { DOMAIN domain = createNewDomainObject(); Assume.assumeTrue(domain instanceof Timestampable); commit(Void.class, new Store(domain)); DOMAIN stored = commit(new Get(domain.getId())); Timestampable timed = (Timestampable) stored; Assert.assertNotNull(timed.getCreated()); Assert.assertEquals(timed.getCreated(), timed.getLastModified()); }
@Test public void shouldNotUpdateObjectOnRollback() throws Exception { final DOMAIN domain = createNewDomainObject(); commit(Void.class, new Store(domain)); DOMAIN stored = commit(new Get(domain.getId())); updateDomainObject(stored); rollback(Void.class, new Store(stored)); DOMAIN updated = commit(new Get(domain.getId())); try { validateUpdatedDomainObject(updated); Assert.fail("Object should not be updated when transaction is rolled back"); } catch (AssertionError error) { // no-op, the updated object should not validate as a updated one } }