diff --git a/build.gradle b/build.gradle index bafb9fc..0b396c5 100644 --- a/build.gradle +++ b/build.gradle @@ -9,14 +9,22 @@ buildscript { classpath 'se.bjurr.gradle:gradle-scripts:2.+' } } + +project.ext.buildConfig = [ + sourceCompatibility: 17, + targetCompatibility: 17, +] apply from: project.buildscript.classLoader.getResource('main.gradle').toURI() dependencies { - api 'com.github.tomakehurst:wiremock:2.27.2' - implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.15.0' - implementation 'javax:javaee-api:8.0.1' + api 'org.wiremock:wiremock:3.5.2' + compileOnly 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.17.0' + compileOnly 'jakarta.ws.rs:jakarta.ws.rs-api:3.1.0' + testImplementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.17.0' + testImplementation 'jakarta.ws.rs:jakarta.ws.rs-api:3.1.0' + testImplementation 'org.glassfish.jaxb:jaxb-runtime:4.0.5' testImplementation 'junit:junit:4.13.2' - testImplementation 'org.assertj:assertj-core:3.24.2' - testImplementation 'io.rest-assured:rest-assured:5.3.0' + testImplementation 'org.assertj:assertj-core:3.25.3' + testImplementation 'io.rest-assured:rest-assured:5.4.0' } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 249e583..d64cd49 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ae04661..a80b22c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index a69d9cb..1aa94a4 100755 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +80,11 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +131,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,11 +198,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/gradlew.bat b/gradlew.bat index 53a6b23..7101f8e 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -42,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -56,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/src/main/java/com/github/tomakehurst/wiremock/client/JaxrsInvocationHandler.java b/src/main/java/com/github/tomakehurst/wiremock/client/JaxrsInvocationHandler.java index 5c03ebf..d9e8feb 100644 --- a/src/main/java/com/github/tomakehurst/wiremock/client/JaxrsInvocationHandler.java +++ b/src/main/java/com/github/tomakehurst/wiremock/client/JaxrsInvocationHandler.java @@ -1,6 +1,18 @@ package com.github.tomakehurst.wiremock.client; import com.github.tomakehurst.wiremock.http.RequestMethod; +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.DELETE; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.HEAD; +import jakarta.ws.rs.OPTIONS; +import jakarta.ws.rs.PATCH; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.PUT; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.QueryParam; import java.lang.annotation.Annotation; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; @@ -8,18 +20,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.HEAD; -import javax.ws.rs.OPTIONS; -import javax.ws.rs.PATCH; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; class JaxrsInvocationHandler implements InvocationHandler { @@ -27,7 +27,6 @@ class JaxrsInvocationHandler implements InvocationHandler { private Class returnType; private String path; private List queryParams; - private List pathParams; private List requestContentTypeList; private List responseContentTypeList; private Object postObject; @@ -35,60 +34,60 @@ class JaxrsInvocationHandler implements InvocationHandler { @Override public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { - this.requestMethod = getRequestMethod(method); + this.requestMethod = this.getRequestMethod(method); this.returnType = method.getReturnType(); - this.queryParams = createQueryParams(method.getParameters(), args); - this.pathParams = createPathParams(method.getParameters(), args); - this.path = substituteParams(createPath(method), queryParams, pathParams); - this.requestContentTypeList = getRequestContentTypeList(method); - this.responseContentTypeList = getResponseContentTypeList(method); - this.postObject = findPostObject(method.getParameters(), args).orElse(null); + this.queryParams = this.createQueryParams(method.getParameters(), args); + final List pathParams = this.createPathParams(method.getParameters(), args); + this.path = this.substituteParams(this.createPath(method), pathParams); + this.requestContentTypeList = this.getRequestContentTypeList(method); + this.responseContentTypeList = this.getResponseContentTypeList(method); + this.postObject = this.findPostObject(method.getParameters(), args).orElse(null); return null; } public RequestMethod getRequestMethod() { - return requestMethod; + return this.requestMethod; } public String getPath() { - return path; + return this.path; } public List getRequestContentTypeList() { - return requestContentTypeList; + return this.requestContentTypeList; } public List getResponseContentTypeList() { - return responseContentTypeList; + return this.responseContentTypeList; } public Class getReturnType() { - return returnType; + return this.returnType; } public List getQueryParams() { - return queryParams; + return this.queryParams; } public Optional findPostObject() { - return Optional.ofNullable(postObject); + return Optional.ofNullable(this.postObject); } RequestMethod getRequestMethod(final Method method) { - if (findAnnotation(method, GET.class).isPresent()) { + if (this.findAnnotation(method, GET.class).isPresent()) { return RequestMethod.GET; - } else if (findAnnotation(method, POST.class).isPresent()) { + } else if (this.findAnnotation(method, POST.class).isPresent()) { return RequestMethod.POST; - } else if (findAnnotation(method, PUT.class).isPresent()) { + } else if (this.findAnnotation(method, PUT.class).isPresent()) { return RequestMethod.PUT; - } else if (findAnnotation(method, DELETE.class).isPresent()) { + } else if (this.findAnnotation(method, DELETE.class).isPresent()) { return RequestMethod.DELETE; - } else if (findAnnotation(method, PATCH.class).isPresent()) { + } else if (this.findAnnotation(method, PATCH.class).isPresent()) { return RequestMethod.PATCH; - } else if (findAnnotation(method, HEAD.class).isPresent()) { + } else if (this.findAnnotation(method, HEAD.class).isPresent()) { return RequestMethod.HEAD; - } else if (findAnnotation(method, OPTIONS.class).isPresent()) { + } else if (this.findAnnotation(method, OPTIONS.class).isPresent()) { return RequestMethod.OPTIONS; } throw new RuntimeException("Cannot find request method of " + method.getName()); @@ -116,8 +115,8 @@ private List getResponseContentTypeList(final Method method) { private String createPath(final Method method) { final Optional classPath = - findAnnotation(method.getDeclaringClass().getAnnotations(), Path.class); - final Optional methodPath = findAnnotation(method, Path.class); + this.findAnnotation(method.getDeclaringClass().getAnnotations(), Path.class); + final Optional methodPath = this.findAnnotation(method, Path.class); String str = ""; if (classPath.isPresent()) { str += classPath.get().value(); @@ -133,7 +132,7 @@ private String createPath(final Method method) { private Optional findAnnotation(final Method method, final Class findAnnotation) { final Annotation[] methodAnnotations = method.getAnnotations(); - return findAnnotation(methodAnnotations, findAnnotation); + return this.findAnnotation(methodAnnotations, findAnnotation); } @SuppressWarnings("unchecked") @@ -148,7 +147,7 @@ private Optional findAnnotation( } private List createQueryParams( - final Parameter[] parameters, final Object[] args) { + final Parameter[] parameters, final Object... args) { final List queryParams = new ArrayList<>(); if (parameters == null || args == null) { return queryParams; @@ -160,7 +159,7 @@ private List createQueryParams( final Object arg = args[i]; final Parameter param = parameters[i]; final Optional paramAnnotation = - findAnnotation(param.getAnnotations(), QueryParam.class); + this.findAnnotation(param.getAnnotations(), QueryParam.class); if (paramAnnotation.isPresent()) { final String name = paramAnnotation.get().value(); final InvocationParam invocationParam = new InvocationParam(name, arg); @@ -170,7 +169,7 @@ private List createQueryParams( return queryParams; } - private Optional findPostObject(final Parameter[] parameters, final Object[] args) { + private Optional findPostObject(final Parameter[] parameters, final Object... args) { if (parameters == null || args == null) { return Optional.empty(); } @@ -181,8 +180,8 @@ private Optional findPostObject(final Parameter[] parameters, final Obje final Object arg = args[i]; final Parameter param = parameters[i]; if ( // - !findAnnotation(param.getAnnotations(), PathParam.class).isPresent() // - && !findAnnotation(param.getAnnotations(), QueryParam.class).isPresent()) { + !this.findAnnotation(param.getAnnotations(), PathParam.class).isPresent() // + && !this.findAnnotation(param.getAnnotations(), QueryParam.class).isPresent()) { return Optional.ofNullable(arg); } } @@ -190,7 +189,7 @@ private Optional findPostObject(final Parameter[] parameters, final Obje } private List createPathParams( - final Parameter[] parameters, final Object[] args) { + final Parameter[] parameters, final Object... args) { final List pathParams = new ArrayList<>(); if (parameters == null || args == null) { return pathParams; @@ -202,7 +201,7 @@ private List createPathParams( final Object arg = args[i]; final Parameter param = parameters[i]; final Optional paramAnnotation = - findAnnotation(param.getAnnotations(), PathParam.class); + this.findAnnotation(param.getAnnotations(), PathParam.class); if (paramAnnotation.isPresent()) { final String name = paramAnnotation.get().value(); final InvocationParam invocationParam = new InvocationParam(name, arg); @@ -212,10 +211,7 @@ private List createPathParams( return pathParams; } - private String substituteParams( - final String createPath, - final List queryParams, - final List pathParams) { + private String substituteParams(final String createPath, final List pathParams) { String substituted = createPath; for (final InvocationParam pathParam : pathParams) { if (pathParam.getValue() == null) { diff --git a/src/main/java/com/github/tomakehurst/wiremock/client/JaxrsInvocationMappingBuilder.java b/src/main/java/com/github/tomakehurst/wiremock/client/JaxrsInvocationMappingBuilder.java index 5591cbf..4f1eda3 100644 --- a/src/main/java/com/github/tomakehurst/wiremock/client/JaxrsInvocationMappingBuilder.java +++ b/src/main/java/com/github/tomakehurst/wiremock/client/JaxrsInvocationMappingBuilder.java @@ -4,8 +4,14 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.github.tomakehurst.wiremock.matching.*; -import javax.ws.rs.core.HttpHeaders; +import com.github.tomakehurst.wiremock.matching.ContentPattern; +import com.github.tomakehurst.wiremock.matching.EqualToJsonPattern; +import com.github.tomakehurst.wiremock.matching.EqualToPattern; +import com.github.tomakehurst.wiremock.matching.EqualToXmlPattern; +import com.github.tomakehurst.wiremock.matching.RegexPattern; +import com.github.tomakehurst.wiremock.matching.StringValuePattern; +import com.github.tomakehurst.wiremock.matching.UrlPattern; +import jakarta.ws.rs.core.HttpHeaders; public class JaxrsInvocationMappingBuilder extends BasicMappingBuilder { @@ -15,7 +21,7 @@ public JaxrsInvocationMappingBuilder(final JaxrsInvocationHandler handler) { super(handler.getRequestMethod(), new UrlPattern(new RegexPattern(get(handler)), true)); this.handler = handler; - String requestBodyContentType = getRequestBodyContentType(handler); + final String requestBodyContentType = this.getRequestBodyContentType(handler); if (requestBodyContentType != null) { this.withHeader(HttpHeaders.CONTENT_TYPE, new EqualToPattern(requestBodyContentType)); } @@ -25,7 +31,8 @@ public JaxrsInvocationMappingBuilder(final JaxrsInvocationHandler handler) { HttpHeaders.ACCEPT, new EqualToPattern(handler.getResponseContentTypeList().get(0))); } - ContentPattern requestBodyContentPattern = createRequestBodyContentPattern(handler); + final ContentPattern requestBodyContentPattern = + this.createRequestBodyContentPattern(handler); if (requestBodyContentPattern != null) { this.withRequestBody(requestBodyContentPattern); } @@ -35,18 +42,19 @@ public JaxrsInvocationMappingBuilder(final JaxrsInvocationHandler handler) { if (value == null) { continue; } - final StringValuePattern valuePattern = getStringValuePattern(value); + final StringValuePattern valuePattern = this.getStringValuePattern(value); this.withQueryParam(qp.getName(), valuePattern); } } - private ContentPattern createRequestBodyContentPattern(JaxrsInvocationHandler handler) { + private ContentPattern createRequestBodyContentPattern( + final JaxrsInvocationHandler handler) { if (!handler.findPostObject().isPresent()) { return null; } - Object requestBody = handler.findPostObject().get(); - String requestBodyContentType = getRequestBodyContentType(handler); + final Object requestBody = handler.findPostObject().get(); + final String requestBodyContentType = this.getRequestBodyContentType(handler); if (requestBodyContentType == null) { if (!(requestBody instanceof String)) { throw new IllegalArgumentException( @@ -77,7 +85,7 @@ private ContentPattern createRequestBodyContentPattern(JaxrsInvocationHa } } - private String getRequestBodyContentType(JaxrsInvocationHandler handler) { + private String getRequestBodyContentType(final JaxrsInvocationHandler handler) { if (handler.getRequestContentTypeList().isEmpty()) { return null; } @@ -91,7 +99,7 @@ private static String get(final JaxrsInvocationHandler handler) { public BasicMappingBuilder willReturn( final ResponseDefinitionBuilder responseDefBuilder, final Object responseObject) { - final Class expectedReturnType = handler.getReturnType(); + final Class expectedReturnType = this.handler.getReturnType(); if (responseDefBuilder.status >= 200 && responseDefBuilder.status <= 299) { if (!expectedReturnType.isAssignableFrom(responseObject.getClass())) { throw new RuntimeException( @@ -101,14 +109,14 @@ public BasicMappingBuilder willReturn( responseDefBuilder.withBody(toJson(responseObject)); - decorateOnWillReturn(responseDefBuilder); + this.decorateOnWillReturn(responseDefBuilder); return super.willReturn(responseDefBuilder); } @Override public BasicMappingBuilder willReturn(final ResponseDefinitionBuilder responseDefBuilder) { - final Class expectedReturnType = handler.getReturnType(); + final Class expectedReturnType = this.handler.getReturnType(); if (responseDefBuilder.status >= 200 && responseDefBuilder.status <= 299) { if (!expectedReturnType.getName().equals("void")) { throw new RuntimeException( @@ -118,31 +126,29 @@ public BasicMappingBuilder willReturn(final ResponseDefinitionBuilder responseDe } } - decorateOnWillReturn(responseDefBuilder); + this.decorateOnWillReturn(responseDefBuilder); return super.willReturn(responseDefBuilder); } private void decorateOnWillReturn(final ResponseDefinitionBuilder responseDefBuilder) { - if (!handler.getResponseContentTypeList().isEmpty()) { + if (!this.handler.getResponseContentTypeList().isEmpty()) { responseDefBuilder.withHeader( - HttpHeaders.CONTENT_TYPE, handler.getResponseContentTypeList().get(0)); + HttpHeaders.CONTENT_TYPE, this.handler.getResponseContentTypeList().get(0)); } } private StringValuePattern getStringValuePattern(final Object value) { - StringValuePattern valuePattern = null; final Boolean ignoreArrayOrder = true; final Boolean ignoreExtraElements = true; if (value.getClass() != Object.class && (value.getClass().isPrimitive() || value.getClass().getName().startsWith("java.lang."))) { - valuePattern = new EqualToPattern(value.toString()); + return new EqualToPattern(value.toString()); } else { final String json = toJson(value); - valuePattern = new EqualToJsonPattern(json, ignoreArrayOrder, ignoreExtraElements); + return new EqualToJsonPattern(json, ignoreArrayOrder, ignoreExtraElements); } - return valuePattern; } private static String toJson(final Object object) { @@ -153,7 +159,8 @@ private static String toXml(final Object object) { return serializeWithObjectMapper(object, new XmlMapper()); } - private static String serializeWithObjectMapper(Object object, ObjectMapper objectMapper) { + private static String serializeWithObjectMapper( + final Object object, final ObjectMapper objectMapper) { try { if (object instanceof String) { return (String) object; diff --git a/src/main/java/com/github/tomakehurst/wiremock/client/JaxrsInvocationMappingBuilderFactory.java b/src/main/java/com/github/tomakehurst/wiremock/client/JaxrsInvocationMappingBuilderFactory.java index 180d5d5..1f76371 100644 --- a/src/main/java/com/github/tomakehurst/wiremock/client/JaxrsInvocationMappingBuilderFactory.java +++ b/src/main/java/com/github/tomakehurst/wiremock/client/JaxrsInvocationMappingBuilderFactory.java @@ -8,9 +8,10 @@ public static JaxrsInvocationMappingBuilder create( final Class resource, final ResourceInvocation invocation) { final JaxrsInvocationHandler handler = new JaxrsInvocationHandler(); + final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); @SuppressWarnings("unchecked") final T recordingProxy = - (T) Proxy.newProxyInstance(resource.getClassLoader(), new Class[] {resource}, handler); + (T) Proxy.newProxyInstance(contextClassLoader, new Class[] {resource}, handler); invocation.invoke(recordingProxy); diff --git a/src/main/java/com/github/tomakehurst/wiremock/client/WireMockJaxrs.java b/src/main/java/com/github/tomakehurst/wiremock/client/WireMockJaxrs.java deleted file mode 100644 index 72e9496..0000000 --- a/src/main/java/com/github/tomakehurst/wiremock/client/WireMockJaxrs.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.github.tomakehurst.wiremock.client; - -public class WireMockJaxrs { - public static JaxrsInvocationMappingBuilder invocation( - final Class resource, final ResourceInvocation invocation) { - return JaxrsInvocationMappingBuilderFactory.create(resource, invocation); - } -} diff --git a/src/main/java/com/github/tomakehurst/wiremock/jaxrs/api/WireMockJaxrs.java b/src/main/java/com/github/tomakehurst/wiremock/jaxrs/api/WireMockJaxrs.java new file mode 100644 index 0000000..1d04ecd --- /dev/null +++ b/src/main/java/com/github/tomakehurst/wiremock/jaxrs/api/WireMockJaxrs.java @@ -0,0 +1,12 @@ +package com.github.tomakehurst.wiremock.jaxrs.api; + +import com.github.tomakehurst.wiremock.client.JaxrsInvocationMappingBuilder; +import com.github.tomakehurst.wiremock.client.JaxrsInvocationMappingBuilderFactory; +import com.github.tomakehurst.wiremock.client.ResourceInvocation; + +public class WireMockJaxrs { + public static JaxrsInvocationMappingBuilder invocation( + final Class resource, final ResourceInvocation invocation) { + return JaxrsInvocationMappingBuilderFactory.create(resource, invocation); + } +} diff --git a/src/test/java/com/github/tomakehurst/wiremock/client/RequestMethodsTest.java b/src/test/java/com/github/tomakehurst/wiremock/client/RequestMethodsTest.java index 89bc751..2e52415 100644 --- a/src/test/java/com/github/tomakehurst/wiremock/client/RequestMethodsTest.java +++ b/src/test/java/com/github/tomakehurst/wiremock/client/RequestMethodsTest.java @@ -1,17 +1,17 @@ package com.github.tomakehurst.wiremock.client; import com.github.tomakehurst.wiremock.http.RequestMethod; +import jakarta.ws.rs.DELETE; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.HEAD; +import jakarta.ws.rs.OPTIONS; +import jakarta.ws.rs.PATCH; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.PUT; import java.lang.reflect.Method; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.HEAD; -import javax.ws.rs.OPTIONS; -import javax.ws.rs.PATCH; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; import org.junit.Test; public class RequestMethodsTest { @@ -45,7 +45,7 @@ public void testThatRequestMethodsCanBeFound() { Arrays.asList(RequestMethod.values()).stream() .map((it) -> it.getName()) .collect(Collectors.toList()); - reqMethodsNotFound.removeAll(Arrays.asList("TRACE", "ANY")); + reqMethodsNotFound.removeAll(Arrays.asList("TRACE", "ANY", "GET_OR_HEAD")); final JaxrsInvocationHandler sut = new JaxrsInvocationHandler(); for (final Method method : AllRequestMethodsResouce.class.getMethods()) { final String foundReqMethod = sut.getRequestMethod(method).getName(); diff --git a/src/test/java/se/bjurr/wiremock/example/WiremockJaxrsExamplesTest.java b/src/test/java/se/bjurr/wiremock/example/WiremockJaxrsExamplesTest.java deleted file mode 100644 index ccbceca..0000000 --- a/src/test/java/se/bjurr/wiremock/example/WiremockJaxrsExamplesTest.java +++ /dev/null @@ -1,133 +0,0 @@ -package se.bjurr.wiremock.example; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; -import static com.github.tomakehurst.wiremock.client.WireMockJaxrs.invocation; -import static io.restassured.RestAssured.given; -import static javax.servlet.http.HttpServletResponse.SC_ACCEPTED; -import static org.assertj.core.api.Assertions.assertThat; - -import com.github.tomakehurst.wiremock.stubbing.StubMapping; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; -import java.util.logging.Logger; -import org.junit.Test; -import se.bjurr.wiremock.test.support.AcceptanceTestBase; - -public class WiremockJaxrsExamplesTest extends AcceptanceTestBase { - private static Logger LOG = Logger.getLogger(WiremockJaxrsExamplesTest.class.getSimpleName()); - - @Test - public void getItems() { - final List responseObject = Arrays.asList(new ItemDTO("pong")); - final StubMapping sm = - stubFor( // - invocation(ItemResouce.class, (r) -> r.getItems()) // - .willReturn(aResponse().withStatus(SC_ACCEPTED), responseObject)); - - final String actual = StubMapping.buildJsonStringFor(clean(sm)); - - final String expected = - "{\n" - + " \"id\" : \"d68fb4e2-48ed-40d2-bc73-0a18f54f3ece\",\n" - + " \"request\" : {\n" - + " \"urlPattern\" : \".*/list$\",\n" - + " \"method\" : \"GET\",\n" - + " \"headers\" : {\n" - + " \"Accept\" : {\n" - + " \"equalTo\" : \"application/json\"\n" - + " }\n" - + " }\n" - + " },\n" - + " \"response\" : {\n" - + " \"status\" : 202,\n" - + " \"body\" : \"[ {\\n \\\"str\\\" : \\\"pong\\\",\\n \\\"id\\\" : 0\\n} ]\",\n" - + " \"headers\" : {\n" - + " \"Content-Type\" : \"application/json\"\n" - + " }\n" - + " },\n" - + " \"uuid\" : \"d68fb4e2-48ed-40d2-bc73-0a18f54f3ece\"\n" - + "}"; - - assertThat(actual) // - .isEqualTo(expected); - - LOG.info("\n" + expected); - - given() // - .accept("application/json") // - .get("/list") // - .then() - .assertThat() // - .statusCode(SC_ACCEPTED) // - .and() // - .contentType("application/json"); - } - - @Test - public void createItem() { - final ItemDTO responseObject = new ItemDTO("the item"); - responseObject.setId(123); - final ItemDTO postedItem = new ItemDTO("the item"); - - final StubMapping sm = - stubFor( // - invocation(ItemResouce.class, (r) -> r.post(postedItem)) // - .willReturn(aResponse().withStatus(SC_ACCEPTED), responseObject)); - - final String actual = StubMapping.buildJsonStringFor(clean(sm)); - - final String expected = - "{\n" - + " \"id\" : \"d68fb4e2-48ed-40d2-bc73-0a18f54f3ece\",\n" - + " \"request\" : {\n" - + " \"urlPattern\" : \".*/create$\",\n" - + " \"method\" : \"POST\",\n" - + " \"headers\" : {\n" - + " \"Content-Type\" : {\n" - + " \"equalTo\" : \"application/json\"\n" - + " },\n" - + " \"Accept\" : {\n" - + " \"equalTo\" : \"application/json\"\n" - + " }\n" - + " },\n" - + " \"bodyPatterns\" : [ {\n" - + " \"equalToJson\" : \"{\\n \\\"str\\\" : \\\"the item\\\",\\n \\\"id\\\" : 0\\n}\",\n" - + " \"ignoreArrayOrder\" : true,\n" - + " \"ignoreExtraElements\" : true\n" - + " } ]\n" - + " },\n" - + " \"response\" : {\n" - + " \"status\" : 202,\n" - + " \"body\" : \"{\\n \\\"str\\\" : \\\"the item\\\",\\n \\\"id\\\" : 123\\n}\",\n" - + " \"headers\" : {\n" - + " \"Content-Type\" : \"application/json\"\n" - + " }\n" - + " },\n" - + " \"uuid\" : \"d68fb4e2-48ed-40d2-bc73-0a18f54f3ece\"\n" - + "}"; - - assertThat(actual) // - .isEqualTo(expected); - - LOG.info("\n" + expected); - - given() // - .accept("application/json") // - .contentType("application/json") // - .request() // - .body(postedItem) // - .post("/create") // - .then() - .assertThat() // - .contentType("application/json") // - .statusCode(SC_ACCEPTED); - } - - private StubMapping clean(final StubMapping sm) { - sm.setUuid(UUID.fromString("d68fb4e2-48ed-40d2-bc73-0a18f54f3ece")); - sm.setId(UUID.fromString("d68fb4e2-48ed-40d2-bc73-0a18f54f3ece")); - return sm; - } -} diff --git a/src/test/java/se/bjurr/wiremock/example/ItemDTO.java b/src/test/java/se/bjurr/wiremock/test/example_apis/resource_with_dto/ItemDTO.java similarity index 81% rename from src/test/java/se/bjurr/wiremock/example/ItemDTO.java rename to src/test/java/se/bjurr/wiremock/test/example_apis/resource_with_dto/ItemDTO.java index 4895823..75bc90b 100644 --- a/src/test/java/se/bjurr/wiremock/example/ItemDTO.java +++ b/src/test/java/se/bjurr/wiremock/test/example_apis/resource_with_dto/ItemDTO.java @@ -1,4 +1,4 @@ -package se.bjurr.wiremock.example; +package se.bjurr.wiremock.test.example_apis.resource_with_dto; public class ItemDTO { private final String str; diff --git a/src/test/java/se/bjurr/wiremock/example/ItemResouce.java b/src/test/java/se/bjurr/wiremock/test/example_apis/resource_with_dto/ItemResouce.java similarity index 56% rename from src/test/java/se/bjurr/wiremock/example/ItemResouce.java rename to src/test/java/se/bjurr/wiremock/test/example_apis/resource_with_dto/ItemResouce.java index 2ef6900..eedcd6e 100644 --- a/src/test/java/se/bjurr/wiremock/example/ItemResouce.java +++ b/src/test/java/se/bjurr/wiremock/test/example_apis/resource_with_dto/ItemResouce.java @@ -1,12 +1,12 @@ -package se.bjurr.wiremock.example; +package se.bjurr.wiremock.test.example_apis.resource_with_dto; +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; import java.util.List; -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; @Path("/") public interface ItemResouce { diff --git a/src/test/java/se/bjurr/wiremock/test/integration/get/StringDTO.java b/src/test/java/se/bjurr/wiremock/test/example_apis/resource_with_get_and_params/StringDTO.java similarity index 69% rename from src/test/java/se/bjurr/wiremock/test/integration/get/StringDTO.java rename to src/test/java/se/bjurr/wiremock/test/example_apis/resource_with_get_and_params/StringDTO.java index c380465..61e1b92 100644 --- a/src/test/java/se/bjurr/wiremock/test/integration/get/StringDTO.java +++ b/src/test/java/se/bjurr/wiremock/test/example_apis/resource_with_get_and_params/StringDTO.java @@ -1,4 +1,4 @@ -package se.bjurr.wiremock.test.integration.get; +package se.bjurr.wiremock.test.example_apis.resource_with_get_and_params; public class StringDTO { private final String str; diff --git a/src/test/java/se/bjurr/wiremock/test/integration/get/TestGetResouce.java b/src/test/java/se/bjurr/wiremock/test/example_apis/resource_with_get_and_params/TestGetResouce.java similarity index 75% rename from src/test/java/se/bjurr/wiremock/test/integration/get/TestGetResouce.java rename to src/test/java/se/bjurr/wiremock/test/example_apis/resource_with_get_and_params/TestGetResouce.java index 5629cfe..ecdf287 100644 --- a/src/test/java/se/bjurr/wiremock/test/integration/get/TestGetResouce.java +++ b/src/test/java/se/bjurr/wiremock/test/example_apis/resource_with_get_and_params/TestGetResouce.java @@ -1,11 +1,11 @@ -package se.bjurr.wiremock.test.integration.get; +package se.bjurr.wiremock.test.example_apis.resource_with_get_and_params; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.QueryParam; +import jakarta.ws.rs.core.MediaType; @Path("/") public interface TestGetResouce { diff --git a/src/test/java/se/bjurr/wiremock/test/integration/post/StringDTO.java b/src/test/java/se/bjurr/wiremock/test/example_apis/resource_with_post_and_params/StringDTO.java similarity index 63% rename from src/test/java/se/bjurr/wiremock/test/integration/post/StringDTO.java rename to src/test/java/se/bjurr/wiremock/test/example_apis/resource_with_post_and_params/StringDTO.java index fee94ae..096a117 100644 --- a/src/test/java/se/bjurr/wiremock/test/integration/post/StringDTO.java +++ b/src/test/java/se/bjurr/wiremock/test/example_apis/resource_with_post_and_params/StringDTO.java @@ -1,6 +1,6 @@ -package se.bjurr.wiremock.test.integration.post; +package se.bjurr.wiremock.test.example_apis.resource_with_post_and_params; -import javax.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlRootElement; @XmlRootElement(name = "StringDTO") public class StringDTO { @@ -20,14 +20,14 @@ public void setId(final Integer id) { } public Integer getId() { - return id; + return this.id; } - public void setStr(String str) { + public void setStr(final String str) { this.str = str; } public String getStr() { - return str; + return this.str; } } diff --git a/src/test/java/se/bjurr/wiremock/test/integration/post/TestPostResouce.java b/src/test/java/se/bjurr/wiremock/test/example_apis/resource_with_post_and_params/TestPostResouce.java similarity index 70% rename from src/test/java/se/bjurr/wiremock/test/integration/post/TestPostResouce.java rename to src/test/java/se/bjurr/wiremock/test/example_apis/resource_with_post_and_params/TestPostResouce.java index d01c8da..5265632 100644 --- a/src/test/java/se/bjurr/wiremock/test/integration/post/TestPostResouce.java +++ b/src/test/java/se/bjurr/wiremock/test/example_apis/resource_with_post_and_params/TestPostResouce.java @@ -1,10 +1,10 @@ -package se.bjurr.wiremock.test.integration.post; +package se.bjurr.wiremock.test.example_apis.resource_with_post_and_params; -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; @Path("/") public interface TestPostResouce { diff --git a/src/test/java/se/bjurr/wiremock/test/integration/get/WiremockJaxrsGetIntergrationTest.java b/src/test/java/se/bjurr/wiremock/test/integration/get/WiremockJaxrsGetIntergrationTest.java deleted file mode 100644 index 859337b..0000000 --- a/src/test/java/se/bjurr/wiremock/test/integration/get/WiremockJaxrsGetIntergrationTest.java +++ /dev/null @@ -1,239 +0,0 @@ -package se.bjurr.wiremock.test.integration.get; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; -import static com.github.tomakehurst.wiremock.client.WireMockJaxrs.invocation; -import static io.restassured.RestAssured.given; -import static javax.servlet.http.HttpServletResponse.SC_ACCEPTED; -import static org.assertj.core.api.Assertions.assertThat; - -import com.github.tomakehurst.wiremock.client.ResourceInvocation; -import com.github.tomakehurst.wiremock.stubbing.StubMapping; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.UUID; -import java.util.logging.Logger; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; -import se.bjurr.wiremock.test.support.AcceptanceTestBase; - -@RunWith(Parameterized.class) -public class WiremockJaxrsGetIntergrationTest extends AcceptanceTestBase { - private static final Object VOID_RESPONSE = null; - - private static Logger LOG = - Logger.getLogger(WiremockJaxrsGetIntergrationTest.class.getSimpleName()); - - private final StringDTO responseObject; - private final ResourceInvocation invocation; - private final List expectedValidRequests; - private final String expected; - private final String acceptContentType; - - @Parameters(name = "{index} - {2}") - public static Collection data() { - return Arrays.asList( - new Object[][] { // - { // - new StringDTO("pong"), // - ri((r) -> r.getWithResponseObject()), // - Arrays.asList("/getWithResponseObject"), // - "{\n" - + " \"id\" : \"d68fb4e2-48ed-40d2-bc73-0a18f54f3ece\",\n" - + " \"request\" : {\n" - + " \"urlPattern\" : \".*/getWithResponseObject$\",\n" - + " \"method\" : \"GET\",\n" - + " \"headers\" : {\n" - + " \"Accept\" : {\n" - + " \"equalTo\" : \"application/json\"\n" - + " }\n" - + " }\n" - + " },\n" - + " \"response\" : {\n" - + " \"status\" : 202,\n" - + " \"body\" : \"{\\n \\\"str\\\" : \\\"pong\\\"\\n}\",\n" - + " \"headers\" : {\n" - + " \"Content-Type\" : \"application/json\"\n" - + " }\n" - + " },\n" - + " \"uuid\" : \"d68fb4e2-48ed-40d2-bc73-0a18f54f3ece\"\n" - + "}", - "application/json" - }, // - { // - VOID_RESPONSE, // - ri((r) -> r.getWithoutResponseObject()), // - Arrays.asList("/getWithoutResponseObject"), // - "{\n" - + " \"id\" : \"d68fb4e2-48ed-40d2-bc73-0a18f54f3ece\",\n" - + " \"request\" : {\n" - + " \"urlPattern\" : \".*/getWithoutResponseObject$\",\n" - + " \"method\" : \"GET\"\n" - + " },\n" - + " \"response\" : {\n" - + " \"status\" : 202\n" - + " },\n" - + " \"uuid\" : \"d68fb4e2-48ed-40d2-bc73-0a18f54f3ece\"\n" - + "}", - "" - }, // - { // - new StringDTO("pong"), // - ri((r) -> r.getWithQueryParams("value1", "value2", null)), // - Arrays.asList( - "/getWithQueryParams?oneparam=value1&secondparam=value2", - "/getWithQueryParams?secondparam=value2&oneparam=value1"), // - "{\n" - + " \"id\" : \"d68fb4e2-48ed-40d2-bc73-0a18f54f3ece\",\n" - + " \"request\" : {\n" - + " \"urlPattern\" : \".*/getWithQueryParams\\\\?.*\",\n" - + " \"method\" : \"GET\",\n" - + " \"headers\" : {\n" - + " \"Accept\" : {\n" - + " \"equalTo\" : \"application/json\"\n" - + " }\n" - + " },\n" - + " \"queryParameters\" : {\n" - + " \"oneparam\" : {\n" - + " \"equalTo\" : \"value1\"\n" - + " },\n" - + " \"secondparam\" : {\n" - + " \"equalTo\" : \"value2\"\n" - + " }\n" - + " }\n" - + " },\n" - + " \"response\" : {\n" - + " \"status\" : 202,\n" - + " \"body\" : \"{\\n \\\"str\\\" : \\\"pong\\\"\\n}\",\n" - + " \"headers\" : {\n" - + " \"Content-Type\" : \"application/json\"\n" - + " }\n" - + " },\n" - + " \"uuid\" : \"d68fb4e2-48ed-40d2-bc73-0a18f54f3ece\"\n" - + "}", - "application/json" - }, - { // - new StringDTO("pong"), // - ri((r) -> r.getWithQueryParams("value1", null, "")), // - Arrays.asList( - "/getWithQueryParams?oneparam=value1&thirdparam=", - "/getWithQueryParams?thirdparam=&oneparam=value1"), // - "{\n" - + " \"id\" : \"d68fb4e2-48ed-40d2-bc73-0a18f54f3ece\",\n" - + " \"request\" : {\n" - + " \"urlPattern\" : \".*/getWithQueryParams\\\\?.*\",\n" - + " \"method\" : \"GET\",\n" - + " \"headers\" : {\n" - + " \"Accept\" : {\n" - + " \"equalTo\" : \"application/json\"\n" - + " }\n" - + " },\n" - + " \"queryParameters\" : {\n" - + " \"oneparam\" : {\n" - + " \"equalTo\" : \"value1\"\n" - + " },\n" - + " \"thirdparam\" : {\n" - + " \"equalTo\" : \"\"\n" - + " }\n" - + " }\n" - + " },\n" - + " \"response\" : {\n" - + " \"status\" : 202,\n" - + " \"body\" : \"{\\n \\\"str\\\" : \\\"pong\\\"\\n}\",\n" - + " \"headers\" : {\n" - + " \"Content-Type\" : \"application/json\"\n" - + " }\n" - + " },\n" - + " \"uuid\" : \"d68fb4e2-48ed-40d2-bc73-0a18f54f3ece\"\n" - + "}", - "application/json" - }, - { // - new StringDTO("pong"), // - ri((r) -> r.getWithPathParams("value1", "value2", "value3")), // - Arrays.asList("/getWithPathParams/value1/value2/value3"), // - "{\n" - + " \"id\" : \"d68fb4e2-48ed-40d2-bc73-0a18f54f3ece\",\n" - + " \"request\" : {\n" - + " \"urlPattern\" : \".*/getWithPathParams/value1/value2/value3$\",\n" - + " \"method\" : \"GET\",\n" - + " \"headers\" : {\n" - + " \"Accept\" : {\n" - + " \"equalTo\" : \"application/json\"\n" - + " }\n" - + " }\n" - + " },\n" - + " \"response\" : {\n" - + " \"status\" : 202,\n" - + " \"body\" : \"{\\n \\\"str\\\" : \\\"pong\\\"\\n}\",\n" - + " \"headers\" : {\n" - + " \"Content-Type\" : \"application/json\"\n" - + " }\n" - + " },\n" - + " \"uuid\" : \"d68fb4e2-48ed-40d2-bc73-0a18f54f3ece\"\n" - + "}", - "application/json" - } - } // - ); - } - - private static ResourceInvocation ri(final ResourceInvocation r) { - return r; - } - - public WiremockJaxrsGetIntergrationTest( - final StringDTO responseObject, - final ResourceInvocation invocation, - final List expectedValidRequests, - final String expected, - final String acceptContentType) { - this.responseObject = responseObject; - this.invocation = invocation; - this.expectedValidRequests = expectedValidRequests; - this.expected = expected; - this.acceptContentType = acceptContentType; - } - - @Test - public void assertResponse() { - StubMapping sm; - if (responseObject == null) { - sm = - stubFor( // - invocation(TestGetResouce.class, invocation) // - .willReturn(aResponse().withStatus(SC_ACCEPTED))); - } else { - sm = - stubFor( // - invocation(TestGetResouce.class, invocation) // - .willReturn(aResponse().withStatus(SC_ACCEPTED), responseObject)); - } - - final String actual = StubMapping.buildJsonStringFor(clean(sm)); - LOG.info("\n" + actual); - assertThat(actual) // - .isEqualTo(expected); - - for (final String path : expectedValidRequests) { - given() // - .accept(acceptContentType) // - .get(path) // - .then() - .assertThat() // - .statusCode(SC_ACCEPTED) // - .and() // - .contentType(acceptContentType); - } - } - - private StubMapping clean(final StubMapping sm) { - sm.setUuid(UUID.fromString("d68fb4e2-48ed-40d2-bc73-0a18f54f3ece")); - sm.setId(UUID.fromString("d68fb4e2-48ed-40d2-bc73-0a18f54f3ece")); - return sm; - } -} diff --git a/src/test/java/se/bjurr/wiremock/test/integration/post/WiremockJaxrsPostIntergrationTest.java b/src/test/java/se/bjurr/wiremock/test/integration/post/WiremockJaxrsPostIntergrationTest.java deleted file mode 100644 index c49f3d0..0000000 --- a/src/test/java/se/bjurr/wiremock/test/integration/post/WiremockJaxrsPostIntergrationTest.java +++ /dev/null @@ -1,206 +0,0 @@ -package se.bjurr.wiremock.test.integration.post; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; -import static com.github.tomakehurst.wiremock.client.WireMockJaxrs.invocation; -import static io.restassured.RestAssured.given; -import static javax.servlet.http.HttpServletResponse.SC_ACCEPTED; -import static org.assertj.core.api.Assertions.assertThat; - -import com.github.tomakehurst.wiremock.client.ResourceInvocation; -import com.github.tomakehurst.wiremock.stubbing.StubMapping; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.UUID; -import java.util.logging.Logger; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; -import se.bjurr.wiremock.test.support.AcceptanceTestBase; - -@RunWith(Parameterized.class) -public class WiremockJaxrsPostIntergrationTest extends AcceptanceTestBase { - private static final Object VOID_RESPONSE = null; - - private static Logger LOG = - Logger.getLogger(WiremockJaxrsPostIntergrationTest.class.getSimpleName()); - - private final StringDTO responseObject; - private final ResourceInvocation invocation; - private final List expectedValidRequests; - private final String expected; - - private final String acceptContentType; - - private final String contentType; - - private final Object postContent; - - @Parameters(name = "{index} - {2}") - public static Collection data() { - final StringDTO stringDtoCreate = new StringDTO("create"); - final StringDTO stringDtoCreated = new StringDTO("create"); - stringDtoCreated.setId(123); - - return Arrays.asList( - new Object[][] { // - { // - new StringDTO("pong"), // - stringDtoCreate, - ri((r) -> r.createStringWithResponse(stringDtoCreate)), // - Arrays.asList("/createStringWithResponse"), // - "{\n" - + " \"id\" : \"d68fb4e2-48ed-40d2-bc73-0a18f54f3ece\",\n" - + " \"request\" : {\n" - + " \"urlPattern\" : \".*/createStringWithResponse$\",\n" - + " \"method\" : \"POST\",\n" - + " \"headers\" : {\n" - + " \"Content-Type\" : {\n" - + " \"equalTo\" : \"application/json\"\n" - + " },\n" - + " \"Accept\" : {\n" - + " \"equalTo\" : \"application/json\"\n" - + " }\n" - + " },\n" - + " \"bodyPatterns\" : [ {\n" - + " \"equalToJson\" : \"{\\n \\\"str\\\" : \\\"create\\\"\\n}\",\n" - + " \"ignoreArrayOrder\" : true,\n" - + " \"ignoreExtraElements\" : true\n" - + " } ]\n" - + " },\n" - + " \"response\" : {\n" - + " \"status\" : 202,\n" - + " \"body\" : \"{\\n \\\"str\\\" : \\\"pong\\\"\\n}\",\n" - + " \"headers\" : {\n" - + " \"Content-Type\" : \"application/json\"\n" - + " }\n" - + " },\n" - + " \"uuid\" : \"d68fb4e2-48ed-40d2-bc73-0a18f54f3ece\"\n" - + "}", - "application/json", // Resp type - "application/json" // Req type - }, // - { // - VOID_RESPONSE, // - stringDtoCreate, - ri((r) -> r.createStringWithoutResponse(stringDtoCreate)), // - Arrays.asList("/createStringWithoutResponse"), // - "{\n" - + " \"id\" : \"d68fb4e2-48ed-40d2-bc73-0a18f54f3ece\",\n" - + " \"request\" : {\n" - + " \"urlPattern\" : \".*/createStringWithoutResponse$\",\n" - + " \"method\" : \"POST\",\n" - + " \"headers\" : {\n" - + " \"Content-Type\" : {\n" - + " \"equalTo\" : \"application/json\"\n" - + " }\n" - + " },\n" - + " \"bodyPatterns\" : [ {\n" - + " \"equalToJson\" : \"{\\n \\\"str\\\" : \\\"create\\\"\\n}\",\n" - + " \"ignoreArrayOrder\" : true,\n" - + " \"ignoreExtraElements\" : true\n" - + " } ]\n" - + " },\n" - + " \"response\" : {\n" - + " \"status\" : 202\n" - + " },\n" - + " \"uuid\" : \"d68fb4e2-48ed-40d2-bc73-0a18f54f3ece\"\n" - + "}", - "", // Resp type - "application/json" // Req type - }, // - { // - VOID_RESPONSE, // - stringDtoCreate, - ri((r) -> r.createXmlStringWithoutResponse(stringDtoCreate)), // - Arrays.asList("/createXmlStringWithoutResponse"), // - "{\n" - + " \"id\" : \"d68fb4e2-48ed-40d2-bc73-0a18f54f3ece\",\n" - + " \"request\" : {\n" - + " \"urlPattern\" : \".*/createXmlStringWithoutResponse$\",\n" - + " \"method\" : \"POST\",\n" - + " \"headers\" : {\n" - + " \"Content-Type\" : {\n" - + " \"equalTo\" : \"application/xml\"\n" - + " }\n" - + " },\n" - + " \"bodyPatterns\" : [ {\n" - + " \"equalToXml\" : \"\\n create\\n\\n\"\n" - + " } ]\n" - + " },\n" - + " \"response\" : {\n" - + " \"status\" : 202\n" - + " },\n" - + " \"uuid\" : \"d68fb4e2-48ed-40d2-bc73-0a18f54f3ece\"\n" - + "}", - "", // Resp type - "application/xml" // Req type - }, // - } // - ); - } - - private static ResourceInvocation ri( - final ResourceInvocation r) { - return r; - } - - public WiremockJaxrsPostIntergrationTest( - final StringDTO responseObject, - final Object postContent, - final ResourceInvocation invocation, - final List expectedValidRequests, - final String expected, - final String acceptContentType, - final String contentType) { - this.responseObject = responseObject; - this.invocation = invocation; - this.expectedValidRequests = expectedValidRequests; - this.expected = expected; - this.acceptContentType = acceptContentType; - this.contentType = contentType; - this.postContent = postContent; - } - - @Test - public void assertResponse() { - StubMapping sm; - if (responseObject == null) { - sm = - stubFor( // - invocation(TestPostResouce.class, invocation) // - .willReturn(aResponse().withStatus(SC_ACCEPTED))); - } else { - sm = - stubFor( // - invocation(TestPostResouce.class, invocation) // - .willReturn(aResponse().withStatus(SC_ACCEPTED), responseObject)); - } - - final String actual = StubMapping.buildJsonStringFor(clean(sm)); - LOG.info("\n" + actual); - assertThat(actual) // - .isEqualTo(expected); - - for (final String path : expectedValidRequests) { - given() // - .accept(acceptContentType) // - .contentType(contentType) // - .request() // - .body(postContent) // - .post(path) // - .then() - .assertThat() // - .contentType(acceptContentType) // - .statusCode(SC_ACCEPTED); - } - } - - private StubMapping clean(final StubMapping sm) { - sm.setUuid(UUID.fromString("d68fb4e2-48ed-40d2-bc73-0a18f54f3ece")); - sm.setId(UUID.fromString("d68fb4e2-48ed-40d2-bc73-0a18f54f3ece")); - return sm; - } -} diff --git a/src/test/java/se/bjurr/wiremock/test/testcases/WiremockJaxrsExamplesTest.java b/src/test/java/se/bjurr/wiremock/test/testcases/WiremockJaxrsExamplesTest.java new file mode 100644 index 0000000..d4bf241 --- /dev/null +++ b/src/test/java/se/bjurr/wiremock/test/testcases/WiremockJaxrsExamplesTest.java @@ -0,0 +1,137 @@ +package se.bjurr.wiremock.test.testcases; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.jaxrs.api.WireMockJaxrs.invocation; +import static io.restassured.RestAssured.given; +import static jakarta.servlet.http.HttpServletResponse.SC_ACCEPTED; +import static org.assertj.core.api.Assertions.assertThat; + +import com.github.tomakehurst.wiremock.stubbing.StubMapping; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; +import java.util.logging.Logger; +import org.junit.Test; +import se.bjurr.wiremock.test.example_apis.resource_with_dto.ItemDTO; +import se.bjurr.wiremock.test.example_apis.resource_with_dto.ItemResouce; +import se.bjurr.wiremock.test.testutils.AcceptanceTestBase; + +public class WiremockJaxrsExamplesTest extends AcceptanceTestBase { + private static Logger LOG = Logger.getLogger(WiremockJaxrsExamplesTest.class.getSimpleName()); + + @Test + public void getItems() { + final List responseObject = Arrays.asList(new ItemDTO("pong")); + final StubMapping sm = + stubFor( // + invocation(ItemResouce.class, (r) -> r.getItems()) // + .willReturn(aResponse().withStatus(SC_ACCEPTED), responseObject)); + + final String actual = StubMapping.buildJsonStringFor(this.clean(sm)); + + final String expected = + """ + { + "id" : "d68fb4e2-48ed-40d2-bc73-0a18f54f3ece", + "request" : { + "urlPattern" : ".*/list$", + "method" : "GET", + "headers" : { + "Accept" : { + "equalTo" : "application/json" + } + } + }, + "response" : { + "status" : 202, + "body" : "[ {\\n \\"str\\" : \\"pong\\",\\n \\"id\\" : 0\\n} ]", + "headers" : { + "Content-Type" : "application/json" + } + }, + "uuid" : "d68fb4e2-48ed-40d2-bc73-0a18f54f3ece" + }"""; + + assertThat(actual) // + .isEqualTo(expected); + + LOG.info("\n" + expected); + + given() // + .accept("application/json") // + .get("/list") // + .then() + .assertThat() // + .statusCode(SC_ACCEPTED) // + .and() // + .contentType("application/json"); + } + + @Test + public void createItem() { + final ItemDTO responseObject = new ItemDTO("the item"); + responseObject.setId(123); + final ItemDTO postedItem = new ItemDTO("the item"); + + final StubMapping sm = + stubFor( // + invocation(ItemResouce.class, (r) -> r.post(postedItem)) // + .willReturn(aResponse().withStatus(SC_ACCEPTED), responseObject)); + + final String actual = StubMapping.buildJsonStringFor(this.clean(sm)); + + final String expected = + """ + { + "id" : "d68fb4e2-48ed-40d2-bc73-0a18f54f3ece", + "request" : { + "urlPattern" : ".*/create$", + "method" : "POST", + "headers" : { + "Content-Type" : { + "equalTo" : "application/json" + }, + "Accept" : { + "equalTo" : "application/json" + } + }, + "bodyPatterns" : [ { + "equalToJson" : "{\\n \\"str\\" : \\"the item\\",\\n \\"id\\" : 0\\n}", + "ignoreArrayOrder" : true, + "ignoreExtraElements" : true + } ] + }, + "response" : { + "status" : 202, + "body" : "{\\n \\"str\\" : \\"the item\\",\\n \\"id\\" : 123\\n}", + "headers" : { + "Content-Type" : "application/json" + } + }, + "uuid" : "d68fb4e2-48ed-40d2-bc73-0a18f54f3ece" + }"""; + + assertThat(actual) // + .isEqualTo(expected); + + LOG.info("\n" + expected); + + given() // + .accept("application/json") // + .contentType("application/json") // + .request() // + .body(postedItem) // + .post("/create") // + .then() + .assertThat() // + .contentType("application/json") // + .statusCode(SC_ACCEPTED); + } + + private StubMapping clean(final StubMapping sm) { + sm.setUuid(UUID.fromString("d68fb4e2-48ed-40d2-bc73-0a18f54f3ece")); + sm.setId(UUID.fromString("d68fb4e2-48ed-40d2-bc73-0a18f54f3ece")); + return sm; + } +} diff --git a/src/test/java/se/bjurr/wiremock/test/testcases/WiremockJaxrsGetIntergrationTest.java b/src/test/java/se/bjurr/wiremock/test/testcases/WiremockJaxrsGetIntergrationTest.java new file mode 100644 index 0000000..6ed43e2 --- /dev/null +++ b/src/test/java/se/bjurr/wiremock/test/testcases/WiremockJaxrsGetIntergrationTest.java @@ -0,0 +1,222 @@ +package se.bjurr.wiremock.test.testcases; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.jaxrs.api.WireMockJaxrs.invocation; +import static io.restassured.RestAssured.given; +import static jakarta.servlet.http.HttpServletResponse.SC_ACCEPTED; +import static org.assertj.core.api.Assertions.assertThat; + +import com.github.tomakehurst.wiremock.client.ResourceInvocation; +import com.github.tomakehurst.wiremock.stubbing.StubMapping; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Logger; +import org.junit.Test; +import se.bjurr.wiremock.test.example_apis.resource_with_get_and_params.StringDTO; +import se.bjurr.wiremock.test.example_apis.resource_with_get_and_params.TestGetResouce; +import se.bjurr.wiremock.test.testutils.AcceptanceTestBase; + +public class WiremockJaxrsGetIntergrationTest extends AcceptanceTestBase { + private static final Object VOID_RESPONSE = null; + + private static Logger LOG = + Logger.getLogger(WiremockJaxrsGetIntergrationTest.class.getSimpleName()); + + @Test + public void getWithResponseObject() { + this.test( + new StringDTO("pong"), // + (r) -> r.getWithResponseObject(), // + Arrays.asList("/getWithResponseObject"), // + """ + { + "id" : "d68fb4e2-48ed-40d2-bc73-0a18f54f3ece", + "request" : { + "urlPattern" : ".*/getWithResponseObject$", + "method" : "GET", + "headers" : { + "Accept" : { + "equalTo" : "application/json" + } + } + }, + "response" : { + "status" : 202, + "body" : "{\\n \\"str\\" : \\"pong\\"\\n}", + "headers" : { + "Content-Type" : "application/json" + } + }, + "uuid" : "d68fb4e2-48ed-40d2-bc73-0a18f54f3ece" + }""", + "application/json"); + } + + @Test + public void getWithoutResponseObject() { + this.test( + VOID_RESPONSE, // + (r) -> r.getWithoutResponseObject(), // + Arrays.asList("/getWithoutResponseObject"), // + """ + { + "id" : "d68fb4e2-48ed-40d2-bc73-0a18f54f3ece", + "request" : { + "urlPattern" : ".*/getWithoutResponseObject$", + "method" : "GET" + }, + "response" : { + "status" : 202 + }, + "uuid" : "d68fb4e2-48ed-40d2-bc73-0a18f54f3ece" + }""", + ""); + } + + @Test + public void getWithQueryParams_value1_value2_null() { + this.test( + new StringDTO("pong"), // + (r) -> r.getWithQueryParams("value1", "value2", null), // + Arrays.asList( + "/getWithQueryParams?oneparam=value1&secondparam=value2", + "/getWithQueryParams?secondparam=value2&oneparam=value1"), // + """ + { + "id" : "d68fb4e2-48ed-40d2-bc73-0a18f54f3ece", + "request" : { + "urlPattern" : ".*/getWithQueryParams\\\\?.*", + "method" : "GET", + "headers" : { + "Accept" : { + "equalTo" : "application/json" + } + }, + "queryParameters" : { + "oneparam" : { + "equalTo" : "value1" + }, + "secondparam" : { + "equalTo" : "value2" + } + } + }, + "response" : { + "status" : 202, + "body" : "{\\n \\"str\\" : \\"pong\\"\\n}", + "headers" : { + "Content-Type" : "application/json" + } + }, + "uuid" : "d68fb4e2-48ed-40d2-bc73-0a18f54f3ece" + }""", + "application/json"); + } + + @Test + public void getWithQueryParams_value1_null_empty() { + this.test( + new StringDTO("pong"), // + (r) -> r.getWithQueryParams("value1", null, ""), // + Arrays.asList( + "/getWithQueryParams?oneparam=value1&thirdparam=", + "/getWithQueryParams?thirdparam=&oneparam=value1"), // + """ + { + "id" : "d68fb4e2-48ed-40d2-bc73-0a18f54f3ece", + "request" : { + "urlPattern" : ".*/getWithQueryParams\\\\?.*", + "method" : "GET", + "headers" : { + "Accept" : { + "equalTo" : "application/json" + } + }, + "queryParameters" : { + "oneparam" : { + "equalTo" : "value1" + }, + "thirdparam" : { + "equalTo" : "" + } + } + }, + "response" : { + "status" : 202, + "body" : "{\\n \\"str\\" : \\"pong\\"\\n}", + "headers" : { + "Content-Type" : "application/json" + } + }, + "uuid" : "d68fb4e2-48ed-40d2-bc73-0a18f54f3ece" + }""", + "application/json"); + } + + @Test + public void getWithPathParams_value1_value2_value3() { + this.test( + new StringDTO("pong"), // + (r) -> r.getWithPathParams("value1", "value2", "value3"), // + Arrays.asList("/getWithPathParams/value1/value2/value3"), // + """ + { + "id" : "d68fb4e2-48ed-40d2-bc73-0a18f54f3ece", + "request" : { + "urlPattern" : ".*/getWithPathParams/value1/value2/value3$", + "method" : "GET", + "headers" : { + "Accept" : { + "equalTo" : "application/json" + } + } + }, + "response" : { + "status" : 202, + "body" : "{\\n \\"str\\" : \\"pong\\"\\n}", + "headers" : { + "Content-Type" : "application/json" + } + }, + "uuid" : "d68fb4e2-48ed-40d2-bc73-0a18f54f3ece" + }""", + "application/json"); + } + + public void test( + final Object responseObject, + final ResourceInvocation invocation, + final List expectedValidRequests, + final String expected, + final String acceptContentType) { + StubMapping sm; + if (responseObject == null) { + sm = + stubFor( // + invocation(TestGetResouce.class, invocation) // + .willReturn(aResponse().withStatus(SC_ACCEPTED))); + } else { + sm = + stubFor( // + invocation(TestGetResouce.class, invocation) // + .willReturn(aResponse().withStatus(SC_ACCEPTED), responseObject)); + } + + final String actual = StubMapping.buildJsonStringFor(this.setStaticUUIDs(sm)); + LOG.info("\n" + actual); + assertThat(actual) // + .isEqualTo(expected); + + for (final String path : expectedValidRequests) { + given() // + .accept(acceptContentType) // + .get(path) // + .then() + .assertThat() // + .statusCode(SC_ACCEPTED) // + .and() // + .contentType(acceptContentType); + } + } +} diff --git a/src/test/java/se/bjurr/wiremock/test/testcases/WiremockJaxrsPostIntergrationTest.java b/src/test/java/se/bjurr/wiremock/test/testcases/WiremockJaxrsPostIntergrationTest.java new file mode 100644 index 0000000..8e43d42 --- /dev/null +++ b/src/test/java/se/bjurr/wiremock/test/testcases/WiremockJaxrsPostIntergrationTest.java @@ -0,0 +1,174 @@ +package se.bjurr.wiremock.test.testcases; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.jaxrs.api.WireMockJaxrs.invocation; +import static io.restassured.RestAssured.given; +import static jakarta.servlet.http.HttpServletResponse.SC_ACCEPTED; +import static org.assertj.core.api.Assertions.assertThat; + +import com.github.tomakehurst.wiremock.client.ResourceInvocation; +import com.github.tomakehurst.wiremock.stubbing.StubMapping; +import java.util.logging.Logger; +import org.junit.Test; +import se.bjurr.wiremock.test.example_apis.resource_with_post_and_params.StringDTO; +import se.bjurr.wiremock.test.example_apis.resource_with_post_and_params.TestPostResouce; +import se.bjurr.wiremock.test.testutils.AcceptanceTestBase; + +public class WiremockJaxrsPostIntergrationTest extends AcceptanceTestBase { + private static final Object VOID_RESPONSE = null; + + private static Logger LOG = + Logger.getLogger(WiremockJaxrsPostIntergrationTest.class.getSimpleName()); + + @Test + public void createStringWithResponse() { + final StringDTO stringDtoCreate = new StringDTO("create"); + final StringDTO stringDtoCreated = new StringDTO("create"); + stringDtoCreated.setId(123); + this.newWiremockJaxrsPostIntergrationTest( + new StringDTO("pong"), // + stringDtoCreate, + (r) -> r.createStringWithResponse(stringDtoCreate), // + "/createStringWithResponse", // + """ + { + "id" : "d68fb4e2-48ed-40d2-bc73-0a18f54f3ece", + "request" : { + "urlPattern" : ".*/createStringWithResponse$", + "method" : "POST", + "headers" : { + "Content-Type" : { + "equalTo" : "application/json" + }, + "Accept" : { + "equalTo" : "application/json" + } + }, + "bodyPatterns" : [ { + "equalToJson" : "{\\n \\"str\\" : \\"create\\"\\n}", + "ignoreArrayOrder" : true, + "ignoreExtraElements" : true + } ] + }, + "response" : { + "status" : 202, + "body" : "{\\n \\"str\\" : \\"pong\\"\\n}", + "headers" : { + "Content-Type" : "application/json" + } + }, + "uuid" : "d68fb4e2-48ed-40d2-bc73-0a18f54f3ece" + }""", + "application/json", + "application/json"); + } + + @Test + public void createStringWithoutResponse() { + final StringDTO stringDtoCreate = new StringDTO("create"); + final StringDTO stringDtoCreated = new StringDTO("create"); + stringDtoCreated.setId(123); + this.newWiremockJaxrsPostIntergrationTest( + VOID_RESPONSE, // + stringDtoCreate, + (r) -> r.createStringWithoutResponse(stringDtoCreate), // + "/createStringWithoutResponse", // + """ + { + "id" : "d68fb4e2-48ed-40d2-bc73-0a18f54f3ece", + "request" : { + "urlPattern" : ".*/createStringWithoutResponse$", + "method" : "POST", + "headers" : { + "Content-Type" : { + "equalTo" : "application/json" + } + }, + "bodyPatterns" : [ { + "equalToJson" : "{\\n \\"str\\" : \\"create\\"\\n}", + "ignoreArrayOrder" : true, + "ignoreExtraElements" : true + } ] + }, + "response" : { + "status" : 202 + }, + "uuid" : "d68fb4e2-48ed-40d2-bc73-0a18f54f3ece" + }""", + "", + "application/json"); + } + + @Test + public void createXmlStringWithoutResponse() { + final StringDTO stringDtoCreate = new StringDTO("create"); + final StringDTO stringDtoCreated = new StringDTO("create"); + stringDtoCreated.setId(123); + this.newWiremockJaxrsPostIntergrationTest( + VOID_RESPONSE, // + stringDtoCreate, + (r) -> r.createXmlStringWithoutResponse(stringDtoCreate), // + "/createXmlStringWithoutResponse", // + """ + { + "id" : "d68fb4e2-48ed-40d2-bc73-0a18f54f3ece", + "request" : { + "urlPattern" : ".*/createXmlStringWithoutResponse$", + "method" : "POST", + "headers" : { + "Content-Type" : { + "equalTo" : "application/xml" + } + }, + "bodyPatterns" : [ { + "equalToXml" : "\\n create\\n\\n" + } ] + }, + "response" : { + "status" : 202 + }, + "uuid" : "d68fb4e2-48ed-40d2-bc73-0a18f54f3ece" + }""", + "", + "application/xml"); + } + + public void newWiremockJaxrsPostIntergrationTest( + final Object responseObject, + final Object postContent, + final ResourceInvocation invocation, + final String expectedValidRequest, + final String expected, + final String acceptContentType, + final String contentType) { + StubMapping sm; + if (responseObject == null) { + sm = + stubFor( // + invocation(TestPostResouce.class, invocation) // + .willReturn(aResponse().withStatus(SC_ACCEPTED))); + } else { + sm = + stubFor( // + invocation(TestPostResouce.class, invocation) // + .willReturn(aResponse().withStatus(SC_ACCEPTED), responseObject)); + } + + final String actual = StubMapping.buildJsonStringFor(this.setStaticUUIDs(sm)); + LOG.info("\n" + actual); + assertThat(actual) // + .isEqualTo(expected); + + given() // + .accept(acceptContentType) // + .contentType(contentType) // + .request() // + .body(postContent) // + .post(expectedValidRequest) // + .then() + .assertThat() // + .contentType(acceptContentType) // + .statusCode(SC_ACCEPTED); + } +} diff --git a/src/test/java/se/bjurr/wiremock/test/support/AcceptanceTestBase.java b/src/test/java/se/bjurr/wiremock/test/testutils/AcceptanceTestBase.java similarity index 84% rename from src/test/java/se/bjurr/wiremock/test/support/AcceptanceTestBase.java rename to src/test/java/se/bjurr/wiremock/test/testutils/AcceptanceTestBase.java index cfa3da7..3729ca7 100644 --- a/src/test/java/se/bjurr/wiremock/test/support/AcceptanceTestBase.java +++ b/src/test/java/se/bjurr/wiremock/test/testutils/AcceptanceTestBase.java @@ -1,4 +1,4 @@ -package se.bjurr.wiremock.test.support; +package se.bjurr.wiremock.test.testutils; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static io.restassured.config.EncoderConfig.encoderConfig; @@ -6,10 +6,12 @@ import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.client.WireMock; import com.github.tomakehurst.wiremock.core.WireMockConfiguration; +import com.github.tomakehurst.wiremock.stubbing.StubMapping; import io.restassured.RestAssured; import io.restassured.config.EncoderConfig; import java.io.File; import java.util.Locale; +import java.util.UUID; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -54,4 +56,10 @@ public void init() throws InterruptedException { encoderConfig().appendDefaultContentCharsetToContentTypeIfUndefined(false); RestAssured.config = RestAssured.config().encoderConfig(encoderConfig); } + + public StubMapping setStaticUUIDs(final StubMapping sm) { + sm.setUuid(UUID.fromString("d68fb4e2-48ed-40d2-bc73-0a18f54f3ece")); + sm.setId(UUID.fromString("d68fb4e2-48ed-40d2-bc73-0a18f54f3ece")); + return sm; + } } diff --git a/wiremock-jaxrs.png b/wiremock-jaxrs.png deleted file mode 100644 index affd0d7..0000000 Binary files a/wiremock-jaxrs.png and /dev/null differ