use of org.apache.tapestry5.internal.structure.ComponentPageElement in project tapestry-5 by apache.
the class PageActivationContextCollectorImplTest method page_with_no_context.
@Test
public void page_with_no_context() {
String pageName = "mypage";
ComponentModel model = mockComponentModel();
ComponentModelSource modelSource = mockComponentModelSource();
RequestPageCache pageCache = mockRequestPageCache();
Page page = mockPage();
ComponentPageElement element = mockComponentPageElement();
expect(modelSource.getPageModel(pageName)).andReturn(model);
expect(model.handlesEvent(EventConstants.PASSIVATE)).andReturn(true);
train_get(pageCache, pageName, page);
train_getRootElement(page, element);
expect(element.triggerEvent(EasyMock.eq(EventConstants.PASSIVATE), (Object[]) EasyMock.isNull(), EasyMock.isA(ComponentEventCallback.class))).andReturn(false);
replay();
PageActivationContextCollector collector = new PageActivationContextCollectorImpl(coercer, pageCache, modelSource);
Object[] actual = collector.collectPageActivationContext(pageName);
assertEquals(actual.length, 0);
}
use of org.apache.tapestry5.internal.structure.ComponentPageElement in project tapestry-5 by apache.
the class PageRenderRequestHandlerImplTest method loopback_request.
@Test
public void loopback_request() throws Exception {
RequestPageCache cache = mockRequestPageCache();
ComponentEventResultProcessor processor = mockComponentEventResultProcessor();
PageResponseRenderer renderer = mockPageResponseRenderer();
Page page = mockPage();
EventContext context = mockEventContext();
ComponentPageElement root = mockComponentPageElement();
InternalComponentResources pageResources = mockInternalComponentResources();
PageActivator activator = newMock(PageActivator.class);
Request request = mockRequest();
train_getAttribute(request, InternalConstants.BYPASS_ACTIVATION, null);
train_get(cache, "foo/Bar", page);
train_getRootElement(page, root);
train_getComponentResources(root, pageResources);
expect(activator.activatePage(pageResources, context, processor)).andReturn(false);
// Skips the pageReset()
renderer.renderPageResponse(page);
replay();
PageRenderRequestHandler handler = new PageRenderRequestHandlerImpl(cache, processor, renderer, activator, request);
PageRenderRequestParameters parameters = new PageRenderRequestParameters("foo/Bar", context, true);
handler.handle(parameters);
verify();
}
use of org.apache.tapestry5.internal.structure.ComponentPageElement in project tapestry-5 by apache.
the class ComponentEventRequestHandlerImpl method handle.
public void handle(ComponentEventRequestParameters parameters) throws IOException {
Page activePage = cache.get(parameters.getActivePageName());
if (pageActivator.activatePage(activePage.getRootElement().getComponentResources(), parameters.getPageActivationContext(), resultProcessor)) {
return;
}
Page containerPage = cache.get(parameters.getContainingPageName());
TrackableComponentEventCallback callback = new ComponentResultProcessorWrapper(resultProcessor);
environment.push(ComponentEventResultProcessor.class, resultProcessor);
environment.push(TrackableComponentEventCallback.class, callback);
ComponentPageElement element = containerPage.getComponentElementByNestedId(parameters.getNestedComponentId());
boolean handled = element.triggerContextEvent(parameters.getEventType(), parameters.getEventContext(), callback);
if (!handled) {
throw new TapestryException(String.format("Request event '%s' (on component %s) was not handled; you must provide a matching event handler method in the component or in one of its containers.", parameters.getEventType(), element.getCompleteId()), element, null);
}
environment.pop(TrackableComponentEventCallback.class);
environment.pop(ComponentEventResultProcessor.class);
if (callback.isAborted()) {
callback.rethrow();
return;
}
if (!response.isCommitted()) {
resultProcessor.processResultValue(activePage.getName());
}
}
use of org.apache.tapestry5.internal.structure.ComponentPageElement in project tapestry-5 by apache.
the class InternalComponentResourcesImplTest method add_page_lifecycle_listener.
@Test
public void add_page_lifecycle_listener() {
Component component = mockComponent();
Instantiator ins = mockInstantiator(component);
ComponentModel model = mockComponentModel();
ComponentPageElement element = mockComponentPageElement();
Page page = mockPage();
PageLifecycleListener listener = newMock(PageLifecycleListener.class);
train_getModel(ins, model);
page.addLifecycleListener(listener);
replay();
InternalComponentResources resources = new InternalComponentResourcesImpl(page, element, null, null, null, null, ins, false);
resources.addPageLifecycleListener(listener);
verify();
}
use of org.apache.tapestry5.internal.structure.ComponentPageElement in project tapestry-5 by apache.
the class InternalComponentResourcesImplTest method get_property_name.
@Test
public void get_property_name() {
Component component = mockComponent();
Instantiator ins = mockInstantiator(component);
ComponentModel model = mockComponentModel();
ComponentPageElement element = mockComponentPageElement();
Page page = mockPage();
Binding binding = mockBinding();
train_getModel(ins, model);
replay();
InternalComponentResources resources = new InternalComponentResourcesImpl(page, element, null, null, null, null, ins, false);
resources.bindParameter("bar", binding);
assertNull(resources.getPropertyName("bar"));
verify();
}
Aggregations