Search in sources :

Example 1 with ComponentDefaultProvider

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

the class ComponentDefaultProviderImplTest method default_translator.

@Test
public void default_translator() {
    ComponentResources resources = mockComponentResources();
    FieldTranslator translator = mockFieldTranslator();
    FieldTranslatorSource source = newMock(FieldTranslatorSource.class);
    train_createDefaultTranslator(source, resources, "object", translator);
    replay();
    ComponentDefaultProvider provider = new ComponentDefaultProviderImpl(null, null, null, source, null);
    assertSame(provider.defaultTranslator("object", resources), translator);
    verify();
}
Also used : FieldTranslatorSource(org.apache.tapestry5.services.FieldTranslatorSource) FieldTranslator(org.apache.tapestry5.FieldTranslator) ComponentResources(org.apache.tapestry5.ComponentResources) ComponentDefaultProvider(org.apache.tapestry5.services.ComponentDefaultProvider) Test(org.testng.annotations.Test)

Example 2 with ComponentDefaultProvider

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

the class ComponentDefaultProviderImplTest method default_label_key_missing.

@Test
public void default_label_key_missing() {
    ComponentResources resources = mockComponentResources();
    ComponentResources container = mockComponentResources();
    Messages messages = mockMessages();
    String componentId = "myField";
    String key = componentId + "-label";
    train_getId(resources, componentId);
    train_getContainerResources(resources, container);
    train_getMessages(container, messages);
    train_contains(messages, key, false);
    replay();
    ComponentDefaultProvider provider = new ComponentDefaultProviderImpl(null, null, null, null, null);
    assertEquals(provider.defaultLabel(resources), "My Field");
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) ComponentResources(org.apache.tapestry5.ComponentResources) ComponentDefaultProvider(org.apache.tapestry5.services.ComponentDefaultProvider) Test(org.testng.annotations.Test)

Example 3 with ComponentDefaultProvider

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

the class ComponentDefaultProviderImplTest method no_matching_property_for_default.

@Test
public void no_matching_property_for_default() {
    String parameterName = "myparam";
    String id = "mycomponentid";
    ComponentResources resources = mockComponentResources();
    Component container = mockComponent();
    PropertyAccess access = mockPropertyAccess();
    ClassPropertyAdapter classPropertyAdapter = mockClassPropertyAdapter();
    BindingSource bindingSource = mockBindingSource();
    train_getId(resources, id);
    train_getContainer(resources, container);
    train_getAdapter(access, container, classPropertyAdapter);
    train_getPropertyAdapter(classPropertyAdapter, id, null);
    replay();
    ComponentDefaultProvider source = new ComponentDefaultProviderImpl(access, bindingSource, null, null, null);
    assertNull(source.defaultBinding(parameterName, resources));
    verify();
}
Also used : BindingSource(org.apache.tapestry5.services.BindingSource) ClassPropertyAdapter(org.apache.tapestry5.commons.services.ClassPropertyAdapter) Component(org.apache.tapestry5.runtime.Component) ComponentResources(org.apache.tapestry5.ComponentResources) PropertyAccess(org.apache.tapestry5.commons.services.PropertyAccess) ComponentDefaultProvider(org.apache.tapestry5.services.ComponentDefaultProvider) Test(org.testng.annotations.Test)

Example 4 with ComponentDefaultProvider

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

the class ComponentDefaultProviderImplTest method default_translator_property_type_is_null.

@Test
public void default_translator_property_type_is_null() {
    ComponentResources resources = mockComponentResources();
    FieldTranslatorSource source = newMock(FieldTranslatorSource.class);
    train_createDefaultTranslator(source, resources, "object", null);
    replay();
    ComponentDefaultProvider provider = new ComponentDefaultProviderImpl(null, null, null, source, null);
    assertNull(provider.defaultTranslator("object", resources));
    verify();
}
Also used : FieldTranslatorSource(org.apache.tapestry5.services.FieldTranslatorSource) ComponentResources(org.apache.tapestry5.ComponentResources) ComponentDefaultProvider(org.apache.tapestry5.services.ComponentDefaultProvider) Test(org.testng.annotations.Test)

Example 5 with ComponentDefaultProvider

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

the class ComponentDefaultProviderImplTest method default_property_exists.

@Test
public void default_property_exists() {
    String parameterName = "myparam";
    String id = "mycomponentid";
    ComponentResources resources = mockComponentResources();
    Component container = mockComponent();
    PropertyAccess access = mockPropertyAccess();
    ClassPropertyAdapter classPropertyAdapter = mockClassPropertyAdapter();
    PropertyAdapter propertyAdapter = mockPropertyAdapter();
    BindingSource bindingSource = mockBindingSource();
    Binding binding = mockBinding();
    ComponentResources containerResources = mockComponentResources();
    train_getId(resources, id);
    train_getContainer(resources, container);
    train_getAdapter(access, container, classPropertyAdapter);
    train_getPropertyAdapter(classPropertyAdapter, id, propertyAdapter);
    train_getContainerResources(resources, containerResources);
    train_newBinding(bindingSource, "default myparam", containerResources, BindingConstants.PROP, id, binding);
    replay();
    ComponentDefaultProvider source = new ComponentDefaultProviderImpl(access, bindingSource, null, null, null);
    assertSame(source.defaultBinding(parameterName, resources), binding);
    verify();
}
Also used : Binding(org.apache.tapestry5.Binding) BindingSource(org.apache.tapestry5.services.BindingSource) ClassPropertyAdapter(org.apache.tapestry5.commons.services.ClassPropertyAdapter) ClassPropertyAdapter(org.apache.tapestry5.commons.services.ClassPropertyAdapter) PropertyAdapter(org.apache.tapestry5.commons.services.PropertyAdapter) Component(org.apache.tapestry5.runtime.Component) ComponentResources(org.apache.tapestry5.ComponentResources) PropertyAccess(org.apache.tapestry5.commons.services.PropertyAccess) ComponentDefaultProvider(org.apache.tapestry5.services.ComponentDefaultProvider) Test(org.testng.annotations.Test)

Aggregations

ComponentResources (org.apache.tapestry5.ComponentResources)6 ComponentDefaultProvider (org.apache.tapestry5.services.ComponentDefaultProvider)6 Test (org.testng.annotations.Test)6 Messages (org.apache.tapestry5.commons.Messages)2 ClassPropertyAdapter (org.apache.tapestry5.commons.services.ClassPropertyAdapter)2 PropertyAccess (org.apache.tapestry5.commons.services.PropertyAccess)2 Component (org.apache.tapestry5.runtime.Component)2 BindingSource (org.apache.tapestry5.services.BindingSource)2 FieldTranslatorSource (org.apache.tapestry5.services.FieldTranslatorSource)2 Binding (org.apache.tapestry5.Binding)1 FieldTranslator (org.apache.tapestry5.FieldTranslator)1 PropertyAdapter (org.apache.tapestry5.commons.services.PropertyAdapter)1