KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > resolver > TestPageSpecificationResolver


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// 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.resolver;
16
17 import java.util.List JavaDoc;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.hivemind.Location;
21 import org.apache.hivemind.Resource;
22 import org.apache.tapestry.INamespace;
23 import org.apache.tapestry.IRequestCycle;
24 import org.apache.tapestry.PageNotFoundException;
25 import org.apache.tapestry.Tapestry;
26 import org.apache.tapestry.engine.ISpecificationSource;
27 import org.apache.tapestry.services.ComponentPropertySource;
28 import org.apache.tapestry.spec.ComponentSpecification;
29 import org.apache.tapestry.spec.IComponentSpecification;
30 import org.apache.tapestry.spec.ILibrarySpecification;
31 import org.easymock.MockControl;
32
33 /**
34  * Tests for {@link org.apache.tapestry.resolver.PageSpecificationResolverImpl}.
35  *
36  * @author Howard M. Lewis Ship
37  * @since 4.0
38  */

39 public class TestPageSpecificationResolver extends AbstractSpecificationResolverTestCase
40 {
41     private static class MockApplicationNamespace implements INamespace
42     {
43         private Resource _specificationLocation;
44
45         String JavaDoc _pageName;
46
47         IComponentSpecification _specification;
48
49         MockApplicationNamespace(Resource specificationLocation)
50         {
51             _specificationLocation = specificationLocation;
52         }
53
54         public String JavaDoc getId()
55         {
56             return null;
57         }
58
59         public String JavaDoc getExtendedId()
60         {
61             return null;
62         }
63
64         public String JavaDoc getNamespaceId()
65         {
66             return null;
67         }
68
69         public INamespace getParentNamespace()
70         {
71             return null;
72         }
73
74         public INamespace getChildNamespace(String JavaDoc id)
75         {
76             return null;
77         }
78
79         public List JavaDoc getChildIds()
80         {
81             return null;
82         }
83
84         public IComponentSpecification getPageSpecification(String JavaDoc name)
85         {
86             return null;
87         }
88
89         public boolean containsPage(String JavaDoc name)
90         {
91             return false;
92         }
93
94         public List JavaDoc getPageNames()
95         {
96             return null;
97         }
98
99         public IComponentSpecification getComponentSpecification(String JavaDoc type)
100         {
101             return null;
102         }
103
104         public boolean containsComponentType(String JavaDoc type)
105         {
106             return false;
107         }
108
109         public ILibrarySpecification getSpecification()
110         {
111             return null;
112         }
113
114         public String JavaDoc constructQualifiedName(String JavaDoc pageName)
115         {
116             return null;
117         }
118
119         public Resource getSpecificationLocation()
120         {
121             return _specificationLocation;
122         }
123
124         public boolean isApplicationNamespace()
125         {
126             return true;
127         }
128
129         public void installPageSpecification(String JavaDoc pageName, IComponentSpecification specification)
130         {
131             _pageName = pageName;
132             _specification = specification;
133         }
134
135         public void installComponentSpecification(String JavaDoc type, IComponentSpecification specification)
136         {
137         }
138
139         public Location getLocation()
140         {
141             return null;
142         }
143
144         public String JavaDoc getPropertyValue(String JavaDoc propertyName)
145         {
146             return null;
147         }
148
149     }
150
151     private ISpecificationSource newSource(INamespace application, INamespace framework)
152     {
153         MockControl control = newControl(ISpecificationSource.class);
154         ISpecificationSource source = (ISpecificationSource) control.getMock();
155
156         source.getApplicationNamespace();
157         control.setReturnValue(application);
158
159         source.getFrameworkNamespace();
160         control.setReturnValue(framework);
161
162         return source;
163     }
164
165     private ISpecificationSource newSource(INamespace application, INamespace framework,
166             Resource resource, IComponentSpecification pageSpec)
167     {
168         MockControl control = newControl(ISpecificationSource.class);
169         ISpecificationSource source = (ISpecificationSource) control.getMock();
170
171         source.getApplicationNamespace();
172         control.setReturnValue(application);
173
174         source.getFrameworkNamespace();
175         control.setReturnValue(framework);
176
177         source.getPageSpecification(resource);
178         control.setReturnValue(pageSpec);
179
180         return source;
181     }
182
183     private INamespace newNamespace()
184     {
185         return (INamespace) newMock(INamespace.class);
186     }
187
188     private INamespace newNamespace(String JavaDoc pageName, IComponentSpecification spec)
189     {
190         MockControl control = newControl(INamespace.class);
191         INamespace namespace = (INamespace) control.getMock();
192
193         namespace.containsPage(pageName);
194         control.setReturnValue(spec != null);
195
196         if (spec != null)
197         {
198             namespace.getPageSpecification(pageName);
199             control.setReturnValue(spec);
200         }
201
202         return namespace;
203     }
204
205     private ComponentPropertySource newPropertySource(INamespace namespace)
206     {
207         MockControl control = newControl(ComponentPropertySource.class);
208         ComponentPropertySource source = (ComponentPropertySource) control.getMock();
209
210         source.getNamespaceProperty(namespace, Tapestry.TEMPLATE_EXTENSION_PROPERTY);
211         control.setReturnValue("html");
212
213         return source;
214     }
215
216     public void testFoundInApplicationNamespace()
217     {
218         Resource contextRoot = newResource("context/");
219         IComponentSpecification spec = newSpecification();
220         INamespace application = newNamespace("ExistingPage", spec);
221         INamespace framework = newNamespace();
222         ISpecificationSource source = newSource(application, framework);
223         IRequestCycle cycle = newCycle();
224
225         replayControls();
226
227         PageSpecificationResolverImpl resolver = new PageSpecificationResolverImpl();
228         resolver.setContextRoot(contextRoot);
229         resolver.setSpecificationSource(source);
230         resolver.initializeService();
231
232         resolver.resolve(cycle, "ExistingPage");
233
234         assertEquals("ExistingPage", resolver.getSimplePageName());
235         assertSame(spec, resolver.getSpecification());
236         assertSame(application, resolver.getNamespace());
237
238         verifyControls();
239     }
240
241     public void testExplicitlyInFrameworkNamespace()
242     {
243         Resource contextRoot = newResource("context/");
244         IComponentSpecification spec = newSpecification();
245         INamespace application = newNamespace();
246         INamespace framework = newNamespace("ExistingPage", spec);
247         ISpecificationSource source = newSource(application, framework);
248         IRequestCycle cycle = newCycle();
249
250         replayControls();
251
252         PageSpecificationResolverImpl resolver = new PageSpecificationResolverImpl();
253         resolver.setContextRoot(contextRoot);
254         resolver.setSpecificationSource(source);
255         resolver.initializeService();
256
257         resolver.resolve(cycle, "framework:ExistingPage");
258
259         assertEquals("ExistingPage", resolver.getSimplePageName());
260         assertSame(spec, resolver.getSpecification());
261         assertSame(framework, resolver.getNamespace());
262
263         verifyControls();
264     }
265
266     public void testFoundInChildNamespace()
267     {
268         Resource contextRoot = newResource("context/");
269         IComponentSpecification spec = newSpecification();
270
271         INamespace child = newNamespace("ChildPage", spec);
272
273         MockControl control = newControl(INamespace.class);
274         INamespace application = (INamespace) control.getMock();
275
276         application.getChildNamespace("foo.bar");
277         control.setReturnValue(child);
278
279         INamespace framework = newNamespace();
280         ISpecificationSource source = newSource(application, framework);
281         IRequestCycle cycle = newCycle();
282
283         replayControls();
284
285         PageSpecificationResolverImpl resolver = new PageSpecificationResolverImpl();
286         resolver.setContextRoot(contextRoot);
287         resolver.setSpecificationSource(source);
288         resolver.initializeService();
289
290         resolver.resolve(cycle, "foo.bar:ChildPage");
291
292         assertEquals("ChildPage", resolver.getSimplePageName());
293         assertSame(spec, resolver.getSpecification());
294         assertSame(child, resolver.getNamespace());
295
296         verifyControls();
297     }
298
299     public void testFoundInNamespaceFolder()
300     {
301         MockControl logc = newControl(Log.class);
302         Log log = (Log) logc.getMock();
303
304         Resource contextRoot = newResource("context/");
305         IComponentSpecification spec = newSpecification();
306
307         Resource resource = contextRoot.getRelativeResource("WEB-INF/NamespacePage.page");
308
309         MockControl applicationc = newControl(INamespace.class);
310         INamespace application = (INamespace) applicationc.getMock();
311
312         INamespace framework = newNamespace();
313         ISpecificationSource source = newSource(application, framework, resource, spec);
314         IRequestCycle cycle = newCycle();
315
316         trainContainsPage(applicationc, application, "NamespacePage", false);
317
318         train(log, logc, ResolverMessages.resolvingPage("NamespacePage", application));
319
320         // Pretend the app spec is in the WEB-INF folder
321

322         trainGetSpecLocation(applicationc, application, contextRoot, "WEB-INF/");
323
324         train(log, logc, ResolverMessages.checkingResource(resource));
325
326         train(log, logc, ResolverMessages.installingPage("NamespacePage", application, spec));
327
328         application.installPageSpecification("NamespacePage", spec);
329
330         replayControls();
331
332         PageSpecificationResolverImpl resolver = new PageSpecificationResolverImpl();
333         resolver.setContextRoot(contextRoot);
334         resolver.setSpecificationSource(source);
335         resolver.initializeService();
336         resolver.setLog(log);
337
338         resolver.resolve(cycle, "NamespacePage");
339
340         assertEquals("NamespacePage", resolver.getSimplePageName());
341         assertSame(spec, resolver.getSpecification());
342         assertSame(application, resolver.getNamespace());
343
344         verifyControls();
345     }
346
347     private void trainGetSpecLocation(MockControl control, INamespace namespace, Resource root, String JavaDoc path)
348     {
349         namespace.getSpecificationLocation();
350         control.setReturnValue(root.getRelativeResource(path));
351     }
352
353     public void testFoundInWebInfAppFolder()
354     {
355         MockControl logc = newControl(Log.class);
356         Log log = (Log) logc.getMock();
357
358         Resource contextRoot = newResource("context/");
359         IComponentSpecification spec = newSpecification();
360
361         Resource resource = contextRoot.getRelativeResource("WEB-INF/myapp/MyAppPage.page");
362
363         MockControl applicationc = newControl(INamespace.class);
364         INamespace application = (INamespace) applicationc.getMock();
365
366         INamespace framework = newNamespace();
367         ISpecificationSource source = newSource(application, framework, resource, spec);
368         IRequestCycle cycle = newCycle();
369
370         trainContainsPage(applicationc, application, "MyAppPage", false);
371
372         train(log, logc, ResolverMessages.resolvingPage("MyAppPage", application));
373
374         // Pretend the app spec is in the WEB-INF folder
375

376         trainGetSpecLocation(applicationc, application, contextRoot, "WEB-INF/");
377         
378         train(log, logc, ResolverMessages.checkingResource(contextRoot
379                 .getRelativeResource("WEB-INF/MyAppPage.page")));
380
381         trainIsApplicationNamespace(applicationc, application, true);
382
383         train(log, logc, ResolverMessages.checkingResource(resource));
384
385         train(log, logc, ResolverMessages.installingPage("MyAppPage", application, spec));
386
387         application.installPageSpecification("MyAppPage", spec);
388
389         replayControls();
390
391         PageSpecificationResolverImpl resolver = new PageSpecificationResolverImpl();
392         resolver.setContextRoot(contextRoot);
393         resolver.setSpecificationSource(source);
394         resolver.setLog(log);
395         resolver.setApplicationId("myapp");
396
397         resolver.initializeService();
398
399         resolver.resolve(cycle, "MyAppPage");
400
401         assertEquals("MyAppPage", resolver.getSimplePageName());
402         assertSame(spec, resolver.getSpecification());
403         assertSame(application, resolver.getNamespace());
404
405         verifyControls();
406     }
407
408     private void trainIsApplicationNamespace(MockControl control, INamespace namespace, boolean isApplicationNamespace)
409     {
410         namespace.isApplicationNamespace();
411         control.setReturnValue(isApplicationNamespace);
412     }
413
414     public void testFoundInWebInfFolder()
415     {
416         MockControl logc = newControl(Log.class);
417         Log log = (Log) logc.getMock();
418
419         Resource contextRoot = newResource("context/");
420         IComponentSpecification spec = newSpecification();
421
422         Resource resource = contextRoot.getRelativeResource("WEB-INF/MyWebInfPage.page");
423
424         MockControl applicationc = newControl(INamespace.class);
425         INamespace application = (INamespace) applicationc.getMock();
426
427         INamespace framework = newNamespace();
428         ISpecificationSource source = newSource(application, framework, resource, spec);
429         IRequestCycle cycle = newCycle();
430
431         application.containsPage("MyWebInfPage");
432         applicationc.setReturnValue(false);
433
434         train(log, logc, ResolverMessages.resolvingPage("MyWebInfPage", application));
435
436         // Pretend the app spec is in the context root folder
437
// Which isn't really something that happens in a real application
438
// but is necessary to keep from finding the file too early.
439

440         application.getSpecificationLocation();
441         applicationc.setReturnValue(contextRoot);
442
443         train(log, logc, ResolverMessages.checkingResource(contextRoot
444                 .getRelativeResource("MyWebInfPage.page")));
445
446         application.isApplicationNamespace();
447         applicationc.setReturnValue(true);
448
449         train(log, logc, ResolverMessages.checkingResource(contextRoot
450                 .getRelativeResource("WEB-INF/myapp/MyWebInfPage.page")));
451
452         train(log, logc, ResolverMessages.checkingResource(resource));
453
454         train(log, logc, ResolverMessages.installingPage("MyWebInfPage", application, spec));
455
456         application.installPageSpecification("MyWebInfPage", spec);
457
458         replayControls();
459
460         PageSpecificationResolverImpl resolver = new PageSpecificationResolverImpl();
461         resolver.setContextRoot(contextRoot);
462         resolver.setSpecificationSource(source);
463         resolver.setLog(log);
464         resolver.setApplicationId("myapp");
465
466         resolver.initializeService();
467
468         resolver.resolve(cycle, "MyWebInfPage");
469
470         assertEquals("MyWebInfPage", resolver.getSimplePageName());
471         assertSame(spec, resolver.getSpecification());
472         assertSame(application, resolver.getNamespace());
473
474         verifyControls();
475     }
476
477     public void testFoundInContextRootFolder()
478     {
479         MockControl logc = newControl(Log.class);
480         Log log = (Log) logc.getMock();
481
482         Resource contextRoot = newResource("context/");
483         IComponentSpecification spec = newSpecification();
484
485         Resource resource = contextRoot.getRelativeResource("ContextRootPage.page");
486
487         MockControl applicationc = newControl(INamespace.class);
488         INamespace application = (INamespace) applicationc.getMock();
489
490         INamespace framework = newNamespace();
491         ISpecificationSource source = newSource(application, framework, resource, spec);
492         IRequestCycle cycle = newCycle();
493
494         trainContainsPage(applicationc, application, "ContextRootPage", false);
495
496         train(log, logc, ResolverMessages.resolvingPage("ContextRootPage", application));
497
498         // Pretend the app spec is in the WEB-INF folder
499

500         trainGetSpecLocation(applicationc, application, contextRoot, "WEB-INF/");
501         
502         train(log, logc, ResolverMessages.checkingResource(contextRoot
503                 .getRelativeResource("WEB-INF/ContextRootPage.page")));
504
505         trainIsApplicationNamespace(applicationc, application, true);
506
507         train(log, logc, ResolverMessages.checkingResource(contextRoot
508                 .getRelativeResource("WEB-INF/myapp/ContextRootPage.page")));
509         train(log, logc, ResolverMessages.checkingResource(contextRoot
510                 .getRelativeResource("WEB-INF/ContextRootPage.page")));
511         train(log, logc, ResolverMessages.checkingResource(resource));
512
513         train(log, logc, ResolverMessages.installingPage("ContextRootPage", application, spec));
514
515         application.installPageSpecification("ContextRootPage", spec);
516
517         replayControls();
518
519         PageSpecificationResolverImpl resolver = new PageSpecificationResolverImpl();
520         resolver.setContextRoot(contextRoot);
521         resolver.setSpecificationSource(source);
522         resolver.setLog(log);
523         resolver.setApplicationId("myapp");
524
525         resolver.initializeService();
526
527         resolver.resolve(cycle, "ContextRootPage");
528
529         assertEquals("ContextRootPage", resolver.getSimplePageName());
530         assertSame(spec, resolver.getSpecification());
531         assertSame(application, resolver.getNamespace());
532
533         verifyControls();
534     }
535
536     private void trainContainsPage(MockControl control, INamespace namespace, String JavaDoc pageName, boolean containsPage)
537     {
538         namespace.containsPage(pageName);
539         control.setReturnValue(containsPage);
540     }
541
542     public void testFoundAsTemplate()
543     {
544         MockControl logc = newControl(Log.class);
545         Log log = (Log) logc.getMock();
546
547         Resource contextRoot = newResource("context/");
548
549         Resource resource = contextRoot.getRelativeResource("TemplatePage.html");
550
551         MockApplicationNamespace application = new MockApplicationNamespace(contextRoot
552                 .getRelativeResource("WEB-INF/"));
553
554         INamespace framework = newNamespace();
555         ISpecificationSource source = newSource(application, framework);
556         IRequestCycle cycle = newCycle();
557
558         ComponentPropertySource propertySource = newPropertySource(application);
559
560         train(log, logc, ResolverMessages.resolvingPage("TemplatePage", application));
561
562         train(log, logc, ResolverMessages.checkingResource(contextRoot
563                 .getRelativeResource("WEB-INF/TemplatePage.page")));
564
565         train(log, logc, ResolverMessages.checkingResource(contextRoot
566                 .getRelativeResource("WEB-INF/myapp/TemplatePage.page")));
567         train(log, logc, ResolverMessages.checkingResource(contextRoot
568                 .getRelativeResource("WEB-INF/TemplatePage.page")));
569         train(log, logc, ResolverMessages.checkingResource(contextRoot
570                 .getRelativeResource("TemplatePage.page")));
571         train(log, logc, ResolverMessages.checkingResource(contextRoot
572                 .getRelativeResource("TemplatePage.html")));
573
574         train(log, logc, ResolverMessages.foundHTMLTemplate(resource));
575
576         IComponentSpecification expectedSpec = new ComponentSpecification();
577         expectedSpec.setPageSpecification(true);
578         expectedSpec.setSpecificationLocation(resource);
579
580         // The toString() on ComponentSpecification means we can't predict
581
// what the string would be.
582

583         trainIsDebugEnabled(logc, log, false);
584
585         replayControls();
586
587         PageSpecificationResolverImpl resolver = new PageSpecificationResolverImpl();
588         resolver.setContextRoot(contextRoot);
589         resolver.setSpecificationSource(source);
590         resolver.setLog(log);
591         resolver.setApplicationId("myapp");
592         resolver.setComponentPropertySource(propertySource);
593
594         resolver.initializeService();
595
596         resolver.resolve(cycle, "TemplatePage");
597
598         IComponentSpecification spec = application._specification;
599
600         assertEquals(true, spec.isPageSpecification());
601         assertEquals(resource, spec.getSpecificationLocation());
602
603         assertEquals("TemplatePage", resolver.getSimplePageName());
604         assertEquals("TemplatePage", application._pageName);
605
606         assertSame(spec, resolver.getSpecification());
607         assertSame(application, resolver.getNamespace());
608
609         verifyControls();
610     }
611
612     private void trainIsDebugEnabled(MockControl control, Log log, boolean isDebugEnabled)
613     {
614         log.isDebugEnabled();
615         control.setReturnValue(isDebugEnabled);
616     }
617
618     public void testFoundInFramework()
619     {
620         MockControl logc = newControl(Log.class);
621         Log log = (Log) logc.getMock();
622
623         Resource contextRoot = newResource("context/");
624         IComponentSpecification spec = newSpecification();
625
626         MockControl applicationc = newControl(INamespace.class);
627         INamespace application = (INamespace) applicationc.getMock();
628
629         ComponentPropertySource propertySource = newPropertySource(application);
630
631         INamespace framework = newNamespace("FrameworkPage", spec);
632         ISpecificationSource source = newSource(application, framework);
633         IRequestCycle cycle = newCycle();
634
635         trainContainsPage(applicationc, application, "FrameworkPage", false);
636
637         train(log, logc, ResolverMessages.resolvingPage("FrameworkPage", application));
638
639         // Pretend the app spec is in the WEB-INF folder
640

641         trainGetSpecLocation(applicationc, application, contextRoot, "WEB-INF/");
642         
643         train(log, logc, ResolverMessages.checkingResource(contextRoot
644                 .getRelativeResource("WEB-INF/FrameworkPage.page")));
645
646         trainIsApplicationNamespace(applicationc, application, true);
647
648         train(log, logc, ResolverMessages.checkingResource(contextRoot
649                 .getRelativeResource("WEB-INF/myapp/FrameworkPage.page")));
650         train(log, logc, ResolverMessages.checkingResource(contextRoot
651                 .getRelativeResource("WEB-INF/FrameworkPage.page")));
652         train(log, logc, ResolverMessages.checkingResource(contextRoot
653                 .getRelativeResource("FrameworkPage.page")));
654         train(log, logc, ResolverMessages.checkingResource(contextRoot
655                 .getRelativeResource("FrameworkPage.html")));
656
657         train(log, logc, ResolverMessages.foundFrameworkPage("FrameworkPage"));
658
659         replayControls();
660
661         PageSpecificationResolverImpl resolver = new PageSpecificationResolverImpl();
662         resolver.setContextRoot(contextRoot);
663         resolver.setSpecificationSource(source);
664         resolver.setLog(log);
665         resolver.setApplicationId("myapp");
666         resolver.setComponentPropertySource(propertySource);
667
668         resolver.initializeService();
669
670         resolver.resolve(cycle, "FrameworkPage");
671
672         assertEquals("FrameworkPage", resolver.getSimplePageName());
673         assertSame(spec, resolver.getSpecification());
674         assertSame(framework, resolver.getNamespace());
675
676         verifyControls();
677     }
678
679     public void testProvidedByDelegate()
680     {
681         MockControl logc = newControl(Log.class);
682         Log log = (Log) logc.getMock();
683
684         Resource contextRoot = newResource("context/");
685         IComponentSpecification spec = newSpecification();
686
687         MockControl applicationc = newControl(INamespace.class);
688         INamespace application = (INamespace) applicationc.getMock();
689
690         INamespace framework = newNamespace();
691         ISpecificationSource source = newSource(application, framework);
692         IRequestCycle cycle = newCycle();
693
694         trainContainsPage(applicationc, application, "DelegatePage", false);
695
696         train(log, logc, ResolverMessages.resolvingPage("DelegatePage", application));
697
698         // Pretend the app spec is in the WEB-INF folder
699

700         trainGetSpecLocation(applicationc, application, contextRoot, "WEB-INF/");
701         
702         train(log, logc, ResolverMessages.checkingResource(contextRoot
703                 .getRelativeResource("WEB-INF/DelegatePage.page")));
704
705         application.isApplicationNamespace();
706         applicationc.setReturnValue(false);
707
708         MockControl delegatec = newControl(ISpecificationResolverDelegate.class);
709         ISpecificationResolverDelegate delegate = (ISpecificationResolverDelegate) delegatec
710                 .getMock();
711
712         delegate.findPageSpecification(cycle, application, "DelegatePage");
713         delegatec.setReturnValue(spec);
714         
715         trainIsDebugEnabled(logc, log, false);
716         
717         application.installPageSpecification("DelegatePage", spec);
718
719         replayControls();
720
721         PageSpecificationResolverImpl resolver = new PageSpecificationResolverImpl();
722         resolver.setContextRoot(contextRoot);
723         resolver.setSpecificationSource(source);
724         resolver.setLog(log);
725         resolver.setApplicationId("myapp");
726         resolver.setDelegate(delegate);
727
728         resolver.initializeService();
729
730         resolver.resolve(cycle, "DelegatePage");
731
732         assertEquals("DelegatePage", resolver.getSimplePageName());
733         assertSame(spec, resolver.getSpecification());
734         assertSame(application, resolver.getNamespace());
735
736         verifyControls();
737     }
738
739     public void testNotFoundAnywhere()
740     {
741         MockControl logc = newControl(Log.class);
742         Log log = (Log) logc.getMock();
743
744         Resource contextRoot = newResource("context/");
745
746         MockControl applicationc = newControl(INamespace.class);
747         INamespace application = (INamespace) applicationc.getMock();
748
749         INamespace framework = newNamespace();
750         ISpecificationSource source = newSource(application, framework);
751         IRequestCycle cycle = newCycle();
752
753         trainContainsPage(applicationc, application, "MissingPage", false);
754
755         train(log, logc, ResolverMessages.resolvingPage("MissingPage", application));
756
757         // Pretend the app spec is in the WEB-INF folder
758

759         trainGetSpecLocation(applicationc, application, contextRoot, "WEB-INF/");
760         
761         train(log, logc, ResolverMessages.checkingResource(contextRoot
762                 .getRelativeResource("WEB-INF/MissingPage.page")));
763
764         application.isApplicationNamespace();
765         applicationc.setReturnValue(false);
766
767         MockControl delegatec = newControl(ISpecificationResolverDelegate.class);
768         ISpecificationResolverDelegate delegate = (ISpecificationResolverDelegate) delegatec
769                 .getMock();
770
771         delegate.findPageSpecification(cycle, application, "MissingPage");
772         delegatec.setReturnValue(null);
773
774         application.getNamespaceId();
775         applicationc.setReturnValue("<application namespace>");
776
777         replayControls();
778
779         PageSpecificationResolverImpl resolver = new PageSpecificationResolverImpl();
780         resolver.setContextRoot(contextRoot);
781         resolver.setSpecificationSource(source);
782         resolver.setLog(log);
783         resolver.setApplicationId("myapp");
784         resolver.setDelegate(delegate);
785
786         resolver.initializeService();
787
788         try
789         {
790             resolver.resolve(cycle, "MissingPage");
791             unreachable();
792         }
793         catch (PageNotFoundException ex)
794         {
795             assertEquals("Page 'MissingPage' not found in <application namespace>.", ex
796                     .getMessage());
797         }
798
799         verifyControls();
800     }
801 }
Popular Tags