KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > pageload > TestNamespaceClassSearchComponentClassProvider


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.pageload;
16
17 import java.util.List JavaDoc;
18
19 import org.apache.hivemind.ClassResolver;
20 import org.apache.hivemind.test.HiveMindTestCase;
21 import org.apache.tapestry.INamespace;
22 import org.apache.tapestry.services.ClassFinder;
23 import org.apache.tapestry.spec.IComponentSpecification;
24 import org.easymock.MockControl;
25
26 /**
27  * Tests for {@link org.apache.tapestry.pageload.NamespaceClassSearchComponentClassProvider}.
28  *
29  * @author Howard M. Lewis Ship
30  * @since 4.0
31  */

32 public class TestNamespaceClassSearchComponentClassProvider extends HiveMindTestCase
33 {
34     private IComponentSpecification newSpec()
35     {
36         return (IComponentSpecification) newMock(IComponentSpecification.class);
37     }
38
39     private INamespace newNamespace(String JavaDoc key, String JavaDoc prefixes)
40     {
41         MockControl control = newControl(INamespace.class);
42         INamespace namespace = (INamespace) control.getMock();
43
44         namespace.getPropertyValue(key);
45         control.setReturnValue(prefixes);
46
47         return namespace;
48     }
49
50     private ClassFinder newClassFinder(String JavaDoc packageList, String JavaDoc className, Class JavaDoc resultClass)
51     {
52         MockControl control = newControl(ClassFinder.class);
53         ClassFinder finder = (ClassFinder) control.getMock();
54
55         finder.findClass(packageList, className);
56         control.setReturnValue(resultClass);
57
58         return finder;
59     }
60
61     public void testFound()
62     {
63         INamespace namespace = newNamespace("zip", "org.apache.tapestry.pageload");
64         ClassFinder finder = newClassFinder(
65                 "org.apache.tapestry.pageload",
66                 "bar.Baz",
67                 TestPageLoader.class);
68
69         IComponentSpecification spec = newSpec();
70
71         replayControls();
72
73         ComponentClassProviderContext context = new ComponentClassProviderContext("bar/Baz", spec,
74                 namespace);
75
76         NamespaceClassSearchComponentClassProvider provider = new NamespaceClassSearchComponentClassProvider();
77         provider.setClassFinder(finder);
78         provider.setPackagesName("zip");
79
80         assertEquals(TestPageLoader.class.getName(), provider.provideComponentClassName(context));
81
82         verifyControls();
83     }
84
85     public void testNotFound()
86     {
87         INamespace namespace = newNamespace("zap", "org.foo");
88         ClassFinder finder = newClassFinder("org.foo", "bar.Baz", null);
89
90         IComponentSpecification spec = newSpec();
91
92         replayControls();
93
94         ComponentClassProviderContext context = new ComponentClassProviderContext("bar/Baz", spec,
95                 namespace);
96
97         NamespaceClassSearchComponentClassProvider provider = new NamespaceClassSearchComponentClassProvider();
98         provider.setClassFinder(finder);
99         provider.setPackagesName("zap");
100
101         assertNull(provider.provideComponentClassName(context));
102
103         verifyControls();
104     }
105 }
Popular Tags