01: // Copyright 2006, 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.internal.test;
16:
17: import org.apache.tapestry.dom.Document;
18: import org.apache.tapestry.internal.services.ComponentInvocation;
19: import org.apache.tapestry.internal.services.InvocationTarget;
20: import org.apache.tapestry.internal.services.PageLinkTarget;
21: import org.apache.tapestry.ioc.Registry;
22: import org.apache.tapestry.services.PageRenderRequestHandler;
23:
24: /**
25: * Simulates a click on a page link.
26: */
27: public class PageLinkInvoker implements ComponentInvoker {
28: private final Registry _registry;
29:
30: private final PageRenderRequestHandler _pageRenderRequestHandler;
31:
32: private final TestableMarkupWriterFactory _markupWriterFactory;
33:
34: public PageLinkInvoker(Registry registry) {
35: _registry = registry;
36: _pageRenderRequestHandler = _registry
37: .getService(PageRenderRequestHandler.class);
38: _markupWriterFactory = _registry
39: .getService(TestableMarkupWriterFactory.class);
40: }
41:
42: /**
43: * Click on the page link.
44: *
45: * @param invocation
46: * The ComponentInvocation object corresponding to the page link.
47: * @return The DOM created. Typically you will assert against it.
48: */
49: public Document invoke(ComponentInvocation invocation) {
50: try {
51: InvocationTarget target = invocation.getTarget();
52:
53: PageLinkTarget pageLinkTarget = (PageLinkTarget) target;
54:
55: _pageRenderRequestHandler.handle(pageLinkTarget
56: .getPageName(), invocation.getContext());
57:
58: return _markupWriterFactory.getLatestMarkupWriter()
59: .getDocument();
60: } finally {
61: _registry.cleanupThread();
62: }
63: }
64:
65: }
|