ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject [4/7] ant git commit: some additional redirect-extension tests
Date Sun, 04 Sep 2016 14:25:01 GMT
some additional redirect-extension tests

https://bz.apache.org/bugzilla/show_bug.cgi?id=60060


Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/9b6f9269
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/9b6f9269
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/9b6f9269

Branch: refs/heads/1.9.x
Commit: 9b6f92697ff0c474da0d27d10321a3c5131c1098
Parents: e345ccf
Author: Stefan Bodewig <bodewig@apache.org>
Authored: Sun Sep 4 12:23:17 2016 +0200
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Sun Sep 4 12:23:17 2016 +0200

----------------------------------------------------------------------
 .../ant/taskdefs/optional/TraXLiaisonTest.java  | 33 +++++++++++++-
 .../optional/junit/JUnitReportTest.java         | 47 ++++++++++++++++++++
 2 files changed, 79 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/9b6f9269/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java
index 52605b4..d4ff72a 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java
@@ -24,6 +24,8 @@ import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.InputStream;
 import java.security.Permission;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
 
 import junit.framework.AssertionFailedError;
 
@@ -57,7 +59,7 @@ public class TraXLiaisonTest extends AbstractXSLTLiaisonTest
     }
 
     @Test
-    public void testXalan2Redirect() throws Exception {
+    public void testXalan2RedirectViaJDKFactory() throws Exception {
         try {
             getClass().getClassLoader().loadClass("org.apache.xalan.lib.Redirect");
         } catch (Exception exc) {
@@ -91,6 +93,35 @@ public class TraXLiaisonTest extends AbstractXSLTLiaisonTest
     }
 
     @Test
+    public void testXalan2RedirectViaXalan() throws Exception {
+        try {
+            getClass().getClassLoader().loadClass("org.apache.xalan.lib.Redirect");
+        } catch (Exception exc) {
+            Assume.assumeNoException("xalan redirect is not on the classpath", exc);
+        }
+        try {
+            String factoryName = TransformerFactory.newInstance().getClass().getName();
+            Assume.assumeTrue("TraxFactory is " + factoryName + " and not Xalan",
+                              "org.apache.xalan.processor.TransformerFactoryImpl"
+                              .equals(factoryName));
+        } catch (TransformerFactoryConfigurationError exc) {
+            throw new RuntimeException(exc);
+        }
+        File xsl = getFile("/taskdefs/optional/xalan-redirect-in.xsl");
+        liaison.setStylesheet(xsl);
+        File out = new File("xalan2-redirect-out-dummy.tmp");
+        File in = getFile("/taskdefs/optional/xsltliaison-in.xsl");
+        try {
+            liaison.addParam("xalan-version", "2");
+            System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission
perm) {}});
+            liaison.transform(in, out);
+        } finally {
+            out.delete();
+            System.setSecurityManager(null);
+        }
+    }
+
+    @Test
     public void testMultipleTransform() throws Exception {
         File xsl = getFile("/taskdefs/optional/xsltliaison-in.xsl");
         liaison.setStylesheet(xsl);

http://git-wip-us.apache.org/repos/asf/ant/blob/9b6f9269/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitReportTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitReportTest.java
b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitReportTest.java
index 8737a94..a7ebbc6 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitReportTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitReportTest.java
@@ -23,14 +23,19 @@ import static org.junit.Assert.assertTrue;
 import static org.apache.tools.ant.AntAssert.assertContains;
 import static org.junit.Assert.fail;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileReader;
 import java.io.InputStream;
 import java.io.IOException;
 import java.net.URL;
+import java.security.Permission;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
 
 import org.apache.tools.ant.BuildFileRule;
 import org.apache.tools.ant.util.FileUtils;
+import org.junit.Assume;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -177,4 +182,46 @@ public class JUnitReportTest {
         assertContains("key1=value1,key2=value2", buildRule.getLog());
         commonIndexFileAssertions();
     }
+
+    @Test
+    public void testWithSecurityManagerAndXalanFactory() throws Exception {
+        try {
+            String factoryName = TransformerFactory.newInstance().getClass().getName();
+            Assume.assumeTrue("TraxFactory is " + factoryName + " and not Xalan",
+                              "org.apache.xalan.processor.TransformerFactoryImpl"
+                              .equals(factoryName));
+        } catch (TransformerFactoryConfigurationError exc) {
+            throw new RuntimeException(exc);
+        }
+        try {
+            System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission
perm) {}});
+            buildRule.executeTarget("testWithStyleFromClasspath");
+            commonIndexFileAssertions();
+        } finally {
+            System.setSecurityManager(null);
+        }
+    }
+
+    @Test
+    public void testWithSecurityManagerAndJDKFactory() throws Exception {
+        ClassLoader orig = Thread.currentThread().getContextClassLoader();
+        try {
+            Thread.currentThread().setContextClassLoader(new ClassLoader(ClassLoader.getSystemClassLoader().getParent())
{
+                public InputStream getResourceAsStream(String name) {
+                    if (name.startsWith("META-INF/services/")) {
+                        // work around JAXP #6723276 in JDK 6
+                        return new ByteArrayInputStream(new byte[0]);
+                    }
+                    return super.getResourceAsStream(name);
+                }
+            });
+            System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission
perm) {}});
+            buildRule.executeTarget("testWithStyleFromClasspath");
+            commonIndexFileAssertions();
+        } finally {
+            System.setSecurityManager(null);
+            Thread.currentThread().setContextClassLoader(orig);
+        }
+    }
+
 }


Mime
View raw message