use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.
the class ComponentEventLinkEncoderImplTest method index_stripped_off.
@Test
public void index_stripped_off() {
RequestSecurityManager manager = mockRequestSecurityManager();
Response response = mockResponse();
ContextPathEncoder contextPathEncoder = getService(ContextPathEncoder.class);
expect(manager.checkPageSecurity("admin/Index")).andReturn(LinkSecurity.INSECURE);
train_encodeURL(response, "/admin/abc", "MAGIC");
replay();
ComponentEventLinkEncoder encoder = new ComponentEventLinkEncoderImpl(null, contextPathEncoder, null, response, manager, null, null, false, "", "", null, null);
PageRenderRequestParameters parameters = new PageRenderRequestParameters("admin/Index", new ArrayEventContext(typeCoercer, "abc"));
Link link = encoder.createPageRenderLink(parameters);
assertEquals(link.toURI(), "MAGIC");
verify();
}
use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.
the class FieldValidatorSourceImplTest method multiple_validators_via_specification.
@SuppressWarnings("unchecked")
@Test
public void multiple_validators_via_specification() throws Exception {
Validator required = mockValidator();
Validator minLength = mockValidator();
TypeCoercer coercer = mockTypeCoercer();
FieldComponent field = newFieldComponent();
Messages messages = mockMessages();
MessageFormatter requiredFormatter = mockMessageFormatter();
MessageFormatter minLengthFormatter = mockMessageFormatter();
Object inputValue = "input value";
ComponentResources resources = mockComponentResources();
Messages containerMessages = mockMessages();
Integer fifteen = 15;
FormSupport fs = mockFormSupport();
Messages globalMessages = mockMessages();
Map<String, Validator> map = newMap();
map.put("required", required);
map.put("minLength", minLength);
train_getFormValidationId(fs, "myform");
train_getConstraintType(required, null);
train_getConstraintType(minLength, Integer.class);
train_getComponentResources(field, resources);
train_getId(resources, "fred");
train_getContainerMessages(resources, containerMessages);
train_contains(containerMessages, "myform-fred-required-message", false);
train_contains(containerMessages, "fred-required-message", false);
train_getMessageKey(required, "required");
train_getMessageFormatter(globalMessages, "required", requiredFormatter);
train_contains(containerMessages, "myform-fred-minLength-message", false);
train_contains(containerMessages, "fred-minLength-message", false);
train_getMessageKey(minLength, "min-length");
train_getMessageFormatter(globalMessages, "min-length", minLengthFormatter);
train_coerce(coercer, "15", Integer.class, fifteen);
train_isRequired(required, true);
train_getValueType(required, Object.class);
required.validate(field, null, requiredFormatter, inputValue);
train_isRequired(minLength, false);
train_getValueType(minLength, String.class);
minLength.validate(field, fifteen, minLengthFormatter, inputValue);
ValidatorMacro macro = mockValidatorMacro();
train_alwaysNull(macro);
replay();
FieldValidatorSource source = new FieldValidatorSourceImpl(globalMessages, coercer, fs, map, macro);
FieldValidator fieldValidator = source.createValidators(field, "required,minLength=15");
fieldValidator.validate(inputValue);
verify();
}
use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.
the class EventContextTests method array_event_context_to_strings.
@Test
public void array_event_context_to_strings() {
EventContext ec = new ArrayEventContext(typeCoercer, 1, 2.3);
assertEquals(ec.toStrings(), new String[] { "1", "2.3" });
}
use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.
the class EventContextTests method to_string_of_event_context.
@Test
public void to_string_of_event_context() {
EventContext ec = new ArrayEventContext(typeCoercer, 1, 2.3);
assertEquals(ec.toString(), "<EventContext: 1, 2.3>");
}
use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.
the class LinkSourceImplTest method testEventLinkCreation2.
private void testEventLinkCreation2(String pageName, String nestedId, String eventType, boolean forForm, Object... context) {
Page primaryPage = mockPage();
PageRenderQueue queue = mockPageRenderQueue();
PageActivationContextCollector collector = mockPageActivationContextCollector();
LinkCreationListener2 listener = mockLinkCreationListener2();
ComponentEventLinkEncoder linkEncoder = mockComponentEventLinkEncoder();
Link link = mockLink();
ArrayEventContext eventContext = new ArrayEventContext(typeCoercer, context);
ArrayEventContext pageEventContext = new ArrayEventContext(typeCoercer, "a", "b");
train_getRenderingPage(queue, null);
train_getName(primaryPage, pageName);
train_collectPageActivationContext(collector, pageName, "a", "b");
ComponentEventRequestParameters parameters = new ComponentEventRequestParameters(pageName, pageName, nestedId, eventType, pageEventContext, eventContext);
expect(linkEncoder.createComponentEventLink(parameters, forForm)).andReturn(link);
listener.createdComponentEventLink(link, parameters);
List<LinkCreationListener2> configuration = CollectionFactory.newList(listener);
replay();
LinkSource source = new LinkSourceImpl(queue, collector, typeCoercer, null, linkEncoder, null, null, configuration);
Link returnedLink = source.createComponentEventLink(primaryPage, nestedId, eventType, forForm, context);
// Make sure the same link is returned.
assertSame(returnedLink, link);
verify();
}
Aggregations