1 15 package org.apache.tapestry.pageload; 16 17 import java.util.List ; 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 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 key, String 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 packageList, String className, Class 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 |