Search in sources :

Example 21 with ComponentModel

use of org.apache.tapestry5.model.ComponentModel in project tapestry-5 by apache.

the class InternalComponentResourcesImplTest method render_informal_parameters_skips_formal_parameters.

@Test
public void render_informal_parameters_skips_formal_parameters() {
    ComponentPageElement element = mockComponentPageElement();
    Component component = mockComponent();
    Instantiator ins = mockInstantiator(component);
    MarkupWriter writer = mockMarkupWriter();
    ComponentModel model = mockComponentModel();
    ParameterModel pmodel = mockParameterModel();
    Binding binding = mockBinding();
    train_getModel(ins, model);
    train_getParameterModel(model, "fred", pmodel);
    replay();
    InternalComponentResources resources = new InternalComponentResourcesImpl(null, element, null, elementResources, null, null, ins, false);
    resources.bindParameter("fred", binding);
    resources.renderInformalParameters(writer);
    verify();
}
Also used : Binding(org.apache.tapestry5.Binding) InternalPropBinding(org.apache.tapestry5.internal.bindings.InternalPropBinding) ParameterModel(org.apache.tapestry5.model.ParameterModel) InternalComponentResources(org.apache.tapestry5.internal.InternalComponentResources) ComponentModel(org.apache.tapestry5.model.ComponentModel) Instantiator(org.apache.tapestry5.internal.services.Instantiator) Component(org.apache.tapestry5.runtime.Component) MarkupWriter(org.apache.tapestry5.MarkupWriter) Test(org.testng.annotations.Test)

Example 22 with ComponentModel

use of org.apache.tapestry5.model.ComponentModel in project tapestry-5 by apache.

the class PublishServerSideEvents method addEventsAttribute.

private void addEventsAttribute(final Element element) {
    if (element == null) {
        throw new IllegalStateException("@PublishEvent used inside a page which didn't generate a <body> element");
    }
    final ComponentResources containerResources = resources.getContainerResources();
    final ComponentModel componentModel = containerResources.getComponentModel();
    final String metaValue = componentModel.getMeta(InternalConstants.PUBLISH_COMPONENT_EVENTS_META);
    final JSONArray componentEvents = new JSONArray(metaValue);
    final JSONObject events = new JSONObject();
    final String existingValue = element.getAttribute(COMPONENT_EVENTS_ATTRIBUTE_NAME);
    if (existingValue != null) {
        final JSONObject existing = new JSONObject(existingValue);
        for (String key : existing.keys()) {
            events.put(key, existing.get(key));
        }
    }
    for (int i = 0; i < componentEvents.length(); i++) {
        final String eventName = componentEvents.getString(i);
        JSONObject event = new JSONObject();
        event.put(PUBLISH_COMPONENT_EVENTS_URL_PROPERTY, containerResources.createEventLink(eventName).toString());
        events.put(eventName, event);
    }
    element.forceAttributes(TapestryConstants.COMPONENT_EVENTS_ATTRIBUTE_NAME, events.toString());
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject) ComponentModel(org.apache.tapestry5.model.ComponentModel) JSONArray(org.apache.tapestry5.json.JSONArray) ComponentResources(org.apache.tapestry5.ComponentResources)

Example 23 with ComponentModel

use of org.apache.tapestry5.model.ComponentModel in project tapestry-5 by apache.

the class ComponentEventImplTest method no_match_one_event_is_aborted.

/**
 * @since 5.2.0
 */
@Test
public void no_match_one_event_is_aborted() {
    ComponentEventCallback handler = mockComponentEventHandler();
    EventContext context = mockEventContext();
    Logger logger = mockLogger();
    Object result = new Object();
    ComponentPageElementResources resources = mockResources();
    ComponentModel model = mockComponentModel();
    train_isDebugEnabled(logger, false);
    train_handleResult(handler, result, true);
    replay();
    ComponentEvent event = new ComponentEventImpl("eventType", "someId", context, handler, resources, false, model, logger);
    event.storeResult(result);
    assertFalse(event.matches("eventType", "someId", 0));
    verify();
}
Also used : EventContext(org.apache.tapestry5.EventContext) ComponentModel(org.apache.tapestry5.model.ComponentModel) ComponentPageElementResources(org.apache.tapestry5.internal.structure.ComponentPageElementResources) ComponentEvent(org.apache.tapestry5.runtime.ComponentEvent) Logger(org.slf4j.Logger) ComponentEventCallback(org.apache.tapestry5.ComponentEventCallback) Test(org.testng.annotations.Test)

