├── src ├── test │ ├── java │ │ └── ru │ │ │ └── lanwen │ │ │ └── wiremock │ │ │ ├── testlib │ │ │ ├── Eticket.java │ │ │ ├── TicketApi.java │ │ │ └── TicketEndpoint.java │ │ │ ├── config │ │ │ ├── DefaultWiremockConfigFactoryTest.java │ │ │ ├── NoopWiremockCustomizerTest.java │ │ │ └── ResponseTemplateTransformerWireMockConfigFactoryTest.java │ │ │ └── ext │ │ │ ├── ValidateTest.java │ │ │ ├── CustomizationContextTest.java │ │ │ ├── WiremockResolverTest.java │ │ │ ├── WiremockResolverUnitTest.java │ │ │ └── WiremockFactoryTest.java │ └── resources │ │ └── logback-test.xml └── main │ └── java │ └── ru │ └── lanwen │ └── wiremock │ ├── ext │ ├── Validate.java │ ├── WiremockUriResolver.java │ ├── WiremockFactory.java │ └── WiremockResolver.java │ └── config │ ├── CustomizationContext.java │ ├── WiremockCustomizer.java │ └── WiremockConfigFactory.java ├── .gitignore ├── .github └── release-drafter.yml ├── .travis ├── deploy.sh └── settings.xml ├── .travis.yml ├── README.md ├── LICENSE └── pom.xml /src/test/java/ru/lanwen/wiremock/testlib/Eticket.java: -------------------------------------------------------------------------------- 1 | package ru.lanwen.wiremock.testlib; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @author lanwen (Kirill Merkushev) 7 | */ 8 | @Data 9 | public class Eticket { 10 | private String uuid; 11 | } 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IDEA Files 2 | .idea 3 | *.iml 4 | *.ipr 5 | *.iws 6 | 7 | # Maven 8 | target 9 | 10 | .gradle 11 | build 12 | 13 | # PhantomJs 14 | phantomjsdriver.log 15 | 16 | node_modules 17 | node 18 | etc 19 | coverage 20 | 21 | owm.properties 22 | 23 | -------------------------------------------------------------------------------- /.github/release-drafter.yml: -------------------------------------------------------------------------------- 1 | name-template: $NEXT_PATCH_VERSION 2 | tag-template: $NEXT_PATCH_VERSION 3 | template: | 4 | ## What’s Changed 5 | $CHANGES 6 | categories: 7 | - title: 🚀 New Features 8 | label: new-feature 9 | - title: 🐛 Bug Fixes 10 | label: bug 11 | - title: 📖 Documentation 12 | label: docs 13 | - title: 📦 Dependency updates 14 | label: dependencies 15 | -------------------------------------------------------------------------------- /src/main/java/ru/lanwen/wiremock/ext/Validate.java: -------------------------------------------------------------------------------- 1 | package ru.lanwen.wiremock.ext; 2 | 3 | import lombok.experimental.UtilityClass; 4 | 5 | /** 6 | * @author lanwen (Kirill Merkushev) 7 | */ 8 | @UtilityClass 9 | class Validate { 10 | 11 | static void validState(boolean stateValid, String message) { 12 | if (!stateValid) { 13 | throw new IllegalStateException(message); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.travis/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | if [ ! -z "$TRAVIS_TAG" ] 3 | then 4 | echo "on a tag -> set pom.xml to $TRAVIS_TAG" 5 | mvn --settings .travis/settings.xml org.codehaus.mojo:versions-maven-plugin:2.1:set -DnewVersion=$TRAVIS_TAG 1>/dev/null 2>/dev/null 6 | else 7 | echo "not on a tag -> keep SNAPSHOT version in pom.xml" 8 | fi 9 | 10 | mvn clean deploy --settings .travis/settings.xml -DskipTests=true -B -U 11 | -------------------------------------------------------------------------------- /src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} [%file:%line] - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/main/java/ru/lanwen/wiremock/config/CustomizationContext.java: -------------------------------------------------------------------------------- 1 | package ru.lanwen.wiremock.config; 2 | 3 | import lombok.Builder; 4 | import lombok.Value; 5 | import lombok.experimental.NonFinal; 6 | import org.junit.jupiter.api.extension.ExtensionContext; 7 | import org.junit.jupiter.api.extension.ParameterContext; 8 | 9 | /** 10 | * @author SourcePond (Roland Hauser) 11 | */ 12 | @Value 13 | @Builder 14 | @NonFinal 15 | public class CustomizationContext { 16 | ExtensionContext extensionContext; 17 | ParameterContext parameterContext; 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/ru/lanwen/wiremock/config/WiremockCustomizer.java: -------------------------------------------------------------------------------- 1 | package ru.lanwen.wiremock.config; 2 | 3 | import com.github.tomakehurst.wiremock.WireMockServer; 4 | import ru.lanwen.wiremock.ext.WiremockResolver; 5 | 6 | 7 | /** 8 | * Helps to create reusable customizer for injected wiremock server 9 | * 10 | * @author lanwen (Merkushev Kirill) 11 | * @see WiremockResolver.Wiremock 12 | */ 13 | public interface WiremockCustomizer { 14 | 15 | default void customize(WireMockServer server) throws Exception { 16 | // noop 17 | } 18 | 19 | default void customize(WireMockServer server, CustomizationContext ctx) throws Exception { 20 | customize(server); 21 | } 22 | 23 | class NoopWiremockCustomizer implements WiremockCustomizer { 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/ru/lanwen/wiremock/config/DefaultWiremockConfigFactoryTest.java: -------------------------------------------------------------------------------- 1 | package ru.lanwen.wiremock.config; 2 | 3 | import com.github.tomakehurst.wiremock.common.Slf4jNotifier; 4 | import com.github.tomakehurst.wiremock.core.WireMockConfiguration; 5 | import org.junit.jupiter.api.Test; 6 | import ru.lanwen.wiremock.config.WiremockConfigFactory.DefaultWiremockConfigFactory; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertEquals; 9 | 10 | /** 11 | * @author SourcePond (Roland Hauser) 12 | */ 13 | public class DefaultWiremockConfigFactoryTest { 14 | private DefaultWiremockConfigFactory factory = new DefaultWiremockConfigFactory(); 15 | 16 | @Test 17 | public void create() { 18 | WireMockConfiguration config = factory.create(); 19 | assertEquals(0, config.portNumber()); 20 | assertEquals(Slf4jNotifier.class, config.notifier().getClass()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | sudo: false 3 | 4 | jdk: 5 | - openjdk8 6 | 7 | install: 8 | - mvn --settings .travis/settings.xml install -DskipTests=true -Dgpg.skip -Dmaven.javadoc.skip=true -B -V 9 | 10 | before_install: 11 | - if [ ! -z "$GPG_SECRET_KEYS" ]; then echo $GPG_SECRET_KEYS | base64 --decode | $GPG_EXECUTABLE --import; fi 12 | - if [ ! -z "$GPG_OWNERTRUST" ]; then echo $GPG_OWNERTRUST | base64 --decode | $GPG_EXECUTABLE --import-ownertrust; fi 13 | 14 | 15 | after_success: 16 | - bash <(curl -s https://codecov.io/bash) 17 | 18 | deploy: 19 | - provider: script 20 | script: .travis/deploy.sh 21 | skip_cleanup: true 22 | on: 23 | repo: lanwen/wiremock-junit5 24 | branch: master 25 | - provider: script 26 | script: .travis/deploy.sh 27 | skip_cleanup: true 28 | on: 29 | repo: lanwen/wiremock-junit5 30 | tags: true 31 | 32 | notifications: 33 | email: false 34 | 35 | cache: 36 | directories: 37 | - $HOME/.m2 38 | 39 | -------------------------------------------------------------------------------- /.travis/settings.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | ossrh 9 | ${env.SONATYPE_USERNAME} 10 | ${env.SONATYPE_PASSWORD} 11 | 12 | 13 | 14 | 15 | ossrh 16 | 17 | true 18 | 19 | 20 | ${env.GPG_EXECUTABLE} 21 | ${env.GPG_PASSPHRASE} 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/test/java/ru/lanwen/wiremock/config/NoopWiremockCustomizerTest.java: -------------------------------------------------------------------------------- 1 | package ru.lanwen.wiremock.config; 2 | 3 | import com.github.tomakehurst.wiremock.WireMockServer; 4 | import org.junit.jupiter.api.Test; 5 | import ru.lanwen.wiremock.config.WiremockCustomizer.NoopWiremockCustomizer; 6 | 7 | import static org.mockito.Mockito.mock; 8 | import static org.mockito.Mockito.verifyZeroInteractions; 9 | 10 | /** 11 | * @author SourcePond (Roland Hauser) 12 | */ 13 | public class NoopWiremockCustomizerTest { 14 | private WireMockServer server = mock(WireMockServer.class); 15 | private CustomizationContext customizable = mock(CustomizationContext.class); 16 | private WiremockCustomizer customizer = new NoopWiremockCustomizer(); 17 | 18 | @Test 19 | public void customize() throws Exception { 20 | customizer.customize(server); 21 | verifyZeroInteractions(server, customizable); 22 | } 23 | 24 | @Test 25 | public void customizeWithContext() throws Exception { 26 | customizer.customize(server, customizable); 27 | verifyZeroInteractions(server, customizable); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/ru/lanwen/wiremock/config/ResponseTemplateTransformerWireMockConfigFactoryTest.java: -------------------------------------------------------------------------------- 1 | package ru.lanwen.wiremock.config; 2 | 3 | import com.github.tomakehurst.wiremock.core.WireMockConfiguration; 4 | import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import java.util.Map; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | /** 12 | * @author SourcePond (Roland Hauser) 13 | */ 14 | public class ResponseTemplateTransformerWireMockConfigFactoryTest { 15 | private WiremockConfigFactory.ResponseTemplateTransformerWireMockConfigFactory factory = new WiremockConfigFactory.ResponseTemplateTransformerWireMockConfigFactory(); 16 | 17 | @Test 18 | public void create() { 19 | WireMockConfiguration config = factory.create(); 20 | 21 | Map map = config.extensionsOfType(ResponseTemplateTransformer.class); 22 | assertFalse(map.isEmpty()); 23 | 24 | ResponseTemplateTransformer transformer = map.get("response-template"); 25 | assertNotNull(transformer); 26 | 27 | assertTrue(transformer.applyGlobally()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/ru/lanwen/wiremock/ext/ValidateTest.java: -------------------------------------------------------------------------------- 1 | package ru.lanwen.wiremock.ext; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.lang.reflect.Constructor; 6 | import java.lang.reflect.InvocationTargetException; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertThrows; 9 | import static ru.lanwen.wiremock.ext.Validate.validState; 10 | 11 | /** 12 | * @author SourcePond (Roland Hauser) 13 | */ 14 | public class ValidateTest { 15 | private static final String EXPECTED_MESSAGE = "Expected message"; 16 | 17 | @Test 18 | public void instantiationNotAllowed() { 19 | assertThrows(UnsupportedOperationException.class, () -> { 20 | Constructor constructor = Validate.class.getDeclaredConstructor(); 21 | constructor.setAccessible(true); 22 | try { 23 | constructor.newInstance(); 24 | } catch (final InvocationTargetException e) { 25 | throw e.getTargetException(); 26 | } 27 | }, "Exception expected"); 28 | } 29 | 30 | @Test 31 | public void verifyValidState() { 32 | // Should not throw an exception 33 | validState(true, EXPECTED_MESSAGE); 34 | assertThrows(IllegalStateException.class, () -> validState(false, EXPECTED_MESSAGE), EXPECTED_MESSAGE); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Wiremock JUnit5 2 | 3 | [![codecov](https://codecov.io/gh/lanwen/wiremock-junit5/branch/master/graph/badge.svg)](https://codecov.io/gh/lanwen/wiremock-junit5) 4 | [![Maven Central](https://img.shields.io/maven-central/v/ru.lanwen.wiremock/wiremock-junit5.svg)](https://maven-badges.herokuapp.com/maven-central/ru.lanwen.wiremock/wiremock-junit5) 5 | 6 | Simple extension to inject ready-to-use wiremock server to JUnit5 test 7 | 8 | 9 | ## Start Guide 10 | 11 | 1. Add dependency 12 | 13 | ``` 14 | ru.lanwen.wiremock:wiremock-junit5:${wiremock-junit5.version} 15 | ``` 16 | 17 | 2. Create JUnit5 test: 18 | 19 | ```java 20 | @ExtendWith({ 21 | WiremockResolver.class, 22 | WiremockUriResolver.class 23 | }) 24 | class WiremockJUnit5Test { 25 | 26 | @Test 27 | void shouldInjectWiremock(@Wiremock WireMockServer server, @WiremockUri String uri) { 28 | customize(server); // your setup 29 | SomeApiClient api = SomeApiClient.connect(uri); 30 | 31 | Response response = api.call(); 32 | assertThat(response.headers(), hasSize(1)); 33 | } 34 | } 35 | 36 | ``` 37 | 38 | ### Reuse customization 39 | 40 | With `ru.lanwen.wiremock.config.WiremockCustomizer` and `ru.lanwen.wiremock.config.WiremockConfigFactory` 41 | you can reuse logic of initial setup. 42 | 43 | Please look into test for example. 44 | 45 | ## Compatibility with JUnit5 46 | 47 | - *v1.0.1* `->` *M4* 48 | - *v1.1.0* `->` *RC2* 49 | - *v1.1.1* `->` *GA* 50 | -------------------------------------------------------------------------------- /src/main/java/ru/lanwen/wiremock/ext/WiremockUriResolver.java: -------------------------------------------------------------------------------- 1 | package ru.lanwen.wiremock.ext; 2 | 3 | import org.junit.jupiter.api.extension.ExtensionContext; 4 | import org.junit.jupiter.api.extension.ParameterContext; 5 | import org.junit.jupiter.api.extension.ParameterResolver; 6 | 7 | import java.lang.annotation.ElementType; 8 | import java.lang.annotation.Retention; 9 | import java.lang.annotation.RetentionPolicy; 10 | import java.lang.annotation.Target; 11 | 12 | 13 | /** 14 | * @author lanwen (Merkushev Kirill) 15 | */ 16 | public class WiremockUriResolver implements ParameterResolver { 17 | @Override 18 | public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { 19 | return parameterContext.getParameter().isAnnotationPresent(WiremockUri.class) 20 | && String.class.isAssignableFrom(parameterContext.getParameter().getType()); 21 | } 22 | 23 | @Override 24 | public Object resolveParameter(ParameterContext parameterContext, ExtensionContext context) { 25 | ExtensionContext.Store store = context.getStore(ExtensionContext.Namespace.create(WiremockResolver.class)); 26 | 27 | return "http://localhost:" + store.get(WiremockResolver.WIREMOCK_PORT); 28 | } 29 | 30 | 31 | /** 32 | * To target host:port injection 33 | */ 34 | @Target({ElementType.PARAMETER}) 35 | @Retention(RetentionPolicy.RUNTIME) 36 | public @interface WiremockUri { 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/ru/lanwen/wiremock/testlib/TicketApi.java: -------------------------------------------------------------------------------- 1 | package ru.lanwen.wiremock.testlib; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import feign.Feign; 5 | import feign.Logger; 6 | import feign.Param; 7 | import feign.RequestLine; 8 | import feign.Response; 9 | import feign.jackson.JacksonDecoder; 10 | import feign.jackson.JacksonEncoder; 11 | import feign.slf4j.Slf4jLogger; 12 | 13 | import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES; 14 | 15 | /** 16 | * Blackbox API 17 | * 18 | * @author lanwen (Merkushev Kirill) 19 | */ 20 | public interface TicketApi { 21 | 22 | @RequestLine("GET /ticket/{id}") 23 | Eticket get(@Param("id") String uid); // can't return both status and eticket 24 | 25 | @RequestLine("POST /ticket") 26 | Response create(Eticket uid); 27 | 28 | /** 29 | * Constructs ready-to use client 30 | * 31 | * @param uri base uri 32 | * @return instance of api class 33 | */ 34 | static TicketApi connect(String uri) { 35 | ObjectMapper mapper = new ObjectMapper() 36 | .disable(FAIL_ON_UNKNOWN_PROPERTIES); 37 | 38 | return Feign.builder() 39 | .decoder(new JacksonDecoder(mapper)) 40 | .encoder(new JacksonEncoder(mapper)) 41 | .logger(new Slf4jLogger(TicketApi.class)) 42 | .logLevel(Logger.Level.FULL) 43 | .target(TicketApi.class, uri); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/ru/lanwen/wiremock/ext/CustomizationContextTest.java: -------------------------------------------------------------------------------- 1 | package ru.lanwen.wiremock.ext; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.junit.jupiter.api.extension.ExtensionContext; 5 | import org.junit.jupiter.api.extension.ParameterContext; 6 | import ru.lanwen.wiremock.config.CustomizationContext; 7 | 8 | import static org.junit.jupiter.api.Assertions.assertSame; 9 | import static org.junit.jupiter.api.Assertions.assertTrue; 10 | import static org.mockito.Mockito.mock; 11 | import static ru.lanwen.wiremock.config.CustomizationContext.builder; 12 | 13 | /** 14 | * @author SourcePond (Roland Hauser) 15 | */ 16 | public class CustomizationContextTest { 17 | private ExtensionContext extensionContext = mock(ExtensionContext.class); 18 | private ParameterContext parameterContext = mock(ParameterContext.class); 19 | private CustomizationContext customizationContext = builder(). 20 | parameterContext(parameterContext). 21 | extensionContext(extensionContext). 22 | build(); 23 | 24 | @Test 25 | public void getExtensionContext() { 26 | assertSame(extensionContext, customizationContext.getExtensionContext()); 27 | } 28 | 29 | @Test 30 | public void getParameterContext() { 31 | assertSame(parameterContext, customizationContext.getParameterContext()); 32 | } 33 | 34 | @Test 35 | public void verifyToString() { 36 | final String toString = customizationContext.toString(); 37 | assertTrue(toString.contains(CustomizationContext.class.getSimpleName())); 38 | assertTrue(toString.contains("extensionContext")); 39 | assertTrue(toString.contains("parameterContext")); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/ru/lanwen/wiremock/config/WiremockConfigFactory.java: -------------------------------------------------------------------------------- 1 | package ru.lanwen.wiremock.config; 2 | 3 | import com.github.tomakehurst.wiremock.common.Slf4jNotifier; 4 | import com.github.tomakehurst.wiremock.core.WireMockConfiguration; 5 | import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer; 6 | import org.junit.jupiter.api.extension.ExtensionContext; 7 | import ru.lanwen.wiremock.ext.WiremockResolver; 8 | 9 | import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; 10 | 11 | /** 12 | * You can create custom config to init wiremock server in test. 13 | * 14 | * @author lanwen (Merkushev Kirill) 15 | * @see WiremockResolver.Wiremock 16 | */ 17 | public interface WiremockConfigFactory { 18 | 19 | /** 20 | * Create config to be used by injected to test method wiremock 21 | * 22 | * @return config for wiremock 23 | */ 24 | default WireMockConfiguration create() { 25 | return options().dynamicPort().notifier(new Slf4jNotifier(true)); 26 | } 27 | 28 | default WireMockConfiguration create(ExtensionContext context) { 29 | return create(); 30 | } 31 | 32 | /** 33 | * By default creates config with dynamic port only and notifier. 34 | */ 35 | class DefaultWiremockConfigFactory implements WiremockConfigFactory {} 36 | 37 | /** 38 | * By default creates config with dynamic port only, notifier and Templating Response enabled. 39 | */ 40 | class ResponseTemplateTransformerWireMockConfigFactory extends DefaultWiremockConfigFactory { 41 | 42 | @Override 43 | public WireMockConfiguration create() { 44 | return super.create() 45 | // enable Templating Response! 46 | // @see : http://wiremock.org/docs/response-templating/ 47 | .extensions(new ResponseTemplateTransformer(true)); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/ru/lanwen/wiremock/ext/WiremockResolverTest.java: -------------------------------------------------------------------------------- 1 | package ru.lanwen.wiremock.ext; 2 | 3 | import com.github.tomakehurst.wiremock.WireMockServer; 4 | import feign.Response; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | import ru.lanwen.wiremock.ext.WiremockResolver.Wiremock; 8 | import ru.lanwen.wiremock.ext.WiremockUriResolver.WiremockUri; 9 | import ru.lanwen.wiremock.testlib.Eticket; 10 | import ru.lanwen.wiremock.testlib.TicketApi; 11 | import ru.lanwen.wiremock.testlib.TicketEndpoint; 12 | 13 | import java.util.Collection; 14 | 15 | import static org.hamcrest.Matchers.hasSize; 16 | import static org.hamcrest.Matchers.notNullValue; 17 | import static org.hamcrest.core.Is.is; 18 | import static org.junit.Assert.assertThat; 19 | import static ru.lanwen.wiremock.testlib.TicketEndpoint.X_TEST_METHOD_NAME_HEADER; 20 | import static ru.lanwen.wiremock.testlib.TicketEndpoint.X_TICKET_ID_HEADER; 21 | 22 | /** 23 | * @author lanwen (Kirill Merkushev) 24 | */ 25 | @ExtendWith({ 26 | WiremockResolver.class, 27 | WiremockUriResolver.class 28 | }) 29 | class WiremockResolverTest { 30 | 31 | @Test 32 | void shouldCreateTicket(@Wiremock(customizer = TicketEndpoint.class) WireMockServer server, @WiremockUri String uri) { 33 | TicketApi api = TicketApi.connect(uri); 34 | 35 | Response response = api.create(new Eticket()); 36 | Collection testMethodNames = response.headers().get(X_TEST_METHOD_NAME_HEADER); 37 | assertThat("testMethodNames", testMethodNames, hasSize(1)); 38 | assertThat("shouldCreateTicket", is(testMethodNames.iterator().next())); 39 | 40 | Collection ids = response.headers().get(X_TICKET_ID_HEADER); 41 | 42 | assertThat("ids", ids, hasSize(1)); 43 | 44 | Eticket ticket = api.get(ids.iterator().next()); 45 | 46 | assertThat(ticket, is(notNullValue())); 47 | assertThat("response content", ticket.getUuid(), is(ids.iterator().next())); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/ru/lanwen/wiremock/ext/WiremockFactory.java: -------------------------------------------------------------------------------- 1 | package ru.lanwen.wiremock.ext; 2 | 3 | import com.github.tomakehurst.wiremock.WireMockServer; 4 | import org.junit.jupiter.api.extension.ExtensionContext; 5 | import org.junit.jupiter.api.extension.ParameterResolutionException; 6 | import ru.lanwen.wiremock.config.CustomizationContext; 7 | import ru.lanwen.wiremock.config.CustomizationContext.CustomizationContextBuilder; 8 | import ru.lanwen.wiremock.config.WiremockConfigFactory; 9 | import ru.lanwen.wiremock.config.WiremockCustomizer; 10 | import ru.lanwen.wiremock.ext.WiremockResolver.Wiremock; 11 | 12 | import static java.lang.String.format; 13 | 14 | /** 15 | * @author SourcePond (Roland Hauser) 16 | */ 17 | class WiremockFactory { 18 | 19 | public WireMockServer createServer(final Wiremock mockedServer) { 20 | return new WireMockServer(createFactoryInstance(mockedServer).create()); 21 | } 22 | 23 | public WireMockServer createServer(final Wiremock mockedServer, ExtensionContext extensionContext) { 24 | return new WireMockServer(createFactoryInstance(mockedServer).create(extensionContext)); 25 | } 26 | 27 | private WiremockConfigFactory createFactoryInstance(final Wiremock mockedServer) { 28 | try { 29 | return mockedServer.factory().newInstance(); 30 | } catch (ReflectiveOperationException e) { 31 | throw new ParameterResolutionException( 32 | format("Can't create config with given factory %s", mockedServer.factory()), 33 | e 34 | ); 35 | } 36 | } 37 | 38 | public CustomizationContextBuilder createContextBuilder() { 39 | return CustomizationContext.builder(); 40 | } 41 | 42 | public WiremockCustomizer createCustomizer(final Wiremock mockedServer) { 43 | try { 44 | return mockedServer.customizer().newInstance(); 45 | } catch (ReflectiveOperationException e) { 46 | throw new ParameterResolutionException( 47 | format("Can't customize server with given customizer %s", mockedServer.customizer()), 48 | e 49 | ); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/ru/lanwen/wiremock/testlib/TicketEndpoint.java: -------------------------------------------------------------------------------- 1 | package ru.lanwen.wiremock.testlib; 2 | 3 | import com.github.tomakehurst.wiremock.WireMockServer; 4 | import org.junit.jupiter.api.extension.ExtensionContext; 5 | import ru.lanwen.wiremock.config.CustomizationContext; 6 | import ru.lanwen.wiremock.config.WiremockCustomizer; 7 | 8 | import java.util.UUID; 9 | 10 | import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; 11 | import static com.github.tomakehurst.wiremock.client.WireMock.get; 12 | import static com.github.tomakehurst.wiremock.client.WireMock.post; 13 | import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; 14 | import static java.lang.String.format; 15 | 16 | /** 17 | * @author lanwen (Merkushev Kirill) 18 | */ 19 | public class TicketEndpoint implements WiremockCustomizer { 20 | 21 | public static final String X_TICKET_ID_HEADER = "X-Ticket-ID"; 22 | public static final String X_TEST_METHOD_NAME_HEADER = "X-TestMethodName"; 23 | 24 | @Override 25 | public void customize(WireMockServer server, CustomizationContext customizationContext) { 26 | ExtensionContext context = customizationContext.getExtensionContext(); 27 | String uuid = UUID.randomUUID().toString(); 28 | String testMethodName = context.getTestMethod().get().getName(); 29 | 30 | server.stubFor( 31 | post(urlPathEqualTo("/ticket")) 32 | .willReturn(aResponse() 33 | .withStatus(201) 34 | .withHeader( 35 | "Location", 36 | format("http://localhost:%s/ticket/%s", server.port(), uuid) 37 | ) 38 | .withHeader(X_TEST_METHOD_NAME_HEADER, testMethodName) 39 | .withHeader(X_TICKET_ID_HEADER, uuid)) 40 | ); 41 | 42 | server.stubFor( 43 | get(urlPathEqualTo("/ticket/" + uuid)) 44 | .willReturn(aResponse() 45 | .withStatus(200) 46 | .withHeader("Content-Type", "application/json") 47 | .withHeader(X_TEST_METHOD_NAME_HEADER, testMethodName) 48 | .withHeader(X_TICKET_ID_HEADER, uuid) 49 | .withBody(format("{ \"uuid\": \"%s\" }", uuid)) 50 | ) 51 | ); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/ru/lanwen/wiremock/ext/WiremockResolver.java: -------------------------------------------------------------------------------- 1 | package ru.lanwen.wiremock.ext; 2 | 3 | import com.github.tomakehurst.wiremock.WireMockServer; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.junit.jupiter.api.extension.AfterEachCallback; 6 | import org.junit.jupiter.api.extension.ExtensionContext; 7 | import org.junit.jupiter.api.extension.ExtensionContext.Namespace; 8 | import org.junit.jupiter.api.extension.ParameterContext; 9 | import org.junit.jupiter.api.extension.ParameterResolutionException; 10 | import org.junit.jupiter.api.extension.ParameterResolver; 11 | import ru.lanwen.wiremock.config.CustomizationContext; 12 | import ru.lanwen.wiremock.config.WiremockConfigFactory; 13 | import ru.lanwen.wiremock.config.WiremockCustomizer; 14 | 15 | import java.lang.annotation.ElementType; 16 | import java.lang.annotation.Retention; 17 | import java.lang.annotation.RetentionPolicy; 18 | import java.lang.annotation.Target; 19 | 20 | import static java.lang.String.format; 21 | import static java.util.Optional.ofNullable; 22 | import static ru.lanwen.wiremock.ext.Validate.validState; 23 | 24 | /** 25 | * @author lanwen (Merkushev Kirill) 26 | */ 27 | @Slf4j 28 | public class WiremockResolver implements ParameterResolver, AfterEachCallback { 29 | static final String WIREMOCK_PORT = "wiremock.port"; 30 | 31 | private final WiremockFactory wiremockFactory; 32 | private WireMockServer server; 33 | 34 | public WiremockResolver() { 35 | this(new WiremockFactory()); 36 | } 37 | 38 | WiremockResolver(final WiremockFactory wiremockFactory) { 39 | this.wiremockFactory = wiremockFactory; 40 | } 41 | 42 | @Override 43 | public void afterEach(ExtensionContext testExtensionContext) throws Exception { 44 | if (server == null || !server.isRunning()) { 45 | return; 46 | } 47 | 48 | server.resetRequests(); 49 | server.resetToDefaultMappings(); 50 | log.info("Stopping wiremock server on localhost:{}", server.port()); 51 | server.stop(); 52 | } 53 | 54 | @Override 55 | public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext context) { 56 | return parameterContext.getParameter().isAnnotationPresent(Wiremock.class); 57 | } 58 | 59 | @Override 60 | public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { 61 | validState( 62 | !ofNullable(server).map(WireMockServer::isRunning).orElse(false), 63 | "Can't inject more than one server" 64 | ); 65 | 66 | Wiremock mockedServer = parameterContext.getParameter().getAnnotation(Wiremock.class); 67 | 68 | server = wiremockFactory.createServer(mockedServer, extensionContext); 69 | server.start(); 70 | 71 | CustomizationContext customizationContext = wiremockFactory.createContextBuilder(). 72 | parameterContext(parameterContext). 73 | extensionContext(extensionContext). 74 | build(); 75 | 76 | try { 77 | wiremockFactory.createCustomizer(mockedServer).customize(server, customizationContext); 78 | } catch (Exception e) { 79 | throw new ParameterResolutionException( 80 | format("Can't customize server with given customizer %s", mockedServer.customizer()), 81 | e 82 | ); 83 | } 84 | 85 | ExtensionContext.Store store = extensionContext.getStore(Namespace.create(WiremockResolver.class)); 86 | store.put(WIREMOCK_PORT, server.port()); 87 | 88 | log.info("Started wiremock server on localhost:{}", server.port()); 89 | return server; 90 | } 91 | 92 | /** 93 | * Enables injection of wiremock server to test. 94 | * Helps to configure instance with {@link #factory} and {@link #customizer} methods 95 | */ 96 | @Target({ElementType.PARAMETER}) 97 | @Retention(RetentionPolicy.RUNTIME) 98 | public @interface Wiremock { 99 | /** 100 | * @return class which defines on how to create config 101 | */ 102 | Class factory() default WiremockConfigFactory.DefaultWiremockConfigFactory.class; 103 | 104 | /** 105 | * @return class which defines on how to customize server after start 106 | */ 107 | Class customizer() default WiremockCustomizer.NoopWiremockCustomizer.class; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/test/java/ru/lanwen/wiremock/ext/WiremockResolverUnitTest.java: -------------------------------------------------------------------------------- 1 | package ru.lanwen.wiremock.ext; 2 | 3 | import com.github.tomakehurst.wiremock.WireMockServer; 4 | import org.junit.jupiter.api.BeforeEach; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | import org.junit.jupiter.api.extension.ExtensionContext; 8 | import org.junit.jupiter.api.extension.ParameterContext; 9 | import org.junit.jupiter.api.extension.ParameterResolutionException; 10 | import org.mockito.Mock; 11 | import org.mockito.junit.jupiter.MockitoExtension; 12 | import ru.lanwen.wiremock.config.CustomizationContext; 13 | import ru.lanwen.wiremock.config.CustomizationContext.CustomizationContextBuilder; 14 | import ru.lanwen.wiremock.config.WiremockCustomizer; 15 | import ru.lanwen.wiremock.ext.WiremockResolver.Wiremock; 16 | 17 | import java.lang.reflect.Parameter; 18 | 19 | import static org.junit.Assert.assertFalse; 20 | import static org.junit.Assert.assertSame; 21 | import static org.junit.Assert.assertTrue; 22 | import static org.junit.jupiter.api.Assertions.fail; 23 | import static org.mockito.Mockito.doThrow; 24 | import static org.mockito.Mockito.verifyZeroInteractions; 25 | import static org.mockito.Mockito.when; 26 | 27 | /** 28 | * @author SourcePond (Roland Hauser) 29 | */ 30 | @ExtendWith(MockitoExtension.class) 31 | public class WiremockResolverUnitTest { 32 | @Mock 33 | private WiremockFactory wiremockFactory; 34 | @Mock 35 | private WireMockServer server; 36 | @Mock 37 | private CustomizationContextBuilder customizationContextBuilder; 38 | @Mock 39 | private CustomizationContext customizationContext; 40 | @Mock 41 | private WiremockCustomizer customizer; 42 | @Mock 43 | private ExtensionContext extensionContext; 44 | @Mock 45 | private ParameterContext parameterContext; 46 | @Mock 47 | private Wiremock mockedServer; 48 | private Parameter serverParameter; 49 | private WiremockResolver resolver; 50 | 51 | private void supportedMethod(@Wiremock WireMockServer server) { 52 | 53 | } 54 | 55 | private void unsupportedMethod(WireMockServer server) { 56 | 57 | } 58 | 59 | @BeforeEach 60 | public void setup() throws Exception { 61 | serverParameter = getClass().getDeclaredMethod("supportedMethod", WireMockServer.class).getParameters()[0]; 62 | mockedServer = serverParameter.getAnnotation(Wiremock.class); 63 | resolver = new WiremockResolver(wiremockFactory); 64 | } 65 | 66 | @Test 67 | public void verifyDefaultConstructor() { 68 | // Make code coverage happy 69 | new WiremockResolver(); 70 | } 71 | 72 | @Test 73 | public void afterEachServerIsNull() throws Exception { 74 | resolver.afterEach(extensionContext); 75 | verifyZeroInteractions(extensionContext); 76 | } 77 | 78 | 79 | @Test 80 | public void supportsParameter() throws Exception { 81 | when(parameterContext.getParameter()).thenReturn(serverParameter); 82 | 83 | assertTrue(resolver.supportsParameter(parameterContext, extensionContext)); 84 | serverParameter = getClass().getDeclaredMethod("unsupportedMethod", WireMockServer.class).getParameters()[0]; 85 | when(parameterContext.getParameter()).thenReturn(serverParameter); 86 | assertFalse(resolver.supportsParameter(parameterContext, extensionContext)); 87 | } 88 | 89 | @Test 90 | public void resolveParameterFailed() throws Exception { 91 | when(wiremockFactory.createServer(mockedServer, extensionContext)).thenReturn(server); 92 | when(wiremockFactory.createContextBuilder()).thenReturn(customizationContextBuilder); 93 | when(wiremockFactory.createCustomizer(mockedServer)).thenReturn(customizer); 94 | when(customizationContextBuilder.extensionContext(extensionContext)).thenReturn(customizationContextBuilder); 95 | when(customizationContextBuilder.parameterContext(parameterContext)).thenReturn(customizationContextBuilder); 96 | when(customizationContextBuilder.build()).thenReturn(customizationContext); 97 | when(parameterContext.getParameter()).thenReturn(serverParameter); 98 | 99 | final Exception expected = new Exception(); 100 | doThrow(expected).when(customizer).customize(server, customizationContext); 101 | try { 102 | resolver.resolveParameter(parameterContext, extensionContext); 103 | fail("Exception expected"); 104 | } catch (final ParameterResolutionException e) { 105 | assertSame(expected, e.getCause()); 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/test/java/ru/lanwen/wiremock/ext/WiremockFactoryTest.java: -------------------------------------------------------------------------------- 1 | package ru.lanwen.wiremock.ext; 2 | 3 | import com.github.tomakehurst.wiremock.WireMockServer; 4 | import com.github.tomakehurst.wiremock.core.WireMockConfiguration; 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.extension.ExtensionContext; 8 | import org.junit.jupiter.api.extension.ParameterResolutionException; 9 | import ru.lanwen.wiremock.config.CustomizationContext.CustomizationContextBuilder; 10 | import ru.lanwen.wiremock.config.WiremockConfigFactory; 11 | import ru.lanwen.wiremock.config.WiremockCustomizer; 12 | import ru.lanwen.wiremock.ext.WiremockResolver.Wiremock; 13 | 14 | import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; 15 | import static org.junit.jupiter.api.Assertions.assertEquals; 16 | import static org.junit.jupiter.api.Assertions.assertNotNull; 17 | import static org.junit.jupiter.api.Assertions.assertNotSame; 18 | import static org.junit.jupiter.api.Assertions.assertSame; 19 | import static org.junit.jupiter.api.Assertions.assertThrows; 20 | import static org.junit.jupiter.api.extension.ExtensionContext.Namespace; 21 | import static org.junit.jupiter.api.extension.ExtensionContext.Store; 22 | import static org.mockito.Mockito.mock; 23 | import static org.mockito.Mockito.when; 24 | 25 | /** 26 | * @author SourcePond (Roland Hauser) 27 | */ 28 | public class WiremockFactoryTest { 29 | 30 | public static class StubClass implements WiremockConfigFactory, WiremockCustomizer { 31 | 32 | @Override 33 | public WireMockConfiguration create() { 34 | return OPTIONS; 35 | } 36 | 37 | @Override 38 | public void customize(WireMockServer server) { 39 | // noop 40 | } 41 | } 42 | 43 | public static class FactoryUsingContext implements WiremockConfigFactory { 44 | @Override 45 | public WireMockConfiguration create(ExtensionContext context) { 46 | Integer port = context.getStore(Namespace.GLOBAL) 47 | .get("port", Integer.class); 48 | return options().port(port); 49 | } 50 | } 51 | 52 | private static class PrivateClassNotAllowed implements WiremockConfigFactory, WiremockCustomizer { 53 | 54 | @Override 55 | public WireMockConfiguration create() { 56 | return null; 57 | } 58 | 59 | @Override 60 | public void customize(WireMockServer server) { 61 | // noop 62 | } 63 | } 64 | 65 | private static final WireMockConfiguration OPTIONS = options(); 66 | private final Wiremock mockedServer = mock(Wiremock.class); 67 | private final WiremockFactory factory = new WiremockFactory(); 68 | 69 | @BeforeEach 70 | public void setup() { 71 | when(mockedServer.customizer()).thenReturn((Class) StubClass.class); 72 | } 73 | 74 | @Test 75 | public void createServer() { 76 | when(mockedServer.factory()).thenReturn((Class) StubClass.class); 77 | WireMockServer srv1 = factory.createServer(mockedServer); 78 | WireMockServer srv2 = factory.createServer(mockedServer); 79 | assertNotNull(srv1); 80 | assertNotNull(srv2); 81 | assertSame(OPTIONS, srv1.getOptions()); 82 | assertSame(OPTIONS, srv2.getOptions()); 83 | assertNotSame(srv1, srv2); 84 | } 85 | 86 | @Test 87 | public void createServerWithContext() { 88 | ExtensionContext ctx = mock(ExtensionContext.class); 89 | Store store = mock(Store.class); 90 | when(ctx.getStore(Namespace.GLOBAL)).thenReturn(store); 91 | when(store.get("port", Integer.class)).thenReturn(9874); 92 | 93 | when(mockedServer.factory()).thenReturn((Class) FactoryUsingContext.class); 94 | 95 | WireMockServer srv1 = factory.createServer(mockedServer, ctx); 96 | WireMockServer srv2 = factory.createServer(mockedServer, ctx); 97 | assertNotNull(srv1); 98 | assertNotNull(srv2); 99 | assertEquals(9874, srv1.getOptions().portNumber()); 100 | assertEquals(9874, srv2.getOptions().portNumber()); 101 | assertNotSame(srv1, srv2); 102 | } 103 | 104 | @Test 105 | public void configFactoryCouldNotBeInstantiated() { 106 | when(mockedServer.factory()).thenReturn((Class) PrivateClassNotAllowed.class); 107 | assertThrows(ParameterResolutionException.class, 108 | () -> factory.createServer(mockedServer, null), 109 | "Can't create config with given factory class ru.lanwen.wiremock.ext.WiremockFactoryTest$PrivateClassNotAllowed"); 110 | } 111 | 112 | @Test 113 | public void createContextBuilder() { 114 | CustomizationContextBuilder builder1 = factory.createContextBuilder(); 115 | CustomizationContextBuilder builder2 = factory.createContextBuilder(); 116 | assertNotNull(builder1); 117 | assertNotNull(builder2); 118 | assertNotSame(builder1, builder2); 119 | } 120 | 121 | @Test 122 | public void createCustomizer() { 123 | WiremockCustomizer customizer1 = factory.createCustomizer(mockedServer); 124 | WiremockCustomizer customizer2 = factory.createCustomizer(mockedServer); 125 | assertNotNull(customizer1); 126 | assertNotNull(customizer2); 127 | assertNotSame(customizer1, customizer2); 128 | } 129 | 130 | @Test 131 | public void customizerCouldNotBeInstantiated() { 132 | when(mockedServer.customizer()).thenReturn((Class) PrivateClassNotAllowed.class); 133 | assertThrows(ParameterResolutionException.class, 134 | () -> factory.createCustomizer(mockedServer), 135 | "Can't customize server with given customizer class ru.lanwen.wiremock.ext.WiremockFactoryTest$PrivateClassNotAllowed"); 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2017 lanwen (Kirill Merkushev) 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | ru.lanwen.wiremock 6 | wiremock-junit5 7 | 2.0.0-SNAPSHOT 8 | jar 9 | 10 | https://github.com/lanwen/wiremock-junit5 11 | wiremock-junit5-root 12 | Wiremock JUnit5 Extension 13 | 14 | 15 | 16 | Apache 2.0 17 | https://raw.githubusercontent.com/lanwen/wiremock-junit5/master/LICENSE 18 | repo 19 | 20 | 21 | 22 | 23 | 24 | lanwen 25 | Merkushev Kirill 26 | 27 | Developer 28 | 29 | 30 | 31 | 32 | 33 | git@github.com:lanwen/wiremock-junit5.git 34 | scm:git:git@github.com:lanwen/wiremock-junit5.git 35 | scm:git:git@github.com:lanwen/wiremock-junit5.git 36 | 37 | 38 | 39 | UTF-8 40 | 2.16.0 41 | 9.6.0 42 | 1.16.20 43 | 1.2.3 44 | 0.7.7.201606060606 45 | 5.1.0 46 | 1.1.0 47 | 2.18.3 48 | 49 | 50 | 51 | 52 | 53 | 54 | org.junit.jupiter 55 | junit-jupiter-api 56 | ${junit.jupiter.version} 57 | 58 | 59 | 60 | com.github.tomakehurst 61 | wiremock 62 | ${wiremock.version} 63 | 64 | 65 | 66 | org.projectlombok 67 | lombok 68 | ${lombok.version} 69 | 70 | 71 | 72 | 73 | io.github.openfeign 74 | feign-core 75 | ${feign.version} 76 | 77 | 78 | 79 | io.github.openfeign 80 | feign-jackson 81 | ${feign.version} 82 | 83 | 84 | 85 | io.github.openfeign 86 | feign-slf4j 87 | ${feign.version} 88 | 89 | 90 | 91 | org.hamcrest 92 | hamcrest-all 93 | 1.3 94 | 95 | 96 | 97 | ch.qos.logback 98 | logback-classic 99 | ${logback.version} 100 | 101 | 102 | 103 | org.mockito 104 | mockito-core 105 | ${mockito.version} 106 | 107 | 108 | org.mockito 109 | mockito-junit-jupiter 110 | ${mockito.version} 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | org.projectlombok 119 | lombok 120 | provided 121 | 122 | 123 | 124 | org.junit.jupiter 125 | junit-jupiter-api 126 | provided 127 | 128 | 129 | 130 | com.github.tomakehurst 131 | wiremock 132 | provided 133 | 134 | 135 | 136 | io.github.openfeign 137 | feign-core 138 | test 139 | 140 | 141 | 142 | io.github.openfeign 143 | feign-jackson 144 | test 145 | 146 | 147 | 148 | io.github.openfeign 149 | feign-slf4j 150 | test 151 | 152 | 153 | 154 | org.hamcrest 155 | hamcrest-all 156 | test 157 | 158 | 159 | 160 | ch.qos.logback 161 | logback-classic 162 | test 163 | 164 | 165 | 166 | org.mockito 167 | mockito-core 168 | test 169 | 170 | 171 | org.mockito 172 | mockito-junit-jupiter 173 | test 174 | 175 | 176 | 177 | 178 | 179 | 180 | org.apache.maven.plugins 181 | maven-compiler-plugin 182 | 3.7.0 183 | 184 | 1.8 185 | 1.8 186 | 187 | 188 | 189 | 190 | org.apache.maven.plugins 191 | maven-surefire-plugin 192 | 2.19.1 193 | 194 | 195 | org.junit.platform 196 | junit-platform-surefire-provider 197 | ${junit.platform.version} 198 | 199 | 200 | org.junit.jupiter 201 | junit-jupiter-engine 202 | ${junit.jupiter.version} 203 | 204 | 205 | 206 | 207 | 208 | org.jacoco 209 | jacoco-maven-plugin 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | org.jacoco 220 | jacoco-maven-plugin 221 | ${jacoco.version} 222 | 223 | 224 | jacoco-agent-for-tests 225 | 226 | prepare-agent 227 | 228 | 229 | argLine 230 | 231 | 232 | 233 | jacoco-report-tests 234 | test 235 | 236 | report 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | ossrh 249 | https://oss.sonatype.org/content/repositories/snapshots 250 | 251 | 252 | ossrh 253 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 254 | 255 | 256 | 257 | 258 | 259 | 260 | deployment 261 | 262 | true 263 | 264 | 265 | 266 | 267 | org.apache.maven.plugins 268 | maven-gpg-plugin 269 | 1.6 270 | 271 | 272 | sign-artifacts 273 | verify 274 | 275 | sign 276 | 277 | 278 | 279 | 280 | 281 | org.sonatype.plugins 282 | nexus-staging-maven-plugin 283 | 1.6.8 284 | true 285 | 286 | ossrh 287 | https://oss.sonatype.org/ 288 | true 289 | 290 | 291 | 292 | 293 | org.apache.maven.plugins 294 | maven-source-plugin 295 | 3.0.1 296 | 297 | 298 | attach-sources 299 | 300 | jar-no-fork 301 | 302 | 303 | 304 | 305 | 306 | 307 | org.apache.maven.plugins 308 | maven-javadoc-plugin 309 | 3.0.0 310 | 311 | 312 | attach-javadocs 313 | 314 | jar 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | --------------------------------------------------------------------------------