This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pipeline { | |
// run on jenkins nodes tha has java 8 label | |
agent { label 'java8' } | |
// global env variables | |
environment { | |
EMAIL_RECIPIENTS = '[email protected]' | |
} | |
stages { | |
stage('Build with unit testing') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stage('Integration tests') { | |
// Run the maven build | |
steps { | |
script { | |
def mvnHome = tool 'Maven 3.3.9' | |
if (isUnix()) { | |
// to skip unit testing execution | |
sh "'${mvnHome}/bin/mvn' verify -Dunit-tests.skip=true" | |
} else { | |
bat(/"${mvnHome}\bin\mvn" verify -Dunit-tests.skip=true/) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* how the feature is executed | |
*/ | |
public class GetHealthStep extends CucumberRoot { | |
private ResponseEntity<String> response; // output | |
@When("^the client calls /health$") | |
public void the_client_issues_GET_health() throws Throwable { | |
response = template.getForEntity("/health", String.class); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* main spring boot integration test with integration test profile | |
*/ | |
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | |
@ActiveProfiles("INTEGRATION_TEST") | |
@ContextConfiguration | |
public class CucumberRoot { | |
@Autowired | |
protected TestRestTemplate template; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* the main class for cucumber where you configure where the features are defined and which formats of reports needed to be generated | |
*/ | |
@RunWith(Cucumber.class) | |
@CucumberOptions(features = {"src/test/resources/features"}, format = {"pretty", "html:target/reports/cucumber/html", | |
"json:target/cucumber.json", "usage:target/usage.jsonx", "junit:target/junit.xml"}) | |
public class CucumberIntegrationIT { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feature: the health can be retrieved | |
Scenario: client makes call to GET /health | |
When the client calls /health | |
Then the client receives response status code of 200 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ApplicationSanityCheck{ | |
@Rule | |
public final RetryRule retry = new RetryRule(); | |
private int port = 8080; | |
private RestTemplate template; | |
private URL base; | |
@Before | |
public void setUp() throws Exception { | |
this.base = new URL("http://localhost:" + port + "/"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class RetryRule implements TestRule { | |
@NotNull | |
private Throwable[] errors = new Throwable[0]; | |
private int currentAttempt = 0; | |
@Override | |
public Statement apply(final Statement base, final Description description) { | |
final Retry retryAnnotation = description.getAnnotation(Retry.class); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* An exception thrown to signal that a retry operation (executed via {@link RetryRule}) has retried more than the | |
* allowed number of times, and has still failed. | |
*/ | |
public final class RetryException extends RuntimeException { | |
private RetryException(@NotNull String message) { | |
super(message); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.test.SpringBootSample.retry; | |
/** | |
* Created by id961900 on 05/09/2017. | |
*/ | |
import java.lang.annotation.ElementType; | |
import java.lang.annotation.Retention; | |
import java.lang.annotation.RetentionPolicy; | |
import java.lang.annotation.Target; |