Search in sources :

Example 26 with Request

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

the class SessionApplicationStatePersistenceStrategyTest method get_aso_needs_to_be_created.

@SuppressWarnings("unchecked")
@Test
public void get_aso_needs_to_be_created() {
    Request request = mockRequest();
    Session session = mockSession();
    Class asoClass = ReadOnlyBean.class;
    Object aso = new ReadOnlyBean();
    String key = "sso:" + asoClass.getName();
    ApplicationStateCreator creator = mockApplicationStateCreator();
    // First for exists()
    train_getSession(request, false, session);
    train_isInvalidated(session, false);
    train_getAttribute(session, key, null);
    // Second for get()
    train_getSession(request, true, session);
    // Not in map
    train_getAttribute(session, key, null);
    train_create(creator, aso);
    train_getSession(request, true, session);
    session.setAttribute(key, aso);
    // Then for exists() after
    train_getSession(request, false, session);
    train_isInvalidated(session, false);
    train_getAttribute(session, key, aso);
    replay();
    ApplicationStatePersistenceStrategy strategy = new SessionApplicationStatePersistenceStrategy(request);
    assertFalse(strategy.exists(asoClass));
    assertSame(strategy.get(asoClass, creator), aso);
    assertTrue(strategy.exists(asoClass));
    verify();
}
Also used : ApplicationStatePersistenceStrategy(org.apache.tapestry5.services.ApplicationStatePersistenceStrategy) Request(org.apache.tapestry5.http.services.Request) ApplicationStateCreator(org.apache.tapestry5.services.ApplicationStateCreator) ReadOnlyBean(org.apache.tapestry5.internal.transform.pages.ReadOnlyBean) Session(org.apache.tapestry5.http.services.Session) Test(org.testng.annotations.Test)

Example 27 with Request

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

the class SessionPersistentFieldStrategyTest method post_change_to_root_component.

@Test
public void post_change_to_root_component() {
    Session session = mockSession();
    Request request = mockRequest();
    Object value = new Object();
    train_getSession(request, true, session);
    session.setAttribute("state:foo.Bar::field", value);
    replay();
    SessionPersistentFieldStrategy strategy = new SessionPersistentFieldStrategy(request);
    strategy.postChange("foo.Bar", null, "field", value);
    verify();
}
Also used : Request(org.apache.tapestry5.http.services.Request) Session(org.apache.tapestry5.http.services.Session) Test(org.testng.annotations.Test)

Example 28 with Request

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

the class SessionPersistentFieldStrategyTest method post_change_to_nested_component.

@Test
public void post_change_to_nested_component() {
    Session session = mockSession();
    Request request = mockRequest();
    Object value = new Object();
    train_getSession(request, true, session);
    session.setAttribute("state:foo.Bar:fee.fum:field", value);
    replay();
    SessionPersistentFieldStrategy strategy = new SessionPersistentFieldStrategy(request);
    strategy.postChange("foo.Bar", "fee.fum", "field", value);
    verify();
}
Also used : Request(org.apache.tapestry5.http.services.Request) Session(org.apache.tapestry5.http.services.Session) Test(org.testng.annotations.Test)

Example 29 with Request

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

the class SessionPersistentFieldStrategyTest method discard_changes.

/**
 * TAPESTRY-1475
 */
@Test
public void discard_changes() {
    Session session = mockSession();
    Request request = mockRequest();
    train_getSession(request, false, session);
    train_getAttributeNames(session, "state:foo.Bar:", "state:foo.Bar:baz:field");
    session.setAttribute("state:foo.Bar:baz:field", null);
    replay();
    SessionPersistentFieldStrategy strategy = new SessionPersistentFieldStrategy(request);
    strategy.discardChanges("foo.Bar");
    verify();
}
Also used : Request(org.apache.tapestry5.http.services.Request) Session(org.apache.tapestry5.http.services.Session) Test(org.testng.annotations.Test)

Example 30 with Request

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

the class PageRenderRequestHandlerImplTest method loopback_request.

@Test
public void loopback_request() throws Exception {
    RequestPageCache cache = mockRequestPageCache();
    ComponentEventResultProcessor processor = mockComponentEventResultProcessor();
    PageResponseRenderer renderer = mockPageResponseRenderer();
    Page page = mockPage();
    EventContext context = mockEventContext();
    ComponentPageElement root = mockComponentPageElement();
    InternalComponentResources pageResources = mockInternalComponentResources();
    PageActivator activator = newMock(PageActivator.class);
    Request request = mockRequest();
    train_getAttribute(request, InternalConstants.BYPASS_ACTIVATION, null);
    train_get(cache, "foo/Bar", page);
    train_getRootElement(page, root);
    train_getComponentResources(root, pageResources);
    expect(activator.activatePage(pageResources, context, processor)).andReturn(false);
    // Skips the pageReset()
    renderer.renderPageResponse(page);
    replay();
    PageRenderRequestHandler handler = new PageRenderRequestHandlerImpl(cache, processor, renderer, activator, request);
    PageRenderRequestParameters parameters = new PageRenderRequestParameters("foo/Bar", context, true);
    handler.handle(parameters);
    verify();
}
Also used : EventContext(org.apache.tapestry5.EventContext) PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ComponentPageElement(org.apache.tapestry5.internal.structure.ComponentPageElement) ComponentEventResultProcessor(org.apache.tapestry5.services.ComponentEventResultProcessor) InternalComponentResources(org.apache.tapestry5.internal.InternalComponentResources) Request(org.apache.tapestry5.http.services.Request) PageRenderRequestHandler(org.apache.tapestry5.services.PageRenderRequestHandler) Page(org.apache.tapestry5.internal.structure.Page) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)86 Request (org.apache.tapestry5.http.services.Request)83 Response (org.apache.tapestry5.http.services.Response)25 HttpServletRequest (javax.servlet.http.HttpServletRequest)19 LocalizationSetter (org.apache.tapestry5.services.LocalizationSetter)19 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)18 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)17 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)15 HttpServletResponse (javax.servlet.http.HttpServletResponse)14 Session (org.apache.tapestry5.http.services.Session)14 Link (org.apache.tapestry5.http.Link)12 RequestImpl (org.apache.tapestry5.http.internal.services.RequestImpl)11 ComponentEventRequestParameters (org.apache.tapestry5.services.ComponentEventRequestParameters)9 Context (org.apache.tapestry5.http.services.Context)8 RequestFilter (org.apache.tapestry5.http.services.RequestFilter)8 RequestHandler (org.apache.tapestry5.http.services.RequestHandler)8 IOException (java.io.IOException)7 BaseURLSourceImpl (org.apache.tapestry5.http.internal.services.BaseURLSourceImpl)7 BaseURLSource (org.apache.tapestry5.http.services.BaseURLSource)7 Dispatcher (org.apache.tapestry5.http.services.Dispatcher)7