use of org.apache.tapestry5.hibernate.web.internal.EntityPersistentFieldStrategy in project tapestry-5 by apache.
the class EntityPersistentFieldStrategyTest method transient_entity.
public void transient_entity() {
SampleEntity entity = new SampleEntity();
Session session = newMock(Session.class);
EntityPersistentFieldStrategy strategy = new EntityPersistentFieldStrategy(session, null);
expect(session.contains(entity)).andReturn(false);
replay();
Object persisted = strategy.convertApplicationValueToPersisted(entity);
assert persisted instanceof SessionRestorable;
Object restored = strategy.convertPersistedToApplicationValue(persisted);
assertSame(entity, restored);
verify();
}
use of org.apache.tapestry5.hibernate.web.internal.EntityPersistentFieldStrategy in project tapestry-5 by apache.
the class EntityPersistentFieldStrategyTest method persistent_entity.
public void persistent_entity() {
SampleEntity entity = new SampleEntity();
SampleEntity restoredEntity = new SampleEntity();
Session session = newMock(Session.class);
EntityPersistentFieldStrategy strategy = new EntityPersistentFieldStrategy(session, null);
expect(session.contains(entity)).andReturn(true);
expect(session.getEntityName(entity)).andReturn("SampleEntity");
expect(session.getIdentifier(entity)).andReturn(42);
expect(session.get("SampleEntity", 42)).andReturn(restoredEntity);
replay();
Object persisted = strategy.convertApplicationValueToPersisted(entity);
assert persisted instanceof SessionRestorable;
Object restored = strategy.convertPersistedToApplicationValue(persisted);
assertSame(restored, restoredEntity);
verify();
}
use of org.apache.tapestry5.hibernate.web.internal.EntityPersistentFieldStrategy in project tapestry-5 by apache.
the class EntityPersistentFieldStrategyTest method not_an_entity.
public void not_an_entity() {
String nonEntity = "foo";
Session session = newMock(Session.class);
EntityPersistentFieldStrategy strategy = new EntityPersistentFieldStrategy(session, null);
expect(session.contains(nonEntity)).andReturn(true);
expect(session.getEntityName(nonEntity)).andThrow(new HibernateException("error"));
replay();
try {
strategy.postChange("pageName", "", "fieldName", nonEntity);
unreachable();
} catch (IllegalArgumentException ex) {
assertEquals(ex.getMessage(), "Failed persisting an entity in the session. entity: foo");
}
verify();
}
Aggregations