Add property to skip integration tests

Generalize the `skip` property to start and stop goals so that one
can control if the Spring Boot app is starting via a configuration
property.

Note that this only controls the Spring Boot Maven plugin and the
failsafe maven plugin should be updated accordingly.

Closes gh-4922
This commit is contained in:
Stephane Nicoll 2016-01-18 09:45:06 +01:00
parent 6c5441d041
commit 7842f50e30
6 changed files with 93 additions and 0 deletions

View File

@ -0,0 +1 @@
invoker.goals=clean verify

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.boot.maven.it</groupId>
<artifactId>start-stop-skip</artifactId>
<version>0.0.1.BUILD-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,28 @@
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.test;
/**
* This sample should not run at all
*/
public class SampleApplication {
public static void main(String[] args) throws Exception {
System.out.println("Ooops, I haz been run");
}
}

View File

@ -0,0 +1,5 @@
import static org.junit.Assert.assertFalse
def file = new File(basedir, "build.log")
assertFalse 'Application should not have run', file.text.contains("Ooops, I haz been run")
assertFalse 'Should not attempt to stop the app', file.text.contains('Stopping application')

View File

@ -151,6 +151,13 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
@Parameter(property = "useTestClasspath", defaultValue = "false")
private Boolean useTestClasspath;
/**
* Skip the execution.
* @since 1.3.2
*/
@Parameter(defaultValue = "false")
private boolean skip;
/**
* Specify if the application process should be forked.
* @return {@code true} if the application process should be forked
@ -170,6 +177,10 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (this.skip) {
getLog().debug("skipping run as per configuration.");
return;
}
final String startClassName = getStartClass();
run(startClassName);
}

View File

@ -62,8 +62,19 @@ public class StopMojo extends AbstractMojo {
@Parameter
private int jmxPort = 9001;
/**
* Skip the execution.
* @since 1.3.2
*/
@Parameter(defaultValue = "false")
private boolean skip;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (this.skip) {
getLog().debug("skipping stop as per configuration.");
return;
}
getLog().info("Stopping application...");
try {
if (Boolean.TRUE.equals(this.fork)) {