maven surefire plugin system properties are always null - maven

I have created a maven plugin whose purpose is to bring up an application, which run in pre-integration phase, it sets a system level prop called "LOOKUPGROUPS". I want this property to be available in my integration tests. However everytime i try to get this property it always comes as null.
Also i have noticed in my task manager that whenever my build reaches the integration stage and my integration tests start to execute a new java process comes up.

I think it works by adding properties in MaverSession.getUserProperties.

Related

Maven failsafe plugin - propagate system property set by maven plugin in pre-integration-test

I've have a following problem and was not able to find any answer elsewhere:
I'm using https://github.com/joelittlejohn/embedmongo-maven-plugin for starting mongo db server in pre-integration-test phase and then run integration tests that interacts with mongo db on specified port. However, with original version of plugin I'm forced to hard code port in plugin configuration which can clash with some other processes running on same machine and effectively denies parallel executions of modules that uses the same port.
Therefore I've prepared a patch https://github.com/jumarko/embedmongo-maven-plugin/compare/jma-random-port that enables me to start mongo db on random port.
However, I'm not able to pass allocated port (allocated by plugin in pre-integration-test phase) to the integration itself running in forked JVM in integration-test phase (see https://github.com/jumarko/embedmongo-maven-plugin/blob/3462a909b546eab6afe1f87691ac49336ddab845/src/test/java/com/github/joelittlejohn/embedmongo/MongoIT.java).
I tried to set allocated port to system property (https://github.com/jumarko/embedmongo-maven-plugin/compare/jma-random-port#L1R201) but this property is not propagated to the forked JVM. As a workaround, I even tried to set this property in failsafe plugin configuration (https://github.com/jumarko/embedmongo-maven-plugin/compare/jma-random-port#L0R104) but it didn't have any effect (I guess that propery resolving happens before the embedmongo-plugin actually sets it).
Is there any way how to propagate system property set dynamically at runtime (by embedmongo-maven-plugin) to the forked JVM used for integration tests execution?
Are there any (possibly better) alternatives how to pass port the mongo db is running on to the integration test itself?
Note: Integration test is able to access system property if failsafe plugin forkMode is set to never but this is not an option for me.
In your plugin you can set the project properties that will propagate to the failsafe plugin configuration by using the AbstractMojo.project field:
project.getProperties().put(propertyName,propertyValue);
I do this exact thing with a work project and it does what you want.
So if you have run
project.getProperties().put("the.port", 1234)
in the mojo then you will be able to use the property ${the.port} in the failsafe configuration.

Bamboo doesn't recognize test in my Spring project

I have a Spring project (Apache CXF, Spring, Hibernate, Maven ...) hosted on BitBucket and I'm trying to use Bamboo as my CI server. My idea is deploying the code directly to Heroku from Bamboo so that deploying time is automated.
I made a plan with a couple of tasks to achieve this. First I have a Source Code Checkout task and a builder task. Both of them are working, code is compiling and test are passing, I can see that in the task log. The problem is that Bamboo doesn't seem to recognize the tests (it marks the task are testless).
I have also tried to create a new JUnit test task and it's even worst. Log shows that everything is working properly but Bamboo marks the plan as a failure after the test task is executed.
Any ideas?
Not sure which version of Bamboo you're using, but in the version that we have, you have to turn on unit test result evaluation on the Builder tab. Please see the attached screenshot, and make sure that this is enabled, and the directory setting is pointing to the directory where Maven Surefire creates the test results (in XML format).

How to run tests after deployment using Maven?

I'm trying to decide how to create a set of Acceptance Tests for a Java-EE web application.
Here's the setup: Maven is used to generate a WAR file and deploy it into Glassfish. On deployment, the MySQL database schema is automatically updated from model classes using Hibernate ("hbm2ddl=auto" option).
The Acceptance Tests need to test the deployed code by invoking various methods and checking the results are as expected(*). We wrote an additional set of packages to hook into an existing system so the Acceptance Tests should show how these can be integrated into the existing codebase.
(*) This may sound more like Unit/Integration Testing but they are Acceptance Tests in the sense that they should prove what we did works and they need to be run after deployment so there is a database in place.
From the above, my current thinking is to use JUnit to check expected values etc. The bit I'm struggling with is how to invoke these tests after deployment. "deploy" is Maven's last phase so not sure if this is possible?
Just because that phase is called deploy doesn't mean that you have to use it for deploying your application for testing. In fact, it should only be used for "deploying" the artifact to a maven repository. Read through the description of the Maven lifecycle phases and you'll see that there are some phases dedicated to your use case:
pre-integration-test
integration-test
post-integration-test
Have a look at the Cargo Maven plugin. It's made to deploy your WAR file to various containers for testing. They definitely show demos of use cases like the one you describe on your site. I would expect that ultimately, you can be using Cargo to deploy to your container ( from one of the earlier phases like pre-integration-test )
Note, Jenkins also has a plugin that is a wrapper around the Cargo plugin. So you might do what you need via Jenkins. Also note, you don't need to run your Jenkins build job as mvn clean deploy. You could have one build job that just runs the integration tests, and fires another "deploy" job only when it succeeds.
If you really need to do stuff after deployment, then you can either run failsafe, and by implication JUnit) as part of the deploy phase.
What I usually do, if to have seperate module. So, you can have one maven project, which contains your project and a separate 'deployment test' project. Then, building the parent project will build and run your war and then run the deployment tests. You can use junit as normal.
The second fits better into jenkins because you'll still have a single project as well.

