Search in sources :

Example 1 with EntityPersistentFieldStrategy

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();
}
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 EntityPersistentFieldStrategy

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

Example 3 with EntityPersistentFieldStrategy

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

Aggregations

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