@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 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 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); }
@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()); } }
private Node getOrCreateNode(Identifiable source, final String nodeClassType) { UniqueFactory<Node> factory = new UniqueFactory.UniqueNodeFactory(graph, PROP_INDEX_NODE) { @Override protected void initialize(Node created, Map<String, Object> properties) { created.setProperty(PROP_ID, properties.get(PROP_ID)); created.setProperty(PROP_NODE_CLASS, nodeClassType); } }; return factory.getOrCreate(PROP_ID, source.getId()); }
@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()); }
@Test public void shouldReturnCreatedDate() throws Exception { ENTITY entity = createInstance(); forceCreated(entity); Assert.assertNotNull(entity.getCreated()); }
@Override public T get(String id) { for(T conference: conferences) { if(conference.getId().equals(id)) { return conference; } } return null; }
@Override public T get(String id) { for(T d : data) { if(d.getId().equals(id)) { return d; } } return null; }
@Override public void appendLinks(LinkableRepresentation<?> representation) { Resource source = getResource(representation); if(source == null) { return; } if(representation instanceof Identifiable) { Identifiable sourceObject = (Identifiable)representation; if(sourceObject.getId() != null) { representation.addLink( generateResourceLink( source, sourceObject.getId(), representation.getUriInfo())); } } }
@Override public void remove(Identifiable source, String type, Identifiable target) { for(int i = 0; i < relations.size(); i++) { ExtendedRelation rel = relations.get(i); if(rel.getSourceId().equals(source.getId()) && rel.getTargetId().equals(target.getId()) && rel.getType().equals(type)) { relations.remove(i); i--; } } }
@SuppressWarnings("unchecked") @Override public <T extends Identifiable> List<T> findTargets(Identifiable source, String type, Class<T> targetType) { List<T> result = new ArrayList<T>(); for(ExtendedRelation rel : relations) { if(rel.getSourceId().equals(source.getId()) && rel.getType().equals(type)) { result.add((T)rel.getTarget()); } } return result; }
@Test public void shouldUpdateObjectOnCommit() throws Exception { final DOMAIN domain = createNewDomainObject(); commit(Void.class, new Store(domain)); DOMAIN stored = commit(new Get(domain.getId())); stored = updateDomainObject(stored); commit(Void.class, new Store(stored)); DOMAIN updated = commit(new Get(domain.getId())); validateUpdatedDomainObject(updated); }
@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 shouldNotUpdateObjectOnRollback() throws Exception { final DOMAIN domain = createNewDomainObject(); commit(Void.class, new Store(domain)); DOMAIN stored = commit(new Get(domain.getId())); stored = 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 } }
@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); }
@Override public void perform() { responseValidation( given(). then(). contentType(getTypedMediaType()) , domain). when(). get(createRootURL() + "/{id}", domain.getId()). body(); } }).inspect(new SetupRepository<DOMAIN>(getDomainClass(), domain));
@Test public void shouldNotRemoveObjectOnRollback() throws Exception { DOMAIN domain = createNewDomainObject(); commit(Void.class, new Store(domain)); rollback(Void.class, new Remove(domain)); DOMAIN stored = commit(new Get(domain.getId())); Assert.assertNotNull( "Object should not be removed when transaction is rolled back", stored); }
@Test public void shouldRemoveObjectOnCommmit() throws Exception { DOMAIN domain = createNewDomainObject(); commit(Void.class, new Store(domain)); commit(Void.class, new Remove(domain)); DOMAIN stored = commit(new Get(domain.getId())); Assert.assertNull( "Object should be removed when transaction is committed", stored); }