@Test public void shouldUseUpdatedAsModifiedDateIfUpdated() throws Exception { ENTITY entity = createInstance(); forceCreated(entity); Date created = entity.getCreated(); Date modified = entity.getLastModified(); Assert.assertEquals(created, modified); Thread.sleep(10); // force a tiny sleep to throw the dates off forceUpdate(entity); modified = entity.getLastModified(); Assert.assertNotEquals(created, modified); }
@GET @Path("/{id}") @Produces({ BASE_JSON_MEDIA_TYPE, BASE_XML_MEDIA_TYPE }) public Response get(@PathParam("id") String id) { DOMAIN entity = getRepository().get(id); if (entity == null) { return Response.status(Status.NOT_FOUND).type(getMediaType()).build(); } return Response.ok(getConverter().from(uriInfo, entity)) .type(getMediaType()) .lastModified(entity.getLastModified()) .build(); }
@Test public void shouldNotLeakCreatedDate() throws Exception { ENTITY entity = createInstance(); forceCreated(entity); Date date = entity.getCreated(); date.setTime(100); Assert.assertNotEquals(date, entity.getCreated()); }
@Test public void shouldNotLeakModifiedDate() throws Exception { ENTITY entity = createInstance(); forceCreated(entity); forceUpdate(entity); Date date = entity.getLastModified(); date.setTime(100); Assert.assertNotEquals(date, entity.getLastModified()); } }
@Test public void shouldReturnCreatedDate() throws Exception { ENTITY entity = createInstance(); forceCreated(entity); Assert.assertNotNull(entity.getCreated()); }
@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 shouldSetUpdatedDate() throws Exception { DOMAIN domain = createNewDomainObject(); Assume.assumeTrue(domain instanceof Timestampable); commit(Void.class, new Store(domain)); DOMAIN stored = commit(new Get(domain.getId())); stored = updateDomainObject(stored); stored = commit(new Get(domain.getId())); Timestampable timed = (Timestampable)stored; Assert.assertNotNull(timed.getCreated()); Assert.assertNotSame(timed.getCreated(), timed.getLastModified()); }