Skip to content

Commit

Permalink
WireMock Integration Tests (#67)
Browse files Browse the repository at this point in the history
* Add CI for amd64 builds

* Add initial integration test

* Stabilize integration tests

* Make the image tag configurable

* Stub for testing samples

* Preserve the directory structure when copying files

* Add Integration test for the "Random" sample

* Add HTTPs smoke test

* Use Maven for integration testing in the CI Pipeline

* Fix the version parameter

* Reduce logging level

* Workaround override of the exposed port

* Disable verbose logging

* Properly disable the JUnit 5 test

* Remove the unnecessary Maven goals

* Do not print downloads to shorten the log
  • Loading branch information
oleg-nenashev authored Jul 12, 2023
1 parent 79b6be3 commit f19748f
Show file tree
Hide file tree
Showing 16 changed files with 642 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:

jobs:
docker-build:
runs-on: ubuntu-latest
strategy:
matrix:
versions:
- CONTEXT: .
TAGS:
- wiremock/wiremock:test
TEST_WIREMOCK_VERSION: test
- CONTEXT: alpine
TAGS:
- wiremock/wiremock:test-alpine
TEST_WIREMOCK_VERSION: test-alpine
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Checkout sources
uses: actions/checkout@main

# TODO: Re-enable if rate limit becomes an issues
# - name: Login to Docker Hub
# uses: docker/login-action@v2
# with:
# username: wiremock
# password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Build Wiremock Docker image
uses: docker/build-push-action@v4
with:
context: ${{ matrix.versions.CONTEXT }}
load: true
file: ${{ matrix.versions.CONTEXT }}/Dockerfile
tags: ${{ matrix.versions.TAGS[0] }}

- name: Build Wiremock Docker image
run: docker buildx build --tag ${{ matrix.versions.TAGS[0] }} --load ${{ matrix.versions.CONTEXT }} --file ${{ matrix.versions.CONTEXT }}/Dockerfile

- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'temurin'
cache: maven

- name: Run integration test
working-directory: test/integration-tests
run: mvn -B -ntp package verify --file pom.xml -DargLine="-Dit.wiremock-version=${{ matrix.versions.TEST_WIREMOCK_VERSION }}"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
.settings
.idea
.history

test/integration-tests/target
test/integration-tests/integration-tests.iml
6 changes: 6 additions & 0 deletions samples/random/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Sample - Random Response Field

> **WARNING:** This sample uses the [WireMock Body Transformer](https://github.com/opentable/wiremock-body-transformer) extension.
> This extension is currently archived and not supported.
> No stability guaranteed provided.
> Use the sample with caution
4 changes: 4 additions & 0 deletions test/integration-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
= WireMock Docker integration tests

This is just for test!
To be deduplicated with Testcontainers.
173 changes: 173 additions & 0 deletions test/integration-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<?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.wiremock.docker</groupId>
<artifactId>integration-tests</artifactId>
<description>Integration Tests for WireMock Docker</description>
<version>1.0-SNAPSHOT</version>

<licenses>
<license>
<name>Apache License Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
<distribution>repo</distribution>
</license>
</licenses>

<properties>
<java.version>11</java.version>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.source>${java.version}</maven.compiler.source>
<wiremock-testcontainers.version>1.0-alpha-5</wiremock-testcontainers.version>
<testcontainers.version>1.18.3</testcontainers.version>
<junit.version>5.9.3</junit.version>
<assertj.version>3.24.2</assertj.version>
<awaitility.version>4.2.0</awaitility.version>
<project.scm.id>github</project.scm.id>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-bom</artifactId>
<version>${testcontainers.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>${junit.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-bom</artifactId>
<version>${assertj.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<!-- Fix dependency convergence [logback-classic vs junit] -->
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.7</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.wiremock</groupId>
<artifactId>wiremock-testcontainers-java</artifactId>
<version>${wiremock-testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>${awaitility.version}</version>
<scope>test</scope>
</dependency> <!--
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.3.7</version>
<scope>provided</scope>
<optional>true</optional>
</dependency> -->
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
</plugin>

<!-- For testing WireMock extensions -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<id>copy</id>
<phase>compile</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.opentable</groupId>
<artifactId>wiremock-body-transformer</artifactId>
<version>1.1.3</version>
</artifactItem>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock-webhooks-extension</artifactId>
<version>2.35.0</version>
</dependency>
</artifactItems>
<outputDirectory>${project.build.directory}/test-wiremock-extension</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<scm>
<connection>scm:git:git://github.com/wiremock/wiremock-docker.git</connection>
<developerConnection>scm:git:https://github.com/wiremock/wiremock-docker.git</developerConnection>
<url>https://github.com/wiremock/wiremock-docker</url>
<tag>${scmTag}</tag>
</scm>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.wiremock.docker.it;

public class Stub {

// No-op
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (C) 2023 WireMock Inc, Oleg Nenashev and all project contributors
*
* 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.wiremock.docker.it;

import org.junit.jupiter.api.Test;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;

import org.wiremock.integrations.testcontainers.WireMockContainer;

import static org.assertj.core.api.Assertions.assertThat;

@Testcontainers(parallel = true)
class SmokeTest {

@Container
public WireMockContainer wiremockServer = new WireMockContainer(TestConfig.WIREMOCK_IMAGE_TAG)
.withMapping("hello", SmokeTest.class, "hello-world.json")
.withMapping("hello-resource", SmokeTest.class, "hello-world-resource.json")
.withFileFromResource("hello-world-resource-response.xml", SmokeTest.class,
"hello-world-resource-response.xml");

@Test
public void helloWorld() throws Exception {
final HttpClient client = HttpClient.newBuilder().build();
final HttpRequest request = HttpRequest.newBuilder()
.uri(new URI(wiremockServer.getUrl("hello")))
.timeout(Duration.ofSeconds(10))
.header("Content-Type", "application/json")
.GET().build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

assertThat(response.body())
.as("Wrong response body")
.contains("Hello, world!");
}

@Test
public void helloWorldFromFile() throws Exception {
final HttpClient client = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_1_1)
.build();

HttpRequest request = HttpRequest.newBuilder()
.uri(new URI(wiremockServer.getUrl("hello-from-file")))
.timeout(Duration.ofSeconds(10))
.header("Content-Type", "application/json")
.GET()
.build();

HttpResponse<String> response =
client.send(request, HttpResponse.BodyHandlers.ofString());

assertThat(response.body())
.as("Wrong response body")
.contains("Hello, world!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.wiremock.docker.it;

import java.io.File;
import java.nio.file.Path;

/**
* WireMock Test configuration.
* To be set by the test runner to configure proper execution.
*/
public class TestConfig {

/**
* Docker image tag to be used for testing.
*/
public static String WIREMOCK_IMAGE_TAG =
System.getProperty("it.wiremock-version", "2.35.0");

public static String SAMPLES_DIR =
System.getProperty("it.samples-path", "../../samples");

public static Path getSamplesPath() {
return new File(SAMPLES_DIR).toPath();
}
}
Loading

0 comments on commit f19748f

Please sign in to comment.