diff options
author | Joakim Erdfelt | 2011-01-28 18:58:47 +0000 |
---|---|---|
committer | Joakim Erdfelt | 2011-01-28 18:58:47 +0000 |
commit | acc4f230fc926f5d9cbee5a23c7535ce46238387 (patch) | |
tree | 106cfaf4585a03b6d9854c67f133b51ad344c527 /jetty-deploy/src/test | |
parent | dd7511a72107a54d219a8076d5b6154679c9c4ea (diff) | |
download | org.eclipse.jetty.project-acc4f230fc926f5d9cbee5a23c7535ce46238387.tar.gz org.eclipse.jetty.project-acc4f230fc926f5d9cbee5a23c7535ce46238387.tar.xz org.eclipse.jetty.project-acc4f230fc926f5d9cbee5a23c7535ce46238387.zip |
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
Diffstat (limited to 'jetty-deploy/src/test')
9 files changed, 52 insertions, 298 deletions
diff --git a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/AppLifeCycleTest.java b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/AppLifeCycleTest.java index 5caa04b68a..65599f3a51 100644 --- a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/AppLifeCycleTest.java +++ b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/AppLifeCycleTest.java @@ -23,8 +23,9 @@ import java.util.List; import org.eclipse.jetty.deploy.graph.GraphOutputDot; import org.eclipse.jetty.deploy.graph.Node; 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.Rule; import org.junit.Test; /** @@ -32,7 +33,10 @@ import org.junit.Test; */ 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>()); } @@ -169,8 +173,7 @@ public class AppLifeCycleTest AppLifeCycle lifecycle = new AppLifeCycle(); List<String> expected = new ArrayList<String>(); - File outputDir = MavenTestingUtils.getTargetTestingDir(this.getClass().getName() + ".testFindPathMultiple"); - outputDir.mkdirs(); + File outputDir = testdir.getEmptyDir(); // Modify graph to add new 'staging' -> 'staged' between 'deployed' and 'started' GraphOutputDot.write(lifecycle,new File(outputDir,"multiple-1.dot")); // before change diff --git a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/DeploymentManagerTest.java b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/DeploymentManagerTest.java index 96f26a1902..99d619444f 100644 --- a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/DeploymentManagerTest.java +++ b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/DeploymentManagerTest.java @@ -4,12 +4,17 @@ import java.util.Collection; import java.util.Set; import org.eclipse.jetty.deploy.test.XmlConfiguredJetty; +import org.eclipse.jetty.toolchain.test.TestingDir; import org.junit.Assert; +import org.junit.Rule; import org.junit.Test; public class DeploymentManagerTest { - @Test + @Rule + public TestingDir testdir = new TestingDir(); + + @Test public void testReceiveApp() throws Exception { DeploymentManager depman = new DeploymentManager(); @@ -59,7 +64,7 @@ public class DeploymentManagerTest XmlConfiguredJetty jetty = null; try { - jetty = new XmlConfiguredJetty(); + jetty = new XmlConfiguredJetty(testdir); jetty.addConfiguration("jetty.xml"); jetty.addConfiguration("jetty-deploymgr-contexts.xml"); diff --git a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/MockAppProvider.java b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/MockAppProvider.java index e42b2650ec..0a5f541afd 100644 --- a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/MockAppProvider.java +++ b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/MockAppProvider.java @@ -17,9 +17,9 @@ package org.eclipse.jetty.deploy; import java.io.File; -import org.eclipse.jetty.deploy.test.MavenTestingUtils; import org.eclipse.jetty.deploy.util.FileID; 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.component.AbstractLifeCycle; import org.eclipse.jetty.util.resource.Resource; @@ -52,7 +52,7 @@ public class MockAppProvider extends AbstractLifeCycle implements AppProvider WebAppContext context = new WebAppContext(); 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(); diff --git a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/MonitoredDirAppProviderRuntimeUpdatesTest.java b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ScanningAppProviderRuntimeUpdatesTest.java index 69608d766a..05dec7f26b 100644 --- a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/MonitoredDirAppProviderRuntimeUpdatesTest.java +++ b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ScanningAppProviderRuntimeUpdatesTest.java @@ -18,22 +18,26 @@ package org.eclipse.jetty.deploy.providers; import java.io.IOException; import org.eclipse.jetty.deploy.test.XmlConfiguredJetty; +import org.eclipse.jetty.toolchain.test.TestingDir; import org.junit.After; import org.junit.Before; +import org.junit.Rule; 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}. */ -public class MonitoredDirAppProviderRuntimeUpdatesTest +public class ScanningAppProviderRuntimeUpdatesTest { + @Rule + public TestingDir testdir = new TestingDir(); private static XmlConfiguredJetty jetty; @Before public void setupEnvironment() throws Exception { - jetty = new XmlConfiguredJetty(); + jetty = new XmlConfiguredJetty(testdir); jetty.addConfiguration("jetty.xml"); jetty.addConfiguration("jetty-deploymgr-contexts.xml"); diff --git a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/MonitoredDirAppProviderStartupTest.java b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ScanningAppProviderStartupTest.java index 9cafb0de8e..e70fc28243 100644 --- a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/MonitoredDirAppProviderStartupTest.java +++ b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/ScanningAppProviderStartupTest.java @@ -16,21 +16,25 @@ package org.eclipse.jetty.deploy.providers; import org.eclipse.jetty.deploy.test.XmlConfiguredJetty; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.eclipse.jetty.toolchain.test.TestingDir; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; import org.junit.Test; /** * 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; - @BeforeClass - public static void setupEnvironment() throws Exception + @Before + public void setupEnvironment() throws Exception { - jetty = new XmlConfiguredJetty(); + jetty = new XmlConfiguredJetty(testdir); jetty.addConfiguration("jetty.xml"); jetty.addConfiguration("jetty-deploymgr-contexts.xml"); @@ -45,8 +49,8 @@ public class MonitoredDirAppProviderStartupTest jetty.start(); } - @AfterClass - public static void teardownEnvironment() throws Exception + @After + public void teardownEnvironment() throws Exception { // Stop jetty. jetty.stop(); diff --git a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/WebAppProviderTest.java b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/WebAppProviderTest.java index 6b0dff60fd..0f2e562f15 100644 --- a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/WebAppProviderTest.java +++ b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/providers/WebAppProviderTest.java @@ -4,19 +4,23 @@ import java.io.File; import java.util.Arrays; 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.BeforeClass; +import org.junit.Before; +import org.junit.Rule; import org.junit.Test; public class WebAppProviderTest { + @Rule + public TestingDir testdir = new TestingDir(); private static XmlConfiguredJetty jetty; - @BeforeClass - public static void setupEnvironment() throws Exception + @Before + public void setupEnvironment() throws Exception { - jetty = new XmlConfiguredJetty(); + jetty = new XmlConfiguredJetty(testdir); jetty.addConfiguration("jetty.xml"); jetty.addConfiguration("jetty-deploy-wars.xml"); @@ -31,8 +35,8 @@ public class WebAppProviderTest jetty.start(); } - @AfterClass - public static void teardownEnvironment() throws Exception + @After + public void teardownEnvironment() throws Exception { // Stop jetty. jetty.stop(); diff --git a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/MavenTestingUtils.java b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/MavenTestingUtils.java deleted file mode 100644 index 367d584aa2..0000000000 --- a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/MavenTestingUtils.java +++ /dev/null @@ -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; - } -} diff --git a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/PathAssert.java b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/PathAssert.java deleted file mode 100644 index e4eaedc6a0..0000000000 --- a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/PathAssert.java +++ /dev/null @@ -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()); - } -} diff --git a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/XmlConfiguredJetty.java b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/XmlConfiguredJetty.java index 09271dcc12..e66db923e1 100644 --- a/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/XmlConfiguredJetty.java +++ b/jetty-deploy/src/test/java/org/eclipse/jetty/deploy/test/XmlConfiguredJetty.java @@ -20,7 +20,6 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.PrintStream; import java.net.InetAddress; import java.net.MalformedURLException; 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.Handler; import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.handler.AbstractHandler; 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.webapp.WebAppContext; import org.eclipse.jetty.xml.XmlConfiguration; @@ -57,17 +58,12 @@ public class XmlConfiguredJetty private String _scheme = HttpSchemes.HTTP; private File _jettyHome; - public XmlConfiguredJetty() throws IOException - { - this(MavenTestingUtils.getTestID()); - } - - public XmlConfiguredJetty(String testname) throws IOException + public XmlConfiguredJetty(TestingDir testdir) throws IOException { _xmlConfigurations = new ArrayList<URL>(); 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. int idx = 0; _jettyHome = new File(jettyHomeBase + "#" + idx); @@ -336,7 +332,6 @@ public class XmlConfiguredJetty return contexts; } - @SuppressWarnings("unchecked") public void load() throws Exception { XmlConfiguration last = null; @@ -351,7 +346,7 @@ public class XmlConfiguredJetty { configuration.getIdMap().putAll(last.getIdMap()); } - configuration.setProperties(_properties); + configuration.getProperties().putAll(_properties); obj[i] = configuration.configure(); last = configuration; } |