Search in sources :

Example 11 with TypeCoercer

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();
}
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) Link(org.apache.tapestry5.http.Link) Test(org.testng.annotations.Test)

Example 12 with TypeCoercer

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();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) TypeCoercer(org.apache.tapestry5.commons.services.TypeCoercer) FieldValidator(org.apache.tapestry5.FieldValidator) ValidatorMacro(org.apache.tapestry5.validator.ValidatorMacro) MessageFormatter(org.apache.tapestry5.commons.MessageFormatter) FormSupport(org.apache.tapestry5.services.FormSupport) ComponentResources(org.apache.tapestry5.ComponentResources) FieldValidatorSource(org.apache.tapestry5.services.FieldValidatorSource) FieldValidator(org.apache.tapestry5.FieldValidator) Validator(org.apache.tapestry5.Validator) Test(org.testng.annotations.Test)

Example 13 with TypeCoercer

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" });
}
Also used : EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) EventContext(org.apache.tapestry5.EventContext) Test(org.testng.annotations.Test)

Example 14 with TypeCoercer

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>");
}
Also used : EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) EventContext(org.apache.tapestry5.EventContext) Test(org.testng.annotations.Test)

Example 15 with TypeCoercer

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();
}
Also used : ComponentEventLinkEncoder(org.apache.tapestry5.services.ComponentEventLinkEncoder) ComponentEventRequestParameters(org.apache.tapestry5.services.ComponentEventRequestParameters) Page(org.apache.tapestry5.internal.structure.Page) LinkCreationListener2(org.apache.tapestry5.services.LinkCreationListener2) Link(org.apache.tapestry5.http.Link)

Aggregations

Test (org.testng.annotations.Test)43 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)27 ComponentResources (org.apache.tapestry5.ComponentResources)19 Messages (org.apache.tapestry5.commons.Messages)13 FieldValidator (org.apache.tapestry5.FieldValidator)11 Validator (org.apache.tapestry5.Validator)11 SymbolSource (org.apache.tapestry5.ioc.services.SymbolSource)11 FieldValidatorSource (org.apache.tapestry5.services.FieldValidatorSource)11 ValidatorMacro (org.apache.tapestry5.validator.ValidatorMacro)11 Link (org.apache.tapestry5.http.Link)10 ComponentModel (org.apache.tapestry5.model.ComponentModel)10 FormSupport (org.apache.tapestry5.services.FormSupport)10 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)9 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)9 EventContext (org.apache.tapestry5.EventContext)7 ComponentEventLinkEncoder (org.apache.tapestry5.services.ComponentEventLinkEncoder)7 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)7 LinkCreationListener2 (org.apache.tapestry5.services.LinkCreationListener2)6 MarkupWriter (org.apache.tapestry5.MarkupWriter)5 HibernateEntityValueEncoder (org.apache.tapestry5.hibernate.web.internal.HibernateEntityValueEncoder)4