Merging back /branches/jetty-bug-296978 revs 2674:HEAD

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2709 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Joakim Erdfelt 2011-01-28 18:58:47 +00:00
parent dd7511a721
commit acc4f230fc
66 changed files with 289 additions and 1524 deletions

View File

@ -72,7 +72,6 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -51,7 +51,6 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -86,10 +86,14 @@
<version>${project.version}</version> <version>${project.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -13,6 +13,7 @@
package org.eclipse.jetty.client; package org.eclipse.jetty.client;
import java.io.File;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -31,6 +32,7 @@ import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.servlet.DefaultServlet; import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
public class SecuredContentExchangeTest public class SecuredContentExchangeTest
extends ContentExchangeTest extends ContentExchangeTest
@ -60,7 +62,8 @@ public class SecuredContentExchangeTest
SelectChannelConnector connector = new SelectChannelConnector(); SelectChannelConnector connector = new SelectChannelConnector();
server.addConnector(connector); server.addConnector(connector);
LoginService loginService = new HashLoginService("MyRealm","src/test/resources/realm.properties"); File realmPropFile = MavenTestingUtils.getTestResourceFile("realm.properties");
LoginService loginService = new HashLoginService("MyRealm",realmPropFile.getAbsolutePath());
server.addBean(loginService); server.addBean(loginService);
ConstraintSecurityHandler security = new ConstraintSecurityHandler(); ConstraintSecurityHandler security = new ConstraintSecurityHandler();

View File

@ -13,6 +13,7 @@
package org.eclipse.jetty.client; package org.eclipse.jetty.client;
import java.io.File;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -32,6 +33,7 @@ import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.servlet.DefaultServlet; import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
public class SecuredErrorStatusTest public class SecuredErrorStatusTest
extends ErrorStatusTest extends ErrorStatusTest
@ -128,7 +130,8 @@ public class SecuredErrorStatusTest
SelectChannelConnector connector = new SelectChannelConnector(); SelectChannelConnector connector = new SelectChannelConnector();
server.addConnector(connector); server.addConnector(connector);
LoginService loginService = new HashLoginService("MyRealm","src/test/resources/realm.properties"); File realmPropFile = MavenTestingUtils.getTestResourceFile("realm.properties");
LoginService loginService = new HashLoginService("MyRealm",realmPropFile.getAbsolutePath());
server.addBean(loginService); server.addBean(loginService);
ConstraintSecurityHandler security = new ConstraintSecurityHandler(); ConstraintSecurityHandler security = new ConstraintSecurityHandler();

View File

@ -13,6 +13,7 @@
package org.eclipse.jetty.client; package org.eclipse.jetty.client;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
@ -43,6 +44,7 @@ import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
/** /**
* Functional testing for HttpExchange. * Functional testing for HttpExchange.
@ -285,7 +287,8 @@ public class SecurityListenerTest extends TestCase
cm.setConstraint(constraint); cm.setConstraint(constraint);
cm.setPathSpec("/*"); cm.setPathSpec("/*");
LoginService loginService = new HashLoginService("MyRealm","src/test/resources/realm.properties"); File realmPropFile = MavenTestingUtils.getTestResourceFile("realm.properties");
LoginService loginService = new HashLoginService("MyRealm",realmPropFile.getAbsolutePath());
ConstraintSecurityHandler sh = new ConstraintSecurityHandler(); ConstraintSecurityHandler sh = new ConstraintSecurityHandler();
sh.setLoginService(loginService); sh.setLoginService(loginService);
sh.setAuthenticator(new BasicAuthenticator()); sh.setAuthenticator(new BasicAuthenticator());

View File

@ -22,6 +22,7 @@ import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
import org.eclipse.jetty.servlet.DefaultServlet; import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
public class SslContentExchangeTest public class SslContentExchangeTest
extends ContentExchangeTest extends ContentExchangeTest
@ -33,8 +34,8 @@ public class SslContentExchangeTest
setProtocol("https"); setProtocol("https");
SslSelectChannelConnector connector = new SslSelectChannelConnector(); SslSelectChannelConnector connector = new SslSelectChannelConnector();
String keystore = new File("src/test/resources/keystore").getAbsolutePath(); File keystore = MavenTestingUtils.getTestResourceFile("keystore");
connector.setKeystore(keystore); connector.setKeystore(keystore.getAbsolutePath());
connector.setPassword("storepwd"); connector.setPassword("storepwd");
connector.setKeyPassword("keypwd"); connector.setKeyPassword("keypwd");
server.addConnector(connector); server.addConnector(connector);

View File

@ -32,6 +32,7 @@ import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
import org.eclipse.jetty.servlet.DefaultServlet; import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
public class SslSecuredContentExchangeTest public class SslSecuredContentExchangeTest
extends ContentExchangeTest extends ContentExchangeTest
@ -59,13 +60,14 @@ extends ContentExchangeTest
}); });
SslSelectChannelConnector connector = new SslSelectChannelConnector(); SslSelectChannelConnector connector = new SslSelectChannelConnector();
String keystore = new File("src/test/resources/keystore").getAbsolutePath(); File keystore = MavenTestingUtils.getTestResourceFile("keystore");
connector.setKeystore(keystore); connector.setKeystore(keystore.getAbsolutePath());
connector.setPassword("storepwd"); connector.setPassword("storepwd");
connector.setKeyPassword("keypwd"); connector.setKeyPassword("keypwd");
server.addConnector(connector); server.addConnector(connector);
LoginService loginService = new HashLoginService("MyRealm","src/test/resources/realm.properties"); File realmPropFile = MavenTestingUtils.getTestResourceFile("realm.properties");
LoginService loginService = new HashLoginService("MyRealm",realmPropFile.getAbsolutePath());
server.addBean(loginService); server.addBean(loginService);
ConstraintSecurityHandler security = new ConstraintSecurityHandler(); ConstraintSecurityHandler security = new ConstraintSecurityHandler();

View File

@ -13,6 +13,7 @@
package org.eclipse.jetty.client; package org.eclipse.jetty.client;
import java.io.File;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -33,6 +34,7 @@ import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.servlet.DefaultServlet; import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
public class SslSecuredErrorStatusTest public class SslSecuredErrorStatusTest
extends ErrorStatusTest extends ErrorStatusTest
@ -126,7 +128,8 @@ public class SslSecuredErrorStatusTest
SelectChannelConnector connector = new SelectChannelConnector(); SelectChannelConnector connector = new SelectChannelConnector();
server.addConnector(connector); server.addConnector(connector);
LoginService loginService = new HashLoginService("MyRealm","src/test/resources/realm.properties"); File realmPropFile = MavenTestingUtils.getTestResourceFile("realm.properties");
LoginService loginService = new HashLoginService("MyRealm",realmPropFile.getAbsolutePath());
server.addBean(loginService); server.addBean(loginService);
ConstraintSecurityHandler security = new ConstraintSecurityHandler(); ConstraintSecurityHandler security = new ConstraintSecurityHandler();

View File

@ -38,6 +38,7 @@ import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.security.ConstraintMapping; import org.eclipse.jetty.security.ConstraintMapping;
import org.eclipse.jetty.security.ConstraintSecurityHandler; import org.eclipse.jetty.security.ConstraintSecurityHandler;
import org.eclipse.jetty.security.HashLoginService; import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.security.LoginService;
import org.eclipse.jetty.security.authentication.BasicAuthenticator; import org.eclipse.jetty.security.authentication.BasicAuthenticator;
import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Handler;
@ -45,6 +46,7 @@ import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.ssl.SslSocketConnector; import org.eclipse.jetty.server.ssl.SslSocketConnector;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
/** /**
@ -162,7 +164,8 @@ public class SslSecurityListenerTest extends TestCase
cm.setConstraint(constraint); cm.setConstraint(constraint);
cm.setPathSpec("/*"); cm.setPathSpec("/*");
HashLoginService loginService = new HashLoginService("MyRealm","src/test/resources/realm.properties"); File realmPropFile = MavenTestingUtils.getTestResourceFile("realm.properties");
LoginService loginService = new HashLoginService("MyRealm",realmPropFile.getAbsolutePath());
_server.addBean(loginService); _server.addBean(loginService);
BasicAuthenticator authenticator = new BasicAuthenticator(); BasicAuthenticator authenticator = new BasicAuthenticator();

View File

@ -15,20 +15,23 @@ package org.eclipse.jetty.client;
import java.io.File; import java.io.File;
import junit.framework.TestCase;
import org.eclipse.jetty.client.security.Realm; import org.eclipse.jetty.client.security.Realm;
import org.eclipse.jetty.client.security.SimpleRealmResolver; import org.eclipse.jetty.client.security.SimpleRealmResolver;
import org.eclipse.jetty.http.HttpMethods;
import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.PathAssert;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
/** /**
* Functional testing for HttpExchange. * Functional testing for HttpExchange.
*
*
*
*/ */
public class WebdavListenerTest extends TestCase//extends HttpExchangeTest public class WebdavListenerTest
{ {
protected String _scheme = "http://"; protected String _scheme = "http://";
protected Server _server; protected Server _server;
@ -43,11 +46,8 @@ public class WebdavListenerTest extends TestCase//extends HttpExchangeTest
private String _dirFileURL; private String _dirFileURL;
private String _dirURL; private String _dirURL;
@Before
public void setUp() throws Exception
@Override
protected void setUp() throws Exception
{ {
_singleFileURL = "https://dav.codehaus.org/user/" + _username + "/foo.txt"; _singleFileURL = "https://dav.codehaus.org/user/" + _username + "/foo.txt";
_dirURL = "https://dav.codehaus.org/user/" + _username + "/ttt/"; _dirURL = "https://dav.codehaus.org/user/" + _username + "/ttt/";
@ -82,25 +82,20 @@ public class WebdavListenerTest extends TestCase//extends HttpExchangeTest
} }
@Override @After
public void tearDown () throws Exception public void tearDown () throws Exception
{ {
_httpClient.stop(); _httpClient.stop();
} }
@Test
@Ignore("Only works with real WebDAV server")
public void testPUTandDELETEwithSSL() throws Exception public void testPUTandDELETEwithSSL() throws Exception
{ {
File file = new File("src/test/resources/foo.txt"); File file = MavenTestingUtils.getTestResourceFile("foo.txt");
assertTrue(file.exists()); PathAssert.assertFileExists("WebDAV test file", file);
/*
* UNCOMMENT TO TEST WITH REAL DAV SERVER
* Remember to set _username and _password to a real user's account.
*
*/
/*
//PUT a FILE //PUT a FILE
ContentExchange singleFileExchange = new ContentExchange(); ContentExchange singleFileExchange = new ContentExchange();
singleFileExchange.setURL(_singleFileURL); singleFileExchange.setURL(_singleFileURL);
@ -112,8 +107,7 @@ public class WebdavListenerTest extends TestCase//extends HttpExchangeTest
singleFileExchange.waitForDone(); singleFileExchange.waitForDone();
String result = singleFileExchange.getResponseContent(); String result = singleFileExchange.getResponseContent();
assertEquals(201, singleFileExchange.getResponseStatus()); Assert.assertEquals(201, singleFileExchange.getResponseStatus());
//PUT a FILE in a directory hierarchy //PUT a FILE in a directory hierarchy
ContentExchange dirFileExchange = new ContentExchange(); ContentExchange dirFileExchange = new ContentExchange();
@ -125,9 +119,7 @@ public class WebdavListenerTest extends TestCase//extends HttpExchangeTest
_httpClient.send(dirFileExchange); _httpClient.send(dirFileExchange);
dirFileExchange.waitForDone(); dirFileExchange.waitForDone();
result = dirFileExchange.getResponseContent(); result = dirFileExchange.getResponseContent();
assertEquals(201, singleFileExchange.getResponseStatus()); Assert.assertEquals(201, singleFileExchange.getResponseStatus());
//DELETE the single file //DELETE the single file
@ -135,15 +127,13 @@ public class WebdavListenerTest extends TestCase//extends HttpExchangeTest
del.setURL(_singleFileURL); del.setURL(_singleFileURL);
del.setMethod(HttpMethods.DELETE); del.setMethod(HttpMethods.DELETE);
_httpClient.send(del); _httpClient.send(del);
del.waitForCompletion(); del.waitForDone();
//DELETE the whole dir //DELETE the whole dir
del.setURL(_dirURL); del.setURL(_dirURL);
del.setMethod(HttpMethods.DELETE); del.setMethod(HttpMethods.DELETE);
del.setRequestHeader("Depth", "infinity"); del.setRequestHeader("Depth", "infinity");
_httpClient.send(del); _httpClient.send(del);
del.waitForCompletion(); del.waitForDone();
*/
} }
} }

View File

@ -92,10 +92,14 @@
<version>${project.version}</version> <version>${project.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -23,8 +23,9 @@ import java.util.List;
import org.eclipse.jetty.deploy.graph.GraphOutputDot; import org.eclipse.jetty.deploy.graph.GraphOutputDot;
import org.eclipse.jetty.deploy.graph.Node; import org.eclipse.jetty.deploy.graph.Node;
import org.eclipse.jetty.deploy.graph.Path; import org.eclipse.jetty.deploy.graph.Path;
import org.eclipse.jetty.deploy.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.TestingDir;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
/** /**
@ -32,7 +33,10 @@ import org.junit.Test;
*/ */
public class AppLifeCycleTest public class AppLifeCycleTest
{ {
private void assertNoPath(String from, String to) @Rule
public TestingDir testdir = new TestingDir();
private void assertNoPath(String from, String to)
{ {
assertPath(from,to,new ArrayList<String>()); assertPath(from,to,new ArrayList<String>());
} }
@ -169,8 +173,7 @@ public class AppLifeCycleTest
AppLifeCycle lifecycle = new AppLifeCycle(); AppLifeCycle lifecycle = new AppLifeCycle();
List<String> expected = new ArrayList<String>(); List<String> expected = new ArrayList<String>();
File outputDir = MavenTestingUtils.getTargetTestingDir(this.getClass().getName() + ".testFindPathMultiple"); File outputDir = testdir.getEmptyDir();
outputDir.mkdirs();
// Modify graph to add new 'staging' -> 'staged' between 'deployed' and 'started' // Modify graph to add new 'staging' -> 'staged' between 'deployed' and 'started'
GraphOutputDot.write(lifecycle,new File(outputDir,"multiple-1.dot")); // before change GraphOutputDot.write(lifecycle,new File(outputDir,"multiple-1.dot")); // before change

View File

@ -4,12 +4,17 @@ import java.util.Collection;
import java.util.Set; import java.util.Set;
import org.eclipse.jetty.deploy.test.XmlConfiguredJetty; import org.eclipse.jetty.deploy.test.XmlConfiguredJetty;
import org.eclipse.jetty.toolchain.test.TestingDir;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
public class DeploymentManagerTest public class DeploymentManagerTest
{ {
@Test @Rule
public TestingDir testdir = new TestingDir();
@Test
public void testReceiveApp() throws Exception public void testReceiveApp() throws Exception
{ {
DeploymentManager depman = new DeploymentManager(); DeploymentManager depman = new DeploymentManager();
@ -59,7 +64,7 @@ public class DeploymentManagerTest
XmlConfiguredJetty jetty = null; XmlConfiguredJetty jetty = null;
try try
{ {
jetty = new XmlConfiguredJetty(); jetty = new XmlConfiguredJetty(testdir);
jetty.addConfiguration("jetty.xml"); jetty.addConfiguration("jetty.xml");
jetty.addConfiguration("jetty-deploymgr-contexts.xml"); jetty.addConfiguration("jetty-deploymgr-contexts.xml");

View File

@ -17,9 +17,9 @@ package org.eclipse.jetty.deploy;
import java.io.File; import java.io.File;
import org.eclipse.jetty.deploy.test.MavenTestingUtils;
import org.eclipse.jetty.deploy.util.FileID; import org.eclipse.jetty.deploy.util.FileID;
import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.component.AbstractLifeCycle; import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.Resource;
@ -52,7 +52,7 @@ public class MockAppProvider extends AbstractLifeCycle implements AppProvider
WebAppContext context = new WebAppContext(); WebAppContext context = new WebAppContext();
File war = new File(webappsDir,app.getOriginId().substring(5)); File war = new File(webappsDir,app.getOriginId().substring(5));
context.setWar(Resource.newResource(war.toURL()).toString()); context.setWar(Resource.newResource(war.toURI().toURL()).toString());
String path = war.getName(); String path = war.getName();

View File

@ -18,22 +18,26 @@ package org.eclipse.jetty.deploy.providers;
import java.io.IOException; import java.io.IOException;
import org.eclipse.jetty.deploy.test.XmlConfiguredJetty; import org.eclipse.jetty.deploy.test.XmlConfiguredJetty;
import org.eclipse.jetty.toolchain.test.TestingDir;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
/** /**
* Similar in scope to {@link MonitoredDirAppProviderStartupTest}, except is concerned with the modification of existing * Similar in scope to {@link ScanningAppProviderStartupTest}, except is concerned with the modification of existing
* deployed webapps due to incoming changes identified by the {@link ScanningAppProvider}. * deployed webapps due to incoming changes identified by the {@link ScanningAppProvider}.
*/ */
public class MonitoredDirAppProviderRuntimeUpdatesTest public class ScanningAppProviderRuntimeUpdatesTest
{ {
@Rule
public TestingDir testdir = new TestingDir();
private static XmlConfiguredJetty jetty; private static XmlConfiguredJetty jetty;
@Before @Before
public void setupEnvironment() throws Exception public void setupEnvironment() throws Exception
{ {
jetty = new XmlConfiguredJetty(); jetty = new XmlConfiguredJetty(testdir);
jetty.addConfiguration("jetty.xml"); jetty.addConfiguration("jetty.xml");
jetty.addConfiguration("jetty-deploymgr-contexts.xml"); jetty.addConfiguration("jetty-deploymgr-contexts.xml");

View File

@ -16,21 +16,25 @@
package org.eclipse.jetty.deploy.providers; package org.eclipse.jetty.deploy.providers;
import org.eclipse.jetty.deploy.test.XmlConfiguredJetty; import org.eclipse.jetty.deploy.test.XmlConfiguredJetty;
import org.junit.AfterClass; import org.eclipse.jetty.toolchain.test.TestingDir;
import org.junit.BeforeClass; import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
/** /**
* Tests {@link ScanningAppProvider} as it starts up for the first time. * Tests {@link ScanningAppProvider} as it starts up for the first time.
*/ */
public class MonitoredDirAppProviderStartupTest public class ScanningAppProviderStartupTest
{ {
@Rule
public TestingDir testdir = new TestingDir();
private static XmlConfiguredJetty jetty; private static XmlConfiguredJetty jetty;
@BeforeClass @Before
public static void setupEnvironment() throws Exception public void setupEnvironment() throws Exception
{ {
jetty = new XmlConfiguredJetty(); jetty = new XmlConfiguredJetty(testdir);
jetty.addConfiguration("jetty.xml"); jetty.addConfiguration("jetty.xml");
jetty.addConfiguration("jetty-deploymgr-contexts.xml"); jetty.addConfiguration("jetty-deploymgr-contexts.xml");
@ -45,8 +49,8 @@ public class MonitoredDirAppProviderStartupTest
jetty.start(); jetty.start();
} }
@AfterClass @After
public static void teardownEnvironment() throws Exception public void teardownEnvironment() throws Exception
{ {
// Stop jetty. // Stop jetty.
jetty.stop(); jetty.stop();

View File

@ -4,19 +4,23 @@ import java.io.File;
import java.util.Arrays; import java.util.Arrays;
import org.eclipse.jetty.deploy.test.XmlConfiguredJetty; import org.eclipse.jetty.deploy.test.XmlConfiguredJetty;
import org.junit.AfterClass; import org.eclipse.jetty.toolchain.test.TestingDir;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
public class WebAppProviderTest public class WebAppProviderTest
{ {
@Rule
public TestingDir testdir = new TestingDir();
private static XmlConfiguredJetty jetty; private static XmlConfiguredJetty jetty;
@BeforeClass @Before
public static void setupEnvironment() throws Exception public void setupEnvironment() throws Exception
{ {
jetty = new XmlConfiguredJetty(); jetty = new XmlConfiguredJetty(testdir);
jetty.addConfiguration("jetty.xml"); jetty.addConfiguration("jetty.xml");
jetty.addConfiguration("jetty-deploy-wars.xml"); jetty.addConfiguration("jetty-deploy-wars.xml");
@ -31,8 +35,8 @@ public class WebAppProviderTest
jetty.start(); jetty.start();
} }
@AfterClass @After
public static void teardownEnvironment() throws Exception public void teardownEnvironment() throws Exception
{ {
// Stop jetty. // Stop jetty.
jetty.stop(); jetty.stop();

View File

@ -1,221 +0,0 @@
// ========================================================================
// Copyright (c) Webtide LLC
// ------------------------------------------------------------------------
// 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.apache.org/licenses/LICENSE-2.0.txt
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.deploy.test;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import junit.framework.TestCase;
import org.eclipse.jetty.util.IO;
/**
* Common utility methods for working with JUnit tests cases in a maven friendly way.
*/
public class MavenTestingUtils
{
private static File basedir;
private static File testResourcesDir;
private static File targetDir;
// private static Boolean surefireRunning;
public static File getBasedir()
{
if (basedir == null)
{
String cwd = System.getProperty("basedir");
if (cwd == null)
{
cwd = System.getProperty("user.dir");
}
basedir = new File(cwd);
}
return basedir;
}
/**
* Get the directory to the /target directory for this project.
*
* @return the directory path to the target directory.
*/
public static File getTargetDir()
{
if (targetDir == null)
{
targetDir = new File(getBasedir(),"target");
PathAssert.assertDirExists("Target Dir",targetDir);
}
return targetDir;
}
/**
* Create a {@link File} object for a path in the /target directory.
*
* @param path
* the path desired, no validation of existence is performed.
* @return the File to the path.
*/
public static File getTargetFile(String path)
{
return new File(getTargetDir(),path.replace("/",File.separator));
}
public static File getTargetTestingDir()
{
File dir = new File(getTargetDir(),"testing");
if (!dir.exists())
{
dir.mkdirs();
}
return dir;
}
/**
* Get a dir in /target/ that uses the JUnit 3.x {@link TestCase#getName()} to make itself unique.
*
* @param test
* the junit 3.x testcase to base this new directory on.
* @return the File path to the testcase specific testing directory underneath the
* <code>${basedir}/target</code> sub directory
*/
public static File getTargetTestingDir(TestCase test)
{
return getTargetTestingDir(test.getName());
}
/**
* Get a dir in /target/ that uses the an arbitrary name.
*
* @param testname
* the testname to create directory against.
* @return the File path to the testname sepecific testing directory underneath the
* <code>${basedir}/target</code> sub directory
*/
public static File getTargetTestingDir(String testname)
{
File dir = new File(getTargetDir(),"test-" + testname);
return dir;
}
/**
* Get a dir from the src/test/resource directory.
*
* @param name
* the name of the path to get (it must exist as a dir)
* @return the dir in src/test/resource
*/
public static File getTestResourceDir(String name)
{
File dir = new File(getTestResourcesDir(),name);
PathAssert.assertDirExists("Test Resource Dir",dir);
return dir;
}
/**
* Get a file from the src/test/resource directory.
*
* @param name
* the name of the path to get (it must exist as a file)
* @return the file in src/test/resource
*/
public static File getTestResourceFile(String name)
{
File file = new File(getTestResourcesDir(),name);
PathAssert.assertFileExists("Test Resource File",file);
return file;
}
/**
* Get a path resource (File or Dir) from the src/test/resource directory.
*
* @param name
* the name of the path to get (it must exist)
* @return the path in src/test/resource
*/
public static File getTestResourcePath(String name)
{
File path = new File(getTestResourcesDir(),name);
PathAssert.assertExists("Test Resource Path",path);
return path;
}
/**
* Get the directory to the src/test/resource directory
*
* @return the directory {@link File} to the src/test/resources directory
*/
public static File getTestResourcesDir()
{
if (testResourcesDir == null)
{
testResourcesDir = new File(basedir,"src/test/resources".replace("/",File.separator));
PathAssert.assertDirExists("Test Resources Dir",testResourcesDir);
}
return testResourcesDir;
}
/**
* Read the contents of a file into a String and return it.
*
* @param file
* the file to read.
* @return the contents of the file.
* @throws IOException
* if unable to read the file.
*/
public static String readToString(File file) throws IOException
{
FileReader reader = null;
try
{
reader = new FileReader(file);
return IO.toString(reader);
}
finally
{
IO.close(reader);
}
}
public static String getTestID()
{
StackTraceElement stacked[] = new Throwable().getStackTrace();
String name = null;
for(StackTraceElement stack: stacked) {
if(stack.getClassName().endsWith("Test"))
{
name = stack.getClassName();
if (stack.getMethodName().startsWith("test"))
{
return stack.getClassName() + "#" + stack.getMethodName();
}
}
}
if(name == null)
{
return "Unidentified_Test";
}
return name;
}
}

View File

@ -1,40 +0,0 @@
// ========================================================================
// Copyright (c) Webtide LLC
// ------------------------------------------------------------------------
// 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.apache.org/licenses/LICENSE-2.0.txt
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.deploy.test;
import java.io.File;
import org.junit.Assert;
public class PathAssert
{
public static void assertDirExists(String msg, File path)
{
assertExists(msg,path);
Assert.assertTrue(msg + " path should be a Dir : " + path.getAbsolutePath(),path.isDirectory());
}
public static void assertFileExists(String msg, File path)
{
assertExists(msg,path);
Assert.assertTrue(msg + " path should be a File : " + path.getAbsolutePath(),path.isFile());
}
public static void assertExists(String msg, File path)
{
Assert.assertTrue(msg + " path should exist: " + path.getAbsolutePath(),path.exists());
}
}

View File

@ -20,7 +20,6 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.PrintStream;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI; import java.net.URI;
@ -38,8 +37,10 @@ import org.eclipse.jetty.http.HttpSchemes;
import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.PathAssert;
import org.eclipse.jetty.toolchain.test.TestingDir;
import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.xml.XmlConfiguration; import org.eclipse.jetty.xml.XmlConfiguration;
@ -57,17 +58,12 @@ public class XmlConfiguredJetty
private String _scheme = HttpSchemes.HTTP; private String _scheme = HttpSchemes.HTTP;
private File _jettyHome; private File _jettyHome;
public XmlConfiguredJetty() throws IOException public XmlConfiguredJetty(TestingDir testdir) throws IOException
{
this(MavenTestingUtils.getTestID());
}
public XmlConfiguredJetty(String testname) throws IOException
{ {
_xmlConfigurations = new ArrayList<URL>(); _xmlConfigurations = new ArrayList<URL>();
Properties properties = new Properties(); Properties properties = new Properties();
String jettyHomeBase = MavenTestingUtils.getTargetTestingDir(testname).getAbsolutePath(); String jettyHomeBase = testdir.getDir().getAbsolutePath();
// Ensure we have a new (pristene) directory to work with. // Ensure we have a new (pristene) directory to work with.
int idx = 0; int idx = 0;
_jettyHome = new File(jettyHomeBase + "#" + idx); _jettyHome = new File(jettyHomeBase + "#" + idx);
@ -336,7 +332,6 @@ public class XmlConfiguredJetty
return contexts; return contexts;
} }
@SuppressWarnings("unchecked")
public void load() throws Exception public void load() throws Exception
{ {
XmlConfiguration last = null; XmlConfiguration last = null;
@ -351,7 +346,7 @@ public class XmlConfiguredJetty
{ {
configuration.getIdMap().putAll(last.getIdMap()); configuration.getIdMap().putAll(last.getIdMap());
} }
configuration.setProperties(_properties); configuration.getProperties().putAll(_properties);
obj[i] = configuration.configure(); obj[i] = configuration.configure();
last = configuration; last = configuration;
} }

View File

@ -20,7 +20,6 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -20,7 +20,6 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -73,7 +73,6 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -56,7 +56,6 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -162,11 +162,8 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -86,7 +86,6 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -126,10 +126,20 @@
<artifactId>jetty-util</artifactId> <artifactId>jetty-util</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-policy</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -24,9 +24,13 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Set; import java.util.Set;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.OS;
import org.junit.After; import org.junit.After;
import org.junit.Assume;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.Ignore;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -35,7 +39,6 @@ import static org.junit.Assert.fail;
public class JettyPolicyRuntimeTest public class JettyPolicyRuntimeTest
{ {
private HashMap<String, String> evaluator = new HashMap<String, String>(); private HashMap<String, String> evaluator = new HashMap<String, String>();
private boolean _runningOnWindows;
@Before @Before
public void init() throws Exception public void init() throws Exception
@ -43,8 +46,6 @@ public class JettyPolicyRuntimeTest
System.setSecurityManager(null); System.setSecurityManager(null);
Policy.setPolicy(null); Policy.setPolicy(null);
_runningOnWindows = System.getProperty( "os.name" ).startsWith( "Windows" );
evaluator.put("jetty.home",MavenTestingUtils.getBaseURI().toASCIIString()); evaluator.put("jetty.home",MavenTestingUtils.getBaseURI().toASCIIString());
evaluator.put("basedir",MavenTestingUtils.getBaseURI().toASCIIString()); evaluator.put("basedir",MavenTestingUtils.getBaseURI().toASCIIString());
} }
@ -115,11 +116,7 @@ public class JettyPolicyRuntimeTest
public void testPolicyRestrictive() throws Exception public void testPolicyRestrictive() throws Exception
{ {
// TODO - temporary, create alternate file to load for windows // TODO - temporary, create alternate file to load for windows
if (_runningOnWindows) Assume.assumeTrue(!OS.IS_WINDOWS); // Ignore test if running under windows.
{
// skip run
return;
}
JettyPolicy ap = new JettyPolicy(getSinglePolicy("global-file-read-only-tmp-permission.policy"),evaluator); JettyPolicy ap = new JettyPolicy(getSinglePolicy("global-file-read-only-tmp-permission.policy"),evaluator);
ap.refresh(); ap.refresh();
@ -148,14 +145,11 @@ public class JettyPolicyRuntimeTest
} }
@Test @Test
@Ignore("Jesse will work on this")
public void testCertificateLoader() throws Exception public void testCertificateLoader() throws Exception
{ {
// TODO - temporary, create alternate file to load for windows // TODO - temporary, create alternate file to load for windows
if (_runningOnWindows) Assume.assumeTrue(!OS.IS_WINDOWS); // Ignore test if running under windows.
{
// skip run
return;
}
JettyPolicy ap = new JettyPolicy(getSinglePolicy("jetty-certificate.policy"),evaluator); JettyPolicy ap = new JettyPolicy(getSinglePolicy("jetty-certificate.policy"),evaluator);
ap.refresh(); ap.refresh();
@ -163,7 +157,7 @@ public class JettyPolicyRuntimeTest
Policy.setPolicy( ap ); Policy.setPolicy( ap );
System.setSecurityManager( new SecurityManager() ); System.setSecurityManager( new SecurityManager() );
URL url = MavenTestingUtils.toTargetURL("test-policy/jetty-test-policy.jar"); URL url = MavenTestingUtils.getTargetURL("test-policy/jetty-test-policy.jar");
URLClassLoader loader ; URLClassLoader loader ;
if (Thread.currentThread().getContextClassLoader() != null ) if (Thread.currentThread().getContextClassLoader() != null )
@ -203,11 +197,7 @@ public class JettyPolicyRuntimeTest
throws Exception throws Exception
{ {
// TODO - temporary, create alternate file to load for windows // TODO - temporary, create alternate file to load for windows
if (_runningOnWindows) Assume.assumeTrue(!OS.IS_WINDOWS); // Ignore test if running under windows.
{
// skip run
return;
}
JettyPolicy ap = new JettyPolicy(getSinglePolicy("jetty-bad-certificate.policy"),evaluator); JettyPolicy ap = new JettyPolicy(getSinglePolicy("jetty-bad-certificate.policy"),evaluator);
ap.refresh(); ap.refresh();
@ -215,7 +205,7 @@ public class JettyPolicyRuntimeTest
Policy.setPolicy( ap ); Policy.setPolicy( ap );
System.setSecurityManager( new SecurityManager() ); System.setSecurityManager( new SecurityManager() );
URL url = MavenTestingUtils.toTargetURL("test-policy/jetty-test-policy.jar"); URL url = MavenTestingUtils.getTargetURL("test-policy/jetty-test-policy.jar");
URLClassLoader loader ; URLClassLoader loader ;
if (Thread.currentThread().getContextClassLoader() != null ) if (Thread.currentThread().getContextClassLoader() != null )

View File

@ -16,6 +16,7 @@
package org.eclipse.jetty.policy; package org.eclipse.jetty.policy;
import java.io.File;
import java.io.FilePermission; import java.io.FilePermission;
import java.net.URL; import java.net.URL;
import java.security.CodeSource; import java.security.CodeSource;
@ -24,7 +25,6 @@ import java.security.PermissionCollection;
import java.security.ProtectionDomain; import java.security.ProtectionDomain;
import java.security.cert.Certificate; import java.security.cert.Certificate;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.PropertyPermission; import java.util.PropertyPermission;
@ -32,6 +32,7 @@ import java.util.Set;
import junit.framework.Assert; import junit.framework.Assert;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -58,8 +59,8 @@ public class JettyPolicyTest
@Test @Test
public void testGlobalAllPermissionLoader() throws Exception public void testGlobalAllPermissionLoader() throws Exception
{ {
File policyFile = MavenTestingUtils.getTestResourceFile("global-all-permission.policy");
JettyPolicy ap = new JettyPolicy( Collections.singleton( MavenTestingUtils.getBasedir().getAbsolutePath() + "/src/test/resources/global-all-permission.policy" ), evaluator ); JettyPolicy ap = new JettyPolicy( Collections.singleton( policyFile.getAbsolutePath() ), evaluator );
ap.refresh(); ap.refresh();
PermissionCollection pc = ap.getPermissions( new ProtectionDomain( null, null ) ); PermissionCollection pc = ap.getPermissions( new ProtectionDomain( null, null ) );
@ -83,9 +84,8 @@ public class JettyPolicyTest
@Test @Test
public void testSingleCodebaseFilePermissionLoader() throws Exception public void testSingleCodebaseFilePermissionLoader() throws Exception
{ {
JettyPolicy ap = File policyFile = MavenTestingUtils.getTestResourceFile("single-codebase-file-permission.policy");
new JettyPolicy( Collections.singleton( MavenTestingUtils.getBasedir().getAbsolutePath() JettyPolicy ap = new JettyPolicy( Collections.singleton( policyFile.getAbsolutePath() ), evaluator );
+ "/src/test/resources/single-codebase-file-permission.policy" ), evaluator );
ap.refresh(); ap.refresh();
URL url = new URL( "file:///foo.jar" ); URL url = new URL( "file:///foo.jar" );
@ -113,9 +113,8 @@ public class JettyPolicyTest
@Test @Test
public void testMultipleCodebaseFilePermissionLoader() throws Exception public void testMultipleCodebaseFilePermissionLoader() throws Exception
{ {
JettyPolicy ap = File policyFile = MavenTestingUtils.getTestResourceFile("multiple-codebase-file-permission.policy");
new JettyPolicy( Collections.singleton( MavenTestingUtils.getBasedir().getAbsolutePath() JettyPolicy ap = new JettyPolicy( Collections.singleton( policyFile.getAbsolutePath() ), evaluator );
+ "/src/test/resources/multiple-codebase-file-permission.policy" ), evaluator );
ap.refresh(); ap.refresh();
@ -168,9 +167,8 @@ public class JettyPolicyTest
@Test @Test
public void testMultipleCodebaseMixedPermissionLoader() throws Exception public void testMultipleCodebaseMixedPermissionLoader() throws Exception
{ {
JettyPolicy ap = File policyFile = MavenTestingUtils.getTestResourceFile("multiple-codebase-mixed-permission.policy");
new JettyPolicy( Collections.singleton( MavenTestingUtils.getBasedir().getAbsolutePath() JettyPolicy ap = new JettyPolicy( Collections.singleton( policyFile.getAbsolutePath() ), evaluator );
+ "/src/test/resources/multiple-codebase-mixed-permission.policy" ), evaluator );
ap.refresh(); ap.refresh();
@ -228,7 +226,8 @@ public class JettyPolicyTest
@Test @Test
public void testSCLoader() throws Exception public void testSCLoader() throws Exception
{ {
JettyPolicy ap = new JettyPolicy(Collections.singleton(MavenTestingUtils.getBasedir().getAbsolutePath() + "/src/main/config/lib/policy/jetty.policy"),evaluator); File policyFile = MavenTestingUtils.getProjectFile("src/main/config/lib/policy/jetty.policy");
JettyPolicy ap = new JettyPolicy(Collections.singleton(policyFile.getAbsolutePath()),evaluator);
ap.refresh(); ap.refresh();
} }
@ -242,8 +241,8 @@ public class JettyPolicyTest
{ {
Set<String> files = new HashSet<String>(); Set<String> files = new HashSet<String>();
files.add( MavenTestingUtils.getBasedir().getAbsolutePath() + "/src/test/resources/single-codebase-file-permission.policy" ); files.add( MavenTestingUtils.getTestResourceFile("single-codebase-file-permission.policy").getAbsolutePath() );
files.add( MavenTestingUtils.getBasedir().getAbsolutePath() + "/src/test/resources/single-codebase-file-permission-2.policy" ); files.add( MavenTestingUtils.getTestResourceFile("single-codebase-file-permission-2.policy").getAbsolutePath() );
JettyPolicy ap = new JettyPolicy( files, evaluator ); JettyPolicy ap = new JettyPolicy( files, evaluator );
@ -274,9 +273,9 @@ public class JettyPolicyTest
{ {
Set<String> files = new HashSet<String>(); Set<String> files = new HashSet<String>();
files.add( MavenTestingUtils.getBasedir().getAbsolutePath() + "/src/test/resources/single-codebase-file-permission.policy" ); files.add( MavenTestingUtils.getTestResourceFile("single-codebase-file-permission.policy").getAbsolutePath() );
files.add( MavenTestingUtils.getBasedir().getAbsolutePath() + "/src/test/resources/single-codebase-file-permission-2.policy" ); files.add( MavenTestingUtils.getTestResourceFile("single-codebase-file-permission-2.policy").getAbsolutePath() );
files.add( MavenTestingUtils.getBasedir().getAbsolutePath() + "/src/test/resources/single-codebase-file-permission-3.policy" ); files.add( MavenTestingUtils.getTestResourceFile("single-codebase-file-permission-3.policy").getAbsolutePath() );
JettyPolicy ap = new JettyPolicy( files, evaluator ); JettyPolicy ap = new JettyPolicy( files, evaluator );
@ -310,8 +309,8 @@ public class JettyPolicyTest
{ {
Set<String> files = new HashSet<String>(); Set<String> files = new HashSet<String>();
files.add( MavenTestingUtils.getBasedir().getAbsolutePath() + "/src/test/resources/single-codebase-file-permission.policy" ); files.add( MavenTestingUtils.getTestResourceFile("single-codebase-file-permission.policy").getAbsolutePath() );
files.add( MavenTestingUtils.getBasedir().getAbsolutePath() + "/src/test/resources/context" ); files.add( MavenTestingUtils.getTestResourceDir("context").getAbsolutePath() );
JettyPolicy ap = new JettyPolicy( files, evaluator ); JettyPolicy ap = new JettyPolicy( files, evaluator );

View File

@ -1,209 +0,0 @@
// ========================================================================
// Copyright (c) Webtide LLC
// ------------------------------------------------------------------------
// 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.apache.org/licenses/LICENSE-2.0.txt
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.policy;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringWriter;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
/**
* Common utility methods for working with JUnit tests cases in a maven friendly way.
*/
public class MavenTestingUtils
{
private static File basedir;
private static File testResourcesDir;
private static File targetDir;
private static URI baseURI;
public static File getBasedir()
{
if (basedir == null)
{
String cwd = System.getProperty("basedir");
if (cwd == null)
{
// System property not set.
// Use CWD.
cwd = System.getProperty("user.dir");
basedir = new File(cwd);
// Set the System property.
System.setProperty("basedir",basedir.getAbsolutePath());
}
else
{
// Has system property, use it.
basedir = new File(cwd);
}
baseURI = basedir.toURI();
}
return basedir;
}
/**
* Get the directory to the /target directory for this project.
*
* @return the directory path to the target directory.
*/
public static File getTargetDir()
{
if (targetDir == null)
{
targetDir = new File(basedir,"target");
// PathAssert.assertDirExists("Target Dir",targetDir);
}
return targetDir;
}
/**
* Get a file from the src/test/resource directory.
*
* @param name
* the name of the path to get (it must exist as a file)
* @return the file in src/test/resource
*/
public static File getTestResourceFile(String name)
{
File file = new File(getTestResourcesDir(),name);
PathAssert.assertFileExists("Test Resource File",file);
return file;
}
/**
* Get a dir from the src/test/resource directory.
*
* @param name
* the name of the path to get (it must exist as a dir)
* @return the dir in src/test/resource
*/
public static File getTestResourceDir(String name)
{
File dir = new File(getTestResourcesDir(),name);
PathAssert.assertDirExists("Test Resource Dir",dir);
return dir;
}
/**
* Get a path resource (File or Dir) from the src/test/resource directory.
*
* @param name
* the name of the path to get (it must exist)
* @return the path in src/test/resource
*/
public static File getTestResourcePath(String name)
{
File path = new File(getTestResourcesDir(),name);
PathAssert.assertExists("Test Resource Path",path);
return path;
}
/**
* Get the directory to the src/test/resource directory
*
* @return the directory {@link File} to the src/test/resources directory
*/
public static File getTestResourcesDir()
{
if (testResourcesDir == null)
{
testResourcesDir = new File(basedir,"src/test/resources".replace("/",File.separator));
PathAssert.assertDirExists("Test Resources Dir",testResourcesDir);
}
return testResourcesDir;
}
/**
* Create a {@link File} object for a path in the /target directory.
*
* @param path
* the path desired, no validation of existence is performed.
* @return the File to the path.
*/
public static File toTargetFile(String path)
{
return new File(getTargetDir(),path.replace("/",File.separator));
}
/**
* Read the contents of a file into a String and return it.
*
* @param file
* the file to read.
* @return the contents of the file.
* @throws IOException
* if unable to read the file.
*/
public static String readToString(File file) throws IOException
{
FileReader reader = null;
try
{
reader = new FileReader(file);
StringWriter writer = new StringWriter();
int bufSize = 8096;
char buf[] = new char[bufSize];
int len = bufSize;
while (true)
{
len = reader.read(buf,0,bufSize);
if (len == -1)
break;
writer.write(buf,0,len);
}
return writer.toString();
}
finally
{
if (reader != null)
{
try
{
reader.close();
}
catch (IOException ignore)
{
/* ignore */
}
}
}
}
public static URI getBaseURI()
{
if (baseURI == null)
{
getBasedir();
}
return baseURI;
}
public static URL toTargetURL(String path) throws MalformedURLException
{
return getBaseURI().resolve("target/" + path).toURL();
}
}

View File

@ -1,40 +0,0 @@
// ========================================================================
// Copyright (c) Webtide LLC
// ------------------------------------------------------------------------
// 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.apache.org/licenses/LICENSE-2.0.txt
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.policy;
import java.io.File;
import junit.framework.Assert;
public class PathAssert
{
public static void assertDirExists(String msg, File path)
{
assertExists(msg,path);
Assert.assertTrue(msg + " path should be a Dir : " + path.getAbsolutePath(),path.isDirectory());
}
public static void assertFileExists(String msg, File path)
{
assertExists(msg,path);
Assert.assertTrue(msg + " path should be a File : " + path.getAbsolutePath(),path.isFile());
}
public static void assertExists(String msg, File path)
{
Assert.assertTrue(msg + " path should exist: " + path.getAbsolutePath(),path.exists());
}
}

View File

@ -26,6 +26,8 @@ import java.util.List;
import org.eclipse.jetty.policy.entry.GrantEntry; import org.eclipse.jetty.policy.entry.GrantEntry;
import org.eclipse.jetty.policy.entry.KeystoreEntry; import org.eclipse.jetty.policy.entry.KeystoreEntry;
import org.eclipse.jetty.policy.loader.PolicyFileScanner; import org.eclipse.jetty.policy.loader.PolicyFileScanner;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.OS;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -34,12 +36,10 @@ import static org.junit.Assert.assertEquals;
public class PolicyContextTest public class PolicyContextTest
{ {
public static final String __PRINCIPAL = "javax.security.auth.x500.X500Principal \"CN=Jetty Policy,OU=Artifact,O=Jetty Project,L=Earth,ST=Internet,C=US\""; public static final String __PRINCIPAL = "javax.security.auth.x500.X500Principal \"CN=Jetty Policy,OU=Artifact,O=Jetty Project,L=Earth,ST=Internet,C=US\"";
private boolean _runningOnWindows;
@Before @Before
public void init() throws Exception public void init() throws Exception
{ {
_runningOnWindows = System.getProperty( "os.name" ).startsWith( "Windows" );
System.setProperty( "basedir", MavenTestingUtils.getBaseURI().toASCIIString() ); System.setProperty( "basedir", MavenTestingUtils.getBaseURI().toASCIIString() );
} }
@ -51,11 +51,11 @@ public class PolicyContextTest
List<GrantEntry> grantEntries = new ArrayList<GrantEntry>(); List<GrantEntry> grantEntries = new ArrayList<GrantEntry>();
List<KeystoreEntry> keystoreEntries = new ArrayList<KeystoreEntry>(); List<KeystoreEntry> keystoreEntries = new ArrayList<KeystoreEntry>();
File policyFile = new File( getWorkingDirectory() + "/src/test/resources/context/jetty-certificate.policy" ); File policyFile = MavenTestingUtils.getTestResourceFile("context/jetty-certificate.policy");
loader.scanStream( new InputStreamReader( new FileInputStream( policyFile ) ), grantEntries, keystoreEntries ); loader.scanStream( new InputStreamReader( new FileInputStream( policyFile ) ), grantEntries, keystoreEntries );
if ( !_runningOnWindows ) //temporary, create alternate file to load for windows if ( !OS.IS_WINDOWS ) //temporary, create alternate file to load for windows
{ {
for (KeystoreEntry node : keystoreEntries) for (KeystoreEntry node : keystoreEntries)
{ {
@ -81,11 +81,11 @@ public class PolicyContextTest
List<GrantEntry> grantEntries = new ArrayList<GrantEntry>(); List<GrantEntry> grantEntries = new ArrayList<GrantEntry>();
List<KeystoreEntry> keystoreEntries = new ArrayList<KeystoreEntry>(); List<KeystoreEntry> keystoreEntries = new ArrayList<KeystoreEntry>();
File policyFile = new File( getWorkingDirectory() + "/src/test/resources/context/jetty-certificate-alias.policy" ); File policyFile = MavenTestingUtils.getTestResourceFile("context/jetty-certificate-alias.policy");
loader.scanStream( new InputStreamReader( new FileInputStream( policyFile ) ), grantEntries, keystoreEntries ); loader.scanStream( new InputStreamReader( new FileInputStream( policyFile ) ), grantEntries, keystoreEntries );
if ( !_runningOnWindows ) //temporary, create alternate file to load for windows if ( !OS.IS_WINDOWS ) //temporary, create alternate file to load for windows
{ {
for (KeystoreEntry node : keystoreEntries) for (KeystoreEntry node : keystoreEntries)
{ {
@ -115,9 +115,4 @@ public class PolicyContextTest
assertEquals(File.separator + File.separator, context.evaluate( "${/}${/}" ) ); assertEquals(File.separator + File.separator, context.evaluate( "${/}${/}" ) );
} }
private String getWorkingDirectory()
{
return MavenTestingUtils.getBasedir().getAbsolutePath();
}
} }

View File

@ -68,7 +68,6 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -79,7 +79,6 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -87,7 +87,6 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -62,12 +62,6 @@
</plugins> </plugins>
</build> </build>
<dependencies> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-security</artifactId> <artifactId>jetty-security</artifactId>
@ -79,5 +73,15 @@
<version>${project.version}</version> <version>${project.version}</version>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,5 +1,7 @@
package org.eclipse.jetty.servlet; package org.eclipse.jetty.servlet;
import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -12,19 +14,26 @@ import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse; import javax.servlet.ServletResponse;
import junit.framework.AssertionFailedError; import junit.framework.AssertionFailedError;
import org.eclipse.jetty.server.LocalConnector; import org.eclipse.jetty.server.LocalConnector;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.OS;
import org.eclipse.jetty.toolchain.test.TestingDir;
import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.StringUtil;
import org.junit.After; import org.junit.After;
import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertTrue;
public class DefaultServletTest public class DefaultServletTest
{ {
private boolean _runningOnWindows; @Rule
public TestingDir testdir = new TestingDir();
private Server server; private Server server;
private LocalConnector connector; private LocalConnector connector;
private ServletContextHandler context; private ServletContextHandler context;
@ -32,8 +41,6 @@ public class DefaultServletTest
@Before @Before
public void init() throws Exception public void init() throws Exception
{ {
_runningOnWindows = System.getProperty( "os.name" ).startsWith( "Windows" );
server = new Server(); server = new Server();
server.setSendServerVersion(false); server.setSendServerVersion(false);
@ -63,12 +70,11 @@ public class DefaultServletTest
defholder.setInitParameter("dirAllowed","true"); defholder.setInitParameter("dirAllowed","true");
defholder.setInitParameter("redirectWelcome","false"); defholder.setInitParameter("redirectWelcome","false");
defholder.setInitParameter("gzip","false"); defholder.setInitParameter("gzip","false");
File testDir = new File("target/tests/" + DefaultServletTest.class.getSimpleName()); testdir.ensureEmpty();
prepareEmptyTestDir(testDir);
/* create some content in the docroot */ /* create some content in the docroot */
File resBase = new File(testDir, "docroot"); File resBase = testdir.getFile("docroot");
assertTrue(resBase.mkdirs()); assertTrue(resBase.mkdirs());
assertTrue(new File(resBase, "one").mkdir()); assertTrue(new File(resBase, "one").mkdir());
assertTrue(new File(resBase, "two").mkdir()); assertTrue(new File(resBase, "two").mkdir());
@ -99,17 +105,17 @@ public class DefaultServletTest
defholder.setInitParameter("redirectWelcome","false"); defholder.setInitParameter("redirectWelcome","false");
defholder.setInitParameter("gzip","false"); defholder.setInitParameter("gzip","false");
File testDir = new File("target/tests/" + DefaultServletTest.class.getSimpleName()); testdir.ensureEmpty();
prepareEmptyTestDir(testDir);
/* create some content in the docroot */ /* create some content in the docroot */
File resBase = new File(testDir, "docroot"); File resBase = testdir.getFile("docroot");
assertTrue(resBase.mkdirs()); FS.ensureDirExists(resBase);
assertTrue(new File(resBase, "one").mkdir()); assertTrue(new File(resBase, "one").mkdir());
assertTrue(new File(resBase, "two").mkdir()); assertTrue(new File(resBase, "two").mkdir());
assertTrue(new File(resBase, "three").mkdir()); assertTrue(new File(resBase, "three").mkdir());
if ( !_runningOnWindows ) if ( !OS.IS_WINDOWS ) {
assertTrue("Creating dir 'f??r' (Might not work in Windows)", new File(resBase, "f??r").mkdir()); assertTrue("Creating dir 'f??r' (Might not work in Windows)", new File(resBase, "f??r").mkdir());
}
String resBasePath = resBase.getAbsolutePath(); String resBasePath = resBase.getAbsolutePath();
defholder.setInitParameter( "resourceBase", resBasePath ); defholder.setInitParameter( "resourceBase", resBasePath );
@ -128,8 +134,9 @@ public class DefaultServletTest
assertResponseContains( "/one/", response ); assertResponseContains( "/one/", response );
assertResponseContains( "/two/", response ); assertResponseContains( "/two/", response );
assertResponseContains( "/three/", response ); assertResponseContains( "/three/", response );
if ( !_runningOnWindows ) if ( !OS.IS_WINDOWS ) {
assertResponseContains( "/f%3F%3Fr", response ); assertResponseContains( "/f%3F%3Fr", response );
}
assertResponseNotContains( "<script>", response ); assertResponseNotContains( "<script>", response );
} }
@ -142,11 +149,10 @@ public class DefaultServletTest
defholder.setInitParameter("redirectWelcome","false"); defholder.setInitParameter("redirectWelcome","false");
defholder.setInitParameter("gzip","false"); defholder.setInitParameter("gzip","false");
File testDir = new File("target/tests/" + DefaultServletTest.class.getSimpleName()); testdir.ensureEmpty();
prepareEmptyTestDir(testDir);
/* create some content in the docroot */ /* create some content in the docroot */
File resBase = new File(testDir, "docroot"); File resBase = testdir.getFile("docroot");
assertTrue(resBase.mkdirs()); assertTrue(resBase.mkdirs());
File wackyDir = new File(resBase, "dir;"); // this should not be double-encoded. File wackyDir = new File(resBase, "dir;"); // this should not be double-encoded.
assertTrue(wackyDir.mkdirs()); assertTrue(wackyDir.mkdirs());
@ -195,27 +201,25 @@ public class DefaultServletTest
defholder.setInitParameter("gzip","false"); defholder.setInitParameter("gzip","false");
defholder.setInitParameter("aliases","true"); defholder.setInitParameter("aliases","true");
File testDir = new File("target/tests/" + DefaultServletTest.class.getSimpleName()); testdir.ensureEmpty();
prepareEmptyTestDir(testDir);
/* create some content in the docroot */ /* create some content in the docroot */
File resBase = new File(testDir, "docroot"); File resBase = testdir.getFile("docroot");
assertTrue(resBase.mkdirs()); assertTrue(resBase.mkdirs());
File index = new File(resBase, "index.html"); File index = new File(resBase, "index.html");
createFile(index, "<h1>Hello Index</h1>"); createFile(index, "<h1>Hello Index</h1>");
File wackyDir = new File(resBase, "dir?"); File wackyDir = new File(resBase, "dir?");
if ( !_runningOnWindows ) if ( !OS.IS_WINDOWS ) {
{ FS.ensureDirExists(wackyDir);
assertTrue(wackyDir.mkdirs());
} }
wackyDir = new File(resBase, "dir;"); wackyDir = new File(resBase, "dir;");
assertTrue(wackyDir.mkdirs()); assertTrue(wackyDir.mkdirs());
/* create some content outside of the docroot */ /* create some content outside of the docroot */
File sekret = new File(testDir, "sekret"); File sekret = testdir.getFile("sekret");
assertTrue(sekret.mkdirs()); assertTrue(sekret.mkdirs());
File pass = new File(sekret, "pass"); File pass = new File(sekret, "pass");
createFile(pass, "Sssh, you shouldn't be seeing this"); createFile(pass, "Sssh, you shouldn't be seeing this");
@ -241,7 +245,7 @@ public class DefaultServletTest
response= connector.getResponses("GET /context/dir?/ HTTP/1.0\r\n\r\n"); response= connector.getResponses("GET /context/dir?/ HTTP/1.0\r\n\r\n");
assertResponseContains("404",response); assertResponseContains("404",response);
if ( !_runningOnWindows ) if ( !OS.IS_WINDOWS )
{ {
response= connector.getResponses("GET /context/dir%3F/ HTTP/1.0\r\n\r\n"); response= connector.getResponses("GET /context/dir%3F/ HTTP/1.0\r\n\r\n");
assertResponseContains("Directory: /context/dir?/<",response); assertResponseContains("Directory: /context/dir?/<",response);
@ -298,10 +302,9 @@ public class DefaultServletTest
@Test @Test
public void testWelcome() throws Exception public void testWelcome() throws Exception
{ {
File testDir = new File("target/tests/" + DefaultServletTest.class.getSimpleName()); testdir.ensureEmpty();
prepareEmptyTestDir(testDir); File resBase = testdir.getFile("docroot");
File resBase = new File(testDir, "docroot"); FS.ensureDirExists(resBase);
assertTrue(resBase.mkdirs());
File inde = new File(resBase, "index.htm"); File inde = new File(resBase, "index.htm");
File index = new File(resBase, "index.html"); File index = new File(resBase, "index.html");
@ -317,6 +320,7 @@ public class DefaultServletTest
defholder.setInitParameter("maxCachedFileSize","512000"); defholder.setInitParameter("maxCachedFileSize","512000");
defholder.setInitParameter("maxCachedFiles","100"); defholder.setInitParameter("maxCachedFiles","100");
@SuppressWarnings("unused")
ServletHolder jspholder = context.addServlet(NoJspServlet.class,"*.jsp"); ServletHolder jspholder = context.addServlet(NoJspServlet.class,"*.jsp");
String response = connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n"); String response = connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n");
@ -342,14 +346,12 @@ public class DefaultServletTest
@Test @Test
public void testWelcomeServlet() throws Exception public void testWelcomeServlet() throws Exception
{ {
File testDir = new File("target/tests/" + DefaultServletTest.class.getSimpleName()); testdir.ensureEmpty();
prepareEmptyTestDir(testDir); File resBase = testdir.getFile("docroot");
File resBase = new File(testDir, "docroot"); FS.ensureDirExists(resBase);
assertTrue(resBase.mkdirs());
File inde = new File(resBase, "index.htm"); File inde = new File(resBase, "index.htm");
File index = new File(resBase, "index.html"); File index = new File(resBase, "index.html");
String resBasePath = resBase.getAbsolutePath(); String resBasePath = resBase.getAbsolutePath();
ServletHolder defholder = context.addServlet(DefaultServlet.class,"/"); ServletHolder defholder = context.addServlet(DefaultServlet.class,"/");
@ -359,7 +361,8 @@ public class DefaultServletTest
defholder.setInitParameter("gzip","false"); defholder.setInitParameter("gzip","false");
defholder.setInitParameter("resourceBase",resBasePath); defholder.setInitParameter("resourceBase",resBasePath);
ServletHolder jspholder = context.addServlet(NoJspServlet.class,"*.jsp"); @SuppressWarnings("unused")
ServletHolder jspholder = context.addServlet(NoJspServlet.class,"*.jsp");
String response; String response;
@ -374,11 +377,11 @@ public class DefaultServletTest
response= connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n"); response= connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n");
assertResponseContains("<h1>Hello Index</h1>",response); assertResponseContains("<h1>Hello Index</h1>",response);
assertTrue(index.delete()); deleteFile(index);
response= connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n"); response= connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n");
assertResponseContains("<h1>Hello Inde</h1>",response); assertResponseContains("<h1>Hello Inde</h1>",response);
assertTrue(inde.delete()); deleteFile(inde);
response= connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n"); response= connector.getResponses("GET /context/ HTTP/1.0\r\n\r\n");
assertResponseContains("JSP support not configured",response); assertResponseContains("JSP support not configured",response);
} }
@ -386,10 +389,9 @@ public class DefaultServletTest
@Test @Test
public void testWelcomeExactServlet() throws Exception public void testWelcomeExactServlet() throws Exception
{ {
File testDir = new File("target/tests/" + DefaultServletTest.class.getSimpleName()); testdir.ensureEmpty();
prepareEmptyTestDir(testDir); File resBase = testdir.getFile("docroot");
File resBase = new File(testDir, "docroot"); FS.ensureDirExists(resBase);
assertTrue(resBase.mkdirs());
File inde = new File(resBase, "index.htm"); File inde = new File(resBase, "index.htm");
File index = new File(resBase, "index.html"); File index = new File(resBase, "index.html");
@ -430,10 +432,9 @@ public class DefaultServletTest
@Test @Test
public void testRangeRequests() throws Exception public void testRangeRequests() throws Exception
{ {
File testDir = new File("target/tests/" + DefaultServletTest.class.getSimpleName()); testdir.ensureEmpty();
prepareEmptyTestDir(testDir); File resBase = testdir.getFile("docroot");
File resBase = new File(testDir, "docroot"); FS.ensureDirExists(resBase);
assertTrue(resBase.mkdirs());
File data = new File(resBase, "data.txt"); File data = new File(resBase, "data.txt");
createFile(data,"01234567890123456789012345678901234567890123456789012345678901234567890123456789"); createFile(data,"01234567890123456789012345678901234567890123456789012345678901234567890123456789");
String resBasePath = resBase.getAbsolutePath(); String resBasePath = resBase.getAbsolutePath();
@ -511,10 +512,9 @@ public class DefaultServletTest
@Test @Test
public void testFiltered() throws Exception public void testFiltered() throws Exception
{ {
File testDir = new File("target/tests/" + DefaultServletTest.class.getSimpleName()); testdir.ensureEmpty();
prepareEmptyTestDir(testDir); File resBase = testdir.getFile("docroot");
File resBase = new File(testDir, "docroot"); FS.ensureDirExists(resBase);
assertTrue(resBase.mkdirs());
File file0 = new File(resBase, "data0.txt"); File file0 = new File(resBase, "data0.txt");
createFile(file0, "Hello Text 0"); createFile(file0, "Hello Text 0");
@ -593,49 +593,6 @@ public class DefaultServletTest
} }
} }
private void prepareEmptyTestDir(File testdir)
{
if (testdir.exists())
{
emptyDir(testdir);
}
else
{
assertTrue(testdir.mkdirs());
}
assertTrue("test dir should exists",testdir.exists());
assertTrue("test dir should be a dir",testdir.isDirectory());
assertTrue("test dir should be empty",isEmpty(testdir));
}
private boolean isEmpty(File dir)
{
if (!dir.isDirectory())
return true;
return dir.list().length == 0;
}
private void emptyDir(File dir)
{
File entries[] = dir.listFiles();
for (File entry : entries)
deletePath(entry);
}
private void deletePath(File path)
{
if (path.isDirectory())
{
File entries[] = path.listFiles();
for (File entry : entries)
deletePath(entry);
}
assertTrue("Deleting: " + path.getAbsolutePath(),path.delete());
}
private void assertResponseNotContains(String forbidden, String response) private void assertResponseNotContains(String forbidden, String response)
{ {
int idx = response.indexOf(forbidden); int idx = response.indexOf(forbidden);
@ -666,4 +623,16 @@ public class DefaultServletTest
} }
return idx; return idx;
} }
private void deleteFile(File file) throws IOException {
if(OS.IS_WINDOWS) {
// Since Windows doesn't seem to like to delete content that was recently created.
File deleted = MavenTestingUtils.getTargetFile(".deleted");
FS.ensureDirExists(deleted);
File dest = File.createTempFile(file.getName(), "deleted", deleted);
Assert.assertTrue("Unable to move file out of the way: " + file.getName(), file.renameTo(dest));
} else {
Assert.assertTrue("Deleting: " + file.getName(), file.delete());
}
}
} }

View File

@ -52,7 +52,6 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -36,7 +36,6 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -73,7 +73,6 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -89,7 +89,6 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -20,7 +20,6 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -75,7 +75,6 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

17
pom.xml
View File

@ -18,7 +18,6 @@
<javax-servlet-jsp-version>2.1.v20100127</javax-servlet-jsp-version> <javax-servlet-jsp-version>2.1.v20100127</javax-servlet-jsp-version>
<javax-transaction-version>1.1.1</javax-transaction-version> <javax-transaction-version>1.1.1</javax-transaction-version>
<jetty.url>http://www.eclipse.org/jetty</jetty.url> <jetty.url>http://www.eclipse.org/jetty</jetty.url>
<junit-version>3.8.2</junit-version>
<junit4-version>4.8.1</junit4-version> <junit4-version>4.8.1</junit4-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<slf4j-version>1.5.11</slf4j-version> <slf4j-version>1.5.11</slf4j-version>
@ -245,6 +244,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId> <artifactId>maven-pmd-plugin</artifactId>
<version>2.5</version>
<configuration> <configuration>
<targetJdk>1.5</targetJdk> <targetJdk>1.5</targetJdk>
<rulesets> <rulesets>
@ -255,10 +255,10 @@
<plugin> <plugin>
<groupId>org.codehaus.mojo</groupId> <groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId> <artifactId>findbugs-maven-plugin</artifactId>
<version>2.3.1</version>
</plugin> </plugin>
</plugins> </plugins>
</reporting> </reporting>
<!--
<repositories> <repositories>
<repository> <repository>
<snapshots> <snapshots>
@ -269,7 +269,6 @@
<url>http://oss.sonatype.org/content/groups/jetty</url> <url>http://oss.sonatype.org/content/groups/jetty</url>
</repository> </repository>
</repositories> </repositories>
-->
<modules> <modules>
<module>jetty-util</module> <module>jetty-util</module>
<module>jetty-jmx</module> <module>jetty-jmx</module>
@ -317,9 +316,9 @@
<version>2.0</version> <version>2.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>junit</artifactId> <artifactId>jetty-test-helper</artifactId>
<version>${junit-version}</version> <version>1.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
@ -351,6 +350,12 @@
<artifactId>activation</artifactId> <artifactId>activation</artifactId>
<version>${javax-activation-version}</version> <version>${javax-activation-version}</version>
</dependency> </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
<!-- <!--

View File

@ -1,6 +1,7 @@
package org.eclipse.jetty.continuation; package org.eclipse.jetty.continuation;
import org.eclipse.jetty.servlets.ProxyServlet; import org.eclipse.jetty.servlets.ProxyServlet;
import org.junit.Ignore;
import org.mortbay.jetty.Connector; import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server; import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector; import org.mortbay.jetty.nio.SelectChannelConnector;
@ -9,6 +10,7 @@ import org.mortbay.jetty.servlet.FilterHolder;
import org.mortbay.jetty.servlet.ServletHandler; import org.mortbay.jetty.servlet.ServletHandler;
import org.mortbay.jetty.servlet.ServletHolder; import org.mortbay.jetty.servlet.ServletHolder;
@Ignore("Not a test case")
public class TestProxyServer public class TestProxyServer
{ {
public static void main(String[] args) throws Exception public static void main(String[] args) throws Exception

View File

@ -23,6 +23,7 @@
<configuration> <configuration>
<excludes> <excludes>
<exclude>**/WebAppTest.java</exclude> <exclude>**/WebAppTest.java</exclude>
<exclude>**/Test*.java</exclude>
</excludes> </excludes>
</configuration> </configuration>
</plugin> </plugin>
@ -40,9 +41,9 @@
<descriptor>config.xml</descriptor> <descriptor>config.xml</descriptor>
<descriptor>src/main/assembly/web-bundle.xml</descriptor> <descriptor>src/main/assembly/web-bundle.xml</descriptor>
</descriptors> </descriptors>
<archive> <archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive> </archive>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>

View File

@ -20,7 +20,6 @@ import java.lang.management.ManagementFactory;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.swing.text.WrappedPlainView;
import org.eclipse.jetty.jmx.MBeanContainer; import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.security.HashLoginService; import org.eclipse.jetty.security.HashLoginService;
@ -42,7 +41,9 @@ import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.StdErrLog; import org.eclipse.jetty.util.log.StdErrLog;
import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.webapp.WebAppContext;
import org.junit.Ignore;
@Ignore("Not a test case")
public class TestServer public class TestServer
{ {
public static void main(String[] args) throws Exception public static void main(String[] args) throws Exception

View File

@ -72,10 +72,14 @@
<artifactId>jetty-client</artifactId> <artifactId>jetty-client</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -1,220 +0,0 @@
// ========================================================================
// Copyright (c) Webtide LLC
// ------------------------------------------------------------------------
// 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.apache.org/licenses/LICENSE-2.0.txt
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.test;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import junit.framework.TestCase;
import org.eclipse.jetty.util.IO;
/**
* Common utility methods for working with JUnit tests cases in a maven friendly way.
*/
public class MavenTestingUtils
{
private static File basedir;
private static File testResourcesDir;
private static File targetDir;
// private static Boolean surefireRunning;
public static File getBasedir()
{
if (basedir == null)
{
String cwd = System.getProperty("basedir");
if (cwd == null)
{
cwd = System.getProperty("user.dir");
}
basedir = new File(cwd);
}
return basedir;
}
/**
* Get the directory to the /target directory for this project.
*
* @return the directory path to the target directory.
*/
public static File getTargetDir()
{
if (targetDir == null)
{
targetDir = new File(getBasedir(),"target");
PathAssert.assertDirExists("Target Dir",targetDir);
}
return targetDir;
}
/**
* Create a {@link File} object for a path in the /target directory.
*
* @param path
* the path desired, no validation of existence is performed.
* @return the File to the path.
*/
public static File getTargetFile(String path)
{
return new File(getTargetDir(),path.replace("/",File.separator));
}
public static File getTargetTestingDir()
{
File dir = new File(getTargetDir(),"testing");
if (!dir.exists())
{
dir.mkdirs();
}
return dir;
}
/**
* Get a dir in /target/ that uses the JUnit 3.x {@link TestCase#getName()} to make itself unique.
*
* @param test
* the junit 3.x testcase to base this new directory on.
* @return the dir in /target/ that uses the JUnit 3.x {@link TestCase#getName()} to make itself unique.
*/
public static File getTargetTestingDir(TestCase test)
{
return getTargetTestingDir(test.getName());
}
/**
* Get a dir in /target/ that uses the an arbitrary name.
*
* @param testname
* the testname to create directory against.
* @return the dir in /target/ that uses the an arbitrary name.
*/
public static File getTargetTestingDir(String testname)
{
File dir = new File(getTargetDir(),"test-" + testname);
return dir;
}
/**
* Get a dir from the src/test/resource directory.
*
* @param name
* the name of the path to get (it must exist as a dir)
* @return the dir in src/test/resource
*/
public static File getTestResourceDir(String name)
{
File dir = new File(getTestResourcesDir(),name);
PathAssert.assertDirExists("Test Resource Dir",dir);
return dir;
}
/**
* Get a file from the src/test/resource directory.
*
* @param name
* the name of the path to get (it must exist as a file)
* @return the file in src/test/resource
*/
public static File getTestResourceFile(String name)
{
File file = new File(getTestResourcesDir(),name);
PathAssert.assertFileExists("Test Resource File",file);
return file;
}
/**
* Get a path resource (File or Dir) from the src/test/resource directory.
*
* @param name
* the name of the path to get (it must exist)
* @return the path in src/test/resource
*/
public static File getTestResourcePath(String name)
{
File path = new File(getTestResourcesDir(),name);
PathAssert.assertExists("Test Resource Path",path);
return path;
}
/**
* Get the directory to the src/test/resource directory
*
* @return the directory {@link File} to the src/test/resources directory
*/
public static File getTestResourcesDir()
{
if (testResourcesDir == null)
{
testResourcesDir = new File(basedir,"src/test/resources".replace("/",File.separator));
PathAssert.assertDirExists("Test Resources Dir",testResourcesDir);
}
return testResourcesDir;
}
/**
* Read the contents of a file into a String and return it.
*
* @param file
* the file to read.
* @return the contents of the file.
* @throws IOException
* if unable to read the file.
*/
public static String readToString(File file) throws IOException
{
FileReader reader = null;
try
{
reader = new FileReader(file);
return IO.toString(reader);
}
finally
{
IO.close(reader);
}
}
public static String getTestID()
{
StackTraceElement stacked[] = new Throwable().getStackTrace();
String name = null;
for (StackTraceElement stack : stacked)
{
if (stack.getClassName().endsWith("Test"))
{
name = stack.getClassName();
if (stack.getMethodName().startsWith("test"))
{
return stack.getClassName() + "#" + stack.getMethodName();
}
}
}
if (name == null)
{
return "Unidentified_Test";
}
return name;
}
}

View File

@ -1,40 +0,0 @@
// ========================================================================
// Copyright (c) Webtide LLC
// ------------------------------------------------------------------------
// 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.apache.org/licenses/LICENSE-2.0.txt
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.test;
import java.io.File;
import org.junit.Assert;
public class PathAssert
{
public static void assertDirExists(String msg, File path)
{
assertExists(msg,path);
Assert.assertTrue(msg + " path should be a Dir : " + path.getAbsolutePath(),path.isDirectory());
}
public static void assertFileExists(String msg, File path)
{
assertExists(msg,path);
Assert.assertTrue(msg + " path should be a File : " + path.getAbsolutePath(),path.isFile());
}
public static void assertExists(String msg, File path)
{
Assert.assertTrue(msg + " path should exist: " + path.getAbsolutePath(),path.exists());
}
}

View File

@ -1,190 +0,0 @@
// ========================================================================
// Copyright (c) Webtide LLC
// ------------------------------------------------------------------------
// 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.apache.org/licenses/LICENSE-2.0.txt
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.test;
import java.util.List;
import junit.framework.Assert;
import junit.framework.AssertionFailedError;
public class StringAssert
{
/**
* Asserts that the string (<code>haystack</code>) starts with the string (
* <code>expected</code>)
*
* @param msg
* the assertion message
* @param haystack
* the text to search in
* @param expected
* the expected starts with text
*/
public static void assertStartsWith(String msg, String haystack, String expected)
{
Assert.assertNotNull(msg + ": haystack should not be null",haystack);
Assert.assertNotNull(msg + ": expected should not be null",expected);
if (!haystack.startsWith(expected))
{
StringBuffer buf = new StringBuffer();
buf.append(msg).append(": String \"");
int len = Math.min(expected.length() + 4,haystack.length());
buf.append(haystack.substring(0,len));
buf.append("\" does not start with expected \"").append(expected).append("\"");
System.err.println(buf);
throw new AssertionFailedError(buf.toString());
}
}
/**
* Asserts that string (<code>haystack</code>) contains specified text (
* <code>needle</code>).
*
* @param msg
* the assertion message
* @param haystack
* the text to search in
* @param needle
* the text to search for
*/
public static void assertContains(String msg, String haystack, String needle)
{
Assert.assertNotNull(msg + ": haystack should not be null",haystack);
Assert.assertNotNull(msg + ": needle should not be null",needle);
int idx = haystack.indexOf(needle);
if (idx == (-1))
{
StringBuffer buf = new StringBuffer();
buf.append(msg).append(": ");
buf.append("Unable to find \"").append(needle).append("\" in \"");
buf.append(haystack).append("\"");
System.err.println(buf);
throw new AssertionFailedError(buf.toString());
}
}
/**
* Asserts that string (<code>haystack</code>) contains specified text (
* <code>needle</code>), starting at offset (in <code>haystack</code>).
*
* @param msg
* the assertion message
* @param haystack
* the text to search in
* @param needle
* the text to search for
* @param offset
* the offset in (haystack) to perform search from
*/
public static void assertContains(String msg, String haystack, String needle, int offset)
{
Assert.assertNotNull(msg + ": haystack should not be null",haystack);
Assert.assertNotNull(msg + ": needle should not be null",needle);
int idx = haystack.indexOf(needle,offset);
if (idx == (-1))
{
StringBuffer buf = new StringBuffer();
buf.append(msg).append(": ");
buf.append("Unable to find \"").append(needle).append("\" in \"");
buf.append(haystack.substring(offset)).append("\"");
System.err.println(buf);
throw new AssertionFailedError(buf.toString());
}
}
/**
* Asserts that string (<code>haystack</code>) does <u>not</u> contain
* specified text (<code>needle</code>).
*
* @param msg
* the assertion message
* @param haystack
* the text to search in
* @param needle
* the text to search for
*/
public static void assertNotContains(String msg, String haystack, String needle)
{
Assert.assertNotNull(msg + ": haystack should not be null",haystack);
Assert.assertNotNull(msg + ": needle should not be null",needle);
int idx = haystack.indexOf(needle);
if (idx != (-1))
{
StringBuffer buf = new StringBuffer();
buf.append(msg).append(": ");
buf.append("Should not have found \"").append(needle).append("\" at offset ");
buf.append(idx).append(" in \"").append(haystack).append("\"");
System.err.println(buf);
throw new AssertionFailedError(buf.toString());
}
}
/**
* Asserts that string (<code>haystack</code>) does <u>not</u> contain
* specified text (<code>needle</code>), starting at offset (in
* <code>haystack</code>).
*
* @param msg
* the assertion message
* @param haystack
* the text to search in
* @param needle
* the text to search for
* @param offset
* the offset in (haystack) to perform search from
*/
public static void assertNotContains(String msg, String haystack, String needle, int offset)
{
Assert.assertNotNull(msg + ": haystack should not be null",haystack);
Assert.assertNotNull(msg + ": needle should not be null",needle);
int idx = haystack.indexOf(needle,offset);
if (idx != (-1))
{
StringBuffer buf = new StringBuffer();
buf.append(msg).append(": ");
buf.append("Should not have found \"").append(needle).append("\" at offset ");
buf.append(idx).append(" in \"").append(haystack.substring(offset)).append("\"");
System.err.println(buf);
throw new AssertionFailedError(buf.toString());
}
}
/**
* Asserts that the list of String lines contains the same lines (without a regard for the order of those lines)
*
* @param msg
* the assertion message
* @param linesExpected
* the list of expected lines
* @param linesActual
* the list of actual lines
*/
public static void assertContainsSame(String msg, List<String> linesExpected, List<String> linesActual)
{
Assert.assertEquals(msg + " line count",linesExpected.size(),linesActual.size());
for (String expected : linesExpected)
{
Assert.assertTrue(msg + ": expecting to see line <" + expected + ">",linesActual.contains(expected));
}
}
}

View File

@ -36,7 +36,7 @@ public class RFC2616BIOHttpTest extends RFC2616BaseTest
server.addConfiguration("RFC2616_Redirects.xml"); server.addConfiguration("RFC2616_Redirects.xml");
server.addConfiguration("RFC2616_Filters.xml"); server.addConfiguration("RFC2616_Filters.xml");
server.addConfiguration("BIOHttp.xml"); server.addConfiguration("BIOHttp.xml");
setUpServer(server); setUpServer(server, RFC2616BIOHttpTest.class);
} }
@Override @Override

View File

@ -37,7 +37,7 @@ public class RFC2616BIOHttpsTest extends RFC2616BaseTest
server.addConfiguration("RFC2616_Redirects.xml"); server.addConfiguration("RFC2616_Redirects.xml");
server.addConfiguration("RFC2616_Filters.xml"); server.addConfiguration("RFC2616_Filters.xml");
server.addConfiguration("BIOHttps.xml"); server.addConfiguration("BIOHttps.xml");
setUpServer(server); setUpServer(server, RFC2616BIOHttpsTest.class);
} }
@Override @Override

View File

@ -31,13 +31,14 @@ import java.util.TimeZone;
import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.test.MavenTestingUtils;
import org.eclipse.jetty.test.StringAssert;
import org.eclipse.jetty.test.support.StringUtil; import org.eclipse.jetty.test.support.StringUtil;
import org.eclipse.jetty.test.support.TestableJettyServer; import org.eclipse.jetty.test.support.TestableJettyServer;
import org.eclipse.jetty.test.support.rawhttp.HttpResponseTester; import org.eclipse.jetty.test.support.rawhttp.HttpResponseTester;
import org.eclipse.jetty.test.support.rawhttp.HttpSocket; import org.eclipse.jetty.test.support.rawhttp.HttpSocket;
import org.eclipse.jetty.test.support.rawhttp.HttpTesting; import org.eclipse.jetty.test.support.rawhttp.HttpTesting;
import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.StringAssert;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
@ -79,16 +80,10 @@ public abstract class RFC2616BaseTest
} }
} }
public static void setUpServer(TestableJettyServer testableserver) throws Exception public static void setUpServer(TestableJettyServer testableserver, Class<?> testclazz) throws Exception
{ {
File targetDir = MavenTestingUtils.getTargetDir(); File testWorkDir = MavenTestingUtils.getTargetTestingDir(testclazz.getName());
String testId = MavenTestingUtils.getTestID(); FS.ensureDirExists(testWorkDir);
File testWorkDir = new File(targetDir,"work" + File.separator + testId);
if (!testWorkDir.exists())
{
testWorkDir.mkdirs();
}
System.setProperty("java.io.tmpdir",testWorkDir.getAbsolutePath()); System.setProperty("java.io.tmpdir",testWorkDir.getAbsolutePath());

View File

@ -36,7 +36,7 @@ public class RFC2616NIOHttpTest extends RFC2616BaseTest
server.addConfiguration("RFC2616_Redirects.xml"); server.addConfiguration("RFC2616_Redirects.xml");
server.addConfiguration("RFC2616_Filters.xml"); server.addConfiguration("RFC2616_Filters.xml");
server.addConfiguration("NIOHttp.xml"); server.addConfiguration("NIOHttp.xml");
setUpServer(server); setUpServer(server, RFC2616NIOHttpTest.class);
} }
@Override @Override

View File

@ -36,7 +36,7 @@ public class RFC2616NIOHttpsTest extends RFC2616BaseTest
server.addConfiguration("RFC2616_Redirects.xml"); server.addConfiguration("RFC2616_Redirects.xml");
server.addConfiguration("RFC2616_Filters.xml"); server.addConfiguration("RFC2616_Filters.xml");
server.addConfiguration("NIOHttps.xml"); server.addConfiguration("NIOHttps.xml");
setUpServer(server); setUpServer(server, RFC2616NIOHttpsTest.class);
} }
@Override @Override

View File

@ -108,7 +108,6 @@ public class TestableJettyServer
_properties.put(key,value); _properties.put(key,value);
} }
@SuppressWarnings("unchecked")
public void load() throws Exception public void load() throws Exception
{ {
XmlConfiguration last = null; XmlConfiguration last = null;
@ -123,7 +122,7 @@ public class TestableJettyServer
{ {
configuration.getIdMap().putAll(last.getIdMap()); configuration.getIdMap().putAll(last.getIdMap());
} }
configuration.setProperties(_properties); configuration.getProperties().putAll(_properties);
obj[i] = configuration.configure(); obj[i] = configuration.configure();
last = configuration; last = configuration;
} }

View File

@ -32,8 +32,8 @@ import org.eclipse.jetty.http.MimeTypes;
import org.eclipse.jetty.io.Buffer; import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.ByteArrayBuffer; import org.eclipse.jetty.io.ByteArrayBuffer;
import org.eclipse.jetty.io.View; import org.eclipse.jetty.io.View;
import org.eclipse.jetty.test.StringAssert;
import org.eclipse.jetty.test.support.StringUtil; import org.eclipse.jetty.test.support.StringUtil;
import org.eclipse.jetty.toolchain.test.StringAssert;
import org.eclipse.jetty.util.ByteArrayOutputStream2; import org.eclipse.jetty.util.ByteArrayOutputStream2;
/** /**

View File

@ -61,7 +61,6 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -60,7 +60,6 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -72,7 +72,6 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -14,7 +14,7 @@ package org.eclipse.jetty.server.session;
import org.eclipse.jetty.server.SessionIdManager; import org.eclipse.jetty.server.SessionIdManager;
import org.eclipse.jetty.server.SessionManager; import org.eclipse.jetty.server.SessionManager;
import org.eclipse.jetty.server.session.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
/** /**
* JdbcTestServer * JdbcTestServer
@ -25,10 +25,9 @@ public class JdbcTestServer extends AbstractTestServer
public static final String CONNECTION_URL = "jdbc:derby:sessions;create=true"; public static final String CONNECTION_URL = "jdbc:derby:sessions;create=true";
public static final int SAVE_INTERVAL = 1; public static final int SAVE_INTERVAL = 1;
static static
{ {
System.setProperty("derby.system.home", MavenTestingUtils.getTargetTestingDir().getAbsolutePath()); System.setProperty("derby.system.home", MavenTestingUtils.getTargetFile("test-derby").getAbsolutePath());
} }
public JdbcTestServer(int port) public JdbcTestServer(int port)

View File

@ -33,21 +33,25 @@
<artifactId>jetty-server</artifactId> <artifactId>jetty-server</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId> <artifactId>jetty-webapp</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId> <artifactId>jetty-client</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>junit</artifactId> <artifactId>jetty-test-helper</artifactId>
<version>${junit4-version}</version> <scope>compile</scope>
<scope>compile</scope> </dependency>
</dependency> <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,221 +0,0 @@
// ========================================================================
// Copyright (c) Webtide LLC
// ------------------------------------------------------------------------
// 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.apache.org/licenses/LICENSE-2.0.txt
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.server.session.test;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import junit.framework.TestCase;
import org.eclipse.jetty.util.IO;
/**
* Common utility methods for working with JUnit tests cases in a maven friendly way.
*/
public class MavenTestingUtils
{
private static File basedir;
private static File testResourcesDir;
private static File targetDir;
// private static Boolean surefireRunning;
public static File getBasedir()
{
if (basedir == null)
{
String cwd = System.getProperty("basedir");
if (cwd == null)
{
cwd = System.getProperty("user.dir");
}
basedir = new File(cwd);
}
return basedir;
}
/**
* Get the directory to the /target directory for this project.
*
* @return the directory path to the target directory.
*/
public static File getTargetDir()
{
if (targetDir == null)
{
targetDir = new File(getBasedir(),"target");
PathAssert.assertDirExists("Target Dir",targetDir);
}
return targetDir;
}
/**
* Create a {@link File} object for a path in the /target directory.
*
* @param path
* the path desired, no validation of existence is performed.
* @return the File to the path.
*/
public static File getTargetFile(String path)
{
return new File(getTargetDir(),path.replace("/",File.separator));
}
public static File getTargetTestingDir()
{
File dir = new File(getTargetDir(),"testing");
if (!dir.exists())
{
dir.mkdirs();
}
return dir;
}
/**
* Get a dir in /target/ that uses the JUnit 3.x {@link TestCase#getName()} to make itself unique.
*
* @param test
* the junit 3.x testcase to base this new directory on.
* @return the File path to the testcase specific testing directory underneath the
* <code>${basedir}/target</code> sub directory
*/
public static File getTargetTestingDir(TestCase test)
{
return getTargetTestingDir(test.getName());
}
/**
* Get a dir in /target/ that uses the an arbitrary name.
*
* @param testname
* the testname to create directory against.
* @return the File path to the testname sepecific testing directory underneath the
* <code>${basedir}/target</code> sub directory
*/
public static File getTargetTestingDir(String testname)
{
File dir = new File(getTargetDir(),"test-" + testname);
return dir;
}
/**
* Get a dir from the src/test/resource directory.
*
* @param name
* the name of the path to get (it must exist as a dir)
* @return the dir in src/test/resource
*/
public static File getTestResourceDir(String name)
{
File dir = new File(getTestResourcesDir(),name);
PathAssert.assertDirExists("Test Resource Dir",dir);
return dir;
}
/**
* Get a file from the src/test/resource directory.
*
* @param name
* the name of the path to get (it must exist as a file)
* @return the file in src/test/resource
*/
public static File getTestResourceFile(String name)
{
File file = new File(getTestResourcesDir(),name);
PathAssert.assertFileExists("Test Resource File",file);
return file;
}
/**
* Get a path resource (File or Dir) from the src/test/resource directory.
*
* @param name
* the name of the path to get (it must exist)
* @return the path in src/test/resource
*/
public static File getTestResourcePath(String name)
{
File path = new File(getTestResourcesDir(),name);
PathAssert.assertExists("Test Resource Path",path);
return path;
}
/**
* Get the directory to the src/test/resource directory
*
* @return the directory {@link File} to the src/test/resources directory
*/
public static File getTestResourcesDir()
{
if (testResourcesDir == null)
{
testResourcesDir = new File(basedir,"src/test/resources".replace("/",File.separator));
PathAssert.assertDirExists("Test Resources Dir",testResourcesDir);
}
return testResourcesDir;
}
/**
* Read the contents of a file into a String and return it.
*
* @param file
* the file to read.
* @return the contents of the file.
* @throws IOException
* if unable to read the file.
*/
public static String readToString(File file) throws IOException
{
FileReader reader = null;
try
{
reader = new FileReader(file);
return IO.toString(reader);
}
finally
{
IO.close(reader);
}
}
public static String getTestID()
{
StackTraceElement stacked[] = new Throwable().getStackTrace();
String name = null;
for(StackTraceElement stack: stacked) {
if(stack.getClassName().endsWith("Test"))
{
name = stack.getClassName();
if (stack.getMethodName().startsWith("test"))
{
return stack.getClassName() + "#" + stack.getMethodName();
}
}
}
if(name == null)
{
return "Unidentified_Test";
}
return name;
}
}

View File

@ -1,40 +0,0 @@
// ========================================================================
// Copyright (c) Webtide LLC
// ------------------------------------------------------------------------
// 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.apache.org/licenses/LICENSE-2.0.txt
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.server.session.test;
import java.io.File;
import org.junit.Assert;
public class PathAssert
{
public static void assertDirExists(String msg, File path)
{
assertExists(msg,path);
Assert.assertTrue(msg + " path should be a Dir : " + path.getAbsolutePath(),path.isDirectory());
}
public static void assertFileExists(String msg, File path)
{
assertExists(msg,path);
Assert.assertTrue(msg + " path should be a File : " + path.getAbsolutePath(),path.isFile());
}
public static void assertExists(String msg, File path)
{
Assert.assertTrue(msg + " path should exist: " + path.getAbsolutePath(),path.exists());
}
}