7
votes

I have an application composed of multiple maven war projects.

I have another maven project that runs JUnit integration tests against the manually-started tomcat-deployed multi-war application using org.springframework.web.client.RestTemplate calls.

However, I'd like my integration test project to actually start my multi-war application (once for the duration of the entire suite) before it runs my tests...in spring-boot!

From my integration test project, I'd like to be able to run all the war projects together as a spring-boot application, each with their own contextPaths (e.g. localhost:8080/a for project 'a', localhost:8080/b for project 'b', etc. ), and without changing the original war projects (that are not (yet) spring-boot aware). If I can't make these projects run from my integration test project in spring-boot without changing them then I'd at least like to minimize the use of spring-boot dependencies and configuration in packaged war files...as much as possible.

I was able to get my integration test project to depend on a single war project, start it up and run tests against it...but I was unsuccessful getting two war projects running together in spring-boot under separate contextPaths.

Any suggestions would be welcome!

Here are some of the resources I've been using to put this together:

1
I'm confused. It sounds like the wars you are trying to run are not using Spring Boot. Assuming that is correct, why are you trying to use Spring Boot to run them? I may well have misunderstood. Could you expand a bit on what you're trying to achieve and why you think Spring Boot will help you to achieve it?Andy Wilkinson
Good question @AndyWilkinson. You're correct. The wars are not using spring boot and I don't plan to make them so. They'll be deployed in WebLogic for production. However, I want to run integration tests against a fully deployed app (both locally and in a Jenkins CI build) in such a way that I don't have to manually start up all the wars in tomcat first...rather something like 'mvn test'. I thought that spring boot might be a good candidate for this. Does that help?sdoxsee
I don't think Spring Boot is the right tool for the job. Can't you use Tomcat's maven plugin and configure it to deploy multiple web apps? Something like this: stackoverflow.com/a/13193937/1384297Andy Wilkinson

1 Answers

6
votes

As per Andy's suggestion, I went with the Tomcat7 Maven Plugin and it worked just fine. The Jetty Maven Plugin was another option (and better documented IMO) although I couldn't find a way to avoid having to provide a "path" to my WAR files. The Tomcat7 Maven Plugin, let me load up my WARs from my local .m2 repository. I should also say that the following links were helpful as well...

Here's part of my integration test project pom...

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.17</version>
            <configuration>
                <skipTests>true</skipTests>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.17</version>
            <configuration>
                <includes>
                    <include>**/*Test*</include>
                </includes>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <path>/</path>
                <webapps>
                    <webapp>
                        <groupId>com.mycompany</groupId>
                        <artifactId>app1</artifactId>
                        <version>${project.version}</version>
                        <type>war</type>
                        <asWebapp>true</asWebapp>
                    </webapp>
                    <webapp>
                        <groupId>com.mycompany</groupId>
                        <artifactId>app2</artifactId>
                        <version>${project.version}</version>
                        <type>war</type>
                        <asWebapp>true</asWebapp>
                    </webapp>
                </webapps>
            </configuration>
            <executions>
                <execution>
                    <id>start-tomcat</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>run-war</goal>
                    </goals>
                    <configuration>
                        <fork>true</fork>
                    </configuration>
                </execution>
                <execution>
                    <id>stop-tomcat</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>shutdown</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>