|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.jetty.toolchain.test.JettyDistro
public class JettyDistro
Basic process based executor for using the Jetty Distribution along with custom configurations to perform basic
Allows for a test specific directory, that is a copied jetty-distribution, and then modified for the test specific testing required.
Requires that you setup the maven-dependency-plugin appropriately for the base distribution you want to use, along with any other dependencies (wars, libs, etc..) that you may need from other maven projects.
Maven Dependency Plugin Setup:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <!-- Common Destination Directories --> <properties> <test-wars-dir>${project.build.directory}/test-wars</test-wars-dir> <test-libs-dir>${project.build.directory}/test-libs</test-libs-dir> <test-distro-dir>${project.build.directory}/test-dist</test-distro-dir> </properties> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.1</version> <executions> <!-- Copy LIB and WAR dependencies into place that JettyDistro can use them --> <execution> <id>test-lib-war-copy</id> <phase>process-test-resources</phase> <goals> <goal>copy</goal> </goals> <configuration> <artifactItems> <artifactItem> <groupId>org.mortbay.jetty.testwars</groupId> <artifactId>test-war-java_util_logging</artifactId> <version>7.3.0</version> <type>war</type> <outputDirectory>${test-wars-dir}</outputDirectory> </artifactItem> <artifactItem> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-aspect-servlet-api-2.5</artifactId> <version>7.3.0</version> <type>jar</type> <outputDirectory>${test-libs-dir}</outputDirectory> </artifactItem> </artifactItems> <overWriteIfNewer>true</overWriteIfNewer> <overWrite>true</overWrite> <stripVersion>true</stripVersion> </configuration> </execution> <!-- Extract Jetty DISTRIBUTION into place that JettyDistro can use it --> <execution> <id>unpack-test-dist</id> <phase>process-test-resources</phase> <goals> <goal>unpack</goal> </goals> <configuration> <artifactItems> <artifactItem> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-distribution</artifactId> <version>7.3.0</version> <type>zip</type> <overWrite>true</overWrite> </artifactItem> </artifactItems> <outputAbsoluteArtifactFilename>true</outputAbsoluteArtifactFilename> <outputDirectory>${test-distro-dir}</outputDirectory> <overWriteSnapshots>true</overWriteSnapshots> <overWriteIfNewer>true</overWriteIfNewer> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
If you have a specific configuration you want to setup, you'll want to prepare this configuration in an overlay directory underneath the
src/test/resources/
directory.
Notes:
JettyDistro
sets up a unique test directory (based on the constructor JettyDistro(Class)
or JettyDistro(TestingDir)
), by
ensuring the directory is empty, then copying the target/test-dist
directory into this new testing directory prior to the test specific changes
to the configuration.src/test/resources
will be the name you use in the overlayConfig(String)
method to provide
replacement configurations for the Jetty Distribution.delete(String)
any files and/or directories from the standard distribution prior to using the overlayConfig(String)
method.copyLib(String, String)
method to copy JAR files from the target/test-libs
directory (created and managed above using the
maven-dependency-plugin
) to copy the lib into the test specific.copyTestWar(String)
method to copy WAR files from the target/test-wars
directory (created and managed above using the
maven-dependency-plugin
) to copy the WAR into the test specific directory.
Next you'll want to use Junit 4.8+ and the @BeforeClass
and @AfterClass
annotations to setup the JettyDistro
class for setting up your testing configuration.
Example Test Case using JettyDistro
class
public class MySampleTest { private static JettyDistro jetty; @BeforeClass public static void initJetty() throws Exception { jetty = new JettyDistro(MySampleTest.class); jetty.copyTestWar("test-war-java_util_logging.war"); jetty.copyTestWar("test-war-policy.war"); jetty.delete("webapps/test.war"); jetty.delete("contexts/test.d"); jetty.delete("contexts/javadoc.xml"); jetty.delete("contexts/test.xml"); jetty.overlayConfig("no_security"); jetty.setDebug(true); jetty.start(); } @AfterClass public static void shutdownJetty() throws Exception { if (jetty != null) { jetty.stop(); } } @Test public void testRequest() throws Exception { SimpleRequest request = new SimpleRequest(jetty.getBaseUri()); String path = "/test-war-policy/security/PRACTICAL/testFilsystem"); String response = request.getString(path); Assert.assertEquals("Success", response); } }
Constructor Summary | |
---|---|
JettyDistro(Class<?> clazz)
Setup the JettyHome as belonging in a testing directory associated with a testing clazz. |
|
JettyDistro(Class<?> clazz,
String artifact)
Setup the JettyHome as belonging in a testing directory associated with a testing clazz. |
|
JettyDistro(TestingDir testdir)
Setup the JettyHome as belonging to a specific testing method directory |
|
JettyDistro(TestingDir testdir,
String artifact)
Setup the JettyHome as belonging to a specific testing method directory |
Method Summary | |
---|---|
void |
copyLib(String libFilename,
String outputPath)
Copy an arbitrary file from target/test-libs/${libFilename} to the testing directory. |
void |
copyProjectMainConfig()
Copy the ${project.basedir}/src/main/config/ tree into the testing directory. |
void |
copyResource(String resourcePath,
String outputPath)
Copy an arbitrary file from src/test/resources/${resourcePath} to the testing directory. |
void |
copyTestWar(String testWarFilename)
Copy a war file from ${project.basedir}/target/test-wars/${testWarFilename} into the ${jetty.home}/webapps/ directory |
void |
createProjectLib(String jarFilename)
Create a ${jetty.home}/lib/self/${jarFilename} jar file from the content in the ${project.basedir}/target/classes/ directory. |
void |
delete(String path)
Delete a File or Directory found in the ${jetty.home} directory. |
URI |
getBaseUri()
Return the baseUri being used for this Jetty Process Instance. |
File |
getJettyHomeDir()
Return the $(jetty.home) directory being used for this JettyDistro |
String |
getJmxUrl()
Return the JMX URL being used for this Jetty Process Instance. |
void |
overlayConfig(String testConfigName)
Take the directory contents from ${project.basedir}/src/test/resources/${testConfigName}/ and copy it over whatever happens to be at ${jetty.home} |
void |
setDebug(boolean debug)
enable debug on the jetty process |
void |
setStartTime(long startTime,
TimeUnit timeUnit)
|
static List<String> |
splitAndUnescapeCommandLine(CharSequence rawCmdLine)
|
void |
start()
Start the jetty server |
void |
stop()
Stop the jetty server |
void |
unpackConfig(String configFilename)
Unpack an arbitrary config from target/test-configs/${configFilename} to the testing directory. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JettyDistro(Class<?> clazz) throws IOException
clazz
- the testing class using this JettyDistro
IOException
- if unable to copy unpacked distribution into place for the provided testing directorypublic JettyDistro(Class<?> clazz, String artifact) throws IOException
clazz
- the testing class using this JettyDistroartifact
- name of jetty distribution artifact
IOException
- if unable to copy unpacked distribution into place for the provided testing directorypublic JettyDistro(TestingDir testdir) throws IOException
testdir
- the testing directory to use as the JettyHome for this JettyDistro
IOException
- if unable to copy unpacked distribution into place for the provided testing directorypublic JettyDistro(TestingDir testdir, String artifact) throws IOException
testdir
- the testing directory to use as the JettyHome for this JettyDistroartifact
- name of jetty distribution artifact
IOException
- if unable to copy unpacked distribution into place for the provided testing directoryMethod Detail |
---|
public File getJettyHomeDir()
public void copyTestWar(String testWarFilename) throws IOException
testWarFilename
- the war file to copy (must exist)
IOException
- if unable to copy the war file.public void copyResource(String resourcePath, String outputPath) throws IOException
src/test/resources/${resourcePath}
to the testing directory.
resourcePath
- the relative path for file content within the src/test/resources
directory.outputPath
- the testing directory relative output path for the file output (will result in a file with the outputPath name being created)
IOException
- if unable to copy resource filepublic void copyLib(String libFilename, String outputPath) throws IOException
target/test-libs/${libFilename}
to the testing directory.
libFilename
- the target/test-libs/${libFilename}
to copyoutputPath
- the destination testing directory relative output path for the lib. (will result in a file with the outputPath name being created)
IOException
- if unable to copy libpublic void copyProjectMainConfig() throws IOException
${project.basedir}/src/main/config/
tree into the testing directory.
IOException
- if unable to copy the directory treepublic void createProjectLib(String jarFilename) throws IOException
${jetty.home}/lib/self/${jarFilename}
jar file from the content in the ${project.basedir}/target/classes/
directory.
IOException
- if unable to copy the directory treepublic void unpackConfig(String configFilename) throws IOException
target/test-configs/${configFilename}
to the testing directory.
configFilename
- the target/test-configs/${configFilename}
to copy
IOException
- if unable to unpack config filepublic void delete(String path)
path
- the path to delete. (can be a file or directory)public URI getBaseUri()
public String getJmxUrl()
public void overlayConfig(String testConfigName) throws IOException
testConfigName
- the src/test/resources/ directory name to use as the source diretory for the configuration we are interested in.
IOException
- if unable to copy directory.public void start() throws IOException
IOException
- if unable to start the server.public static List<String> splitAndUnescapeCommandLine(CharSequence rawCmdLine)
public void setDebug(boolean debug)
debug
- public void stop()
public void setStartTime(long startTime, TimeUnit timeUnit)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |