use of org.apache.tapestry5.internal.structure.ComponentPageElementResources 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();
}
use of org.apache.tapestry5.internal.structure.ComponentPageElementResources 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();
}
use of org.apache.tapestry5.internal.structure.ComponentPageElementResources 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.internal.structure.ComponentPageElementResources in project tapestry-5 by apache.
the class ComponentEventImplTest method unable_to_coerce.
@Test
public void unable_to_coerce() {
ComponentEventCallback handler = mockComponentEventHandler();
EventContext context = mockEventContext();
ComponentPageElementResources resources = mockComponentPageElementResources();
Logger logger = mockLogger();
ComponentModel model = mockComponentModel();
train_isDebugEnabled(logger, true);
logger.debug(eq(TapestryMarkers.EVENT_HANDLER_METHOD), isA(String.class));
train_toClass(resources, Integer.class.getName(), Integer.class);
train_getCount(context, 1);
expect(context.get(Integer.class, 0)).andThrow(new NumberFormatException("Not so easy, is it?"));
replay();
ComponentEvent event = new ComponentEventImpl("eventType", "someId", context, handler, resources, false, model, logger);
event.setMethodDescription("foo.Bar.baz()");
try {
event.coerceContext(0, "java.lang.Integer");
unreachable();
} catch (IllegalArgumentException ex) {
// Different JVMs will report the conversion error slightly differently,
// so we don't try to check that part of the error message.
assertTrue(ex.getMessage().startsWith("Exception in method foo.Bar.baz(), parameter #1:"));
}
verify();
}
use of org.apache.tapestry5.internal.structure.ComponentPageElementResources in project tapestry-5 by apache.
the class ComponentEventImplTest method store_result_and_abort.
@Test
public void store_result_and_abort() {
Object result = new Object();
String methodDescription = "foo.Bar.baz()";
Logger logger = mockLogger();
ComponentModel model = mockComponentModel();
train_isDebugEnabled(logger, true);
EasyMock.expectLastCall().atLeastOnce();
ComponentPageElementResources resources = mockResources();
logger.debug(eq(TapestryMarkers.EVENT_HANDLER_METHOD), isA(String.class));
ComponentEventCallback handler = mockComponentEventHandler();
train_handleResult(handler, result, true);
replay();
ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler, resources, false, model, logger);
event.setMethodDescription(methodDescription);
assertFalse(event.isAborted());
assertTrue(event.storeResult(result));
assertTrue(event.isAborted());
verify();
}
Aggregations