use of org.apache.tapestry5.services.ContextValueEncoder 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();
}
use of org.apache.tapestry5.services.ContextValueEncoder 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();
}
use of org.apache.tapestry5.services.ContextValueEncoder in project tapestry-5 by apache.
the class ContextValueEncoderImplTest method to_value.
@Test
public void to_value() {
ValueEncoder valueEncoder = mockValueEncoder();
ValueEncoderSource source = mockValueEncoderSource();
Long value = 23L;
String clientValue = "twentythree";
train_getValueEncoder(source, Long.class, valueEncoder);
train_toValue(valueEncoder, clientValue, value);
replay();
ContextValueEncoder cve = new ContextValueEncoderImpl(source);
assertSame(cve.toValue(Long.class, clientValue), value);
verify();
}
use of org.apache.tapestry5.services.ContextValueEncoder 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();
}
use of org.apache.tapestry5.services.ContextValueEncoder in project tapestry-5 by apache.
the class ContextValueEncoderImplTest method to_client.
@Test
public void to_client() {
ValueEncoder valueEncoder = mockValueEncoder();
ValueEncoderSource source = mockValueEncoderSource();
Long value = 23L;
String encoded = "twentythree";
train_getValueEncoder(source, Long.class, valueEncoder);
train_toClient(valueEncoder, value, encoded);
replay();
ContextValueEncoder cve = new ContextValueEncoderImpl(source);
assertSame(cve.toClient(value), encoded);
verify();
}
Aggregations