Automate JUnit tests for functionality on the server in Eclipse? - eclipse

I would have added some JUnit tests to an Eclipse project that test functionality on the server to an Eclipse web project.
I can run the web application from inside Eclipse on an external Tomcat server (Run As | Run on Server) and then run the JUnit tests also from inside Eclipse while the first is still up.
I understand that is should be possible to fully automate both steps as one by making use of a Jetty (instead of Tomcat) server that runs inside Eclipse and that could be booted e.g. in #BeforeClass (or earlier).
Does Eclipse support this kind of unit testing out-of-the-box. I am currently using Eclipse Java EE IDE for Web Developers (Version: Kepler Service Release 2).

Eclipse (and any other IDE for that matter) doesn't stop you from doing anything in unit tests. It doesn't really support much, either, which is the core of your problem: Eclipse won't start a server for your unit tests. The same is true for all other IDEs that I know of.
Instead, you need to read up on how to embed Jetty in a Java application (= your unit tests) so the first test can start the server. Use a lazy init pattern for this:
private static JettyManager jetty;
#Before public void startServer() {
if( null == jetty ) {
jetty = new JettyManager();
jetty.start();
}
}
You can use a JVM shutdown hook to cleanly stop the server.
I use the same pattern to create the database which should be used during the tests to make sure it's clean. For this, I embed an H2 database.
If you want more automation, look at Maven. It can run integration tests (including deploying the WAR before starting the tests). See http://www.benoitschweblin.com/2013/03/run-jetty-in-maven-life-cycle.html
With the Maven Cargo plugin, you can deploy to almost every J2EE container.
Or use Jenkins: http://programmaticponderings.wordpress.com/2013/11/13/building-a-deployment-pipeline-using-git-maven-jenkins-and-glassfish-part-2-of-2/

Related

Headless eclipse managed by Jenkins to run OSGi application server

we would like to adapt our Jenkins CI roundtrip as it takes to long (late feedback).
The current flow looks like described below:
OSGi server bundles are checked out and build with ant.
the OSGi bundles are packaged to be used on linux distros.
a server is set up to install the above packages and to run HTTP interface tests (integration tests) against it.
We would like to get rid of creating the linux packages and to install a server with these packages as this consumes most of the time.
Instead we would like to execute the existing tests against a headless eclipse which is running the server (based on compiled jars or imported projects if possible) managed by Jenkins CI.
Now some questions:
Is it possible to run a headless eclipse within Jenkins (I think so as it is just executing a java application)?
Is it possible (and does it makes sense) to have an eclipse instance permanently running and to get used from more than one job? So we have to only update the jars/imported projects that have been changed ... or
do we have to extract eclipse and set it up each test run?
Is it possible to import projects within the headless eclipse or do we have to throw compiled jars into its installation?
Are there any other ways to get HTTP interface tests executed against a running server we are currently not thinking about?
Thanks a lot!

How to have a proper JMeter Maven Tomcat workflow?

I have, a few JMeter scripts, which make HTTP calls to test my own web service, written in Spring. I would like the JMeter scripts to be automatically executed for every build and test if the build is good. So, as suggested at:- http://ribblescode.wordpress.com/2012/04/16/how-to-run-jmeter-tests-with-maven/ I have set up my Maven .pom files of my Spring web service project to have the Jmeter plugin stuff defined. And, I have added my JMeter scripts to src/test/JMeter. Now, I use Eclipse as my IDE and when I have my project already running on Tomcat from within Eclipse (Run As-> Run on Server) and then do Run As->Maven Install on my project with this setup, it executes the JMeter scripts and works as intended.
However, if my web service is not already running on Tomcat, the Maven build fails as the JMeter is not able to successfully make the HTTP calls.
Now, my problem is that this setup means the JMeter script is actually making calls to the old build which is already running and not on the new build which was generated when I clicked on Run As-> Maven Install at that point in time.
So, given this scenario how do I have it so that, when I make some code change, and then do a new build using Maven, it first deploys it and then runs the JMeter script on this new build?
Maven is not intended to test the Tomcat running in your Eclipse. Jmeter is an integration test tool, so all you have to do is to haang the appropriate plugins on the appropriate maven lifecycle phases. You actions needed:
pre-integration-test phase steps
download and unzip Tomcat
deploy your packaged webapp
start tomcat
integration-test phase step
Download and unzip Jmeter (for example with maven-dependency-plugin)
run jmeter tests
post-integration-test phase
stop tomcat
Thats all you need. One tool to use could be the Cargo Maven Plugin, which helps you in deployment, start and stop.
An example is here http://www.alexecollins.com/content/jmeter-integration-test-template-pom/
If you are interested, it is also possible to collect coverage info for your JMeter tests: http://docs.codehaus.org/display/SONAR/Code+Coverage+by+Integration+Tests+for+Java+Project

