[java-metadata-aggregator COMMIT] in /trunk/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom: BaseDomTes...

noreply at shibboleth.net noreply at shibboleth.net
Fri Mar 15 17:06:53 EDT 2013


Author: iay
Date: Fri Mar 15 17:06:53 2013
New Revision: 228

URL: http://svn.shibboleth.net/view/java-metadata-aggregator?rev=228&view=rev
Log:
MDA-81 fix some failing EntitiesDescriptorAssemblerStage tests
Work around JSPT-21 ClasspathResource.getLocation() does not return a useful location

Modified:
    trunk/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/BaseDomTest.java
    trunk/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/MultiOutputXSLTtransformationStageTest.java
    trunk/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/XSLTtransformationStageTest.java

Modified: trunk/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/BaseDomTest.java
URL: http://svn.shibboleth.net/view/java-metadata-aggregator/trunk/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/BaseDomTest.java?rev=228&r1=227&r2=228&view=diff
==============================================================================
--- trunk/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/BaseDomTest.java (original)
+++ trunk/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/BaseDomTest.java Fri Mar 15 17:06:53 2013
@@ -18,11 +18,14 @@
 package net.shibboleth.metadata.dom;
 
 import java.io.InputStream;
+import java.net.URL;
 import java.security.Security;
 
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
 import net.shibboleth.utilities.java.support.logic.Constraint;
 import net.shibboleth.utilities.java.support.primitive.StringSupport;
+import net.shibboleth.utilities.java.support.resource.ClasspathResource;
+import net.shibboleth.utilities.java.support.resource.Resource;
 import net.shibboleth.utilities.java.support.xml.BasicParserPool;
 import net.shibboleth.utilities.java.support.xml.ParserPool;
 import net.shibboleth.utilities.java.support.xml.XMLParserException;
@@ -63,6 +66,53 @@
         return parserPool;
     }
 
+    /**
+     * Variant of ClasspathResource that patches round the problem described
+     * in JSPT-21.
+     */
+    private class FixedClasspathResource extends ClasspathResource {
+    
+        /**
+         * Constructor.
+         *
+         * @param resourcePath classpath path to the resource
+         */
+        public FixedClasspathResource(final String resourcePath) {
+            super(resourcePath);
+            // Work around the fact that ClasspathResource doesn't handle location correctly
+            final URL resourceURL = this.getClass().getClassLoader().getResource(resourcePath);
+            setLocation(resourceURL.toExternalForm());
+        }
+        
+    }
+    
+    /**
+     * Helper method to acquire a ClasspathResource based on the given resource path.
+     * 
+     * @param resourcePath classpath path to the resource
+     * @return the data file as a resource
+     */
+    public Resource getClasspathResource(final String resourcePath) {
+        return new FixedClasspathResource(resourcePath);
+    }
+    
+    /**
+     * Acquires a Resource encapsulating a data file located in the resource directory named for the class that is being tested. For example,
+     * for the class <code>net.shibboleth.metadata.dom.saml.RemoveContactPersonStage</code>, the data file will be
+     * looked for in <code>src/test/resources/net/shibboleth/metadata/dom/saml/RemoveContactPersonStage/</code>.
+     * 
+     * @param classBeingTested the class that is being unit tested
+     * @param dataFile the data file to be encapsulated as a resource
+     * 
+     * @return the data file as a Resource
+     */
+    public Resource getTestRelativeClasspathResource(final Class classBeingTested, final String dataFile) {
+        StringBuilder absoluteDataPath = new StringBuilder();
+        absoluteDataPath.append("/").append(classBeingTested.getName().replace('.', '/'));
+        absoluteDataPath.append("/").append(dataFile);
+        return new FixedClasspathResource(absoluteDataPath.toString());
+    }
+    
     /**
      * Parses and XML data file located in the resource directory named for the class that is being tested. For example,
      * for the class <code>net.shibboleth.metadata.dom.saml.RemoveContactPersonStage</code>, the data file will be

Modified: trunk/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/MultiOutputXSLTtransformationStageTest.java
URL: http://svn.shibboleth.net/view/java-metadata-aggregator/trunk/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/MultiOutputXSLTtransformationStageTest.java?rev=228&r1=227&r2=228&view=diff
==============================================================================
--- trunk/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/MultiOutputXSLTtransformationStageTest.java (original)
+++ trunk/aggregator-pipeline/src/test/java/net/shibboleth/metadata/dom/MultiOutputXSLTtransformationStageTest.java Fri Mar 15 17:06:53 2013
@@ -231,7 +231,7 @@
         ArrayList<DomElementItem> mdCol = new ArrayList<DomElementItem>();
         mdCol.add(makeInput());
 

[... 21 lines stripped ...]


More information about the commits mailing list