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.services;
16:
17: import org.apache.tapestry.internal.structure.ComponentPageElement;
18: import org.apache.tapestry.internal.structure.Page;
19: import org.apache.tapestry.internal.test.InternalBaseTestCase;
20: import org.apache.tapestry.runtime.Component;
21: import org.apache.tapestry.services.ComponentSource;
22: import org.testng.annotations.Test;
23:
24: public class ComponentSourceImplTest extends InternalBaseTestCase {
25: private static final String PAGE_NAME = "Bar";
26:
27: private static final String NESTED_ELEMENT_ID = "zip.zoom";
28:
29: @Test
30: public void root_element_of_page() {
31: RequestPageCache cache = mockRequestPageCache();
32: Page page = mockPage();
33: Component component = mockComponent();
34:
35: train_get(cache, PAGE_NAME, page);
36:
37: train_getRootComponent(page, component);
38:
39: replay();
40:
41: ComponentSource source = new ComponentSourceImpl(cache);
42:
43: assertSame(source.getComponent(PAGE_NAME), component);
44:
45: verify();
46: }
47:
48: @Test
49: public void nested_element_within_page() {
50: RequestPageCache cache = mockRequestPageCache();
51: Page page = mockPage();
52: ComponentPageElement element = mockComponentPageElement();
53: Component component = mockComponent();
54:
55: train_get(cache, PAGE_NAME, page);
56:
57: train_getComponentElementByNestedId(page, NESTED_ELEMENT_ID,
58: element);
59:
60: train_getComponent(element, component);
61:
62: replay();
63:
64: ComponentSource source = new ComponentSourceImpl(cache);
65:
66: assertSame(source.getComponent(PAGE_NAME + ":"
67: + NESTED_ELEMENT_ID), component);
68:
69: verify();
70: }
71:
72: @Test
73: public void get_page_by_logical_name() {
74: RequestPageCache cache = mockRequestPageCache();
75: Page page = mockPage();
76: Component component = mockComponent();
77:
78: train_get(cache, PAGE_NAME, page);
79: train_getRootComponent(page, component);
80:
81: replay();
82:
83: ComponentSource source = new ComponentSourceImpl(cache);
84:
85: assertSame(source.getPage(PAGE_NAME), component);
86:
87: verify();
88: }
89:
90: @Test
91: public void get_page_by_class() {
92: }
93:
94: }
|