Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Erdfelt2016-01-13 17:02:54 -0500
committerJoakim Erdfelt2016-01-13 17:02:54 -0500
commitcf9ea6e2a9d1e937f52662bb4be30a5924b3cec2 (patch)
tree5b1186a7d70e33280c941ef8161f2ecb2988bfde
parent0a1b0b2bc69ea7e7f5f44992f47a84f926cdeebb (diff)
downloadorg.eclipse.jetty.project-cf9ea6e2a9d1e937f52662bb4be30a5924b3cec2.tar.gz
org.eclipse.jetty.project-cf9ea6e2a9d1e937f52662bb4be30a5924b3cec2.tar.xz
org.eclipse.jetty.project-cf9ea6e2a9d1e937f52662bb4be30a5924b3cec2.zip
AttributeNormalizerTest failures on user.dir
-rw-r--r--tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/AttributeNormalizerTest.java203
-rw-r--r--tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/QuickStartTest.java74
2 files changed, 204 insertions, 73 deletions
diff --git a/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/AttributeNormalizerTest.java b/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/AttributeNormalizerTest.java
new file mode 100644
index 0000000000..e31a6a71a5
--- /dev/null
+++ b/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/AttributeNormalizerTest.java
@@ -0,0 +1,203 @@
+ //
+// ========================================================================
+// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+package org.eclipse.jetty.quickstart;
+
+import static org.junit.Assert.assertEquals;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.jetty.util.resource.Resource;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class AttributeNormalizerTest
+{
+ @Parameters(name="{0} = {1}")
+ public static List<String[]> data()
+ {
+ String[][] tests = {
+ { "WAR", "/opt/jetty-distro/demo.base/webapps/root" },
+ { "jetty.home", "/opt/jetty-distro" },
+ { "jetty.base", "/opt/jetty-distro/demo.base" },
+ { "user.home", "/home/user" },
+ { "user.dir", "/etc/init.d" },
+ };
+
+ return Arrays.asList(tests);
+ }
+
+ private static String origJettyBase;
+ private static String origJettyHome;
+ private static String origUserHome;
+ private static String origUserDir;
+
+ @BeforeClass
+ public static void initProperties()
+ {
+ origJettyBase = System.getProperty("jetty.base");
+ origJettyHome = System.getProperty("jetty.home");
+ origUserHome = System.getProperty("user.home");
+ origUserDir = System.getProperty("user.dir");
+
+ System.setProperty("jetty.home","/opt/jetty-distro");
+ System.setProperty("jetty.base","/opt/jetty-distro/demo.base");
+ System.setProperty("user.home","/home/user");
+ System.setProperty("user.dir","/etc/init.d");
+ }
+
+ @AfterClass
+ public static void restoreProperties()
+ {
+ if(origJettyBase != null) System.setProperty("jetty.base",origJettyBase);
+ if(origJettyHome != null) System.setProperty("jetty.home",origJettyHome);
+ if(origUserHome != null) System.setProperty("user.home",origUserHome);
+ if(origUserDir != null) System.setProperty("user.dir",origUserDir);
+ }
+
+ @Parameter(0)
+ public String key;
+
+ @Parameter(1)
+ public String path;
+
+ private AttributeNormalizer normalizer;
+
+ public AttributeNormalizerTest() throws MalformedURLException
+ {
+ normalizer = new AttributeNormalizer(Resource.newResource("/opt/jetty-distro/demo.base/webapps/root"));
+ }
+
+ @Test
+ public void testEqual()
+ {
+ assertEquals("file:${" + key + "}",normalizer.normalize("file:" + path));
+ }
+
+ @Test
+ public void testEqualsSlash()
+ {
+ assertEquals("file:${" + key + "}",normalizer.normalize("file:" + path + "/"));
+ }
+
+ @Test
+ public void testEqualsSlashFile()
+ {
+ assertEquals("file:${" + key + "}/file",normalizer.normalize("file:" + path + "/file"));
+ }
+
+ @Test
+ public void testURIEquals() throws URISyntaxException
+ {
+ assertEquals("file:${" + key + "}",normalizer.normalize(new URI("file:" + path)));
+ }
+
+ @Test
+ public void testURIEqualsSlash() throws URISyntaxException
+ {
+ assertEquals("file:${" + key + "}",normalizer.normalize(new URI("file:" + path + "/")));
+ }
+
+ @Test
+ public void testURIEqualsSlashFile() throws URISyntaxException
+ {
+ assertEquals("file:${" + key + "}/file",normalizer.normalize(new URI("file:" + path + "/file")));
+ }
+
+ @Test
+ public void testURLEquals() throws MalformedURLException
+ {
+ assertEquals("file:${" + key + "}",normalizer.normalize(new URL("file:" + path)));
+ }
+
+ @Test
+ public void testURLEqualsSlash() throws MalformedURLException
+ {
+ assertEquals("file:${" + key + "}",normalizer.normalize(new URL("file:" + path + "/")));
+ }
+
+ @Test
+ public void testURLEqualsSlashFile() throws MalformedURLException
+ {
+ assertEquals("file:${" + key + "}/file",normalizer.normalize(new URL("file:" + path + "/file")));
+ }
+
+ @Test
+ public void testJarFileEquals_BangFile()
+ {
+ assertEquals("jar:file:${" + key + "}!/file",normalizer.normalize("jar:file:" + path + "!/file"));
+ }
+
+ @Test
+ public void testJarFileEquals_SlashBangFile()
+ {
+ assertEquals("jar:file:${" + key + "}!/file",normalizer.normalize("jar:file:" + path + "/!/file"));
+ }
+
+ @Test
+ public void testJarFileEquals_FileBangFile()
+ {
+ assertEquals("jar:file:${" + key + "}/file!/file",normalizer.normalize("jar:file:" + path + "/file!/file"));
+ }
+
+ @Test
+ public void testJarFileEquals_URIBangFile() throws URISyntaxException
+ {
+ assertEquals("jar:file:${" + key + "}!/file",normalizer.normalize(new URI("jar:file:" + path + "!/file")));
+ }
+
+ @Test
+ public void testJarFileEquals_URISlashBangFile() throws URISyntaxException
+ {
+ assertEquals("jar:file:${" + key + "}!/file",normalizer.normalize(new URI("jar:file:" + path + "/!/file")));
+ }
+
+ @Test
+ public void testJarFileEquals_URIFileBangFile() throws URISyntaxException
+ {
+ assertEquals("jar:file:${" + key + "}/file!/file",normalizer.normalize(new URI("jar:file:" + path + "/file!/file")));
+ }
+
+ @Test
+ public void testJarFileEquals_URLBangFile() throws MalformedURLException
+ {
+ assertEquals("jar:file:${" + key + "}!/file",normalizer.normalize(new URL("jar:file:" + path + "!/file")));
+ }
+
+ @Test
+ public void testJarFileEquals_URLSlashBangFile() throws MalformedURLException
+ {
+ assertEquals("jar:file:${" + key + "}!/file",normalizer.normalize(new URL("jar:file:" + path + "/!/file")));
+ }
+
+ @Test
+ public void testJarFileEquals_URLFileBangFile() throws MalformedURLException
+ {
+ assertEquals("jar:file:${" + key + "}/file!/file",normalizer.normalize(new URL("jar:file:" + path + "/file!/file")));
+ }
+}
diff --git a/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/QuickStartTest.java b/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/QuickStartTest.java
index 54b0caa031..5ce9c56894 100644
--- a/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/QuickStartTest.java
+++ b/tests/test-quickstart/src/test/java/org/eclipse/jetty/quickstart/QuickStartTest.java
@@ -21,10 +21,8 @@ package org.eclipse.jetty.quickstart;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
-import java.io.File;
import java.io.InputStream;
import java.net.HttpURLConnection;
-import java.net.URI;
import java.net.URL;
import org.eclipse.jetty.server.NetworkConnector;
@@ -35,7 +33,6 @@ import org.eclipse.jetty.webapp.WebDescriptor;
import org.eclipse.jetty.xml.XmlConfiguration;
import org.eclipse.jetty.xml.XmlParser.Node;
import org.hamcrest.Matchers;
-import org.junit.Assert;
import org.junit.Test;
public class QuickStartTest
@@ -163,7 +160,7 @@ public class QuickStartTest
if (contextXml != null)
{
// System.err.println("Applying "+contextXml);
- XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURL());
+ XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURI().toURL());
xmlConfiguration.configure(webapp);
}
@@ -179,73 +176,4 @@ public class QuickStartTest
server.stop();
}
-
- @Test
- public void testNormalize() throws Exception
- {
- String jetty_base=System.getProperty("jetty.base");
- String jetty_home=System.getProperty("jetty.home");
- String user_home=System.getProperty("user.home");
- String user_dir=System.getProperty("user.dir");
- try
- {
- System.setProperty("jetty.home","/opt/jetty-distro");
- System.setProperty("jetty.base","/opt/jetty-distro/demo.base");
- System.setProperty("user.home","/home/user");
- System.setProperty("user.dir","/etc/init.d");
- AttributeNormalizer normalizer = new AttributeNormalizer(Resource.newResource("/opt/jetty-distro/demo.base/webapps/root"));
-
- String[][] tests = {
- { "WAR", "/opt/jetty-distro/demo.base/webapps/root" },
- { "jetty.home", "/opt/jetty-distro" },
- { "jetty.base", "/opt/jetty-distro/demo.base" },
- { "user.home", "/home/user" },
- { "user.dir", "/etc/init.d" },
- };
-
- for (String[] test : tests)
- {
- Assert.assertEquals("file:${"+test[0]+"}",normalizer.normalize("file:"+test[1]));
- Assert.assertEquals("file:${"+test[0]+"}",normalizer.normalize("file:"+test[1]+"/"));
- Assert.assertEquals("file:${"+test[0]+"}/file",normalizer.normalize("file:"+test[1]+"/file"));
- Assert.assertEquals("file:${"+test[0]+"}",normalizer.normalize(new URI("file:"+test[1])));
- Assert.assertEquals("file:${"+test[0]+"}",normalizer.normalize(new URI("file:"+test[1]+"/")));
- Assert.assertEquals("file:${"+test[0]+"}/file",normalizer.normalize(new URI("file:"+test[1]+"/file")));
- Assert.assertEquals("file:${"+test[0]+"}",normalizer.normalize(new URL("file:"+test[1])));
- Assert.assertEquals("file:${"+test[0]+"}",normalizer.normalize(new URL("file:"+test[1]+"/")));
- Assert.assertEquals("file:${"+test[0]+"}/file",normalizer.normalize(new URL("file:"+test[1]+"/file")));
- Assert.assertEquals("jar:file:${"+test[0]+"}!/file",normalizer.normalize("jar:file:"+test[1]+"!/file"));
- Assert.assertEquals("jar:file:${"+test[0]+"}!/file",normalizer.normalize("jar:file:"+test[1]+"/!/file"));
- Assert.assertEquals("jar:file:${"+test[0]+"}/file!/file",normalizer.normalize("jar:file:"+test[1]+"/file!/file"));
- Assert.assertEquals("jar:file:${"+test[0]+"}!/file",normalizer.normalize(new URI("jar:file:"+test[1]+"!/file")));
- Assert.assertEquals("jar:file:${"+test[0]+"}!/file",normalizer.normalize(new URI("jar:file:"+test[1]+"/!/file")));
- Assert.assertEquals("jar:file:${"+test[0]+"}/file!/file",normalizer.normalize(new URI("jar:file:"+test[1]+"/file!/file")));
- Assert.assertEquals("jar:file:${"+test[0]+"}!/file",normalizer.normalize(new URL("jar:file:"+test[1]+"!/file")));
- Assert.assertEquals("jar:file:${"+test[0]+"}!/file",normalizer.normalize(new URL("jar:file:"+test[1]+"/!/file")));
- Assert.assertEquals("jar:file:${"+test[0]+"}/file!/file",normalizer.normalize(new URL("jar:file:"+test[1]+"/file!/file")));
- }
- }
- finally
- {
- if (user_dir==null)
- System.clearProperty("user.dir");
- else
- System.setProperty("user.dir",user_dir);
-
- if (user_home==null)
- System.clearProperty("user.home");
- else
- System.setProperty("user.home",user_home);
-
- if (jetty_home==null)
- System.clearProperty("jetty.home");
- else
- System.setProperty("jetty.home",jetty_home);
-
- if (jetty_base==null)
- System.clearProperty("jetty.base");
- else
- System.setProperty("jetty.base",jetty_base);
- }
- }
}

Back to the top