Replace DOMParser with calls to pool or helper class.
[java-idp.git] / tests / edu / internet2 / middleware / shibboleth / hs / provider / NameMapperTests.java
index b9e709c..65cbfba 100644 (file)
@@ -37,7 +37,6 @@ import junit.framework.TestCase;
 import org.apache.log4j.BasicConfigurator;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
-import org.apache.xerces.parsers.DOMParser;
 import org.opensaml.SAMLNameIdentifier;
 import org.xml.sax.EntityResolver;
 import org.xml.sax.ErrorHandler;
@@ -48,11 +47,13 @@ import org.xml.sax.SAXParseException;
 import edu.internet2.middleware.shibboleth.common.AuthNPrincipal;
 import edu.internet2.middleware.shibboleth.common.Credential;
 import edu.internet2.middleware.shibboleth.common.IdentityProvider;
+import edu.internet2.middleware.shibboleth.common.NameIdentifierMapping;
 import edu.internet2.middleware.shibboleth.common.NameIdentifierMappingException;
 import edu.internet2.middleware.shibboleth.common.NameMapper;
 import edu.internet2.middleware.shibboleth.common.ServiceProvider;
-import edu.internet2.middleware.shibboleth.hs.HSNameIdentifierMapping;
-import edu.internet2.middleware.shibboleth.hs.HSNameMapper;
+import edu.internet2.middleware.shibboleth.xml.Parser;
+
+
 
 /**
  * Validation suite for the <code>NameMapper</code>.
@@ -62,7 +63,7 @@ import edu.internet2.middleware.shibboleth.hs.HSNameMapper;
 
 public class NameMapperTests extends TestCase {
 
-       private DOMParser parser = new DOMParser();
+       private Parser.DOMParser parser = new Parser.DOMParser(true);
 
        public NameMapperTests(String name) {
 
@@ -82,56 +83,14 @@ public class NameMapperTests extends TestCase {
        protected void setUp() throws Exception {
 
                super.setUp();
-               try {
-
-                       parser.setFeature("http://xml.org/sax/features/validation", true);
-                       parser.setFeature("http://apache.org/xml/features/validation/schema", true);
-                       parser.setEntityResolver(new EntityResolver() {
-
-                               public InputSource resolveEntity(String publicId, String systemId) throws SAXException {
-
-                                       if (systemId.endsWith("namemapper.xsd")) {
-                                               InputStream stream;
-                                               try {
-                                                       stream = new FileInputStream("src/schemas/namemapper.xsd");
-                                                       if (stream != null) { return new InputSource(stream); }
-                                                       throw new SAXException("Could not load entity: Null input stream");
-                                               } catch (FileNotFoundException e) {
-                                                       throw new SAXException("Could not load entity: " + e);
-                                               }
-                                       } else {
-                                               return null;
-                                       }
-                               }
-                       });
-
-                       parser.setErrorHandler(new ErrorHandler() {
-
-                               public void error(SAXParseException arg0) throws SAXException {
-
-                                       throw new SAXException("Error parsing xml file: " + arg0);
-                               }
-
-                               public void fatalError(SAXParseException arg0) throws SAXException {
-
-                                       throw new SAXException("Error parsing xml file: " + arg0);
-                               }
 
-                               public void warning(SAXParseException arg0) throws SAXException {
-
-                                       throw new SAXException("Error parsing xml file: " + arg0);
-                               }
-                       });
-               } catch (Exception e) {
-                       fail("Failed to setup xml parser: " + e);
-               }
        }
 
        public void testCryptoMapping() {
 
                try {
 
-                       HSNameMapper nameMapper = new HSNameMapper();
+                       NameMapper nameMapper = new NameMapper();
 
                        File file = new File("data/handle.jks");
 
@@ -171,7 +130,7 @@ public class NameMapperTests extends TestCase {
 
                try {
 
-                       HSNameMapper nameMapper = new HSNameMapper();
+                       NameMapper nameMapper = new NameMapper();
 
                        File file = new File("data/handle.jks");
 
@@ -214,7 +173,7 @@ public class NameMapperTests extends TestCase {
 
                try {
 
-                       HSNameMapper nameMapper = new HSNameMapper();
+                       NameMapper nameMapper = new NameMapper();
 
                        File file = new File("data/handle.jks");
 
@@ -257,7 +216,7 @@ public class NameMapperTests extends TestCase {
 
                try {
 
-                       HSNameMapper nameMapper = new HSNameMapper();
+                       NameMapper nameMapper = new NameMapper();
 
                        SAMLNameIdentifier nameId = nameMapper.getNameIdentifierName(null, new AuthNPrincipal("testprincipal"),
                                        new BasicServiceProvider(), new BasicIdentityProvider("urn-x:testid"));
@@ -278,7 +237,7 @@ public class NameMapperTests extends TestCase {
 
                try {
 
-                       HSNameMapper nameMapper = new HSNameMapper();
+                       NameMapper nameMapper = new NameMapper();
 
                        File file = new File("data/handle.jks");
 
@@ -305,7 +264,7 @@ public class NameMapperTests extends TestCase {
 
                        assertEquals("Round-trip handle validation failed.", principal.getName(), "testprincipal");
 
-                       HSNameIdentifierMapping nameMapping = nameMapper.getNameIdentifierMappingById(null);
+                       NameIdentifierMapping nameMapping = nameMapper.getNameIdentifierMappingById(null);
                        if (!(nameMapping instanceof CryptoShibHandle)) {
                                fail("HSNameMapper defaulted to incorrect name mapping.");
                        }
@@ -321,7 +280,7 @@ public class NameMapperTests extends TestCase {
 
                try {
 
-                       HSNameMapper nameMapper = new HSNameMapper();
+                       NameMapper nameMapper = new NameMapper();
 
                        File file = new File("data/handle.jks");
 
@@ -374,7 +333,7 @@ public class NameMapperTests extends TestCase {
 
                try {
 
-                       HSNameMapper nameMapper = new HSNameMapper();
+                       NameMapper nameMapper = new NameMapper();
 
                        String rawConfig = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                                        + "<NameMapping xmlns=\"urn:mace:shibboleth:namemapper:1.0\""
@@ -408,7 +367,7 @@ public class NameMapperTests extends TestCase {
 
                try {
 
-                       HSNameMapper nameMapper = new HSNameMapper();
+                       NameMapper nameMapper = new NameMapper();
 
                        String rawConfig = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                                        + "<NameMapping xmlns=\"urn:mace:shibboleth:namemapper:1.0\""