Julien,
You're not starting jetty6 correctly in the JettySetup setup() method.
You need to do:
Server server = new Server();
XmlConfiguration xmlConfiguration = new XmlConfiguration(jettyConfig);
xmlConfiguration.configure(server);
server.start();
server.getThreadPool().join();
Instead of running jetty once for all the test cases, you could do
a startup and shutdown of Jetty in the individual TestCase setUp()
and tearDown() methods, and have the surefire plugin run **/*Test.java
cheers
Jan
Julien Henry wrote:
Hi Jan,
Here is currently how it works. I have many JUnit tests. These tests are
grouped in a test suite called AllTests.java this way :
public class AllTests extends TestSuite {
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(NavigationTest.class);
suite.addTestSuite(WebAssertionsTest.class);
....
return new JettySetup(suite);
}
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
}
JettySetup is used to launch Jetty only one time before all tests, and
to close it after :
public class JettySetup extends TestSetup {
private Server jettyServer = null;
public void setUp() {
try {
URL jettyConfig = JettySetup.class
.getResource("/jetty-test-config.xml");
if(jettyConfig==null) {
fail("Unable to locate jetty-test-config.xml on the
classpath");
}
jettyServer = new Server(jettyConfig);
jettyServer.start();
} catch (Exception e) {
e.printStackTrace();
fail("Could not start the Jetty server: " + e);
}
}
public void tearDown() {
try {
jettyServer.stop();
} catch (InterruptedException e) {
e.printStackTrace();
fail("Jetty server was interrupted: " + e);
}
}
}
With Maven 2, I only select AllTests as test to be launched :
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/AllTests.java</include>
</includes>
</configuration>
</plugin>
But I see a few drawbacks to this configuration :
- I don't have the detail of each test in Maven report (due to Surefire
bug I think) :
>> [INFO] Generate "Maven Surefire Report" report.
>> java.lang.NumberFormatException: For input string: "25,814"
>> at
org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:691)
>> ...
>> java.lang.NullPointerException
>> at
org.codehaus.mojo.surefire.SurefireReportGenerator.constructTestCasesSection(SurefireReportGenerator.java:344)
- I would like to run all tests 2 times, with a different parameter,
but without restarting Jetty. And if I can have a clear report that show
the number of success/failure for each value of the parameter, it would
be perfect.
Jan Bartel a écrit :
Julien,
Embedding Jetty6 is pretty simple. The jetty.xml config file is written
in a straightforward mapping from the java API to xml syntax. There is
the
beginnings of a guide to embedding jetty also on the wiki at:
http://docs.codehaus.org/display/JETTY/Embedding+Jetty
Jetty is often used in the unit tests of other projects - a jetty Server
instance is started in the test setup and stopped in the test teardown.
However, if you want to use the plugin instead, you simply include the
relevant lines into your pom.xml file, and invoke it:
mvn jetty6:run
When you want to stop it, you <cntrl-c> it.
There is all the information on how to configure and run the plugin
here:
http://jetty.mortbay.org/jetty6/maven-plugin/index.html
cheers
Jan
Julien Henry wrote:
Hi Jan,
I tried to migrate to Jetty 6, but there are too few doc about how to
use embedded Jetty. I discovered that a Jetty6 plugin exists, and I
think it could be a good thing to start jetty before the JUnit tests,
and to stop Jetty after, because it exactly what I want. Do you know
a simple way to do this ?
Thanks
Julien
Jan Bartel a écrit :
Hi Julien.
Jetty 5.x is built by ant, but the artifacts are made available on
ibiblio. The jetty5.x series, whilst the current stable series is
about to be superceded by the 6.x series.
Jetty 6.x is built by maven2 and has full poms with dependencies
listed which maven2 will transitively resolve for you.
I suggest you switch to jetty 6.x as 1) it is built by maven2 and
2) anyway has many many less dependencies.
cheers
Jan
Julien Henry wrote:
Hi,
I'm using Jetty to test my project. I have this in my pom (I use
JSP) :
<dependency>
<groupId>jetty</groupId>
<artifactId>org.mortbay.jetty</artifactId>
<version>5.1.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jetty</groupId>
<artifactId>jasper-runtime</artifactId>
<version>4.2.20RC0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jetty</groupId>
<artifactId>jasper-compiler</artifactId>
<version>4.2.20RC0</version>
<scope>test</scope>
</dependency>
But the server can't be launched. I discovered that Jetty need
org.apache.commons-logging. So I added :
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.4</version>
<scope>test</scope>
</dependency>
But why don't put commons-logging as a dependency of Jetty in the
pom on ibiblio ?
Thanks
Julien
This message contains information that may be privileged or
confidential and is the property of the Capgemini Group. It is
intended only for the person to whom it is addressed. If you are
not the intended recipient, you are not authorized to read, print,
retain, copy, disseminate, distribute, or use this message or any
part thereof. If you receive this message in error, please notify
the sender immediately and delete all copies of this message.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]