Search in sources :

Example 1 with EmptyEventContext

use of org.apache.tapestry5.internal.EmptyEventContext 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 2 with EmptyEventContext

use of org.apache.tapestry5.internal.EmptyEventContext 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 3 with EmptyEventContext

use of org.apache.tapestry5.internal.EmptyEventContext in project tapestry-5 by apache.

the class RequestSecurityManagerImplTest method check_page_not_secure.

@Test
public void check_page_not_secure() throws Exception {
    Request request = mockRequest();
    Response response = mockResponse();
    MetaDataLocator locator = mockMetaDataLocator();
    ComponentEventLinkEncoder encoder = newMock(ComponentEventLinkEncoder.class);
    train_isSecure(request, false);
    train_isSecure(locator, PAGE_NAME, false);
    replay();
    PageRenderRequestParameters parameters = new PageRenderRequestParameters(PAGE_NAME, new EmptyEventContext(), false);
    RequestSecurityManager manager = new RequestSecurityManagerImpl(request, response, encoder, locator, true);
    assertFalse(manager.checkForInsecurePageRenderRequest(parameters));
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ComponentEventLinkEncoder(org.apache.tapestry5.services.ComponentEventLinkEncoder) EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) Request(org.apache.tapestry5.http.services.Request) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Example 4 with EmptyEventContext

use of org.apache.tapestry5.internal.EmptyEventContext in project tapestry-5 by apache.

the class StreamPageContentResultProcessor method processResultValue.

public void processResultValue(StreamPageContent value) throws IOException {
    Class<?> pageClass = value.getPageClass();
    Object[] activationContext = value.getPageActivationContext();
    final String pageName = pageClass == null ? requestGlobals.getActivePageName() : resolver.resolvePageClassNameToPageName(pageClass.getName());
    final EventContext context = activationContext == null ? new EmptyEventContext() : new ArrayEventContext(typeCoercer, activationContext);
    if (value.isBypassActivation()) {
        request.setAttribute(InternalConstants.BYPASS_ACTIVATION, true);
    }
    request.setAttribute(TapestryConstants.RESPONSE_RENDERER, new IOOperation<Void>() {

        public Void perform() throws IOException {
            handler.handle(new PageRenderRequestParameters(pageName, context, false));
            return null;
        }
    });
}
Also used : EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) EventContext(org.apache.tapestry5.EventContext) PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) IOException(java.io.IOException)

Example 5 with EmptyEventContext

use of org.apache.tapestry5.internal.EmptyEventContext in project tapestry-5 by apache.

the class ComponentEventLinkEncoderImplTest method root_index_page_gone.

@Test
public void root_index_page_gone() {
    RequestSecurityManager manager = mockRequestSecurityManager();
    Response response = mockResponse();
    ContextPathEncoder contextPathEncoder = getService(ContextPathEncoder.class);
    expect(manager.checkPageSecurity("Index")).andReturn(LinkSecurity.INSECURE);
    train_encodeURL(response, "/", "MAGIC");
    replay();
    ComponentEventLinkEncoder encoder = new ComponentEventLinkEncoderImpl(null, contextPathEncoder, null, response, manager, null, null, false, "", "", null, null);
    PageRenderRequestParameters parameters = new PageRenderRequestParameters("Index", new EmptyEventContext());
    Link link = encoder.createPageRenderLink(parameters);
    assertEquals(link.toURI(), "MAGIC");
    verify();
}
Also used : Response(org.apache.tapestry5.http.services.Response) PageRenderRequestParameters(org.apache.tapestry5.services.PageRenderRequestParameters) ContextPathEncoder(org.apache.tapestry5.services.ContextPathEncoder) ComponentEventLinkEncoder(org.apache.tapestry5.services.ComponentEventLinkEncoder) EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Aggregations

EmptyEventContext (org.apache.tapestry5.internal.EmptyEventContext)10 Response (org.apache.tapestry5.http.services.Response)9 Test (org.testng.annotations.Test)8 Request (org.apache.tapestry5.http.services.Request)7 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)7 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)6 ComponentEventLinkEncoder (org.apache.tapestry5.services.ComponentEventLinkEncoder)5 Dispatcher (org.apache.tapestry5.http.services.Dispatcher)4 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)4 ComponentEventRequestParameters (org.apache.tapestry5.services.ComponentEventRequestParameters)4 ComponentRequestHandler (org.apache.tapestry5.services.ComponentRequestHandler)4 LocalizationSetter (org.apache.tapestry5.services.LocalizationSetter)4 Link (org.apache.tapestry5.http.Link)3 URLEventContext (org.apache.tapestry5.internal.URLEventContext)2 ContextPathEncoder (org.apache.tapestry5.services.ContextPathEncoder)2 IOException (java.io.IOException)1 EventContext (org.apache.tapestry5.EventContext)1 ClientWhitelist (org.apache.tapestry5.services.security.ClientWhitelist)1