Search in sources :

Example 1 with URLEventContext

use of org.apache.tapestry5.internal.URLEventContext 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 URLEventContext

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

the class SelectTest method context_that_needs_to_be_encoded.

@Test
public void context_that_needs_to_be_encoded() throws Exception {
    ValueEncoderSource valueEncoderSource = mockValueEncoderSource();
    TypeCoercer typeCoercer = getService(TypeCoercer.class);
    ContextValueEncoder contextValueEncoder = new ContextValueEncoderImpl(valueEncoderSource);
    ValueEncoder<Platform> platformEncoder = new ValueEncoder<SelectTest.Platform>() {

        @Override
        public Platform toValue(String clientValue) {
            return Platform.valueOf(clientValue.substring(10));
        }

        @Override
        public String toClient(Platform value) {
            return "Platform: " + value.name();
        }
    };
    InternalComponentResources resources = mockInternalComponentResources();
    expect(valueEncoderSource.getValueEncoder(Platform.class)).andReturn(platformEncoder).anyTimes();
    expect(valueEncoderSource.getValueEncoder(String.class)).andReturn(new StringValueEncoder()).anyTimes();
    expect(resources.triggerContextEvent(EasyMock.eq(EventConstants.VALUE_CHANGED), eqEventContext(null, Platform.LINUX), EasyMock.isA(ComponentEventCallback.class))).andReturn(true);
    Select select = new Select();
    set(select, "resources", resources);
    set(select, "encoder", new StringValueEncoder());
    set(select, "typeCoercer", typeCoercer);
    replay();
    select.onChange(new URLEventContext(contextValueEncoder, new String[] { platformEncoder.toClient(Platform.LINUX) }), null);
    verify();
}
Also used : Platform(org.apache.tapestry5.corelib.components.SelectTest.Platform) InternalComponentResources(org.apache.tapestry5.internal.InternalComponentResources) TypeCoercer(org.apache.tapestry5.commons.services.TypeCoercer) StringValueEncoder(org.apache.tapestry5.internal.services.StringValueEncoder) ValueEncoderSource(org.apache.tapestry5.services.ValueEncoderSource) EnumValueEncoder(org.apache.tapestry5.util.EnumValueEncoder) ContextValueEncoder(org.apache.tapestry5.services.ContextValueEncoder) StringValueEncoder(org.apache.tapestry5.internal.services.StringValueEncoder) URLEventContext(org.apache.tapestry5.internal.URLEventContext) ContextValueEncoder(org.apache.tapestry5.services.ContextValueEncoder) ContextValueEncoderImpl(org.apache.tapestry5.internal.services.ContextValueEncoderImpl) Test(org.testng.annotations.Test)

Example 3 with URLEventContext

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

the class ComponentEventDispatcherTest method page_activation_context_in_request.

@Test
public void page_activation_context_in_request() throws Exception {
    ComponentRequestHandler handler = mockComponentRequestHandler();
    Request request = mockRequest();
    Response response = mockResponse();
    ComponentClassResolver resolver = mockComponentClassResolver();
    LocalizationSetter ls = mockLocalizationSetter();
    MetaDataLocator metaDataLocator = neverWhitelistProtected();
    ComponentEventRequestParameters expectedParameters = new ComponentEventRequestParameters("mypage", "mypage", "", "eventname", new URLEventContext(contextValueEncoder, new String[] { "alpha", "beta" }), new EmptyEventContext());
    train_getPath(request, "/mypage:eventname");
    expect(ls.isSupportedLocaleName("mypage:eventname")).andReturn(false);
    train_isPageName(resolver, "mypage", true);
    train_canonicalizePageName(resolver, "mypage", "mypage");
    train_getParameter(request, InternalConstants.PAGE_CONTEXT_NAME, "alpha/beta");
    train_getParameter(request, InternalConstants.CONTAINER_PAGE_NAME, null);
    expect(request.getAttribute(InternalConstants.REFERENCED_COMPONENT_NOT_FOUND)).andStubReturn(null);
    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 : Request(org.apache.tapestry5.http.services.Request) LocalizationSetter(org.apache.tapestry5.services.LocalizationSetter) Dispatcher(org.apache.tapestry5.http.services.Dispatcher) 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) ComponentClassResolver(org.apache.tapestry5.services.ComponentClassResolver) ComponentRequestHandler(org.apache.tapestry5.services.ComponentRequestHandler) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) Test(org.testng.annotations.Test)

Aggregations

URLEventContext (org.apache.tapestry5.internal.URLEventContext)3 Dispatcher (org.apache.tapestry5.http.services.Dispatcher)2 Request (org.apache.tapestry5.http.services.Request)2 Response (org.apache.tapestry5.http.services.Response)2 EmptyEventContext (org.apache.tapestry5.internal.EmptyEventContext)2 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)2 ComponentEventRequestParameters (org.apache.tapestry5.services.ComponentEventRequestParameters)2 ComponentRequestHandler (org.apache.tapestry5.services.ComponentRequestHandler)2 LocalizationSetter (org.apache.tapestry5.services.LocalizationSetter)2 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)2 Test (org.testng.annotations.Test)2 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)1 Platform (org.apache.tapestry5.corelib.components.SelectTest.Platform)1 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)1 ContextValueEncoderImpl (org.apache.tapestry5.internal.services.ContextValueEncoderImpl)1 StringValueEncoder (org.apache.tapestry5.internal.services.StringValueEncoder)1 ContextValueEncoder (org.apache.tapestry5.services.ContextValueEncoder)1 ValueEncoderSource (org.apache.tapestry5.services.ValueEncoderSource)1 EnumValueEncoder (org.apache.tapestry5.util.EnumValueEncoder)1