Search in sources :

Example 6 with Request

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

the class ComponentEventDispatcherTest method request_path_reference_non_existent_page.

@Test
public void request_path_reference_non_existent_page() throws Exception {
    Request request = mockRequest();
    Response response = mockResponse();
    ComponentClassResolver resolver = mockComponentClassResolver();
    LocalizationSetter ls = mockLocalizationSetter();
    expect(ls.isSupportedLocaleName("en")).andReturn(true);
    train_getPath(request, "/en/mypage.foo");
    train_isPageName(resolver, "mypage", false);
    replay();
    Dispatcher dispatcher = new ComponentEventDispatcher(null, new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, response, null, null, null, true, null, "", null, null));
    assertFalse(dispatcher.dispatch(request, response));
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) Request(org.apache.tapestry5.http.services.Request) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) Dispatcher(org.apache.tapestry5.http.services.Dispatcher) Test(org.testng.annotations.Test)

Example 7 with Request

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

the class ComponentEventDispatcherTest method no_dot_or_colon_in_path.

@Test
public void no_dot_or_colon_in_path() throws Exception {
    Request request = mockRequest();
    Response response = mockResponse();
    LocalizationSetter ls = mockLocalizationSetter();
    expect(ls.isSupportedLocaleName("foo")).andReturn(false);
    train_getPath(request, "/foo/bar/baz");
    replay();
    Dispatcher dispatcher = new ComponentEventDispatcher(null, new ComponentEventLinkEncoderImpl(null, contextPathEncoder, ls, response, null, null, null, true, null, "", null, null));
    assertFalse(dispatcher.dispatch(request, response));
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) Request(org.apache.tapestry5.http.services.Request) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) Dispatcher(org.apache.tapestry5.http.services.Dispatcher) Test(org.testng.annotations.Test)

Example 8 with Request

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

the class ComponentEventDispatcherTest method test.

private void test(String requestPath, String localeName, String containerPageName, String nestedComponentId, String eventType, String... eventContext) throws IOException {
    ComponentRequestHandler handler = mockComponentRequestHandler();
    Request request = mockRequest();
    Response response = mockResponse();
    ComponentClassResolver resolver = mockComponentClassResolver();
    LocalizationSetter localizationSetter = mockLocalizationSetter();
    MetaDataLocator metaDataLocator = neverWhitelistProtected();
    ComponentEventRequestParameters expectedParameters = new ComponentEventRequestParameters(containerPageName, containerPageName, nestedComponentId, eventType, new EmptyEventContext(), new URLEventContext(contextValueEncoder, eventContext));
    train_getPath(request, requestPath);
    expect(localizationSetter.isSupportedLocaleName(localeName)).andReturn(false);
    train_isPageName(resolver, containerPageName, true);
    train_canonicalizePageName(resolver, containerPageName, containerPageName);
    train_getParameter(request, InternalConstants.PAGE_CONTEXT_NAME, null);
    train_getParameter(request, InternalConstants.CONTAINER_PAGE_NAME, null);
    expect(request.getAttribute(InternalConstants.REFERENCED_COMPONENT_NOT_FOUND)).andStubReturn(null);
    handler.handleComponentEvent(expectedParameters);
    train_for_request_locale(request, localizationSetter);
    replay();
    Dispatcher dispatcher = new ComponentEventDispatcher(handler, new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, localizationSetter, response, null, null, null, true, null, "", metaDataLocator, null));
    assertTrue(dispatcher.dispatch(request, response));
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) URLEventContext(org.apache.tapestry5.internal.URLEventContext) ComponentEventRequestParameters(org.apache.tapestry5.services.ComponentEventRequestParameters) EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) Request(org.apache.tapestry5.http.services.Request) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) ComponentRequestHandler(org.apache.tapestry5.services.ComponentRequestHandler) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) Dispatcher(org.apache.tapestry5.http.services.Dispatcher) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator)

Example 9 with Request

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

the class ComponentEventDispatcherTest method different_active_and_containing_pages.

@Test
public void different_active_and_containing_pages() throws Exception {
    ComponentRequestHandler handler = mockComponentRequestHandler();
    Request request = mockRequest();
    Response response = mockResponse();
    ComponentClassResolver resolver = mockComponentClassResolver();
    LocalizationSetter ls = mockLocalizationSetter();
    MetaDataLocator metaDataLocator = neverWhitelistProtected();
    ComponentEventRequestParameters expectedParameters = new ComponentEventRequestParameters("activepage", "mypage", "", "eventname", new EmptyEventContext(), new EmptyEventContext());
    train_getPath(request, "/activepage:eventname");
    expect(ls.isSupportedLocaleName("activepage:eventname")).andReturn(false);
    train_isPageName(resolver, "activepage", true);
    train_canonicalizePageName(resolver, "activepage", "activepage");
    train_getParameter(request, InternalConstants.PAGE_CONTEXT_NAME, null);
    train_getParameter(request, InternalConstants.CONTAINER_PAGE_NAME, "mypage");
    expect(request.getAttribute(InternalConstants.REFERENCED_COMPONENT_NOT_FOUND)).andStubReturn(null);
    train_canonicalizePageName(resolver, "mypage", "mypage");
    train_for_request_locale(request, ls);
    handler.handleComponentEvent(expectedParameters);
    replay();
    Dispatcher dispatcher = new ComponentEventDispatcher(handler, new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, response, null, null, null, true, null, "", metaDataLocator, null));
    assertTrue(dispatcher.dispatch(request, response));
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) ComponentEventRequestParameters(org.apache.tapestry5.services.ComponentEventRequestParameters) EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) Request(org.apache.tapestry5.http.services.Request) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) ComponentRequestHandler(org.apache.tapestry5.services.ComponentRequestHandler) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) Dispatcher(org.apache.tapestry5.http.services.Dispatcher) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Example 10 with Request

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

the class BaseURLSourceImplTest method contributed_hostname.

@Test
public void contributed_hostname() {
    expect(request.getServerPort()).andReturn(80).once();
    expect(request.isSecure()).andReturn(false);
    replay();
    BaseURLSource baseURLSource = new BaseURLSourceImpl(request, "my.server.com", 0, 0);
    assertEquals(baseURLSource.getBaseURL(false), "http://my.server.com");
    verify();
}
Also used : BaseURLSourceImpl(org.apache.tapestry5.http.internal.services.BaseURLSourceImpl) BaseURLSource(org.apache.tapestry5.http.services.BaseURLSource) 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