Search in sources :

Example 16 with Session

use of org.apache.tapestry5.services.Session in project tapestry-5 by apache.

the class SessionPersistentFieldStrategyTest method gather_changes_with_active_session.

@Test
public void gather_changes_with_active_session() {
    Session session = mockSession();
    Request request = mockRequest();
    train_getSession(request, false, session);
    train_getAttributeNames(session, "state:foo.Bar:", "state:foo.Bar::root", "state:foo.Bar:nested:down");
    train_getAttribute(session, "state:foo.Bar::root", "ROOT");
    train_getAttribute(session, "state:foo.Bar:nested:down", "DOWN");
    replay();
    SessionPersistentFieldStrategy stategy = new SessionPersistentFieldStrategy(request);
    Collection<PersistentFieldChange> changes = stategy.gatherFieldChanges("foo.Bar");
    assertEquals(changes.size(), 2);
    Iterator<PersistentFieldChange> i = changes.iterator();
    PersistentFieldChange change1 = i.next();
    assertEquals(change1.getComponentId(), "");
    assertEquals(change1.getFieldName(), "root");
    assertEquals(change1.getValue(), "ROOT");
    PersistentFieldChange change2 = i.next();
    assertEquals(change2.getComponentId(), "nested");
    assertEquals(change2.getFieldName(), "down");
    assertEquals(change2.getValue(), "DOWN");
    verify();
}
Also used : Request(org.apache.tapestry5.http.services.Request) PersistentFieldChange(org.apache.tapestry5.services.PersistentFieldChange) Session(org.apache.tapestry5.http.services.Session) Test(org.testng.annotations.Test)

Example 17 with Session

use of org.apache.tapestry5.services.Session in project tapestry-5 by apache.

the class HibernateSessionSourceImplTest method startup_without_packages.

@Test
public void startup_without_packages() {
    Collection<String> packageNames = CollectionFactory.newList("org.example.myapp.entities", "org.example.app0.entities");
    HibernateEntityPackageManager packageManager = newMock(HibernateEntityPackageManager.class);
    TestBase.expect(packageManager.getPackageNames()).andReturn(packageNames);
    ClasspathScannerImpl scanner = new ClasspathScannerImpl(new ClasspathURLConverterImpl());
    ClassNameLocatorImpl classNameLocator = new ClassNameLocatorImpl(scanner);
    List<HibernateConfigurer> filters = Arrays.asList(new DefaultHibernateConfigurer(true), new PackageNameHibernateConfigurer(packageManager, classNameLocator));
    replay();
    HibernateSessionSource source = new HibernateSessionSourceImpl(log, filters);
    Session session = source.create();
    Assert.assertNotNull(session);
    // make sure it found the entity in the package
    ClassMetadata meta = session.getSessionFactory().getClassMetadata(User.class);
    Assert.assertEquals(meta.getEntityName(), "org.example.app0.entities.User");
    verify();
}
Also used : ClassMetadata(org.hibernate.metadata.ClassMetadata) HibernateSessionSourceImpl(org.apache.tapestry5.hibernate.internal.HibernateSessionSourceImpl) PackageNameHibernateConfigurer(org.apache.tapestry5.hibernate.internal.PackageNameHibernateConfigurer) DefaultHibernateConfigurer(org.apache.tapestry5.hibernate.internal.DefaultHibernateConfigurer) HibernateSessionSource(org.apache.tapestry5.hibernate.HibernateSessionSource) ClasspathScannerImpl(org.apache.tapestry5.ioc.internal.services.ClasspathScannerImpl) DefaultHibernateConfigurer(org.apache.tapestry5.hibernate.internal.DefaultHibernateConfigurer) PackageNameHibernateConfigurer(org.apache.tapestry5.hibernate.internal.PackageNameHibernateConfigurer) HibernateConfigurer(org.apache.tapestry5.hibernate.HibernateConfigurer) ClasspathURLConverterImpl(org.apache.tapestry5.ioc.internal.services.ClasspathURLConverterImpl) ClassNameLocatorImpl(org.apache.tapestry5.ioc.internal.services.ClassNameLocatorImpl) HibernateEntityPackageManager(org.apache.tapestry5.hibernate.HibernateEntityPackageManager) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 18 with Session

use of org.apache.tapestry5.services.Session in project tapestry-5 by apache.

the class SSOEntity method getPersistedEntityClassName.

public String getPersistedEntityClassName() {
    Session session = request.getSession(true);
    Object value = session.getAttribute("sso:" + User.class.getName());
    System.err.println("getPersistedEntityClassName(): " + value);
    return value.getClass().getName();
}
Also used : Session(org.apache.tapestry5.http.services.Session)

Example 19 with Session

use of org.apache.tapestry5.services.Session 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 20 with Session

use of org.apache.tapestry5.services.Session 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

Test (org.testng.annotations.Test)31 Session (org.apache.tapestry5.http.services.Session)30 Request (org.apache.tapestry5.http.services.Request)14 HttpSession (javax.servlet.http.HttpSession)10 Logger (org.slf4j.Logger)8 ClusteredSessionImpl (org.apache.tapestry5.http.internal.services.ClusteredSessionImpl)7 Session (org.hibernate.Session)7 SessionImpl (org.apache.tapestry5.http.internal.services.SessionImpl)6 ApplicationStatePersistenceStrategy (org.apache.tapestry5.services.ApplicationStatePersistenceStrategy)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Resource (org.apache.tapestry5.commons.Resource)5 SessionLock (org.apache.tapestry5.http.internal.services.SessionLock)5 MutableComponentModel (org.apache.tapestry5.model.MutableComponentModel)5 HibernateEntityValueEncoder (org.apache.tapestry5.hibernate.web.internal.HibernateEntityValueEncoder)4 ReadOnlyBean (org.apache.tapestry5.internal.transform.pages.ReadOnlyBean)4 EntityPersistentFieldStrategy (org.apache.tapestry5.hibernate.web.internal.EntityPersistentFieldStrategy)3 RequestImpl (org.apache.tapestry5.http.internal.services.RequestImpl)3 TapestrySessionFactory (org.apache.tapestry5.http.internal.services.TapestrySessionFactory)3 PersistentFieldChange (org.apache.tapestry5.services.PersistentFieldChange)3 Enumeration (java.util.Enumeration)2