Search in sources :

Example 1 with SessionRestorable

use of org.apache.tapestry5.hibernate.web.internal.SessionRestorable 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();
}
Also used : EntityPersistentFieldStrategy(org.apache.tapestry5.hibernate.web.internal.EntityPersistentFieldStrategy) SessionRestorable(org.apache.tapestry5.hibernate.web.internal.SessionRestorable) Session(org.hibernate.Session)

Example 2 with SessionRestorable

use of org.apache.tapestry5.hibernate.web.internal.SessionRestorable 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();
}
Also used : EntityPersistentFieldStrategy(org.apache.tapestry5.hibernate.web.internal.EntityPersistentFieldStrategy) SessionRestorable(org.apache.tapestry5.hibernate.web.internal.SessionRestorable) Session(org.hibernate.Session)

Aggregations

EntityPersistentFieldStrategy (org.apache.tapestry5.hibernate.web.internal.EntityPersistentFieldStrategy)2 SessionRestorable (org.apache.tapestry5.hibernate.web.internal.SessionRestorable)2 Session (org.hibernate.Session)2