Search in sources :

Example 36 with TypeCoercer

use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.

the class FieldValidatorSourceImplTest method validator_with_no_constraint.

@SuppressWarnings("unchecked")
@Test
public void validator_with_no_constraint() throws Exception {
    Validator validator = mockValidator();
    TypeCoercer coercer = mockTypeCoercer();
    FieldComponent field = newFieldComponent();
    Messages globalMessages = mockMessages();
    MessageFormatter formatter = mockMessageFormatter();
    Object inputValue = new Object();
    ComponentResources resources = mockComponentResources();
    Messages containerMessages = mockMessages();
    FormSupport fs = mockFormSupport();
    ValidatorMacro macro = mockValidatorMacro();
    Map<String, Validator> map = singletonMap("required", validator);
    train_getConstraintType(validator, null);
    train_getFormValidationId(fs, "form");
    train_getComponentResources(field, resources);
    train_getId(resources, "fred");
    train_getContainerMessages(resources, containerMessages);
    train_alwaysNull(macro);
    train_contains(containerMessages, "form-fred-required-message", false);
    train_contains(containerMessages, "fred-required-message", false);
    train_getMessageKey(validator, "key");
    train_getMessageFormatter(globalMessages, "key", formatter);
    train_isRequired(validator, false);
    train_getValueType(validator, Object.class);
    validator.validate(field, null, formatter, inputValue);
    replay();
    FieldValidatorSource source = new FieldValidatorSourceImpl(globalMessages, coercer, fs, map, macro);
    FieldValidator fieldValidator = source.createValidator(field, "required", null);
    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 37 with TypeCoercer

use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.

the class PageElementFactoryImplTest method attribute.

@Test
public void attribute() {
    TypeCoercer typeCoercer = mockTypeCoercer();
    BindingSource bindingSource = mockBindingSource();
    MarkupWriter writer = new MarkupWriterImpl(xmlModel);
    Location l = mockLocation();
    RenderQueue queue = mockRenderQueue();
    replay();
    PageElementFactory factory = new PageElementFactoryImpl(typeCoercer, bindingSource);
    AttributeToken token = new AttributeToken(null, "name", "value", l);
    RenderCommand element = factory.newAttributeElement(null, token);
    writer.element("root");
    element.render(writer, queue);
    verify();
    assertEquals(writer.toString(), "<?xml version=\"1.0\"?>\n<root name=\"value\"/>");
}
Also used : RenderCommand(org.apache.tapestry5.runtime.RenderCommand) BindingSource(org.apache.tapestry5.services.BindingSource) TypeCoercer(org.apache.tapestry5.commons.services.TypeCoercer) RenderQueue(org.apache.tapestry5.runtime.RenderQueue) AttributeToken(org.apache.tapestry5.internal.parser.AttributeToken) MarkupWriter(org.apache.tapestry5.MarkupWriter) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 38 with TypeCoercer

use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.

the class MetaDataLocatorImplTest method subfolder_default_overrides_high_level_default.

@Test
public void subfolder_default_overrides_high_level_default() {
    ComponentResources resources = mockComponentResources();
    ComponentModel model = mockComponentModel();
    SymbolSource symbolSource = mockSymbolSource();
    ComponentModelSource modelSource = mockComponentModelSource();
    String key = "foo.bar";
    String value = "zaphod";
    String completeId = "foo.Bar";
    train_getCompleteId(resources, completeId);
    train_getComponentModel(resources, model);
    train_getMeta(model, key, null);
    train_getContainerResources(resources, null);
    train_getPageName(resources, "foo/Bar");
    train_expandSymbols(symbolSource, value, value);
    replay();
    Map<String, String> configuration = newMap();
    configuration.put(key, "xxx");
    configuration.put("foo:" + key, value);
    MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource, configuration);
    assertSame(locator.findMeta(key, resources, String.class), value);
    verify();
    // And check that it's cached:
    train_getCompleteId(resources, completeId);
    replay();
    assertSame(locator.findMeta(key, resources, String.class), value);
    verify();
}
Also used : SymbolSource(org.apache.tapestry5.ioc.services.SymbolSource) ComponentModel(org.apache.tapestry5.model.ComponentModel) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Example 39 with TypeCoercer

use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.

the class MetaDataLocatorImplTest method found_via_high_level_default.

@Test
public void found_via_high_level_default() {
    ComponentResources resources = mockComponentResources();
    ComponentModel model = mockComponentModel();
    SymbolSource symbolSource = mockSymbolSource();
    ComponentModelSource modelSource = mockComponentModelSource();
    String key = "foo.bar";
    String value = "zaphod";
    String completeId = "Bar";
    String logicalPageName = completeId;
    train_getCompleteId(resources, completeId);
    train_getComponentModel(resources, model);
    train_getMeta(model, key, null);
    train_getContainerResources(resources, null);
    train_getPageName(resources, logicalPageName);
    train_expandSymbols(symbolSource, value, value);
    replay();
    Map<String, String> configuration = newMap();
    configuration.put(key, value);
    MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource, configuration);
    assertSame(locator.findMeta(key, resources, String.class), value);
    verify();
    // And check that it's cached:
    train_getCompleteId(resources, completeId);
    replay();
    assertSame(locator.findMeta(key, resources, String.class), value);
    verify();
}
Also used : SymbolSource(org.apache.tapestry5.ioc.services.SymbolSource) ComponentModel(org.apache.tapestry5.model.ComponentModel) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Example 40 with TypeCoercer

use of org.apache.tapestry5.commons.services.TypeCoercer in project tapestry-5 by apache.

the class MetaDataLocatorImplTest method default_matching_is_case_insensitive.

@Test
public void default_matching_is_case_insensitive() {
    ComponentResources resources = mockComponentResources();
    ComponentModel model = mockComponentModel();
    SymbolSource symbolSource = mockSymbolSource();
    ComponentModelSource modelSource = mockComponentModelSource();
    String key = "foo.bar";
    String value = "zaphod";
    String completeId = "foo.Bar";
    train_getCompleteId(resources, completeId);
    train_getComponentModel(resources, model);
    train_getMeta(model, key, null);
    train_getContainerResources(resources, null);
    train_getPageName(resources, "foo/Bar");
    train_expandSymbols(symbolSource, value, value);
    replay();
    Map<String, String> configuration = newMap();
    configuration.put(key.toUpperCase(), value);
    MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource, configuration);
    assertSame(locator.findMeta(key, resources, String.class), value);
    verify();
    // And check that it's cached:
    train_getCompleteId(resources, completeId);
    replay();
    assertSame(locator.findMeta(key, resources, String.class), value);
    verify();
}
Also used : SymbolSource(org.apache.tapestry5.ioc.services.SymbolSource) ComponentModel(org.apache.tapestry5.model.ComponentModel) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

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