1 package org.sapia.util.xml.idefix.test; 2 3 import java.lang.reflect.Method ; 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 23 public class PatternNamespaceFactoryTest extends TestCase { 24 25 static { 26 BasicConfigurator.configure(); 27 } 28 29 public static void main(String [] args) { 30 TestRunner.run(PatternNamespaceFactoryTest.class); 31 } 32 33 36 public PatternNamespaceFactoryTest(String aName) { 37 super(aName); 38 } 39 40 41 44 public void testSimple_ClassResolution() throws Exception { 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 58 public void testPackageFallback_ClassResolution() throws Exception { 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 72 public void testInvalid_ClassResolution() throws Exception { 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 85 public void testSimple_MethodResolution() throws Exception { 86 PatternNamespaceFactory aFactory = new PatternNamespaceFactory(); 87 Namespace aNamespace = new Namespace("http://schema.sapia-oss.org/junit", "JUNIT"); 88 Method aMethod = getClass().getMethod("testSimple_MethodResolution", new Class [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 100 public void testClassCallback_MethodResolution() throws Exception { 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 aMethod = getClass().getMethod("testClassCallback_MethodResolution", new Class [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 115 public void testPackageCallback_MethodResolution() throws Exception { 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 aMethod = getClass().getMethod("testPackageCallback_MethodResolution", new Class [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 130 public void testInvalid_MethodResolution() throws Exception { 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 aMethod = getClass().getMethod("testInvalid_MethodResolution", new Class [0]); 136 Namespace anotherNamespace = aFactory.getNamespaceFor(aMethod); 137 assertNull("The namespace found is invalid, ir should be null", anotherNamespace); 138 } 139 140 141 144 public void testOverloaded_MethodResolution() throws Exception { 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 .class, PatternNamespaceFactory.DEFAULT_NAMESPACE); 152 153 Method aMethod = getClass().getMethod("testOverloaded_MethodResolution", new Class [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 [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 [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 |