001: // Copyright 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 java.util.Locale;
018:
019: import org.apache.tapestry.internal.test.InternalBaseTestCase;
020: import org.apache.tapestry.ioc.Resource;
021: import org.apache.tapestry.model.ComponentModel;
022: import org.apache.tapestry.services.ComponentClassResolver;
023: import org.testng.annotations.Test;
024:
025: public class PageTemplateLocatorImplTest extends InternalBaseTestCase {
026: @Test
027: public void not_a_page_class() {
028: ComponentModel model = mockComponentModel();
029: Resource root = mockResource();
030: ComponentClassResolver resolver = mockComponentClassResolver();
031:
032: train_getComponentClassName(model, "foo.bar.Baz");
033:
034: replay();
035:
036: PageTemplateLocator locator = new PageTemplateLocatorImpl(root,
037: resolver);
038:
039: assertNull(locator.findPageTemplateResource(model,
040: Locale.FRENCH));
041:
042: verify();
043: }
044:
045: @Test
046: public void template_found() {
047: ComponentModel model = mockComponentModel();
048: Resource root = mockResource();
049: Resource withExtension = mockResource();
050: Resource forLocale = mockResource();
051: Locale locale = Locale.FRENCH;
052: String className = "myapp.pages.Foo";
053:
054: ComponentClassResolver resolver = mockComponentClassResolver();
055:
056: train_getComponentClassName(model, className);
057:
058: train_resolvePageClassNameToPageName(resolver, className, "Foo");
059:
060: train_forFile(root, "WEB-INF/Foo.html", withExtension);
061: train_forLocale(withExtension, locale, forLocale);
062:
063: replay();
064:
065: PageTemplateLocator locator = new PageTemplateLocatorImpl(root,
066: resolver);
067:
068: assertSame(locator.findPageTemplateResource(model, locale),
069: forLocale);
070:
071: verify();
072: }
073:
074: /**
075: * Because of how Tapestry maps class names to logical page names, part of the name may be have
076: * been stripped off and we want to make sure we get it back.
077: */
078: @Test
079: public void uses_simple_class_name_in_folders() {
080: ComponentModel model = mockComponentModel();
081: Resource root = mockResource();
082: Resource withExtension = mockResource();
083: Resource forLocale = mockResource();
084: Locale locale = Locale.FRENCH;
085: String className = "myapp.pages.foo.CreateFoo";
086:
087: ComponentClassResolver resolver = mockComponentClassResolver();
088:
089: train_getComponentClassName(model, className);
090:
091: // Notice: foo/Create not foo/CreateFoo; we're simulating how the redundancy gets stripped
092: // out of the class name.
093: train_resolvePageClassNameToPageName(resolver, className,
094: "foo/Create");
095:
096: // Abnd here's where we're showing that PTLI stitches it back together.
097: train_forFile(root, "WEB-INF/foo/CreateFoo.html", withExtension);
098: train_forLocale(withExtension, locale, forLocale);
099:
100: replay();
101:
102: PageTemplateLocator locator = new PageTemplateLocatorImpl(root,
103: resolver);
104:
105: assertSame(locator.findPageTemplateResource(model, locale),
106: forLocale);
107:
108: verify();
109: }
110:
111: @Test
112: public void template_not_found() {
113: ComponentModel model = mockComponentModel();
114: Resource root = mockResource();
115: Resource withExtension = mockResource();
116: Locale locale = Locale.GERMAN;
117: String className = "myapp.pages.bar.Baz";
118:
119: ComponentClassResolver resolver = mockComponentClassResolver();
120:
121: train_getComponentClassName(model, className);
122:
123: train_resolvePageClassNameToPageName(resolver, className,
124: "bar/Baz");
125:
126: train_forFile(root, "WEB-INF/bar/Baz.html", withExtension);
127: train_forLocale(withExtension, locale, null);
128:
129: replay();
130:
131: PageTemplateLocator locator = new PageTemplateLocatorImpl(root,
132: resolver);
133:
134: assertNull(locator.findPageTemplateResource(model, locale));
135:
136: verify();
137: }
138:
139: }
|