Search in sources :

Example 1 with ComponentModel

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

the class ComponentEventImplTest method matches_on_event_type.

@Test
public void matches_on_event_type() {
    ComponentEventCallback handler = mockComponentEventHandler();
    EventContext context = mockEventContext();
    Logger logger = mockLogger();
    ComponentModel model = mockComponentModel();
    train_isDebugEnabled(logger, false);
    train_getCount(context, 0);
    replay();
    ComponentEvent event = new ComponentEventImpl("eventType", "someId", context, handler, null, false, model, logger);
    assertTrue(event.matches("eventType", "someId", 0));
    assertFalse(event.matches("foo", "someId", 0));
    verify();
}
Also used : EventContext(org.apache.tapestry5.EventContext) ComponentModel(org.apache.tapestry5.model.ComponentModel) ComponentEvent(org.apache.tapestry5.runtime.ComponentEvent) Logger(org.slf4j.Logger) ComponentEventCallback(org.apache.tapestry5.ComponentEventCallback) Test(org.testng.annotations.Test)

Example 2 with ComponentModel

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

the class ComponentEventImplTest method store_null_result_does_not_abort_or_invoke_handler.

@Test
public void store_null_result_does_not_abort_or_invoke_handler() {
    ComponentEventCallback handler = mockComponentEventHandler();
    Logger logger = mockLogger();
    ComponentModel model = mockComponentModel();
    train_isDebugEnabled(logger, true);
    logger.debug(eq(TapestryMarkers.EVENT_HANDLER_METHOD), isA(String.class));
    replay();
    ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler, null, false, model, logger);
    event.setMethodDescription("foo.Bar.baz()");
    assertFalse(event.storeResult(null));
    assertFalse(event.isAborted());
    verify();
}
Also used : ComponentModel(org.apache.tapestry5.model.ComponentModel) ComponentEvent(org.apache.tapestry5.runtime.ComponentEvent) Logger(org.slf4j.Logger) ComponentEventCallback(org.apache.tapestry5.ComponentEventCallback) Test(org.testng.annotations.Test)

Example 3 with ComponentModel

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

the class ComponentEventImplTest method store_result_and_continue.

@Test
public void store_result_and_continue() {
    Object result = new Object();
    String methodDescription = "foo.Bar.baz()";
    ComponentEventCallback handler = mockComponentEventHandler();
    Logger logger = mockLogger();
    ComponentPageElementResources resources = mockResources();
    ComponentModel model = mockComponentModel();
    train_isDebugEnabled(logger, true);
    logger.debug(eq(TapestryMarkers.EVENT_HANDLER_METHOD), isA(String.class));
    train_handleResult(handler, result, false);
    replay();
    ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler, resources, false, model, logger);
    event.setMethodDescription(methodDescription);
    assertFalse(event.storeResult(result));
    assertFalse(event.isAborted());
    verify();
}
Also used : 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 4 with ComponentModel

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

the class ComponentEventImplTest method matches_on_component_id.

@Test
public void matches_on_component_id() {
    ComponentEventCallback handler = mockComponentEventHandler();
    EventContext context = mockEventContext();
    Logger logger = mockLogger();
    ComponentModel model = mockComponentModel();
    train_isDebugEnabled(logger, false);
    train_getCount(context, 0);
    replay();
    ComponentEvent event = new ComponentEventImpl("eventType", "someId", context, handler, null, false, model, logger);
    assertTrue(event.matches("eventType", "someId", 0));
    assertFalse(event.matches("eventtype", "bar", 0));
    verify();
}
Also used : EventContext(org.apache.tapestry5.EventContext) ComponentModel(org.apache.tapestry5.model.ComponentModel) ComponentEvent(org.apache.tapestry5.runtime.ComponentEvent) Logger(org.slf4j.Logger) ComponentEventCallback(org.apache.tapestry5.ComponentEventCallback) Test(org.testng.annotations.Test)

Example 5 with ComponentModel

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

the class ComponentEventImplTest method coerce_context.

@Test
public void coerce_context() {
    ComponentEventCallback handler = mockComponentEventHandler();
    ComponentPageElementResources resources = mockComponentPageElementResources();
    EventContext context = mockEventContext();
    Integer value = new Integer(27);
    Logger logger = mockLogger();
    ComponentModel model = mockComponentModel();
    train_isDebugEnabled(logger, false);
    train_toClass(resources, "java.lang.Integer", Integer.class);
    train_getCount(context, 2);
    train_get(context, Integer.class, 0, value);
    replay();
    ComponentEvent event = new ComponentEventImpl("eventType", "someId", context, handler, resources, false, model, logger);
    assertSame(event.coerceContext(0, "java.lang.Integer"), value);
    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)

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