001: // Copyright 2006, 2007 The Apache Software Foundation
002: //
003: // Licensed under the Apache License, Version 2.0 (the "License");
004: // you may not use this file except in compliance with the License.
005: // You may obtain a copy of the License at
006: //
007: // http://www.apache.org/licenses/LICENSE-2.0
008: //
009: // Unless required by applicable law or agreed to in writing, software
010: // distributed under the License is distributed on an "AS IS" BASIS,
011: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: // See the License for the specific language governing permissions and
013: // limitations under the License.
014:
015: package org.apache.tapestry.internal.services;
016:
017: import org.apache.commons.logging.Log;
018: import org.apache.tapestry.ComponentResources;
019: import org.apache.tapestry.Link;
020: import org.apache.tapestry.internal.structure.Page;
021: import org.apache.tapestry.internal.test.InternalBaseTestCase;
022: import org.apache.tapestry.runtime.Component;
023: import org.apache.tapestry.services.ComponentEventResultProcessor;
024: import org.apache.tapestry.services.Response;
025: import org.testng.annotations.Test;
026:
027: public class ComponentInstanceResultProcessorTest extends
028: InternalBaseTestCase {
029: private static final String PAGE_NAME = "Zoop";
030:
031: private static final String METHOD_DESCRIPTION = "foo.bar.Baz.biff()";
032:
033: private static final String LINK_URI = "{LinkURI}";
034:
035: @Test
036: public void result_is_root_component() throws Exception {
037: Component result = mockComponent();
038: Component source = mockComponent();
039: ComponentResources resources = mockComponentResources();
040: Log log = mockLog();
041: RequestPageCache cache = mockRequestPageCache();
042: Page page = mockPage();
043: LinkFactory factory = mockLinkFactory();
044: Response response = mockResponse();
045: Link link = mockLink();
046:
047: train_getComponentResources(result, resources);
048: train_getContainer(resources, null);
049:
050: train_getPageName(resources, PAGE_NAME);
051: train_get(cache, PAGE_NAME, page);
052:
053: train_createPageLink(factory, page, link);
054: train_toRedirectURI(link, LINK_URI);
055:
056: response.sendRedirect(LINK_URI);
057:
058: replay();
059:
060: ComponentEventResultProcessor<Component> processor = new ComponentInstanceResultProcessor(
061: cache, factory, log);
062:
063: processor.processComponentEvent(result, source,
064: METHOD_DESCRIPTION).sendClientResponse(response);
065:
066: verify();
067: }
068:
069: @Test
070: public void warning_for_component_is_not_root_component()
071: throws Exception {
072: Component value = mockComponent();
073: Component source = mockComponent();
074: Component root = mockComponent();
075: Component containerResources = mockComponent();
076: ComponentResources rootResources = mockComponentResources();
077: ComponentResources valueResources = mockComponentResources();
078: ComponentResources sourceResources = mockComponentResources();
079: Log log = mockLog();
080: RequestPageCache cache = mockRequestPageCache();
081: Page page = mockPage();
082: LinkFactory factory = mockLinkFactory();
083: Response response = mockResponse();
084: Link link = mockLink();
085:
086: train_getComponentResources(value, valueResources);
087:
088: train_getContainer(valueResources, containerResources);
089: train_getComponentResources(source, sourceResources);
090:
091: train_getCompleteId(sourceResources, PAGE_NAME + ":source");
092: train_getCompleteId(valueResources, PAGE_NAME + ":child");
093:
094: log
095: .warn("Method foo.bar.Baz.biff() (for component Zoop:source) returned component Zoop:child, which is not a page component. The page containing the component will render the client response.");
096:
097: train_getPageName(valueResources, PAGE_NAME);
098: train_get(cache, PAGE_NAME, page);
099:
100: train_createPageLink(factory, page, link);
101: train_toRedirectURI(link, LINK_URI);
102:
103: response.sendRedirect(LINK_URI);
104:
105: replay();
106:
107: ComponentEventResultProcessor<Component> processor = new ComponentInstanceResultProcessor(
108: cache, factory, log);
109:
110: processor.processComponentEvent(value, source,
111: METHOD_DESCRIPTION).sendClientResponse(response);
112:
113: verify();
114: }
115: }
|