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();
}
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());
}
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();
}
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();
}
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();
}
Aggregations