Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jetty-webapp')
-rw-r--r--jetty-webapp/pom.xml1
-rw-r--r--jetty-webapp/src/test/java/org/eclipse/jetty/webapp/WebAppClassLoaderTest.java70
-rw-r--r--jetty-webapp/src/test/java/org/eclipse/jetty/webapp/WebAppContextTest.java35
3 files changed, 57 insertions, 49 deletions
diff --git a/jetty-webapp/pom.xml b/jetty-webapp/pom.xml
index 1a4871ce4d..3ddd3d21ea 100644
--- a/jetty-webapp/pom.xml
+++ b/jetty-webapp/pom.xml
@@ -93,6 +93,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
+ <version>${junit4-version}</version>
<scope>test</scope>
</dependency>
<dependency>
diff --git a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/WebAppClassLoaderTest.java b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/WebAppClassLoaderTest.java
index 9a8db2c868..6fad762310 100644
--- a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/WebAppClassLoaderTest.java
+++ b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/WebAppClassLoaderTest.java
@@ -2,62 +2,61 @@ package org.eclipse.jetty.webapp;
import java.net.URL;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
import org.eclipse.jetty.util.resource.Resource;
+import org.junit.Before;
+import org.junit.Test;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
-public class WebAppClassLoaderTest extends TestCase
+public class WebAppClassLoaderTest
{
- WebAppContext _context;
- WebAppClassLoader _loader;
-
- /* ------------------------------------------------------------ */
- /**
- * @see junit.framework.TestCase#setUp()
- */
- @Override
- protected void setUp() throws Exception
+ private WebAppContext _context;
+ private WebAppClassLoader _loader;
+
+ @Before
+ public void init() throws Exception
{
Resource webapp = Resource.newResource("./src/test/webapp");
-
+
_context = new WebAppContext();
_context.setBaseResource(webapp);
_context.setContextPath("/test");
-
+
_loader = new WebAppClassLoader(_context);
_loader.addJars(webapp.addPath("WEB-INF/lib"));
_loader.addClassPath(webapp.addPath("WEB-INF/classes").toString());
_loader.setName("test");
-
}
-
-
+
+ @Test
public void testParentLoad() throws Exception
{
_context.setParentLoaderPriority(true);
assertTrue(canLoadClass("org.acme.webapp.ClassInJarA"));
assertTrue(canLoadClass("org.acme.webapp.ClassInJarB"));
assertTrue(canLoadClass("org.acme.other.ClassInClassesC"));
-
+
assertFalse(canLoadClass("org.eclipse.jetty.webapp.Configuration"));
-
+
Class clazzA = _loader.loadClass("org.acme.webapp.ClassInJarA");
assertTrue(clazzA.getField("FROM_PARENT")!=null);
}
-
+
+ @Test
public void testWebAppLoad() throws Exception
{
_context.setParentLoaderPriority(false);
assertTrue(canLoadClass("org.acme.webapp.ClassInJarA"));
assertTrue(canLoadClass("org.acme.webapp.ClassInJarB"));
assertTrue(canLoadClass("org.acme.other.ClassInClassesC"));
-
+
assertFalse(canLoadClass("org.eclipse.jetty.webapp.Configuration"));
-
+
Class<?> clazzA = _loader.loadClass("org.acme.webapp.ClassInJarA");
try
{
@@ -69,7 +68,8 @@ public class WebAppClassLoaderTest extends TestCase
assertTrue(true);
}
}
-
+
+ @Test
public void testExposedClass() throws Exception
{
String[] oldSC=_context.getServerClasses();
@@ -77,15 +77,16 @@ public class WebAppClassLoaderTest extends TestCase
newSC[0]="-org.eclipse.jetty.webapp.Configuration";
System.arraycopy(oldSC,0,newSC,1,oldSC.length);
_context.setServerClasses(newSC);
-
+
assertTrue(canLoadClass("org.acme.webapp.ClassInJarA"));
assertTrue(canLoadClass("org.acme.webapp.ClassInJarB"));
assertTrue(canLoadClass("org.acme.other.ClassInClassesC"));
-
+
assertTrue(canLoadClass("org.eclipse.jetty.webapp.Configuration"));
assertFalse(canLoadClass("org.eclipse.jetty.webapp.JarScanner"));
}
-
+
+ @Test
public void testSystemServerClass() throws Exception
{
String[] oldServC=_context.getServerClasses();
@@ -93,32 +94,33 @@ public class WebAppClassLoaderTest extends TestCase
newServC[0]="org.eclipse.jetty.webapp.Configuration";
System.arraycopy(oldServC,0,newServC,1,oldServC.length);
_context.setServerClasses(newServC);
-
+
String[] oldSysC=_context.getSystemClasses();
String[] newSysC=new String[oldSysC.length+1];
newSysC[0]="org.eclipse.jetty.webapp.";
System.arraycopy(oldSysC,0,newSysC,1,oldSysC.length);
_context.setSystemClasses(newSysC);
-
+
assertTrue(canLoadClass("org.acme.webapp.ClassInJarA"));
assertTrue(canLoadClass("org.acme.webapp.ClassInJarB"));
assertTrue(canLoadClass("org.acme.other.ClassInClassesC"));
-
+
assertFalse(canLoadClass("org.eclipse.jetty.webapp.Configuration"));
assertFalse(canLoadClass("org.eclipse.jetty.webapp.JarScanner"));
}
-
+
+ @Test
public void testResources() throws Exception
{
List<URL> resources;
-
+
_context.setParentLoaderPriority(false);
resources =toList( _loader.getResources("org/acme/resource.txt"));
assertEquals(3,resources.size());
assertEquals(0,resources.get(0).toString().indexOf("jar:file:"));
assertEquals(-1,resources.get(1).toString().indexOf("test-classes"));
assertEquals(0,resources.get(2).toString().indexOf("file:"));
-
+
_context.setParentLoaderPriority(true);
resources =toList( _loader.getResources("org/acme/resource.txt"));
assertEquals(3,resources.size());
@@ -150,7 +152,7 @@ public class WebAppClassLoaderTest extends TestCase
assertEquals(1,resources.size());
assertEquals(0,resources.get(0).toString().indexOf("file:"));
}
-
+
private List<URL> toList(Enumeration<URL> e)
{
List<URL> list = new ArrayList<URL>();
@@ -159,7 +161,7 @@ public class WebAppClassLoaderTest extends TestCase
return list;
}
- private boolean canLoadClass(String clazz)
+ private boolean canLoadClass(String clazz)
{
try
{
diff --git a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/WebAppContextTest.java b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/WebAppContextTest.java
index ad83f66680..4fe342a346 100644
--- a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/WebAppContextTest.java
+++ b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/WebAppContextTest.java
@@ -4,22 +4,26 @@
// 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
+// 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.
+// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.webapp;
import java.util.Arrays;
import org.eclipse.jetty.server.Server;
+import org.junit.Test;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
-public class WebAppContextTest extends TestCase
+public class WebAppContextTest
{
+ @Test
public void testConfigurationClassesFromDefault ()
{
Server server = new Server();
@@ -28,19 +32,20 @@ public class WebAppContextTest extends TestCase
assertNull(wac.getConfigurations());
String[] classNames = wac.getConfigurationClasses();
assertNotNull(classNames);
-
+
//test if no classname set, and none from server its the defaults
wac.setServer(server);
- assertEquals(classNames, wac.getConfigurationClasses());
+ assertTrue(Arrays.equals(classNames, wac.getConfigurationClasses()));
}
-
+
+ @Test
public void testConfigurationClassesExplicit ()
{
String[] classNames = {"x.y.z"};
-
+
Server server = new Server();
server.setAttribute(WebAppContext.SERVER_CONFIG, classNames);
-
+
//test an explicitly set classnames list overrides that from the server
WebAppContext wac = new WebAppContext();
String[] myClassNames = {"a.b.c", "d.e.f"};
@@ -48,21 +53,22 @@ public class WebAppContextTest extends TestCase
wac.setServer(server);
String[] names = wac.getConfigurationClasses();
assertTrue(Arrays.equals(myClassNames, names));
-
-
+
+
//test if no explicit classnames, they come from the server
WebAppContext wac2 = new WebAppContext();
wac2.setServer(server);
- assertTrue(Arrays.equals(classNames, wac2.getConfigurationClasses()));
+ assertTrue(Arrays.equals(classNames, wac2.getConfigurationClasses()));
}
-
+
+ @Test
public void testConfigurationInstances ()
{
Configuration[] configs = {new WebInfConfiguration()};
WebAppContext wac = new WebAppContext();
wac.setConfigurations(configs);
assertTrue(Arrays.equals(configs, wac.getConfigurations()));
-
+
//test that explicit config instances override any from server
String[] classNames = {"x.y.z"};
Server server = new Server();
@@ -70,5 +76,4 @@ public class WebAppContextTest extends TestCase
wac.setServer(server);
assertTrue(Arrays.equals(configs,wac.getConfigurations()));
}
-
}

Back to the top