use of org.apache.tapestry5.internal.plastic.asm.tree.analysis.Analyzer in project tapestry-5 by apache.
the class ClientPersistentFieldStorageImplTest method null_value_is_a_remove.
@Test
public void null_value_is_a_remove() {
Request request = mockRequest(null);
Link link = mockLink();
String pageName = "Foo";
String componentId = "bar.baz";
String fieldName = "woops";
replay();
ClientPersistentFieldStorage storage = new ClientPersistentFieldStorageImpl(request, clientDataEncoder, analyzer);
storage.postChange(pageName, componentId, fieldName, 99);
storage.postChange(pageName, componentId, fieldName, null);
storage.updateLink(link);
assertTrue(storage.gatherFieldChanges(pageName).isEmpty());
verify();
}
use of org.apache.tapestry5.internal.plastic.asm.tree.analysis.Analyzer 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.internal.plastic.asm.tree.analysis.Analyzer in project tapestry-5 by apache.
the class ClientPersistentFieldStorageImplTest method value_not_serializable.
@Test
public void value_not_serializable() {
Request request = mockRequest(null);
Object badBody = new Object() {
@Override
public String toString() {
return "<BadBoy>";
}
};
replay();
ClientPersistentFieldStorage storage = new ClientPersistentFieldStorageImpl(request, clientDataEncoder, analyzer);
try {
storage.postChange("Foo", "bar.baz", "woops", badBody);
unreachable();
} catch (IllegalArgumentException ex) {
assertEquals(ex.getMessage(), "State persisted on the client must be serializable, but <BadBoy> does not implement the Serializable interface.");
}
verify();
}
use of org.apache.tapestry5.internal.plastic.asm.tree.analysis.Analyzer in project tapestry-5 by apache.
the class SessionImplTest method dirty_persisted_object_is_forced_to_update.
@Test
public void dirty_persisted_object_is_forced_to_update() {
HttpSession hs = mockHttpSession();
HttpServletRequest hsr = mockHttpServletRequest();
SessionPersistedObjectAnalyzer analyzer = newMock(SessionPersistedObjectAnalyzer.class);
Object dirty = new Object();
SessionLock lock = mockLock();
lock.acquireWriteLock();
train_getAttribute(hs, "dirty", dirty);
replay();
Session session = new ClusteredSessionImpl(hsr, hs, lock, analyzer);
assertSame(session.getAttribute("dirty"), dirty);
verify();
expect(analyzer.checkAndResetDirtyState(dirty)).andReturn(true);
train_getSession(hsr, false, hs);
lock.acquireWriteLock();
hs.setAttribute("dirty", dirty);
replay();
session.restoreDirtyObjects();
verify();
}
use of org.apache.tapestry5.internal.plastic.asm.tree.analysis.Analyzer in project tapestry-5 by apache.
the class ResponseRendererImplTest method content_type_from_component.
@Test
public void content_type_from_component() {
RequestPageCache cache = mockRequestPageCache();
PageContentTypeAnalyzer analyzer = mockPageContentTypeAnalyzer();
Component component = mockComponent();
String pageName = "foo/bar";
Page page = mockPage();
ContentType contentType = new ContentType("zig/zag");
ComponentResources resources = mockComponentResources();
train_getComponentResources(component, resources);
train_getPageName(resources, pageName);
train_get(cache, pageName, page);
train_findContentType(analyzer, page, contentType);
replay();
ResponseRenderer renderer = new ResponseRendererImpl(cache, analyzer, null);
assertSame(renderer.findContentType(component), contentType);
verify();
}
Aggregations