Unable to run mavenized GWT application in eclipse with embedded Tomcat

I have a proof of concept GWT 2.4 / Spring 3.1 / Maven 3 / Eclipse Indigo project that I have been working on. I am able to run the application in Dev Mode using the embedded Jetty server. I am able to create a war (mvn package with help of the gwt-maven-plugin) and run the application on an installed Tomcat server. But when I try to Run as > Run on Server, it does not use/copy the generated/compiled JavaScript. When I go to the wtpwebapps dir, all is there but the generated/compiled JavaScript. The generated/compiled JavaScript is in the correct location in the maven target dir, it seems, but the eclipse process that copies the code the applcation to the wtpwebapps dir doesn't pick it up.
I'm not sure if I need to give more info to solve this problem, but any help is appreciated.
You could use a custom com.google.gwt.core.ext.ServletContainerLauncher using the embedded Tomcat API, or much more simply run your server code in Tomcat (using WTP or the tomcat7-maven-plugin) and then run DevMode in -noserver mode.
See https://developers.google.com/eclipse/docs/faq#gwt_with_maven and https://developers.google.com/web-toolkit/doc/latest/DevGuideCompilingAndDebugging#How_do_I_use_my_own_server_in_development_mode_instead_of_GWT's
I'm using the second approach in https://github.com/tbroyer/gwt-maven-archetypes
The archetype uses Jetty for now, but I'm successfully using the tomcat7-maven-plugin on a project based on the archetype (with too many tricks preventing me to set it as the default in the archetype; those tricks only being needed because of the multi-module nature of the project; but there are tricks for Jetty too).
I encountered a similar problem with GWT-dev 2.8.0-beta1 and jetty 9 in my eclipse maven project. Since the GWT-dev jar includes Jetty and other code directly in its jar (which is bad), it conflicts with the jetty I import in my project. The work around was to create a separate module just for running super dev mode, importing GWT-dev and my project's code but excluding the jetty jars. I then run super dev mode via the main below. This way, the super dev mode runs without seeing my jetty libs.
import com.google.gwt.dev.codeserver.CodeServer;
public class SuperDevModeMain {
public static void main(String[] pArgs) throws Exception {
System.out.println("Starting management-station-web-sdm!");
String[] options = "-port 9876 com.something.ms.web.MsWeb".split(" ");
CodeServer.main(options);
}
}

Testing #RooJavaBean class in Eclipse IDE with JUnit

I use Spring Roo to generate getters/setters.
When I update my class under test and then run JUnit tests from Eclipse IDE (STS), it does't see changes I have made.
For example:
java.lang.NoSuchMethodError: com.example.web.forms.UserRegistrationForm_Roo_JavaBean.ajc$interMethodDispatch1$com_datefitting_web_forms_UserRegistrationForm_Roo_JavaBean$com_example_web_forms_UserRegistrationForm$setName(Lcom/datefitting/web/forms/UserRegistrationForm;Ljava/lang/String;)V`
After running roo>perform tests everything runs fine even in IDE. In project settings there is AspectJ builder.
How to run JUnit tests of #RooJavaBean annotated class in IDE, without invoking mvn test or roo>perform tests?
Is the Roo shell open in STS while you are running? In order for your aspects to be recreated based on changes to the target types, the Roo shell must be running in the IDE. If it is running on the command line (from outside the IDE), STS will not be made aware that changes have been made to aspects and it will not be picked up in your project.

How to create stand-alone lift web application?

How to make a standalone lift application? Which tools/libraries to use? How does the performance compare to using lift application as a war in some application server?
With onejar maven plugin http://onejar-maven-plugin.googlecode.com/svn/mavensite/usage.html and maven I could package jetty and project with dependencies inside one jar.
The part of the question on performance doesn't really fit with the rest. You are primarily asking how to package the Lift application as a single JAR/WAR. This doesn't have anything to do with the runtime.
At runtime you will still be running inside a Servlet container (could be Jetty, Tomcat or a full-blown Java EE server). How you package your application won't affect the performance.
You could take a look at Hudson (a great Continuous Integration Server) to see how they deliver as a single WAR file that contains an embedded Servlet container. You can download the WAR file and run it from the command line: java -jar hudson.war
I know this is an old question, but...
If you are using sbt, I wrote a plugin to produce 'executable' wars like those mentioned above.
https://github.com/glenford/sbt-jetty-embed