Skip to content

Instantly share code, notes, and snippets.

View Romeh's full-sized avatar

MRomeh Romeh

View GitHub Profile
pipeline {
// run on jenkins nodes tha has java 8 label
agent { label 'java8' }
// global env variables
environment {
EMAIL_RECIPIENTS = 'mahmoud.romeh@test.com'
}
stages {
stage('Build with unit testing') {
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/)
/**
* 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);
}
/**
* 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;
/**
* 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 {
}
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
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 + "/");
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);
/**
* 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);
}
@Romeh
Romeh / Retry.java
Last active December 3, 2017 17:43
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;