use of org.apache.tapestry5.services.PersistentFieldChange in project tapestry-5 by apache.
the class ClientPersistentFieldStorageImplTest method store_and_restore_a_change.
@SuppressWarnings("unchecked")
@Test
public void store_and_restore_a_change() {
Request request = mockRequest(null);
Link link = mockLink();
String pageName = "Foo";
String componentId = "bar.baz";
String fieldName = "biff";
Object value = 99;
final Holder<String> holder = captureLinkModification(link);
replay();
ClientPersistentFieldStorage storage1 = new ClientPersistentFieldStorageImpl(request, clientDataEncoder, analyzer);
storage1.postChange(pageName, componentId, fieldName, value);
List<PersistentFieldChange> changes1 = newList(storage1.gatherFieldChanges(pageName));
storage1.updateLink(link);
verify();
assertEquals(changes1.size(), 1);
PersistentFieldChange change1 = changes1.get(0);
assertEquals(change1.getComponentId(), componentId);
assertEquals(change1.getFieldName(), fieldName);
assertEquals(change1.getValue(), value);
// Now more training ...
train_getParameter(request, ClientPersistentFieldStorageImpl.PARAMETER_NAME, holder.get());
replay();
ClientPersistentFieldStorage storage2 = new ClientPersistentFieldStorageImpl(request, clientDataEncoder, analyzer);
List<PersistentFieldChange> changes2 = newList(storage2.gatherFieldChanges(pageName));
verify();
assertEquals(changes2.size(), 1);
PersistentFieldChange change2 = changes2.get(0);
assertEquals(change2.getComponentId(), componentId);
assertEquals(change2.getFieldName(), fieldName);
assertEquals(change2.getValue(), value);
assertNotSame(change1, change2);
}
use of org.apache.tapestry5.services.PersistentFieldChange in project tapestry-5 by apache.
the class PersistentFieldBundleImplTest method get_nested_component_value.
@Test
public void get_nested_component_value() {
String value = "FIELD-VALUE";
PersistentFieldChange change = new PersistentFieldChangeImpl("foo.bar", "field", value);
Collection<PersistentFieldChange> changes = Arrays.asList(change);
PersistentFieldBundle bundle = new PersistentFieldBundleImpl(changes);
assertTrue(bundle.containsValue("foo.bar", "field"));
assertSame(bundle.getValue("foo.bar", "field"), value);
assertFalse(bundle.containsValue("foo.bar", "other"));
}
use of org.apache.tapestry5.services.PersistentFieldChange in project tapestry-5 by apache.
the class PersistentFieldBundleImplTest method get_root_component_value.
@Test
public void get_root_component_value() {
String value = "FIELD-VALUE";
PersistentFieldChange change = new PersistentFieldChangeImpl("", "field", value);
Collection<PersistentFieldChange> changes = Arrays.asList(change);
PersistentFieldBundle bundle = new PersistentFieldBundleImpl(changes);
assertTrue(bundle.containsValue("", "field"));
assertTrue(bundle.containsValue(null, "field"));
assertSame(bundle.getValue("", "field"), value);
assertSame(bundle.getValue(null, "field"), value);
assertFalse(bundle.containsValue("", "other"));
assertFalse(bundle.containsValue(null, "other"));
}
use of org.apache.tapestry5.services.PersistentFieldChange 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.PersistentFieldChange in project tapestry-5 by apache.
the class AbstractSessionPersistentFieldStrategy method gatherFieldChanges.
public final Collection<PersistentFieldChange> gatherFieldChanges(String pageName) {
Session session = request.getSession(false);
if (session == null)
return Collections.emptyList();
List<PersistentFieldChange> result = newList();
String fullPrefix = prefix + pageName + ":";
for (String name : session.getAttributeNames(fullPrefix)) {
Object persistedValue = session.getAttribute(name);
Object applicationValue = persistedValue == null ? null : convertPersistedToApplicationValue(persistedValue);
PersistentFieldChange change = buildChange(name, applicationValue);
result.add(change);
didReadChange(session, name);
}
return result;
}
Aggregations