Maven/Spring: Automatic Test Run of Generated WAR

Let's say we have a project that consists of some Eclipse-projects and Spring 3.1, the final result is a WAR-file. We use WTP for development. All the unit tests and integration tests are working (our Maven does this automatically). The project runs in WTP with a local configuration. In other words everything looks as if it is ready to roll.
Now we want to test run that WAR-file with different sets of configuration files for different platforms. The test should only start the context and see if that causes any issues (missing/misspelt property in a property file, too many beans for auto-wiring, ...). AFAIK it isn't necessary to have access to (or it accessible to) the outside world. Basically it should only start the context, close it and continue with the next configuration. If one context fails, the build should break.
How should we do this? Can we do this with Maven? Something external?
EDIT: Forgot to say: We will run our stuff with Tomcat 6.
Sounds like you are talking about integration test.
You should look at the failsafe plug for this:
http://maven.apache.org/surefire/maven-failsafe-plugin/usage.html
Using jetty and maven-failsafe-plugin You need to bind one of
jetty:run, jetty:run-exploded or jetty:run-war to the
pre-integration-test phase with deamon set to true, bind
failsafe:integration-test to the integration-test phase, bind
jetty:stop to the post-integration-test phase and finally bind
failsafe:verify to the verify phase. Here is an example:
Another possibility is a selenium test. Selenium tests require the war to be deployed and running before the tests are run. So there are plugins that do all this.
Then you would have a very simple selenium test case that just made a simple http request to the app to see if it was running.
You would use a different profile for each different configuration you wanted to test.

maven cargo integration test - how to get cargo.hostname or profile?

I'm using Maven 2 w/ cargo to deploy to different remote tomcats depending on the maven profile used.
I also have integration tests (junit w/ remote webservice calls) that I would like to automatically run.
Question: How do I setup my test code to be able to read either the cargo.hostname (preferred, changed property value based on maven profile) or the maven profile actived so it knows which url to go run the tests against?
Specifically, this is in java in the test case.
Thanks!
Either you define a fixed value for the cargo.hostname (not the best; but sometimes it workds well, cause using a fixed test server) or better define an appropriate property in Maven for it and put the information also into a properties file which will be filtered by the build process in the src/test/resources folder which can be read before the real integration tests.

Resources