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