Search in sources :

Example 1 with Analyzer

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();
}
Also used : Request(org.apache.tapestry5.http.services.Request) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 2 with Analyzer

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);
}
Also used : Request(org.apache.tapestry5.http.services.Request) PersistentFieldChange(org.apache.tapestry5.services.PersistentFieldChange) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 3 with Analyzer

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();
}
Also used : Request(org.apache.tapestry5.http.services.Request) Test(org.testng.annotations.Test)

Example 4 with Analyzer

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();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SessionPersistedObjectAnalyzer(org.apache.tapestry5.http.services.SessionPersistedObjectAnalyzer) ClusteredSessionImpl(org.apache.tapestry5.http.internal.services.ClusteredSessionImpl) HttpSession(javax.servlet.http.HttpSession) SessionLock(org.apache.tapestry5.http.internal.services.SessionLock) HttpSession(javax.servlet.http.HttpSession) Session(org.apache.tapestry5.http.services.Session) Test(org.testng.annotations.Test)

Example 5 with Analyzer

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();
}
Also used : ContentType(org.apache.tapestry5.http.ContentType) ResponseRenderer(org.apache.tapestry5.services.ResponseRenderer) Page(org.apache.tapestry5.internal.structure.Page) Component(org.apache.tapestry5.runtime.Component) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)13 Request (org.apache.tapestry5.http.services.Request)8 Link (org.apache.tapestry5.http.Link)6 AnnotationDataTypeAnalyzer (org.apache.tapestry5.commons.internal.services.AnnotationDataTypeAnalyzer)2 DataTypeAnalyzer (org.apache.tapestry5.commons.services.DataTypeAnalyzer)2 PropertyAdapter (org.apache.tapestry5.commons.services.PropertyAdapter)2 BasicValue (org.apache.tapestry5.internal.plastic.asm.tree.analysis.BasicValue)2 Page (org.apache.tapestry5.internal.structure.Page)2 PersistentFieldChange (org.apache.tapestry5.services.PersistentFieldChange)2 ResponseRenderer (org.apache.tapestry5.services.ResponseRenderer)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpSession (javax.servlet.http.HttpSession)1 ComponentResources (org.apache.tapestry5.ComponentResources)1 ContentType (org.apache.tapestry5.http.ContentType)1 ClusteredSessionImpl (org.apache.tapestry5.http.internal.services.ClusteredSessionImpl)1