KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > util > xml > idefix > test > PatternNamespaceFactoryTest


1 package org.sapia.util.xml.idefix.test;
2
3 import java.lang.reflect.Method JavaDoc;
4
5 import org.apache.log4j.BasicConfigurator;
6 import org.sapia.util.xml.Namespace;
7 import org.sapia.util.xml.idefix.PatternNamespaceFactory;
8
9 import junit.framework.TestCase;
10 import junit.textui.TestRunner;
11
12
13 /**
14  *
15  *
16  * @author <a HREF="mailto:jc@sapia-oss.org">Jean-Cedric Desrochers</a>
17  * <dl>
18  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
19  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
20  * <a HREF="http://www.sapia-oss.org/license.html" target="sapia-license">license page</a> at the Sapia OSS web site</dd></dt>
21  * </dl>
22  */

23 public class PatternNamespaceFactoryTest extends TestCase {
24
25   static {
26     BasicConfigurator.configure();
27   }
28
29   public static void main(String JavaDoc[] args) {
30     TestRunner.run(PatternNamespaceFactoryTest.class);
31   }
32
33   /**
34    * Creates a new PatternNamespaceFactory instance.
35    */

36   public PatternNamespaceFactoryTest(String JavaDoc aName) {
37     super(aName);
38   }
39
40
41   /**
42    *
43    */

44   public void testSimple_ClassResolution() throws Exception JavaDoc {
45     PatternNamespaceFactory aFactory = new PatternNamespaceFactory();
46     Namespace aNamespace = new Namespace("http://schema.sapia-oss.org/junit", "JUNIT");
47     aFactory.addNamespace(PatternNamespaceFactoryTest.class, aNamespace);
48     
49     Namespace anotherNamespace = aFactory.getNamespaceFor(PatternNamespaceFactoryTest.class);
50     assertNotNull("The namespace found is null", anotherNamespace);
51     assertEquals("The namespace found is invalid", aNamespace, anotherNamespace);
52   }
53
54
55   /**
56    *
57    */

58   public void testPackageFallback_ClassResolution() throws Exception JavaDoc {
59     PatternNamespaceFactory aFactory = new PatternNamespaceFactory();
60     Namespace aNamespace = new Namespace("http://schema.sapia-oss.org/junit", "JUNIT");
61     aFactory.addNamespace(PatternNamespaceFactoryTest.class.getPackage(), aNamespace);
62     
63     Namespace anotherNamespace = aFactory.getNamespaceFor(PatternNamespaceFactoryTest.class);
64     assertNotNull("The namespace found is null", anotherNamespace);
65     assertEquals("The namespace found is invalid", aNamespace, anotherNamespace);
66   }
67
68
69   /**
70    *
71    */

72   public void testInvalid_ClassResolution() throws Exception JavaDoc {
73     PatternNamespaceFactory aFactory = new PatternNamespaceFactory();
74     Namespace aNamespace = new Namespace("http://schema.sapia-oss.org/junit", "JUNIT");
75     aFactory.addNamespace(PatternNamespaceFactory.class, aNamespace);
76     
77     Namespace anotherNamespace = aFactory.getNamespaceFor(PatternNamespaceFactoryTest.class);
78     assertNull("The namespace found is invalid, ir should be null", anotherNamespace);
79   }
80
81
82   /**
83    *
84    */

85   public void testSimple_MethodResolution() throws Exception JavaDoc {
86     PatternNamespaceFactory aFactory = new PatternNamespaceFactory();
87     Namespace aNamespace = new Namespace("http://schema.sapia-oss.org/junit", "JUNIT");
88     Method JavaDoc aMethod = getClass().getMethod("testSimple_MethodResolution", new Class JavaDoc[0]);
89     aFactory.addNamespace(aMethod, aNamespace);
90     
91     Namespace anotherNamespace = aFactory.getNamespaceFor(aMethod);
92     assertNotNull("The namespace found is null", anotherNamespace);
93     assertEquals("The namespace found is invalid", aNamespace, anotherNamespace);
94   }
95
96
97   /**
98    *
99    */

100   public void testClassCallback_MethodResolution() throws Exception JavaDoc {
101     PatternNamespaceFactory aFactory = new PatternNamespaceFactory();
102     Namespace aNamespace = new Namespace("http://schema.sapia-oss.org/junit", "JUNIT");
103     aFactory.addNamespace(PatternNamespaceFactoryTest.class, aNamespace);
104     
105     Method JavaDoc aMethod = getClass().getMethod("testClassCallback_MethodResolution", new Class JavaDoc[0]);
106     Namespace anotherNamespace = aFactory.getNamespaceFor(aMethod);
107     assertNotNull("The namespace found is null", anotherNamespace);
108     assertEquals("The namespace found is invalid", aNamespace, anotherNamespace);
109   }
110
111
112   /**
113    *
114    */

115   public void testPackageCallback_MethodResolution() throws Exception JavaDoc {
116     PatternNamespaceFactory aFactory = new PatternNamespaceFactory();
117     Namespace aNamespace = new Namespace("http://schema.sapia-oss.org/junit", "JUNIT");
118     aFactory.addNamespace(PatternNamespaceFactoryTest.class.getPackage(), aNamespace);
119     
120     Method JavaDoc aMethod = getClass().getMethod("testPackageCallback_MethodResolution", new Class JavaDoc[0]);
121     Namespace anotherNamespace = aFactory.getNamespaceFor(aMethod);
122     assertNotNull("The namespace found is null", anotherNamespace);
123     assertEquals("The namespace found is invalid", aNamespace, anotherNamespace);
124   }
125
126
127   /**
128    *
129    */

130   public void testInvalid_MethodResolution() throws Exception JavaDoc {
131     PatternNamespaceFactory aFactory = new PatternNamespaceFactory();
132     Namespace aNamespace = new Namespace("http://schema.sapia-oss.org/junit", "JUNIT");
133     aFactory.addNamespace(PatternNamespaceFactory.class, aNamespace);
134     
135     Method JavaDoc aMethod = getClass().getMethod("testInvalid_MethodResolution", new Class JavaDoc[0]);
136     Namespace anotherNamespace = aFactory.getNamespaceFor(aMethod);
137     assertNull("The namespace found is invalid, ir should be null", anotherNamespace);
138   }
139
140
141   /**
142    *
143    */

144   public void testOverloaded_MethodResolution() throws Exception JavaDoc {
145     Namespace aSapiaNamespace = new Namespace("http://schema.sapia-oss.org/junit", "SAPIA");
146     Namespace aJunitNamespace = new Namespace("http://www.junit.org/junit", "JUNIT");
147
148     PatternNamespaceFactory aFactory = new PatternNamespaceFactory();
149     aFactory.addNamespace(PatternNamespaceFactoryTest.class, aSapiaNamespace);
150     aFactory.addNamespace(TestCase.class, aJunitNamespace);
151     aFactory.addNamespace(Object JavaDoc.class, PatternNamespaceFactory.DEFAULT_NAMESPACE);
152     
153     Method JavaDoc aMethod = getClass().getMethod("testOverloaded_MethodResolution", new Class JavaDoc[0]);
154     Namespace anotherNamespace = aFactory.getNamespaceFor(aMethod);
155     assertNotNull("The namespace found is null", anotherNamespace);
156     assertEquals("The namespace found is invalid", aSapiaNamespace, anotherNamespace);
157
158     aMethod = getClass().getMethod("runBare", new Class JavaDoc[0]);
159     anotherNamespace = aFactory.getNamespaceFor(aMethod);
160     assertNotNull("The namespace found is null", anotherNamespace);
161     assertEquals("The namespace found is invalid", aJunitNamespace, anotherNamespace);
162
163     aMethod = getClass().getMethod("hashCode", new Class JavaDoc[0]);
164     anotherNamespace = aFactory.getNamespaceFor(aMethod);
165     assertNotNull("The namespace found is null", anotherNamespace);
166     assertEquals("The namespace found is invalid", PatternNamespaceFactory.DEFAULT_NAMESPACE, anotherNamespace);
167   }
168 }
169
Popular Tags