Example 24 with ComponentModel

use of org.apache.tapestry5.model.ComponentModel in project tapestry-5 by apache.

the class ComponentMessagesSourceImplTest method simple_component.

@Test
public void simple_component() {
    ComponentModel model = mockComponentModel();
    train_getComponentClassName(model, SIMPLE_COMPONENT_CLASS_NAME);
    train_getBaseResource(model, simpleComponentResource);
    train_getParentModel(model, null);
    replay();
    forceCacheClear();
    Messages messages = source.getMessages(model, Locale.ENGLISH);
    assertEquals(messages.get("color"), "color");
    assertEquals(messages.get("framework"), "Tapestry");
    // Check normal caching
    assertSame(source.getMessages(model, Locale.ENGLISH), messages);
    // Now, force a cache clear and retry.
    forceCacheClear();
    Messages messages2 = source.getMessages(model, Locale.ENGLISH);
    // Check that a new Messages was created
    assertNotSame(messages2, messages);
    assertEquals(messages2.get("color"), "color");
    assertEquals(messages2.get("framework"), "Tapestry");
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) ComponentModel(org.apache.tapestry5.model.ComponentModel) Test(org.testng.annotations.Test)

Example 25 with ComponentModel

use of org.apache.tapestry5.model.ComponentModel in project tapestry-5 by apache.

the class ComponentMessagesSourceImplTest method subclass_inherits_base_class_messages.

@Test
public void subclass_inherits_base_class_messages() {
    ComponentModel model = mockComponentModel();
    ComponentModel parent = mockComponentModel();
    train_getComponentClassName(model, "org.apache.tapestry5.internal.services.SubclassComponent");
    train_getBaseResource(model, new ClasspathResource("org/apache/tapestry5/internal/services/SubclassComponent.class"));
    train_getParentModel(model, parent);
    train_getComponentClassName(parent, SIMPLE_COMPONENT_CLASS_NAME);
    train_getBaseResource(parent, simpleComponentResource);
    train_getParentModel(parent, null);
    replay();
    forceCacheClear();
    Messages messages = source.getMessages(model, Locale.ENGLISH);
    assertEquals(messages.get("color"), "color");
    assertEquals(messages.get("framework"), "Tapestry");
    assertEquals(messages.get("source"), "SubclassComponent");
    assertEquals(messages.get("metal"), "steel");
    assertEquals(messages.get("app-catalog-source"), "AppCatalog");
    assertEquals(messages.get("app-catalog-overridden"), "Overridden by Component");
    messages = source.getMessages(model, Locale.UK);
    assertEquals(messages.get("color"), "colour");
    assertEquals(messages.get("framework"), "Tapestry");
    assertEquals(messages.get("source"), "SubclassComponent");
    assertEquals(messages.get("metal"), "aluminium");
    verify();
}
Also used : ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) Messages(org.apache.tapestry5.commons.Messages) ComponentModel(org.apache.tapestry5.model.ComponentModel) Test(org.testng.annotations.Test)

Aggregations

ComponentModel (org.apache.tapestry5.model.ComponentModel)64 Test (org.testng.annotations.Test)48 ComponentResources (org.apache.tapestry5.ComponentResources)16 ComponentEventCallback (org.apache.tapestry5.ComponentEventCallback)15 Logger (org.slf4j.Logger)14 ComponentEvent (org.apache.tapestry5.runtime.ComponentEvent)12 Instantiator (org.apache.tapestry5.internal.services.Instantiator)11 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)11 Resource (org.apache.tapestry5.commons.Resource)10 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)10 Component (org.apache.tapestry5.runtime.Component)10 SymbolSource (org.apache.tapestry5.ioc.services.SymbolSource)9 EventContext (org.apache.tapestry5.EventContext)8 ClasspathResource (org.apache.tapestry5.ioc.internal.util.ClasspathResource)7 EmbeddedComponentModel (org.apache.tapestry5.model.EmbeddedComponentModel)7 ComponentTemplate (org.apache.tapestry5.internal.parser.ComponentTemplate)6 ComponentPageElementResources (org.apache.tapestry5.internal.structure.ComponentPageElementResources)6 ComponentResourceLocator (org.apache.tapestry5.services.pageload.ComponentResourceLocator)6 Messages (org.apache.tapestry5.commons.Messages)5 PersistentFieldStrategy (org.apache.tapestry5.services.PersistentFieldStrategy)5