diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1686dcd..1f26c53 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,11 +11,6 @@ jobs: timeout-minutes: 15 permissions: contents: write - env: - QUARKUS_JACOCO_REPORT_LOCATION: 'coverage' - QUARKUS_JACOCO_FOOTER: 'httpbucket' - QUARKUS_JACOCO_TITLE: 'httpbucket' - QUARKUS_JACOCO_EXCLUDES: '**/SimpleHealthCheck.class' steps: - name: Code Checkout uses: actions/checkout@v4 @@ -87,10 +82,10 @@ jobs: - name: Overwrite Coverage Theme run: | - /bin/cp -rf helpers/coverage/* build/coverage/. + /bin/cp -rf helpers/jacoco-report/* build/jacoco-report/. - name: Publishing to GitHub Pages uses: peaceiris/actions-gh-pages@v3 with: - publish_dir: ./build/coverage + publish_dir: ./build/jacoco-report github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/build.gradle b/build.gradle index 09cd296..4e87de7 100644 --- a/build.gradle +++ b/build.gradle @@ -13,8 +13,8 @@ dependencies { implementation 'io.quarkus:quarkus-micrometer-registry-prometheus' implementation 'io.quarkus:quarkus-smallrye-openapi' implementation "io.quarkus:quarkus-smallrye-health" - implementation 'io.quarkus:quarkus-resteasy' - implementation 'io.quarkus:quarkus-resteasy-jackson' + implementation 'io.quarkus:quarkus-resteasy-reactive' + implementation 'io.quarkus:quarkus-resteasy-reactive-jackson' implementation 'io.quarkus:quarkus-container-image-jib' implementation 'io.quarkus:quarkus-info' implementation 'io.quarkus:quarkus-arc' @@ -25,7 +25,7 @@ dependencies { } group 'com.testainers' -version '0.0.5' +version '0.0.6' java { sourceCompatibility = JavaVersion.VERSION_17 diff --git a/coverage.sh b/coverage.sh index cd2b14d..ef0f861 100755 --- a/coverage.sh +++ b/coverage.sh @@ -2,13 +2,8 @@ set -e -export QUARKUS_JACOCO_REPORT_LOCATION='coverage' -export QUARKUS_JACOCO_FOOTER='httpbucket' -export QUARKUS_JACOCO_TITLE='httpbucket' -export QUARKUS_JACOCO_EXCLUDES='**/SimpleHealthCheck.class' - ./gradlew cleanTest test -/bin/cp -rf helpers/coverage/* build/coverage/. +/bin/cp -rf helpers/jacoco-report/* build/jacoco-report/. -/opt/google/chrome/google-chrome build/coverage/index.html +# /opt/google/chrome/google-chrome build/coverage/index.html diff --git a/helpers/coverage/jacoco-resources/prettify.css b/helpers/jacoco-report/jacoco-resources/prettify.css similarity index 100% rename from helpers/coverage/jacoco-resources/prettify.css rename to helpers/jacoco-report/jacoco-resources/prettify.css diff --git a/helpers/coverage/jacoco-resources/report.css b/helpers/jacoco-report/jacoco-resources/report.css similarity index 99% rename from helpers/coverage/jacoco-resources/report.css rename to helpers/jacoco-report/jacoco-resources/report.css index 9d7a750..4767e4d 100644 --- a/helpers/coverage/jacoco-resources/report.css +++ b/helpers/jacoco-report/jacoco-resources/report.css @@ -241,8 +241,8 @@ table.coverage tfoot td.ctr2 { margin-top: 20px; border-top: #d6d3ce 1px solid; padding-top: 2px; - font-size: 8pt; color: #a0a0a0; + font-size: 1.5em; } .footer a { @@ -250,6 +250,6 @@ table.coverage tfoot td.ctr2 { } .right { - float: right; + display: none; } diff --git a/src/main/java/com/testainers/BasicAuthResource.java b/src/main/java/com/testainers/BasicAuthResource.java index 75bf970..629b94c 100644 --- a/src/main/java/com/testainers/BasicAuthResource.java +++ b/src/main/java/com/testainers/BasicAuthResource.java @@ -1,14 +1,16 @@ package com.testainers; import io.quarkus.security.Authenticated; +import io.vertx.core.http.HttpServerRequest; import jakarta.inject.Inject; import jakarta.ws.rs.*; import jakarta.ws.rs.core.HttpHeaders; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.core.UriInfo; import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; import org.eclipse.microprofile.openapi.annotations.responses.APIResponses; -import org.jboss.resteasy.spi.HttpRequest; +import org.jboss.resteasy.reactive.RestHeader; import java.nio.charset.StandardCharsets; import java.util.Base64; @@ -18,52 +20,60 @@ /** * @author Eduardo Folly */ -@Path("/basic-auth") @Authenticated +@Path("/basic-auth/{user}/{pass}") +@APIResponses({ + @APIResponse(responseCode = "200"), + @APIResponse(responseCode = "401"), + @APIResponse(responseCode = "403"), +}) +@Produces(MediaType.APPLICATION_JSON) public class BasicAuthResource { @Inject - HttpRequest request; + HttpServerRequest request; + + @Inject + UriInfo uriInfo; @GET - @HEAD - @Path("/{user}/{pass}") - @APIResponses({ - @APIResponse(responseCode = "200"), - @APIResponse(responseCode = "401"), - @APIResponse(responseCode = "403"), - }) - @Produces(MediaType.APPLICATION_JSON) - public Response withoutBody( - @HeaderParam(HttpHeaders.AUTHORIZATION) String auth, - @PathParam("user") String user, - @PathParam("pass") String pass - ) { + public Response get(@RestHeader(HttpHeaders.AUTHORIZATION) String auth, + String user, String pass) { + return getResponse(auth, user, pass, null); } @POST + public Response post(@RestHeader(HttpHeaders.AUTHORIZATION) String auth, + String user, String pass, Object body) { + + return getResponse(auth, user, pass, body); + } + @PUT + public Response put(@RestHeader(HttpHeaders.AUTHORIZATION) String auth, + String user, String pass, Object body) { + + return getResponse(auth, user, pass, body); + } + @PATCH + public Response patch(@RestHeader(HttpHeaders.AUTHORIZATION) String auth, + String user, String pass, Object body) { + + return getResponse(auth, user, pass, body); + } + @DELETE - @Path("/{user}/{pass}") - @APIResponses({ - @APIResponse(responseCode = "200"), - @APIResponse(responseCode = "401"), - @APIResponse(responseCode = "403"), - }) - @Produces(MediaType.APPLICATION_JSON) - public Response withBody( - @HeaderParam(HttpHeaders.AUTHORIZATION) String auth, - @PathParam("user") String user, - @PathParam("pass") String pass, - Object body) { + public Response delete(@RestHeader(HttpHeaders.AUTHORIZATION) String auth, + String user, String pass, Object body) { + return getResponse(auth, user, pass, body); } private Response getResponse(String auth, String user, String pass, Object body) { - ResponseBody responseBody = new ResponseBody(request, body); + ResponseBody responseBody = new ResponseBody(request, uriInfo, body); int code = 403; Map bodyMap = new HashMap<>(); diff --git a/src/main/java/com/testainers/DelayResource.java b/src/main/java/com/testainers/DelayResource.java index 6d767b4..f2dc1a2 100644 --- a/src/main/java/com/testainers/DelayResource.java +++ b/src/main/java/com/testainers/DelayResource.java @@ -1,69 +1,85 @@ package com.testainers; +import io.vertx.core.http.HttpServerRequest; import jakarta.inject.Inject; import jakarta.ws.rs.*; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.core.UriInfo; import org.eclipse.microprofile.openapi.annotations.media.Schema; import org.eclipse.microprofile.openapi.annotations.parameters.Parameter; import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; import org.eclipse.microprofile.openapi.annotations.responses.APIResponses; -import org.jboss.resteasy.spi.HttpRequest; /** * @author Eduardo Folly */ -@Path("/delay") +@Path("/delay/{delay}") +@APIResponses({ + @APIResponse(responseCode = "200"), + @APIResponse(responseCode = "400"), + @APIResponse(responseCode = "500"), +}) +@Produces(MediaType.APPLICATION_JSON) public class DelayResource { @Inject - HttpRequest request; + HttpServerRequest request; + + @Inject + UriInfo uriInfo; @GET - @HEAD - @Path("/{delay}") - @APIResponses({ - @APIResponse(responseCode = "200"), - @APIResponse(responseCode = "400"), - @APIResponse(responseCode = "500"), - }) - @Produces(MediaType.APPLICATION_JSON) - public Response withoutBody( + public Response get( @Parameter(description = "Delay must be between 0 and 10 seconds.", schema = @Schema(minimum = "1", maximum = "10", - defaultValue = "10" - ) - ) - @PathParam("delay") int delay - ) { - return getResponse(delay, null); + defaultValue = "10")) int delay) { + + return internal(delay, null); } @POST + public Response post( + @Parameter(description = "Delay must be between 0 and 10 seconds.", + schema = @Schema(minimum = "1", maximum = "10", + defaultValue = "10")) + int delay, Object body) { + + return internal(delay, body); + } + @PUT + public Response put( + @Parameter(description = "Delay must be between 0 and 10 seconds.", + schema = @Schema(minimum = "1", maximum = "10", + defaultValue = "10")) + int delay, Object body) { + + return internal(delay, body); + } + @PATCH + public Response patch( + @Parameter(description = "Delay must be between 0 and 10 seconds.", + schema = @Schema(minimum = "1", maximum = "10", + defaultValue = "10")) + int delay, Object body) { + + return internal(delay, body); + } + @DELETE - @Path("/{delay}") - @APIResponses({ - @APIResponse(responseCode = "200"), - @APIResponse(responseCode = "400"), - @APIResponse(responseCode = "500"), - }) - @Produces(MediaType.APPLICATION_JSON) - public Response withBody( + public Response delete( @Parameter(description = "Delay must be between 0 and 10 seconds.", schema = @Schema(minimum = "1", maximum = "10", - defaultValue = "10" - ) - ) - @PathParam("delay") int delay, - Object body - ) { - return getResponse(delay, body); + defaultValue = "10")) + int delay, Object body) { + + return internal(delay, body); } - private Response getResponse(int delay, Object body) { - ResponseBody responseBody = new ResponseBody(request, body); + private Response internal(int delay, Object body) { + ResponseBody responseBody = new ResponseBody(request, uriInfo, body); int code = 200; if (delay < 0 || delay > 10) { diff --git a/src/main/java/com/testainers/LengthResource.java b/src/main/java/com/testainers/LengthResource.java index f12f99c..212e1b0 100644 --- a/src/main/java/com/testainers/LengthResource.java +++ b/src/main/java/com/testainers/LengthResource.java @@ -9,6 +9,7 @@ import org.eclipse.microprofile.openapi.annotations.parameters.Parameter; import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; import org.eclipse.microprofile.openapi.annotations.responses.APIResponses; +import org.jboss.resteasy.reactive.RestHeader; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -16,32 +17,77 @@ /** * @author Eduardo Folly */ -@Path("/length") +@Path("/length/{size}") +@APIResponses({ + @APIResponse(responseCode = "200", content = { + @Content(mediaType = MediaType.TEXT_PLAIN), + @Content(mediaType = MediaType.APPLICATION_OCTET_STREAM) + }), + @APIResponse(responseCode = "500", description = "Invalid size: X.") +}) public class LengthResource { @GET - @HEAD + public Response get(@RestHeader(HttpHeaders.ACCEPT) String accept, + @Parameter(description = "Size must be " + + "between 1 and 2048.", + schema = @Schema(minimum = "1", + maximum = "2048", + defaultValue = "10" + )) int size) { + + return internal(accept, size); + } + @POST + public Response post(@RestHeader(HttpHeaders.ACCEPT) String accept, + @Parameter(description = "Size must be " + + "between 1 and 2048.", + schema = @Schema(minimum = "1", + maximum = "2048", + defaultValue = "10" + )) int size) { + + return internal(accept, size); + } + @PUT + public Response put(@RestHeader(HttpHeaders.ACCEPT) String accept, + @Parameter(description = "Size must be " + + "between 1 and 2048.", + schema = @Schema(minimum = "1", + maximum = "2048", + defaultValue = "10" + )) int size) { + + return internal(accept, size); + } + @PATCH + public Response patch(@RestHeader(HttpHeaders.ACCEPT) String accept, + @Parameter(description = "Size must be " + + "between 1 and 2048.", + schema = @Schema(minimum = "1", + maximum = "2048", + defaultValue = "10" + )) int size) { + + return internal(accept, size); + } + @DELETE - @Path("/{size}") - @APIResponses({ - @APIResponse(responseCode = "200", content = { - @Content(mediaType = MediaType.TEXT_PLAIN), - @Content(mediaType = MediaType.APPLICATION_OCTET_STREAM) - }), - @APIResponse(responseCode = "500", description = "Invalid size: X.") - }) - public Response length( - @HeaderParam(HttpHeaders.ACCEPT) String accept, - @Parameter(description = "Size must be between 1 and 2048.", - schema = @Schema(minimum = "1", maximum = "2048", - defaultValue = "10" - ) - ) - @PathParam("size") int size - ) { + public Response delete(@RestHeader(HttpHeaders.ACCEPT) String accept, + @Parameter(description = "Size must be " + + "between 1 and 2048.", + schema = @Schema(minimum = "1", + maximum = "2048", + defaultValue = "10" + )) int size) { + + return internal(accept, size); + } + + private Response internal(String accept, int size) { if (size < 1 || size > 2048) { return Response .status(500) diff --git a/src/main/java/com/testainers/MethodsResource.java b/src/main/java/com/testainers/MethodsResource.java index 32516fb..142219a 100644 --- a/src/main/java/com/testainers/MethodsResource.java +++ b/src/main/java/com/testainers/MethodsResource.java @@ -1,37 +1,54 @@ package com.testainers; +import io.vertx.core.http.HttpServerRequest; import jakarta.inject.Inject; import jakarta.ws.rs.*; import jakarta.ws.rs.core.*; import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; import org.eclipse.microprofile.openapi.annotations.responses.APIResponses; -import org.jboss.resteasy.spi.HttpRequest; /** * @author Eduardo Folly */ @Path("/methods") +@APIResponses({@APIResponse(responseCode = "200")}) +@Produces(MediaType.APPLICATION_JSON) public class MethodsResource { @Inject - HttpRequest request; + HttpServerRequest request; + + @Inject + UriInfo uriInfo; @GET + public ResponseBody get() { + return new ResponseBody(request, uriInfo, null); + } + @HEAD - @APIResponses({@APIResponse(responseCode = "200")}) - @Produces(MediaType.APPLICATION_JSON) - public ResponseBody withoutBody() { - return new ResponseBody(request, null); + public ResponseBody head() { + return new ResponseBody(request, uriInfo, null); } @POST + public ResponseBody post(Object body) { + return new ResponseBody(request, uriInfo, body); + } + @PUT + public ResponseBody put(Object body) { + return new ResponseBody(request, uriInfo, body); + } + @PATCH + public ResponseBody patch(Object body) { + return new ResponseBody(request, uriInfo, body); + } + @DELETE - @APIResponses({@APIResponse(responseCode = "200")}) - @Produces(MediaType.APPLICATION_JSON) - public ResponseBody withBody(Object body) { - return new ResponseBody(request, body); + public ResponseBody delete(Object body) { + return new ResponseBody(request, uriInfo, body); } } diff --git a/src/main/java/com/testainers/RedirectResource.java b/src/main/java/com/testainers/RedirectResource.java index 79dec72..0926a31 100644 --- a/src/main/java/com/testainers/RedirectResource.java +++ b/src/main/java/com/testainers/RedirectResource.java @@ -15,44 +15,88 @@ * @author Eduardo Folly */ @Path("/redirect") +@APIResponses({ + @APIResponse(responseCode = "30X", description = "Redirected"), + @APIResponse(responseCode = "500", + description = "'Invalid URL' or " + + "'Invalid URL Scheme' or " + + "'Invalid status code: 30X'") +}) public class RedirectResource { @GET - @HEAD + public Response get( + @Parameter(description = "URL to redirect.", required = true) + @QueryParam("url") String url, + @Parameter(description = "Response status code.", + schema = @Schema(minimum = "300", maximum = "399")) + @QueryParam("code") @DefaultValue("302") Integer code) { + + return internal(url, code); + } + @POST + public Response post( + @Parameter(description = "URL to redirect.", required = true) + @QueryParam("url") String url, + @Parameter(description = "Response status code.", + schema = @Schema(minimum = "300", maximum = "399")) + @QueryParam("code") @DefaultValue("302") Integer code) { + + return internal(url, code); + } + @PUT + public Response put( + @Parameter(description = "URL to redirect.", required = true) + @QueryParam("url") String url, + @Parameter(description = "Response status code.", + schema = @Schema(minimum = "300", maximum = "399")) + @QueryParam("code") @DefaultValue("302") Integer code) { + + return internal(url, code); + } + @PATCH + public Response patch( + @Parameter(description = "URL to redirect.", required = true) + @QueryParam("url") String url, + @Parameter(description = "Response status code.", + schema = @Schema(minimum = "300", maximum = "399")) + @QueryParam("code") @DefaultValue("302") Integer code) { + + return internal(url, code); + } + @DELETE - @APIResponses({ - @APIResponse(responseCode = "30X", description = "Redirected"), - @APIResponse(responseCode = "500", - description = "'Invalid URL' or " + - "'Invalid URL Scheme' or " + - "'Invalid status code: 30X'") - }) - public Response redirect( + public Response delete( @Parameter(description = "URL to redirect.", required = true) @QueryParam("url") String url, @Parameter(description = "Response status code.", schema = @Schema(minimum = "300", maximum = "399")) - @QueryParam("code") - @DefaultValue("302") Integer code) { + @QueryParam("code") @DefaultValue("302") Integer code) { - if (url == null) { + return internal(url, code); + } + + private Response internal(String url, Integer code) { + URI uri; + + try { + uri = URI.create(url); + } catch (Exception e) { return Response .status(500) .header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN) - .entity("Invalid URL") + .entity(String.format("Invalid URL: %s", url)) .build(); } - URI uri = URI.create(url); - if (uri.getScheme() == null) { return Response .status(500) .header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN) - .entity("Invalid URL Scheme") + .entity(String.format("Invalid URL Scheme: %s", url)) .build(); } diff --git a/src/main/java/com/testainers/ResponseBody.java b/src/main/java/com/testainers/ResponseBody.java index dfc581d..879b53b 100644 --- a/src/main/java/com/testainers/ResponseBody.java +++ b/src/main/java/com/testainers/ResponseBody.java @@ -1,11 +1,13 @@ package com.testainers; import io.quarkus.runtime.annotations.RegisterForReflection; +import io.vertx.core.http.HttpServerRequest; +import jakarta.ws.rs.core.MultivaluedHashMap; import jakarta.ws.rs.core.MultivaluedMap; import jakarta.ws.rs.core.UriInfo; -import org.jboss.resteasy.spi.HttpRequest; import java.net.URI; +import java.util.Map; /** * @author Eduardo Folly @@ -23,13 +25,19 @@ public class ResponseBody { public Object body; - public ResponseBody(HttpRequest request, Object body) { - this.method = request.getHttpMethod(); - this.remoteAddress = request.getRemoteAddress(); - this.remoteHost = request.getRemoteHost(); - this.headers = request.getHttpHeaders().getRequestHeaders(); + public ResponseBody(HttpServerRequest request, UriInfo uriInfo, + Object body) { + + this.method = request.method().name(); + this.remoteAddress = request.remoteAddress().toString(); + this.remoteHost = request.remoteAddress().host(); + + headers = new MultivaluedHashMap<>(); + + for (Map.Entry entry : request.headers()) { + headers.add(entry.getKey(), entry.getValue()); + } - UriInfo uriInfo = request.getUri(); this.uri = uriInfo.getAbsolutePath(); this.pathParameters = uriInfo.getPathParameters(); this.queryParameters = uriInfo.getQueryParameters(); diff --git a/src/main/java/com/testainers/StatusResource.java b/src/main/java/com/testainers/StatusResource.java index 3846543..4d38551 100644 --- a/src/main/java/com/testainers/StatusResource.java +++ b/src/main/java/com/testainers/StatusResource.java @@ -1,53 +1,84 @@ package com.testainers; +import io.vertx.core.http.HttpServerRequest; import jakarta.inject.Inject; import jakarta.ws.rs.*; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.core.UriInfo; import org.eclipse.microprofile.openapi.annotations.media.Schema; import org.eclipse.microprofile.openapi.annotations.parameters.Parameter; -import org.jboss.resteasy.spi.HttpRequest; /** * @author Eduardo Folly */ @Path("/status/{code}") +@Produces(MediaType.APPLICATION_JSON) public class StatusResource { @Inject - HttpRequest request; + HttpServerRequest request; + + @Inject + UriInfo uriInfo; @GET - @HEAD - @Produces(MediaType.APPLICATION_JSON) public Response get( @Parameter(description = "Code must be between 200 and 599. " + "Informational responses (1XX) " + "are not supported.", schema = @Schema(minimum = "200", maximum = "599") - ) - @PathParam("code") Integer code) { - return getResponse(code, null); + ) Integer code) { + + return internal(code, null); } @POST + public Response post( + @Parameter(description = "Code must be between 200 and 599. " + + "Informational responses (1XX) " + + "are not supported.", + schema = @Schema(minimum = "200", maximum = "599") + ) Integer code, Object body) { + + return internal(code, body); + } + @PUT + public Response put( + @Parameter(description = "Code must be between 200 and 599. " + + "Informational responses (1XX) " + + "are not supported.", + schema = @Schema(minimum = "200", maximum = "599") + ) Integer code, Object body) { + + return internal(code, body); + } + @PATCH + public Response patch( + @Parameter(description = "Code must be between 200 and 599. " + + "Informational responses (1XX) " + + "are not supported.", + schema = @Schema(minimum = "200", maximum = "599") + ) Integer code, Object body) { + + return internal(code, body); + } + @DELETE - @Produces(MediaType.APPLICATION_JSON) - public Response others( + public Response delete( @Parameter(description = "Code must be between 200 and 599. " + "Informational responses (1XX) " + "are not supported.", schema = @Schema(minimum = "200", maximum = "599") - ) - @PathParam("code") Integer code, - Object body) { - return getResponse(code, body); + ) Integer code, Object body) { + + return internal(code, body); } - private Response getResponse(int code, Object body) { - ResponseBody responseBody = new ResponseBody(request, body); + private Response internal(int code, Object body) { + ResponseBody responseBody = new ResponseBody(request, uriInfo, body); if (code < 200 || code > 599) { String message; diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 54cb835..61fb417 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -30,3 +30,7 @@ quarkus.swagger-ui.path=/swagger-ui quarkus.swagger-ui.theme=flattop quarkus.swagger-ui.title=httpbucket quarkus.swagger-ui.footer=© 2024 - Testainers +# +%test.quarkus.jacoco.footer=httpbucket +%test.quarkus.jacoco.title=httpbucket +%test.quarkus.jacoco.excludes=**/SimpleHealthCheck.class diff --git a/src/native-test/java/com/testainers/BasicAuthResourceIT.java b/src/native-test/java/com/testainers/BasicAuthResourceIT.java index 11ce8f9..3f7e734 100644 --- a/src/native-test/java/com/testainers/BasicAuthResourceIT.java +++ b/src/native-test/java/com/testainers/BasicAuthResourceIT.java @@ -2,6 +2,9 @@ import io.quarkus.test.junit.QuarkusIntegrationTest; +/** + * @author Eduardo Folly + */ @QuarkusIntegrationTest public class BasicAuthResourceIT extends BasicAuthResourceTest { // Execute the same tests but in packaged mode. diff --git a/src/native-test/java/com/testainers/DelayResourceDeleteIT.java b/src/native-test/java/com/testainers/DelayResourceIT.java similarity index 63% rename from src/native-test/java/com/testainers/DelayResourceDeleteIT.java rename to src/native-test/java/com/testainers/DelayResourceIT.java index 99c3713..a6be142 100644 --- a/src/native-test/java/com/testainers/DelayResourceDeleteIT.java +++ b/src/native-test/java/com/testainers/DelayResourceIT.java @@ -2,7 +2,10 @@ import io.quarkus.test.junit.QuarkusIntegrationTest; +/** + * @author Eduardo Folly + */ @QuarkusIntegrationTest -public class DelayResourceDeleteIT extends DelayResourceDeleteTest { +public class DelayResourceIT extends DelayResourceTest { // Execute the same tests but in packaged mode. } diff --git a/src/native-test/java/com/testainers/DelayResourcePostIT.java b/src/native-test/java/com/testainers/DelayResourcePostIT.java deleted file mode 100644 index b6d82f5..0000000 --- a/src/native-test/java/com/testainers/DelayResourcePostIT.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -public class DelayResourcePostIT extends DelayResourcePostTest { - // Execute the same tests but in packaged mode. -} diff --git a/src/native-test/java/com/testainers/DelayResourcePutIT.java b/src/native-test/java/com/testainers/DelayResourcePutIT.java deleted file mode 100644 index 68dbbec..0000000 --- a/src/native-test/java/com/testainers/DelayResourcePutIT.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -public class DelayResourcePutIT extends DelayResourcePutTest { - // Execute the same tests but in packaged mode. -} diff --git a/src/native-test/java/com/testainers/LengthResourceDeleteIT.java b/src/native-test/java/com/testainers/LengthResourceDeleteIT.java deleted file mode 100644 index 837b994..0000000 --- a/src/native-test/java/com/testainers/LengthResourceDeleteIT.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -public class LengthResourceDeleteIT extends LengthResourceDeleteTest { - // Execute the same tests but in packaged mode. -} diff --git a/src/native-test/java/com/testainers/LengthResourceGetIT.java b/src/native-test/java/com/testainers/LengthResourceGetIT.java deleted file mode 100644 index b59a268..0000000 --- a/src/native-test/java/com/testainers/LengthResourceGetIT.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -public class LengthResourceGetIT extends LengthResourceGetTest { - // Execute the same tests but in packaged mode. -} diff --git a/src/native-test/java/com/testainers/DelayResourceGetIT.java b/src/native-test/java/com/testainers/LengthResourceIT.java similarity index 63% rename from src/native-test/java/com/testainers/DelayResourceGetIT.java rename to src/native-test/java/com/testainers/LengthResourceIT.java index add151e..990d64e 100644 --- a/src/native-test/java/com/testainers/DelayResourceGetIT.java +++ b/src/native-test/java/com/testainers/LengthResourceIT.java @@ -2,7 +2,10 @@ import io.quarkus.test.junit.QuarkusIntegrationTest; +/** + * @author Eduardo Folly + */ @QuarkusIntegrationTest -public class DelayResourceGetIT extends DelayResourceGetTest { +public class LengthResourceIT extends LengthResourceTest { // Execute the same tests but in packaged mode. } diff --git a/src/native-test/java/com/testainers/LengthResourcePatchIT.java b/src/native-test/java/com/testainers/LengthResourcePatchIT.java deleted file mode 100644 index e8c9909..0000000 --- a/src/native-test/java/com/testainers/LengthResourcePatchIT.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -public class LengthResourcePatchIT extends LengthResourcePatchTest { - // Execute the same tests but in packaged mode. -} diff --git a/src/native-test/java/com/testainers/LengthResourcePostIT.java b/src/native-test/java/com/testainers/LengthResourcePostIT.java deleted file mode 100644 index 7566576..0000000 --- a/src/native-test/java/com/testainers/LengthResourcePostIT.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -public class LengthResourcePostIT extends LengthResourcePostTest { - // Execute the same tests but in packaged mode. -} diff --git a/src/native-test/java/com/testainers/LengthResourcePutIT.java b/src/native-test/java/com/testainers/LengthResourcePutIT.java deleted file mode 100644 index a5e4069..0000000 --- a/src/native-test/java/com/testainers/LengthResourcePutIT.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -public class LengthResourcePutIT extends LengthResourcePutTest { - // Execute the same tests but in packaged mode. -} diff --git a/src/native-test/java/com/testainers/MethodsResourceIT.java b/src/native-test/java/com/testainers/MethodsResourceIT.java index 262c0d0..025c846 100644 --- a/src/native-test/java/com/testainers/MethodsResourceIT.java +++ b/src/native-test/java/com/testainers/MethodsResourceIT.java @@ -2,7 +2,10 @@ import io.quarkus.test.junit.QuarkusIntegrationTest; +/** + * @author Eduardo Folly + */ @QuarkusIntegrationTest -public class MethodsResourceIT extends MethodsResourceResourceTest { +public class MethodsResourceIT extends MethodsResourceTest { // Execute the same tests but in packaged mode. } diff --git a/src/native-test/java/com/testainers/RedirectResourceDeleteIT.java b/src/native-test/java/com/testainers/RedirectResourceDeleteIT.java deleted file mode 100644 index f81d6f9..0000000 --- a/src/native-test/java/com/testainers/RedirectResourceDeleteIT.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -public class RedirectResourceDeleteIT extends RedirectResourceDeleteTest { - // Execute the same tests but in packaged mode. -} diff --git a/src/native-test/java/com/testainers/RedirectResourceGetIT.java b/src/native-test/java/com/testainers/RedirectResourceGetIT.java deleted file mode 100644 index 97f9c12..0000000 --- a/src/native-test/java/com/testainers/RedirectResourceGetIT.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -public class RedirectResourceGetIT extends RedirectResourceGetTest { - // Execute the same tests but in packaged mode. -} diff --git a/src/native-test/java/com/testainers/DelayResourcePatchIT.java b/src/native-test/java/com/testainers/RedirectResourceIT.java similarity index 62% rename from src/native-test/java/com/testainers/DelayResourcePatchIT.java rename to src/native-test/java/com/testainers/RedirectResourceIT.java index 6c85dd1..7eb6bef 100644 --- a/src/native-test/java/com/testainers/DelayResourcePatchIT.java +++ b/src/native-test/java/com/testainers/RedirectResourceIT.java @@ -2,7 +2,10 @@ import io.quarkus.test.junit.QuarkusIntegrationTest; +/** + * @author Eduardo Folly + */ @QuarkusIntegrationTest -public class DelayResourcePatchIT extends DelayResourcePatchTest { +public class RedirectResourceIT extends RedirectResourceTest { // Execute the same tests but in packaged mode. } diff --git a/src/native-test/java/com/testainers/RedirectResourcePatchIT.java b/src/native-test/java/com/testainers/RedirectResourcePatchIT.java deleted file mode 100644 index ba2e85e..0000000 --- a/src/native-test/java/com/testainers/RedirectResourcePatchIT.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -public class RedirectResourcePatchIT extends RedirectResourcePatchTest { - // Execute the same tests but in packaged mode. -} diff --git a/src/native-test/java/com/testainers/RedirectResourcePostIT.java b/src/native-test/java/com/testainers/RedirectResourcePostIT.java deleted file mode 100644 index 82ec058..0000000 --- a/src/native-test/java/com/testainers/RedirectResourcePostIT.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -public class RedirectResourcePostIT extends RedirectResourcePostTest { - // Execute the same tests but in packaged mode. -} diff --git a/src/native-test/java/com/testainers/RedirectResourcePutIT.java b/src/native-test/java/com/testainers/RedirectResourcePutIT.java deleted file mode 100644 index eb2f2bc..0000000 --- a/src/native-test/java/com/testainers/RedirectResourcePutIT.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -public class RedirectResourcePutIT extends RedirectResourcePutTest { - // Execute the same tests but in packaged mode. -} diff --git a/src/native-test/java/com/testainers/StatusResourceDeleteIT.java b/src/native-test/java/com/testainers/StatusResourceDeleteIT.java deleted file mode 100644 index e819a15..0000000 --- a/src/native-test/java/com/testainers/StatusResourceDeleteIT.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -public class StatusResourceDeleteIT extends StatusResourceDeleteResourceTest { - // Execute the same tests but in packaged mode. -} diff --git a/src/native-test/java/com/testainers/StatusResourceGetIT.java b/src/native-test/java/com/testainers/StatusResourceGetIT.java deleted file mode 100644 index db3e29f..0000000 --- a/src/native-test/java/com/testainers/StatusResourceGetIT.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -public class StatusResourceGetIT extends StatusResourceGetResourceTest { - // Execute the same tests but in packaged mode. -} diff --git a/src/native-test/java/com/testainers/StatusResourceHeadIT.java b/src/native-test/java/com/testainers/StatusResourceHeadIT.java deleted file mode 100644 index 48c5a1b..0000000 --- a/src/native-test/java/com/testainers/StatusResourceHeadIT.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -public class StatusResourceHeadIT extends StatusResourceHeadResourceTest { - // Execute the same tests but in packaged mode. -} diff --git a/src/native-test/java/com/testainers/DelayResourceHeadIT.java b/src/native-test/java/com/testainers/StatusResourceIT.java similarity index 63% rename from src/native-test/java/com/testainers/DelayResourceHeadIT.java rename to src/native-test/java/com/testainers/StatusResourceIT.java index 3a03348..7060bf1 100644 --- a/src/native-test/java/com/testainers/DelayResourceHeadIT.java +++ b/src/native-test/java/com/testainers/StatusResourceIT.java @@ -2,7 +2,10 @@ import io.quarkus.test.junit.QuarkusIntegrationTest; +/** + * @author Eduardo Folly + */ @QuarkusIntegrationTest -public class DelayResourceHeadIT extends DelayResourceHeadTest { +public class StatusResourceIT extends StatusResourceTest { // Execute the same tests but in packaged mode. } diff --git a/src/native-test/java/com/testainers/StatusResourcePatchIT.java b/src/native-test/java/com/testainers/StatusResourcePatchIT.java deleted file mode 100644 index 7c38797..0000000 --- a/src/native-test/java/com/testainers/StatusResourcePatchIT.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -public class StatusResourcePatchIT extends StatusResourcePatchResourceTest { - // Execute the same tests but in packaged mode. -} diff --git a/src/native-test/java/com/testainers/StatusResourcePostIT.java b/src/native-test/java/com/testainers/StatusResourcePostIT.java deleted file mode 100644 index 72d5518..0000000 --- a/src/native-test/java/com/testainers/StatusResourcePostIT.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -public class StatusResourcePostIT extends StatusResourcePostResourceTest { - // Execute the same tests but in packaged mode. -} diff --git a/src/native-test/java/com/testainers/StatusResourcePutIT.java b/src/native-test/java/com/testainers/StatusResourcePutIT.java deleted file mode 100644 index cf24588..0000000 --- a/src/native-test/java/com/testainers/StatusResourcePutIT.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -public class StatusResourcePutIT extends StatusResourcePutResourceTest { - // Execute the same tests but in packaged mode. -} diff --git a/src/test/java/com/testainers/BaseResourceTest.java b/src/test/java/com/testainers/BaseResourceTest.java index e16fdec..be69b06 100644 --- a/src/test/java/com/testainers/BaseResourceTest.java +++ b/src/test/java/com/testainers/BaseResourceTest.java @@ -1,12 +1,18 @@ package com.testainers; +import io.restassured.RestAssured; +import io.restassured.config.LogConfig; +import io.restassured.config.RestAssuredConfig; import io.restassured.http.ContentType; +import io.restassured.http.Method; import io.restassured.specification.RequestSpecification; +import java.util.ArrayList; import java.util.List; import java.util.Map; import static io.restassured.RestAssured.given; +import static io.restassured.config.RedirectConfig.redirectConfig; import static org.hamcrest.Matchers.*; /** @@ -14,6 +20,17 @@ */ public class BaseResourceTest { + protected static final List METHODS = + List.of(Method.GET, Method.POST, Method.PUT, + Method.PATCH, Method.DELETE); + + protected static final RestAssuredConfig CONFIG = RestAssured + .config() + .logConfig(LogConfig + .logConfig() + .enableLoggingOfRequestAndResponseIfValidationFails() + .enablePrettyPrinting(true)) + .redirect(redirectConfig().followRedirects(false)); protected static final Map HEADERS = Map.of("test-header", List.of("test-header-value"), "test-header-2", List.of("test-header-value-2")); @@ -21,30 +38,38 @@ public class BaseResourceTest { protected static final Map QUERY_PARAMS = Map.of("test-qs", List.of("test-qs")); - protected static final Map BODY = Map - .of("test_string", "test", - "test_int", 1, - "test_boolean", true); + protected static final Map BODY = + Map.of("test_string", "test", + "test_int", 1, + "test_boolean", true); protected RequestSpecification base() { - return given().when() + return given().config(CONFIG) + .when() .headers(HEADERS) - .queryParams(QUERY_PARAMS); - + .queryParams(QUERY_PARAMS) + .contentType(ContentType.JSON); } - protected RequestSpecification json() { - return base() - .contentType(ContentType.JSON) - .body(BODY); + protected RequestSpecification json(Method method) { + if (method == null || method == Method.GET) { + return base(); + } else { + return base().body(BODY); + } } - protected Object[] bodyMatchers(String method) { - return new Object[]{"method", is(method), - "queryParameters", is(QUERY_PARAMS), - "headers", aMapWithSize(greaterThanOrEqualTo(HEADERS.size())), - "headers", hasEntry(in(HEADERS.keySet()), in(HEADERS.values())), - }; + protected Object[] bodyMatchers(Method method) { + List matchers = new ArrayList<>(); + matchers.add("method"); + matchers.add(is(method.name())); + matchers.add("queryParameters"); + matchers.add(is(QUERY_PARAMS)); + matchers.add("headers"); + matchers.add(aMapWithSize(greaterThanOrEqualTo(HEADERS.size()))); + matchers.add("headers"); + matchers.add(hasEntry(in(HEADERS.keySet()), in(HEADERS.values()))); + return matchers.toArray(); } } diff --git a/src/test/java/com/testainers/BasicAuthResourceTest.java b/src/test/java/com/testainers/BasicAuthResourceTest.java index 8fa5708..d87ad8d 100644 --- a/src/test/java/com/testainers/BasicAuthResourceTest.java +++ b/src/test/java/com/testainers/BasicAuthResourceTest.java @@ -1,6 +1,7 @@ package com.testainers; import io.quarkus.test.junit.QuarkusTest; +import io.restassured.http.Method; import org.junit.jupiter.api.Test; import java.util.Map; @@ -17,314 +18,75 @@ public class BasicAuthResourceTest extends BaseResourceTest { private static final String pass = "test-pass0"; @Test - public void getNoHeader() { - base().get("/basic-auth/{user}/{pass}", user, pass) - .then() - .statusCode(401) - .body("body", - is(Map.of("auth", false, - "user", user, - "pass", pass, - "message", "Authorization header not present.")), - bodyMatchers("GET")); - } - - @Test - public void getSuccess() { - base().auth().preemptive().basic(user, pass) - .get("/basic-auth/{user}/{pass}", user, pass) - .then() - .statusCode(200) - .body("body", is(Map.of("auth", true, - "user", user, - "pass", pass, - "message", "Success.")), - bodyMatchers("GET")); - } - - @Test - public void getUserFail() { - base().auth().preemptive().basic(user, pass) - .get("/basic-auth/{user}Fail/{pass}", user, pass) - .then() - .statusCode(403) - .body("body", is(Map.of("auth", false, - "user", user + "Fail", - "pass", pass, - "message", "Forbidden.")), - bodyMatchers("GET")); - } - - @Test - public void getPassFail() { - base().auth().preemptive().basic(user, pass) - .get("/basic-auth/{user}/{pass}Fail", user, pass) - .then() - .statusCode(403) - .body("body", is(Map.of("auth", false, - "user", user, - "pass", pass + "Fail", - "message", "Forbidden.")), - bodyMatchers("GET")); - } - - @Test - public void headNoHeader() { - base().head("/basic-auth/{user}/{pass}", user, pass) - .then() - .statusCode(401) - .body(is("")); - } - - @Test - public void headSuccess() { - base().auth().preemptive().basic(user, pass) - .head("/basic-auth/{user}/{pass}", user, pass) - .then() - .statusCode(200) - .body(is("")); - } - - @Test - public void headUserFail() { - base().auth().preemptive().basic(user, pass) - .head("/basic-auth/{user}Fail/{pass}", user, pass) - .then() - .statusCode(403) - .body(is("")); - } - - @Test - public void headPassFail() { - base().auth().preemptive().basic(user, pass) - .head("/basic-auth/{user}/{pass}Fail", user, pass) - .then() - .statusCode(403) - .body(is("")); - } - - @Test - public void postNoHeader() { - json().post("/basic-auth/{user}/{pass}", user, pass) - .then() - .statusCode(401) - .body("body", - is(Map.of("auth", false, - "user", user, - "pass", pass, - "body", BODY, - "message", "Authorization header not present.")), - bodyMatchers("POST")); - } - - @Test - public void postSuccess() { - json().auth().preemptive().basic(user, pass) - .post("/basic-auth/{user}/{pass}", user, pass) - .then() - .statusCode(200) - .body("body", is(Map.of("auth", true, - "user", user, - "pass", pass, - "body", BODY, - "message", "Success.")), - bodyMatchers("POST")); - } - - @Test - public void postUserFail() { - json().auth().preemptive().basic(user, pass) - .post("/basic-auth/{user}Fail/{pass}", user, pass) - .then() - .statusCode(403) - .body("body", is(Map.of("auth", false, - "user", user + "Fail", - "pass", pass, - "body", BODY, - "message", "Forbidden.")), - bodyMatchers("POST")); - } - - @Test - public void postPassFail() { - json().auth().preemptive().basic(user, pass) - .post("/basic-auth/{user}/{pass}Fail", user, pass) - .then() - .statusCode(403) - .body("body", is(Map.of("auth", false, - "user", user, - "pass", pass + "Fail", - "body", BODY, - "message", "Forbidden.")), - bodyMatchers("POST")); - } - - @Test - public void putNoHeader() { - json().put("/basic-auth/{user}/{pass}", user, pass) - .then() - .statusCode(401) - .body("body", - is(Map.of("auth", false, - "user", user, - "pass", pass, - "body", BODY, - "message", "Authorization header not present.")), - bodyMatchers("PUT")); - } - - @Test - public void putSuccess() { - json().auth().preemptive().basic(user, pass) - .put("/basic-auth/{user}/{pass}", user, pass) - .then() - .statusCode(200) - .body("body", is(Map.of("auth", true, - "user", user, - "pass", pass, - "body", BODY, - "message", "Success.")), - bodyMatchers("PUT")); - } - - @Test - public void putUserFail() { - json().auth().preemptive().basic(user, pass) - .put("/basic-auth/{user}Fail/{pass}", user, pass) - .then() - .statusCode(403) - .body("body", is(Map.of("auth", false, - "user", user + "Fail", - "pass", pass, - "body", BODY, - "message", "Forbidden.")), - bodyMatchers("PUT")); - } - - @Test - public void putPassFail() { - json().auth().preemptive().basic(user, pass) - .put("/basic-auth/{user}/{pass}Fail", user, pass) - .then() - .statusCode(403) - .body("body", is(Map.of("auth", false, - "user", user, - "pass", pass + "Fail", - "body", BODY, - "message", "Forbidden.")), - bodyMatchers("PUT")); - } - - @Test - public void patchNoHeader() { - json().patch("/basic-auth/{user}/{pass}", user, pass) - .then() - .statusCode(401) - .body("body", - is(Map.of("auth", false, - "user", user, - "pass", pass, - "body", BODY, - "message", "Authorization header not present.")), - bodyMatchers("PATCH")); - } - - @Test - public void patchSuccess() { - json().auth().preemptive().basic(user, pass) - .patch("/basic-auth/{user}/{pass}", user, pass) - .then() - .statusCode(200) - .body("body", is(Map.of("auth", true, - "user", user, - "pass", pass, - "body", BODY, - "message", "Success.")), - bodyMatchers("PATCH")); - } - - @Test - public void patchUserFail() { - json().auth().preemptive().basic(user, pass) - .patch("/basic-auth/{user}Fail/{pass}", user, pass) - .then() - .statusCode(403) - .body("body", is(Map.of("auth", false, - "user", user + "Fail", - "pass", pass, - "body", BODY, - "message", "Forbidden.")), - bodyMatchers("PATCH")); - } - - @Test - public void patchPassFail() { - json().auth().preemptive().basic(user, pass) - .patch("/basic-auth/{user}/{pass}Fail", user, pass) - .then() - .statusCode(403) - .body("body", is(Map.of("auth", false, - "user", user, - "pass", pass + "Fail", - "body", BODY, - "message", "Forbidden.")), - bodyMatchers("PATCH")); - } - - @Test - public void deleteNoHeader() { - json().delete("/basic-auth/{user}/{pass}", user, pass) - .then() - .statusCode(401) - .body("body", - is(Map.of("auth", false, - "user", user, - "pass", pass, - "body", BODY, - "message", "Authorization header not present.")), - bodyMatchers("DELETE")); - } - - @Test - public void deleteSuccess() { - json().auth().preemptive().basic(user, pass) - .delete("/basic-auth/{user}/{pass}", user, pass) - .then() - .statusCode(200) - .body("body", is(Map.of("auth", true, - "user", user, - "pass", pass, - "body", BODY, - "message", "Success.")), - bodyMatchers("DELETE")); - } - - @Test - public void deleteUserFail() { - json().auth().preemptive().basic(user, pass) - .delete("/basic-auth/{user}Fail/{pass}", user, pass) - .then() - .statusCode(403) - .body("body", is(Map.of("auth", false, - "user", user + "Fail", - "pass", pass, - "body", BODY, - "message", "Forbidden.")), - bodyMatchers("DELETE")); - } - - @Test - public void deletePassFail() { - json().auth().preemptive().basic(user, pass) - .delete("/basic-auth/{user}/{pass}Fail", user, pass) - .then() - .statusCode(403) - .body("body", is(Map.of("auth", false, - "user", user, - "pass", pass + "Fail", - "body", BODY, - "message", "Forbidden.")), - bodyMatchers("DELETE")); + public void noHeader() { + for (Method method : METHODS) { + base().pathParam("user", user) + .pathParam("pass", pass) + .request(method, "/basic-auth/{user}/{pass}") + .then() + .statusCode(401) + .body("body", + is(Map.of("auth", false, + "user", user, + "pass", pass, + "message", + "Authorization header not present.")), + bodyMatchers(method)); + } + } + + @Test + public void success() { + for (Method method : METHODS) { + base().auth().preemptive().basic(user, pass) + .pathParam("user", user) + .pathParam("pass", pass) + .request(method, "/basic-auth/{user}/{pass}") + .then() + .statusCode(200) + .body("body", + is(Map.of("auth", true, + "user", user, + "pass", pass, + "message", "Success.")), + bodyMatchers(method)); + } + } + + @Test + public void userFail() { + for (Method method : METHODS) { + base().auth().preemptive().basic(user, pass) + .pathParam("user", user + "Fail") + .pathParam("pass", pass) + .request(method, "/basic-auth/{user}/{pass}") + .then() + .statusCode(403) + .body("body", + is(Map.of("auth", false, + "user", user + "Fail", + "pass", pass, + "message", "Forbidden.")), + bodyMatchers(method)); + } + } + + @Test + public void passFail() { + for (Method method : METHODS) { + base().auth().preemptive().basic(user, pass) + .pathParam("user", user) + .pathParam("pass", pass + "Fail") + .request(method, "/basic-auth/{user}/{pass}") + .then() + .statusCode(403) + .body("body", + is(Map.of("auth", false, + "user", user, + "pass", pass + "Fail", + "message", "Forbidden.")), + bodyMatchers(method)); + } } } diff --git a/src/test/java/com/testainers/DelayResourceDeleteTest.java b/src/test/java/com/testainers/DelayResourceDeleteTest.java deleted file mode 100644 index 0dcf99f..0000000 --- a/src/test/java/com/testainers/DelayResourceDeleteTest.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusTest; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.Matchers.containsStringIgnoringCase; -import static org.hamcrest.Matchers.is; - -/** - * @author Eduardo Folly - */ -@QuarkusTest -public class DelayResourceDeleteTest extends BaseResourceTest { - - @Test - public void testDelayDeleteEmpty() { - json().delete("/delay") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testDelayDeleteString() { - json().delete("/delay/a") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testDelayDeleteDouble() { - json().delete("/delay/1.8") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testDelayDeleteNegative() { - json().delete("/delay/-1") - .then() - .statusCode(400) - .body("body", is("Invalid delay: -1"), - bodyMatchers("DELETE")); - } - - @Test - public void testDelayDelete0() { - json().delete("/delay/0") - .then() - .statusCode(200) - .body("body", is("Slept for 0 seconds."), - bodyMatchers("DELETE")); - } - - @Test - public void testDelayDelete1() { - json().delete("/delay/1") - .then() - .statusCode(200) - .body("body", is("Slept for 1 seconds."), - bodyMatchers("DELETE")); - } - - @Test - public void testDelayDelete10() { - json().delete("/delay/10") - .then() - .statusCode(200) - .body("body", is("Slept for 10 seconds."), - bodyMatchers("DELETE")); - } - - @Test - public void testDelayDelete11() { - json().delete("/delay/11") - .then() - .statusCode(400) - .body("body", is("Invalid delay: 11"), - bodyMatchers("DELETE")); - } - -} diff --git a/src/test/java/com/testainers/DelayResourceGetTest.java b/src/test/java/com/testainers/DelayResourceGetTest.java deleted file mode 100644 index 3375729..0000000 --- a/src/test/java/com/testainers/DelayResourceGetTest.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusTest; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.Matchers.*; - -/** - * @author Eduardo Folly - */ -@QuarkusTest -public class DelayResourceGetTest extends BaseResourceTest { - - @Test - public void testDelayGetEmpty() { - base().get("/delay") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testDelayGetString() { - base().get("/delay/a") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testDelayGetDouble() { - base().get("/delay/1.8") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testDelayGetNegative() { - base().get("/delay/-1") - .then() - .statusCode(400) - .body("body", is("Invalid delay: -1"), - bodyMatchers("GET")); - } - - @Test - public void testDelayGet0() { - base().get("/delay/0") - .then() - .statusCode(200) - .body("body", is("Slept for 0 seconds."), - bodyMatchers("GET")); - } - - @Test - public void testDelayGet1() { - base().get("/delay/1") - .then() - .statusCode(200) - .body("body", is("Slept for 1 seconds."), - bodyMatchers("GET")); - } - - @Test - public void testDelayGet10() { - base().get("/delay/10") - .then() - .statusCode(200) - .body("body", is("Slept for 10 seconds."), - bodyMatchers("GET")); - } - - @Test - public void testDelayGet11() { - base().get("/delay/11") - .then() - .statusCode(400) - .body("body", is("Invalid delay: 11"), - bodyMatchers("GET")); - } - -} diff --git a/src/test/java/com/testainers/DelayResourceHeadTest.java b/src/test/java/com/testainers/DelayResourceHeadTest.java deleted file mode 100644 index f3af995..0000000 --- a/src/test/java/com/testainers/DelayResourceHeadTest.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusTest; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.Matchers.containsStringIgnoringCase; -import static org.hamcrest.Matchers.is; - -/** - * @author Eduardo Folly - */ -@QuarkusTest -public class DelayResourceHeadTest extends BaseResourceTest { - - @Test - public void testDelayHeadEmpty() { - base().head("/delay") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testDelayHeadString() { - base().head("/delay/a") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testDelayHeadDouble() { - base().head("/delay/1.8") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testDelayHeadNegative() { - base().head("/delay/-1") - .then() - .statusCode(400) - .body(is("")); - } - - @Test - public void testDelayHead0() { - base().head("/delay/0") - .then() - .statusCode(200) - .body(is("")); - } - - @Test - public void testDelayHead1() { - base().head("/delay/1") - .then() - .statusCode(200) - .body(is("")); - } - - @Test - public void testDelayHead10() { - base().head("/delay/10") - .then() - .statusCode(200) - .body(is("")); - } - - @Test - public void testDelayHead11() { - base().head("/delay/11") - .then() - .statusCode(400) - .body(is("")); - } - -} diff --git a/src/test/java/com/testainers/DelayResourcePatchTest.java b/src/test/java/com/testainers/DelayResourcePatchTest.java deleted file mode 100644 index 9836b1c..0000000 --- a/src/test/java/com/testainers/DelayResourcePatchTest.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusTest; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.Matchers.containsStringIgnoringCase; -import static org.hamcrest.Matchers.is; - -/** - * @author Eduardo Folly - */ -@QuarkusTest -public class DelayResourcePatchTest extends BaseResourceTest { - - @Test - public void testDelayPatchEmpty() { - json().patch("/delay") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testDelayPatchString() { - json().patch("/delay/a") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testDelayPatchDouble() { - json().patch("/delay/1.8") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testDelayPatchNegative() { - json().patch("/delay/-1") - .then() - .statusCode(400) - .body("body", is("Invalid delay: -1"), - bodyMatchers("PATCH")); - } - - @Test - public void testDelayPatch0() { - json().patch("/delay/0") - .then() - .statusCode(200) - .body("body", is("Slept for 0 seconds."), - bodyMatchers("PATCH")); - } - - @Test - public void testDelayPatch1() { - json().patch("/delay/1") - .then() - .statusCode(200) - .body("body", is("Slept for 1 seconds."), - bodyMatchers("PATCH")); - } - - @Test - public void testDelayPatch10() { - json().patch("/delay/10") - .then() - .statusCode(200) - .body("body", is("Slept for 10 seconds."), - bodyMatchers("PATCH")); - } - - @Test - public void testDelayPatch11() { - json().patch("/delay/11") - .then() - .statusCode(400) - .body("body", is("Invalid delay: 11"), - bodyMatchers("PATCH")); - } - -} diff --git a/src/test/java/com/testainers/DelayResourcePostTest.java b/src/test/java/com/testainers/DelayResourcePostTest.java deleted file mode 100644 index 4830166..0000000 --- a/src/test/java/com/testainers/DelayResourcePostTest.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusTest; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.Matchers.containsStringIgnoringCase; -import static org.hamcrest.Matchers.is; - -/** - * @author Eduardo Folly - */ -@QuarkusTest -public class DelayResourcePostTest extends BaseResourceTest { - - @Test - public void testDelayPostEmpty() { - json().post("/delay") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testDelayPostString() { - json().post("/delay/a") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testDelayPostDouble() { - json().post("/delay/1.8") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testDelayPostNegative() { - json().post("/delay/-1") - .then() - .statusCode(400) - .body("body", is("Invalid delay: -1"), - bodyMatchers("POST")); - } - - @Test - public void testDelayPost0() { - json().post("/delay/0") - .then() - .statusCode(200) - .body("body", is("Slept for 0 seconds."), - bodyMatchers("POST")); - } - - @Test - public void testDelayPost1() { - json().post("/delay/1") - .then() - .statusCode(200) - .body("body", is("Slept for 1 seconds."), - bodyMatchers("POST")); - } - - @Test - public void testDelayPost10() { - json().post("/delay/10") - .then() - .statusCode(200) - .body("body", is("Slept for 10 seconds."), - bodyMatchers("POST")); - } - - @Test - public void testDelayPost11() { - json().post("/delay/11") - .then() - .statusCode(400) - .body("body", is("Invalid delay: 11"), - bodyMatchers("POST")); - } - -} diff --git a/src/test/java/com/testainers/DelayResourcePutTest.java b/src/test/java/com/testainers/DelayResourcePutTest.java deleted file mode 100644 index 68456b1..0000000 --- a/src/test/java/com/testainers/DelayResourcePutTest.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusTest; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.Matchers.containsStringIgnoringCase; -import static org.hamcrest.Matchers.is; - -/** - * @author Eduardo Folly - */ -@QuarkusTest -public class DelayResourcePutTest extends BaseResourceTest { - - @Test - public void testDelayPutEmpty() { - json().put("/delay") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testDelayPutString() { - json().put("/delay/a") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testDelayPutDouble() { - json().put("/delay/1.8") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testDelayPutNegative() { - json().put("/delay/-1") - .then() - .statusCode(400) - .body("body", is("Invalid delay: -1"), - bodyMatchers("PUT")); - } - - @Test - public void testDelayPut0() { - json().put("/delay/0") - .then() - .statusCode(200) - .body("body", is("Slept for 0 seconds."), - bodyMatchers("PUT")); - } - - @Test - public void testDelayPut1() { - json().put("/delay/1") - .then() - .statusCode(200) - .body("body", is("Slept for 1 seconds."), - bodyMatchers("PUT")); - } - - @Test - public void testDelayPut10() { - json().put("/delay/10") - .then() - .statusCode(200) - .body("body", is("Slept for 10 seconds."), - bodyMatchers("PUT")); - } - - @Test - public void testDelayPut11() { - json().put("/delay/11") - .then() - .statusCode(400) - .body("body", is("Invalid delay: 11"), - bodyMatchers("PUT")); - } - -} diff --git a/src/test/java/com/testainers/DelayResourceTest.java b/src/test/java/com/testainers/DelayResourceTest.java new file mode 100644 index 0000000..fa68e11 --- /dev/null +++ b/src/test/java/com/testainers/DelayResourceTest.java @@ -0,0 +1,111 @@ +package com.testainers; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.http.Method; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.containsStringIgnoringCase; +import static org.hamcrest.Matchers.is; + +/** + * @author Eduardo Folly + */ +@QuarkusTest +public class DelayResourceTest extends BaseResourceTest { + + @Test + public void delayEmpty() { + for (Method method : METHODS) { + json(method) + .request(method, "/delay") + .then() + .statusCode(404) + .statusLine(containsStringIgnoringCase("Not Found")); + } + } + + @Test + public void delayString() { + for (Method method : METHODS) { + json(method) + .request(method, "/delay/a") + .then() + .statusCode(404) + .statusLine(containsStringIgnoringCase("Not Found")); + } + } + + @Test + public void delayDouble() { + for (Method method : METHODS) { + json(method) + .request(method, "/delay/1.8") + .then() + .statusCode(404) + .statusLine(containsStringIgnoringCase("Not Found")); + } + } + + @Test + public void delayNegative() { + for (Method method : METHODS) { + json(method) + .request(method, "/delay/-1") + .then() + .statusCode(400) + .body("body", is("Invalid delay: -1"), + bodyMatchers(method)); + } + } + + @Test + public void delay0() { + for (Method method : METHODS) { + json(method) + .request(method, "/delay/0") + .then() + .statusCode(200) + .body("body", is("Slept for 0 seconds."), + bodyMatchers(method)); + } + } + + @Test + public void delay1() { + for (Method method : METHODS) { + json(method) + .request(method, "/delay/1") + .then() + .statusCode(200) + .body("body", is("Slept for 1 seconds."), + bodyMatchers(method)); + } + } + + @Test + @Disabled + public void delay10() { + for (Method method : METHODS) { + json(method) + .request(method, "/delay/10") + .then() + .statusCode(200) + .body("body", is("Slept for 10 seconds."), + bodyMatchers(method)); + } + } + + @Test + public void delay11() { + for (Method method : METHODS) { + json(method) + .request(method, "/delay/11") + .then() + .statusCode(400) + .body("body", is("Invalid delay: 11"), + bodyMatchers(method)); + } + } + +} diff --git a/src/test/java/com/testainers/LengthResourceDeleteTest.java b/src/test/java/com/testainers/LengthResourceDeleteTest.java deleted file mode 100644 index bab4983..0000000 --- a/src/test/java/com/testainers/LengthResourceDeleteTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusTest; -import io.restassured.http.ContentType; -import jakarta.ws.rs.core.MediaType; -import org.junit.jupiter.api.Test; - -import static io.restassured.RestAssured.given; -import static org.hamcrest.Matchers.*; - -/** - * @author Eduardo Folly - */ -@QuarkusTest -public class LengthResourceDeleteTest { - - @Test - public void testLengthDelete0() { - given().when() - .delete("/length/0") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid size: 0")); - } - - @Test - public void testLengthDelete5() { - given().when() - .delete("/length/5") - .then() - .statusCode(200) - .contentType(ContentType.TEXT) - .header("content-length", "5") - .body(is("00000")); - } - - @Test - public void testLengthDelete10() { - given().when() - .accept(MediaType.TEXT_PLAIN) - .delete("/length/10") - .then() - .statusCode(200) - .contentType(ContentType.TEXT) - .header("content-length", "10") - .body(is("0000000000")); - } - - @Test - public void testLengthDelete1024() { - given().when() - .accept(MediaType.APPLICATION_OCTET_STREAM) - .delete("/length/1024") - .then() - .statusCode(200) - .contentType(ContentType.BINARY) - .header("content-length", "1024") - .body(notNullValue()); - } - - @Test - public void testLengthDelete2049() { - given().when() - .accept(MediaType.APPLICATION_OCTET_STREAM) - .delete("/length/2049") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid size: 2049")); - } - -} \ No newline at end of file diff --git a/src/test/java/com/testainers/LengthResourceGetTest.java b/src/test/java/com/testainers/LengthResourceGetTest.java deleted file mode 100644 index 41f2a00..0000000 --- a/src/test/java/com/testainers/LengthResourceGetTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusTest; -import io.restassured.http.ContentType; -import jakarta.ws.rs.core.MediaType; -import org.junit.jupiter.api.Test; - -import static io.restassured.RestAssured.given; -import static org.hamcrest.Matchers.*; - -/** - * @author Eduardo Folly - */ -@QuarkusTest -public class LengthResourceGetTest { - - @Test - public void testLengthGet0() { - given().when() - .get("/length/0") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid size: 0")); - } - - @Test - public void testLengthGet5() { - given().when() - .get("/length/5") - .then() - .statusCode(200) - .contentType(ContentType.TEXT) - .header("content-length", "5") - .body(is("00000")); - } - - @Test - public void testLengthGet10() { - given().when() - .accept(MediaType.TEXT_PLAIN) - .get("/length/10") - .then() - .statusCode(200) - .contentType(ContentType.TEXT) - .header("content-length", "10") - .body(is("0000000000")); - } - - @Test - public void testLengthGet1024() { - given().when() - .accept(MediaType.APPLICATION_OCTET_STREAM) - .get("/length/1024") - .then() - .statusCode(200) - .contentType(ContentType.BINARY) - .header("content-length", "1024") - .body(notNullValue()); - } - - @Test - public void testLengthGet2049() { - given().when() - .accept(MediaType.APPLICATION_OCTET_STREAM) - .get("/length/2049") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid size: 2049")); - } - -} \ No newline at end of file diff --git a/src/test/java/com/testainers/LengthResourcePatchTest.java b/src/test/java/com/testainers/LengthResourcePatchTest.java deleted file mode 100644 index 7579775..0000000 --- a/src/test/java/com/testainers/LengthResourcePatchTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusTest; -import io.restassured.http.ContentType; -import jakarta.ws.rs.core.MediaType; -import org.junit.jupiter.api.Test; - -import static io.restassured.RestAssured.given; -import static org.hamcrest.Matchers.*; - -/** - * @author Eduardo Folly - */ -@QuarkusTest -public class LengthResourcePatchTest { - - @Test - public void testLengthPatch0() { - given().when() - .patch("/length/0") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid size: 0")); - } - - @Test - public void testLengthPatch5() { - given().when() - .patch("/length/5") - .then() - .statusCode(200) - .contentType(ContentType.TEXT) - .header("content-length", "5") - .body(is("00000")); - } - - @Test - public void testLengthPatch10() { - given().when() - .accept(MediaType.TEXT_PLAIN) - .patch("/length/10") - .then() - .statusCode(200) - .contentType(ContentType.TEXT) - .header("content-length", "10") - .body(is("0000000000")); - } - - @Test - public void testLengthPatch1024() { - given().when() - .accept(MediaType.APPLICATION_OCTET_STREAM) - .patch("/length/1024") - .then() - .statusCode(200) - .contentType(ContentType.BINARY) - .header("content-length", "1024") - .body(notNullValue()); - } - - @Test - public void testLengthPatch2049() { - given().when() - .accept(MediaType.APPLICATION_OCTET_STREAM) - .patch("/length/2049") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid size: 2049")); - } - -} \ No newline at end of file diff --git a/src/test/java/com/testainers/LengthResourcePostTest.java b/src/test/java/com/testainers/LengthResourcePostTest.java deleted file mode 100644 index 9801c70..0000000 --- a/src/test/java/com/testainers/LengthResourcePostTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusTest; -import io.restassured.http.ContentType; -import jakarta.ws.rs.core.MediaType; -import org.junit.jupiter.api.Test; - -import static io.restassured.RestAssured.given; -import static org.hamcrest.Matchers.*; - -/** - * @author Eduardo Folly - */ -@QuarkusTest -public class LengthResourcePostTest { - - @Test - public void testLengthPost0() { - given().when() - .post("/length/0") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid size: 0")); - } - - @Test - public void testLengthPost5() { - given().when() - .post("/length/5") - .then() - .statusCode(200) - .contentType(ContentType.TEXT) - .header("content-length", "5") - .body(is("00000")); - } - - @Test - public void testLengthPost10() { - given().when() - .accept(MediaType.TEXT_PLAIN) - .post("/length/10") - .then() - .statusCode(200) - .contentType(ContentType.TEXT) - .header("content-length", "10") - .body(is("0000000000")); - } - - @Test - public void testLengthPost1024() { - given().when() - .accept(MediaType.APPLICATION_OCTET_STREAM) - .post("/length/1024") - .then() - .statusCode(200) - .contentType(ContentType.BINARY) - .header("content-length", "1024") - .body(notNullValue()); - } - - @Test - public void testLengthPost2049() { - given().when() - .accept(MediaType.APPLICATION_OCTET_STREAM) - .post("/length/2049") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid size: 2049")); - } - -} \ No newline at end of file diff --git a/src/test/java/com/testainers/LengthResourcePutTest.java b/src/test/java/com/testainers/LengthResourcePutTest.java deleted file mode 100644 index 0cc0c89..0000000 --- a/src/test/java/com/testainers/LengthResourcePutTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusTest; -import io.restassured.http.ContentType; -import jakarta.ws.rs.core.MediaType; -import org.junit.jupiter.api.Test; - -import static io.restassured.RestAssured.given; -import static org.hamcrest.Matchers.*; - -/** - * @author Eduardo Folly - */ -@QuarkusTest -public class LengthResourcePutTest { - - @Test - public void testLengthPut0() { - given().when() - .put("/length/0") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid size: 0")); - } - - @Test - public void testLengthPut5() { - given().when() - .put("/length/5") - .then() - .statusCode(200) - .contentType(ContentType.TEXT) - .header("content-length", "5") - .body(is("00000")); - } - - @Test - public void testLengthPut10() { - given().when() - .accept(MediaType.TEXT_PLAIN) - .put("/length/10") - .then() - .statusCode(200) - .contentType(ContentType.TEXT) - .header("content-length", "10") - .body(is("0000000000")); - } - - @Test - public void testLengthPut1024() { - given().when() - .accept(MediaType.APPLICATION_OCTET_STREAM) - .put("/length/1024") - .then() - .statusCode(200) - .contentType(ContentType.BINARY) - .header("content-length", "1024") - .body(notNullValue()); - } - - @Test - public void testLengthPut2049() { - given().when() - .accept(MediaType.APPLICATION_OCTET_STREAM) - .put("/length/2049") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid size: 2049")); - } - -} \ No newline at end of file diff --git a/src/test/java/com/testainers/LengthResourceTest.java b/src/test/java/com/testainers/LengthResourceTest.java new file mode 100644 index 0000000..4d37598 --- /dev/null +++ b/src/test/java/com/testainers/LengthResourceTest.java @@ -0,0 +1,90 @@ +package com.testainers; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.http.ContentType; +import io.restassured.http.Method; +import jakarta.ws.rs.core.MediaType; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.*; + +/** + * @author Eduardo Folly + */ +@QuarkusTest +public class LengthResourceTest { + + static final List METHODS = + List.of(Method.GET, Method.POST, Method.PUT, + Method.PATCH, Method.DELETE); + + @Test + public void length0() { + for (Method method : METHODS) { + given().when() + .request(method, "/length/0") + .then() + .statusCode(500) + .contentType(ContentType.TEXT) + .body(is("Invalid size: 0")); + } + } + + @Test + public void length5() { + for (Method method : METHODS) { + given().when() + .request(method, "/length/5") + .then() + .statusCode(200) + .contentType(ContentType.TEXT) + .header("content-length", "5") + .body(is("00000")); + } + } + + @Test + public void length10() { + for (Method method : METHODS) { + given().when() + .accept(MediaType.TEXT_PLAIN) + .request(method, "/length/10") + .then() + .statusCode(200) + .contentType(ContentType.TEXT) + .header("content-length", "10") + .body(is("0000000000")); + } + } + + @Test + public void length1024() { + for (Method method : METHODS) { + given().when() + .accept(MediaType.APPLICATION_OCTET_STREAM) + .request(method, "/length/1024") + .then() + .statusCode(200) + .contentType(ContentType.BINARY) + .header("content-length", "1024") + .body(notNullValue()); + } + } + + @Test + public void length2049() { + for (Method method : METHODS) { + given().when() + .accept(MediaType.APPLICATION_OCTET_STREAM) + .request(method, "/length/2049") + .then() + .statusCode(500) + .contentType(ContentType.TEXT) + .body(is("Invalid size: 2049")); + } + } + +} \ No newline at end of file diff --git a/src/test/java/com/testainers/MethodsResourceResourceTest.java b/src/test/java/com/testainers/MethodsResourceResourceTest.java deleted file mode 100644 index b449b4c..0000000 --- a/src/test/java/com/testainers/MethodsResourceResourceTest.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusTest; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.Matchers.*; - -/** - * @author Eduardo Folly - */ -@QuarkusTest -public class MethodsResourceResourceTest extends BaseResourceTest { - - @Test - public void testMethodsGet() { - base().get("/methods") - .then() - .statusCode(200) - .body("method", is("GET"), - "queryParameters", is(QUERY_PARAMS), - "headers", - aMapWithSize(greaterThanOrEqualTo(HEADERS.size())), - "headers", - hasEntry(in(HEADERS.keySet()), in(HEADERS.values())) - ); - - } - - @Test - public void testMethodsHead() { - base().head("/methods") - .then() - .statusCode(200); - } - - @Test - public void testMethodsPost() { - json().post("/methods") - .then() - .statusCode(200) - .body("method", is("POST"), - "queryParameters", is(QUERY_PARAMS), - "headers", - aMapWithSize(greaterThanOrEqualTo(HEADERS.size())), - "headers", - hasEntry(in(HEADERS.keySet()), in(HEADERS.values())), - "body", is(BODY) - ); - } - - @Test - public void testMethodsPut() { - json().put("/methods") - .then() - .statusCode(200) - .body("method", is("PUT"), - "queryParameters", is(QUERY_PARAMS), - "headers", - aMapWithSize(greaterThanOrEqualTo(HEADERS.size())), - "headers", - hasEntry(in(HEADERS.keySet()), in(HEADERS.values())), - "body", is(BODY) - ); - } - - @Test - public void testMethodsPatch() { - json().patch("/methods") - .then() - .statusCode(200) - .body("method", is("PATCH"), - "queryParameters", is(QUERY_PARAMS), - "headers", - aMapWithSize(greaterThanOrEqualTo(HEADERS.size())), - "headers", - hasEntry(in(HEADERS.keySet()), in(HEADERS.values())), - "body", is(BODY) - ); - } - - @Test - public void testMethodsDelete() { - json().delete("/methods") - .then() - .statusCode(200) - .body("method", is("DELETE"), - "queryParameters", is(QUERY_PARAMS), - "headers", - aMapWithSize(greaterThanOrEqualTo(HEADERS.size())), - "headers", - hasEntry(in(HEADERS.keySet()), in(HEADERS.values())), - "body", is(BODY) - ); - } - -} \ No newline at end of file diff --git a/src/test/java/com/testainers/MethodsResourceTest.java b/src/test/java/com/testainers/MethodsResourceTest.java new file mode 100644 index 0000000..3ed929c --- /dev/null +++ b/src/test/java/com/testainers/MethodsResourceTest.java @@ -0,0 +1,67 @@ +package com.testainers; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.http.Method; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.*; + +/** + * @author Eduardo Folly + */ +@QuarkusTest +public class MethodsResourceTest extends BaseResourceTest { + + @Test + public void methodsGet() { + base() + .get("/methods") + .then() + .statusCode(200) + .body("", not(""), bodyMatchers(Method.GET)); + } + + @Test + public void methodsHead() { + base().head("/methods") + .then() + .statusCode(200); + } + + @Test + public void methodsPost() { + json(Method.POST) + .post("/methods") + .then() + .statusCode(200) + .body("body", is(BODY), bodyMatchers(Method.POST)); + } + + @Test + public void methodsPut() { + json(Method.PUT) + .put("/methods") + .then() + .statusCode(200) + .body("body", is(BODY), bodyMatchers(Method.PUT)); + } + + @Test + public void methodsPatch() { + json(Method.PATCH) + .patch("/methods") + .then() + .statusCode(200) + .body("body", is(BODY), bodyMatchers(Method.PATCH)); + } + + @Test + public void methodsDelete() { + json(Method.DELETE) + .delete("/methods") + .then() + .statusCode(200) + .body("body", is(BODY), bodyMatchers(Method.DELETE)); + } + +} \ No newline at end of file diff --git a/src/test/java/com/testainers/RedirectResourceDeleteTest.java b/src/test/java/com/testainers/RedirectResourceDeleteTest.java deleted file mode 100644 index 9da4538..0000000 --- a/src/test/java/com/testainers/RedirectResourceDeleteTest.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusTest; -import io.restassured.RestAssured; -import io.restassured.config.RestAssuredConfig; -import io.restassured.http.ContentType; -import jakarta.ws.rs.core.HttpHeaders; -import org.junit.jupiter.api.Test; - -import static io.restassured.RestAssured.given; -import static io.restassured.config.RedirectConfig.redirectConfig; -import static org.hamcrest.Matchers.is; - -/** - * @author Eduardo Folly - */ -@QuarkusTest -public class RedirectResourceDeleteTest { - - static final String LOCATION = "https://testainers.com"; - - static final RestAssuredConfig CONFIG = RestAssured - .config() - .redirect(redirectConfig().followRedirects(false)); - - @Test - public void testRedirectDelete302() { - given().config(CONFIG) - .when() - .queryParam("url", LOCATION) - .delete("/redirect") - .then() - .statusCode(302) - .header(HttpHeaders.LOCATION, LOCATION) - .header(HttpHeaders.CONTENT_LENGTH, "0"); - } - - @Test - public void testRedirectDelete303() { - given().config(CONFIG) - .when() - .queryParam("url", LOCATION) - .queryParam("code", 303) - .delete("/redirect") - .then() - .statusCode(303) - .header(HttpHeaders.LOCATION, LOCATION) - .header(HttpHeaders.CONTENT_LENGTH, "0"); - } - - @Test - public void testRedirectDelete299() { - given().config(CONFIG) - .when() - .queryParam("url", LOCATION) - .queryParam("code", 299) - .delete("/redirect") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid status code: 299")); - } - - @Test - public void testRedirectDelete499() { - given().config(CONFIG) - .when() - .queryParam("url", LOCATION) - .queryParam("code", 499) - .delete("/redirect") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid status code: 499")); - } - - @Test - public void testRedirectDeleteNoUrl() { - given().config(CONFIG) - .when() - .delete("/redirect") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid URL")); - } - - @Test - public void testRedirectDeleteEmptyUrl() { - given().config(CONFIG) - .when() - .queryParam("url", "") - .delete("/redirect") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid URL Scheme")); - } - -} \ No newline at end of file diff --git a/src/test/java/com/testainers/RedirectResourceGetTest.java b/src/test/java/com/testainers/RedirectResourceGetTest.java deleted file mode 100644 index 8f0608c..0000000 --- a/src/test/java/com/testainers/RedirectResourceGetTest.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusTest; -import io.restassured.RestAssured; -import io.restassured.config.RestAssuredConfig; -import io.restassured.http.ContentType; -import jakarta.ws.rs.core.HttpHeaders; -import org.junit.jupiter.api.Test; - -import static io.restassured.RestAssured.given; -import static io.restassured.config.RedirectConfig.redirectConfig; -import static org.hamcrest.Matchers.is; - -/** - * @author Eduardo Folly - */ -@QuarkusTest -public class RedirectResourceGetTest { - - static final String LOCATION = "https://testainers.com"; - - static final RestAssuredConfig CONFIG = RestAssured - .config() - .redirect(redirectConfig().followRedirects(false)); - - @Test - public void testRedirectGet302() { - given().config(CONFIG) - .when() - .queryParam("url", LOCATION) - .get("/redirect") - .then() - .statusCode(302) - .header(HttpHeaders.LOCATION, LOCATION) - .header(HttpHeaders.CONTENT_LENGTH, "0"); - } - - @Test - public void testRedirectGet303() { - given().config(CONFIG) - .when() - .queryParam("url", LOCATION) - .queryParam("code", 303) - .get("/redirect") - .then() - .statusCode(303) - .header(HttpHeaders.LOCATION, LOCATION) - .header(HttpHeaders.CONTENT_LENGTH, "0"); - } - - @Test - public void testRedirectGet299() { - given().config(CONFIG) - .when() - .queryParam("url", LOCATION) - .queryParam("code", 299) - .get("/redirect") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid status code: 299")); - } - - @Test - public void testRedirectGet499() { - given().config(CONFIG) - .when() - .queryParam("url", LOCATION) - .queryParam("code", 499) - .get("/redirect") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid status code: 499")); - } - - @Test - public void testRedirectGetNoUrl() { - given().config(CONFIG) - .when() - .get("/redirect") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid URL")); - } - - @Test - public void testRedirectGetEmptyUrl() { - given().config(CONFIG) - .when() - .queryParam("url", "") - .get("/redirect") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid URL Scheme")); - } - -} \ No newline at end of file diff --git a/src/test/java/com/testainers/RedirectResourcePatchTest.java b/src/test/java/com/testainers/RedirectResourcePatchTest.java deleted file mode 100644 index ef9f124..0000000 --- a/src/test/java/com/testainers/RedirectResourcePatchTest.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusTest; -import io.restassured.RestAssured; -import io.restassured.config.RestAssuredConfig; -import io.restassured.http.ContentType; -import jakarta.ws.rs.core.HttpHeaders; -import org.junit.jupiter.api.Test; - -import static io.restassured.RestAssured.given; -import static io.restassured.config.RedirectConfig.redirectConfig; -import static org.hamcrest.Matchers.is; - -/** - * @author Eduardo Folly - */ -@QuarkusTest -public class RedirectResourcePatchTest { - - static final String LOCATION = "https://testainers.com"; - - static final RestAssuredConfig CONFIG = RestAssured - .config() - .redirect(redirectConfig().followRedirects(false)); - - @Test - public void testRedirectPatch302() { - given().config(CONFIG) - .when() - .queryParam("url", LOCATION) - .patch("/redirect") - .then() - .statusCode(302) - .header(HttpHeaders.LOCATION, LOCATION) - .header(HttpHeaders.CONTENT_LENGTH, "0"); - } - - @Test - public void testRedirectPatch303() { - given().config(CONFIG) - .when() - .queryParam("url", LOCATION) - .queryParam("code", 303) - .patch("/redirect") - .then() - .statusCode(303) - .header(HttpHeaders.LOCATION, LOCATION) - .header(HttpHeaders.CONTENT_LENGTH, "0"); - } - - @Test - public void testRedirectPatch299() { - given().config(CONFIG) - .when() - .queryParam("url", LOCATION) - .queryParam("code", 299) - .patch("/redirect") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid status code: 299")); - } - - @Test - public void testRedirectPatch499() { - given().config(CONFIG) - .when() - .queryParam("url", LOCATION) - .queryParam("code", 499) - .patch("/redirect") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid status code: 499")); - } - - @Test - public void testRedirectPatchNoUrl() { - given().config(CONFIG) - .when() - .patch("/redirect") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid URL")); - } - - @Test - public void testRedirectPatchEmptyUrl() { - given().config(CONFIG) - .when() - .queryParam("url", "") - .patch("/redirect") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid URL Scheme")); - } - -} \ No newline at end of file diff --git a/src/test/java/com/testainers/RedirectResourcePostTest.java b/src/test/java/com/testainers/RedirectResourcePostTest.java deleted file mode 100644 index 50c5d1e..0000000 --- a/src/test/java/com/testainers/RedirectResourcePostTest.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusTest; -import io.restassured.RestAssured; -import io.restassured.config.RestAssuredConfig; -import io.restassured.http.ContentType; -import jakarta.ws.rs.core.HttpHeaders; -import org.junit.jupiter.api.Test; - -import static io.restassured.RestAssured.given; -import static io.restassured.config.RedirectConfig.redirectConfig; -import static org.hamcrest.Matchers.is; - -/** - * @author Eduardo Folly - */ -@QuarkusTest -public class RedirectResourcePostTest { - - static final String LOCATION = "https://testainers.com"; - - static final RestAssuredConfig CONFIG = RestAssured - .config() - .redirect(redirectConfig().followRedirects(false)); - - @Test - public void testRedirectPost302() { - given().config(CONFIG) - .when() - .queryParam("url", LOCATION) - .post("/redirect") - .then() - .statusCode(302) - .header(HttpHeaders.LOCATION, LOCATION) - .header(HttpHeaders.CONTENT_LENGTH, "0"); - } - - @Test - public void testRedirectPost303() { - given().config(CONFIG) - .when() - .queryParam("url", LOCATION) - .queryParam("code", 303) - .post("/redirect") - .then() - .statusCode(303) - .header(HttpHeaders.LOCATION, LOCATION) - .header(HttpHeaders.CONTENT_LENGTH, "0"); - } - - @Test - public void testRedirectPost299() { - given().config(CONFIG) - .when() - .queryParam("url", LOCATION) - .queryParam("code", 299) - .post("/redirect") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid status code: 299")); - } - - @Test - public void testRedirectPost499() { - given().config(CONFIG) - .when() - .queryParam("url", LOCATION) - .queryParam("code", 499) - .post("/redirect") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid status code: 499")); - } - - @Test - public void testRedirectPostNoUrl() { - given().config(CONFIG) - .when() - .post("/redirect") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid URL")); - } - - @Test - public void testRedirectPostEmptyUrl() { - given().config(CONFIG) - .when() - .queryParam("url", "") - .post("/redirect") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid URL Scheme")); - } - -} \ No newline at end of file diff --git a/src/test/java/com/testainers/RedirectResourcePutTest.java b/src/test/java/com/testainers/RedirectResourcePutTest.java deleted file mode 100644 index b6cd130..0000000 --- a/src/test/java/com/testainers/RedirectResourcePutTest.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusTest; -import io.restassured.RestAssured; -import io.restassured.config.RestAssuredConfig; -import io.restassured.http.ContentType; -import jakarta.ws.rs.core.HttpHeaders; -import org.junit.jupiter.api.Test; - -import static io.restassured.RestAssured.given; -import static io.restassured.config.RedirectConfig.redirectConfig; -import static org.hamcrest.Matchers.is; - -/** - * @author Eduardo Folly - */ -@QuarkusTest -public class RedirectResourcePutTest { - - static final String LOCATION = "https://testainers.com"; - - static final RestAssuredConfig CONFIG = RestAssured - .config() - .redirect(redirectConfig().followRedirects(false)); - - @Test - public void testRedirectPut302() { - given().config(CONFIG) - .when() - .queryParam("url", LOCATION) - .put("/redirect") - .then() - .statusCode(302) - .header(HttpHeaders.LOCATION, LOCATION) - .header(HttpHeaders.CONTENT_LENGTH, "0"); - } - - @Test - public void testRedirectPut303() { - given().config(CONFIG) - .when() - .queryParam("url", LOCATION) - .queryParam("code", 303) - .put("/redirect") - .then() - .statusCode(303) - .header(HttpHeaders.LOCATION, LOCATION) - .header(HttpHeaders.CONTENT_LENGTH, "0"); - } - - @Test - public void testRedirectPut299() { - given().config(CONFIG) - .when() - .queryParam("url", LOCATION) - .queryParam("code", 299) - .put("/redirect") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid status code: 299")); - } - - @Test - public void testRedirectPut499() { - given().config(CONFIG) - .when() - .queryParam("url", LOCATION) - .queryParam("code", 499) - .put("/redirect") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid status code: 499")); - } - - @Test - public void testRedirectPutNoUrl() { - given().config(CONFIG) - .when() - .put("/redirect") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid URL")); - } - - @Test - public void testRedirectPutEmptyUrl() { - given().config(CONFIG) - .when() - .queryParam("url", "") - .put("/redirect") - .then() - .statusCode(500) - .contentType(ContentType.TEXT) - .body(is("Invalid URL Scheme")); - } - -} \ No newline at end of file diff --git a/src/test/java/com/testainers/RedirectResourceTest.java b/src/test/java/com/testainers/RedirectResourceTest.java new file mode 100644 index 0000000..8add5db --- /dev/null +++ b/src/test/java/com/testainers/RedirectResourceTest.java @@ -0,0 +1,135 @@ +package com.testainers; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import io.restassured.config.RestAssuredConfig; +import io.restassured.http.ContentType; +import io.restassured.http.Method; +import jakarta.ws.rs.core.HttpHeaders; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static io.restassured.RestAssured.given; +import static io.restassured.config.RedirectConfig.redirectConfig; +import static org.hamcrest.Matchers.is; + +/** + * @author Eduardo Folly + */ +@QuarkusTest +public class RedirectResourceTest { + + static final String LOCATION = "https://testainers.com"; + + static final String INVALID_SCHEME = "testainers.com"; + + static final List METHODS = + List.of(Method.GET, Method.POST, Method.PUT, + Method.PATCH, Method.DELETE); + + static final RestAssuredConfig CONFIG = RestAssured + .config() + .redirect(redirectConfig().followRedirects(false)); + + @Test + public void redirect302() { + for (Method method : METHODS) { + given().config(CONFIG) + .when() + .queryParam("url", LOCATION) + .request(method, "/redirect") + .then() + .statusCode(302) + .header(HttpHeaders.LOCATION, LOCATION) + .header(HttpHeaders.CONTENT_LENGTH, "0"); + } + } + + @Test + public void redirect303() { + for (Method method : METHODS) { + given().config(CONFIG) + .when() + .queryParam("url", LOCATION) + .queryParam("code", 303) + .request(method, "/redirect") + .then() + .statusCode(303) + .header(HttpHeaders.LOCATION, LOCATION) + .header(HttpHeaders.CONTENT_LENGTH, "0"); + } + } + + @Test + public void redirect299() { + for (Method method : METHODS) { + given().config(CONFIG) + .when() + .queryParam("url", LOCATION) + .queryParam("code", 299) + .request(method, "/redirect") + .then() + .statusCode(500) + .contentType(ContentType.TEXT) + .body(is("Invalid status code: 299")); + } + } + + @Test + public void redirect499() { + for (Method method : METHODS) { + given().config(CONFIG) + .when() + .queryParam("url", LOCATION) + .queryParam("code", 499) + .request(method, "/redirect") + .then() + .statusCode(500) + .contentType(ContentType.TEXT) + .body(is("Invalid status code: 499")); + } + } + + @Test + public void redirectNoUrl() { + for (Method method : METHODS) { + given().config(CONFIG) + .when() + .request(method, "/redirect") + .then() + .statusCode(500) + .contentType(ContentType.TEXT) + .body(is("Invalid URL: null")); + } + } + + @Test + public void redirectEmptyUrl() { + for (Method method : METHODS) { + given().config(CONFIG) + .when() + .queryParam("url", "") + .request(method, "/redirect") + .then() + .statusCode(500) + .contentType(ContentType.TEXT) + .body(is("Invalid URL Scheme: ")); + } + } + + @Test + public void redirectInvalidScheme() { + for (Method method : METHODS) { + given().config(CONFIG) + .when() + .queryParam("url", INVALID_SCHEME) + .request(method, "/redirect") + .then() + .statusCode(500) + .contentType(ContentType.TEXT) + .body(is("Invalid URL Scheme: " + INVALID_SCHEME)); + } + } + +} \ No newline at end of file diff --git a/src/test/java/com/testainers/StatusResourceDeleteResourceTest.java b/src/test/java/com/testainers/StatusResourceDeleteResourceTest.java deleted file mode 100644 index bd64fd4..0000000 --- a/src/test/java/com/testainers/StatusResourceDeleteResourceTest.java +++ /dev/null @@ -1,130 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusTest; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.Matchers.*; - -/** - * @author Eduardo Folly - */ -@QuarkusTest -public class StatusResourceDeleteResourceTest extends BaseResourceTest { - - @Test - public void testStatusDeleteString() { - json().delete("/status/a") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testStatusDeleteDouble() { - json().delete("/status/1.8") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testStatusDeleteNegative() { - json().delete("/status/-1") - .then() - .statusCode(500) - .body("body", is("Unknown status code: -1"), - bodyMatchers("DELETE")); - } - - @Test - public void testStatusDelete0() { - json().delete("/status/0") - .then() - .statusCode(500) - .body("body", is("Unknown status code: 0"), - bodyMatchers("DELETE")); - } - - @Test - public void testStatusDelete99() { - json().delete("/status/99") - .then() - .statusCode(500) - .body("body", is("Unknown status code: 99"), - bodyMatchers("DELETE")); - } - - @Test - public void testStatusDelete100() { - json().delete("/status/100") - .then() - .statusCode(500) - .body("body", - is("Informational responses are not supported: 100"), - bodyMatchers("DELETE")); - } - - @Test - public void testStatusDelete199() { - json().delete("/status/199") - .then() - .statusCode(500) - .body("body", - is("Informational responses are not supported: 199"), - bodyMatchers("DELETE")); - } - - @Test - public void testStatusDelete200() { - json().delete("/status/200") - .then() - .statusCode(200) - .body("body", is(BODY), - bodyMatchers("DELETE")); - } - - @Test - public void testStatusDelete204() { - json().delete("/status/204") - .then() - .statusCode(204) - .body(is("")); - } - - @Test - public void testStatusDelete205() { - json().delete("/status/205") - .then() - .statusCode(205) - .headers("content-length", "0") - .body(is("")); - } - - @Test - public void testStatusDelete304() { - json().delete("/status/304") - .then() - .statusCode(304) - .body(is("")); - } - - @Test - public void testStatusDelete599() { - json().delete("/status/599") - .then() - .statusCode(599) - .body("body", is(BODY), - bodyMatchers("DELETE") - ); - } - - @Test - public void testStatusDelete600() { - json().delete("/status/600") - .then() - .statusCode(500) - .body("body", is("Unknown status code: 600"), - bodyMatchers("DELETE")); - } - -} diff --git a/src/test/java/com/testainers/StatusResourceGetResourceTest.java b/src/test/java/com/testainers/StatusResourceGetResourceTest.java deleted file mode 100644 index 683ece0..0000000 --- a/src/test/java/com/testainers/StatusResourceGetResourceTest.java +++ /dev/null @@ -1,138 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusTest; - -import org.junit.jupiter.api.Test; - -import static org.hamcrest.Matchers.*; - -/** - * @author Eduardo Folly - */ -@QuarkusTest -public class StatusResourceGetResourceTest extends BaseResourceTest { - - @Test - public void testStatusGetEmpty() { - base().get("/status") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testStatusGetString() { - base().get("/status/a") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testStatusGetDouble() { - base().get("/status/1.8") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testStatusGetNegative() { - base().get("/status/-1") - .then() - .statusCode(500) - .body("body", is("Unknown status code: -1"), - bodyMatchers("GET")); - } - - @Test - public void testStatusGet0() { - base().get("/status/0") - .then() - .statusCode(500) - .body("body", is("Unknown status code: 0"), - bodyMatchers("GET")); - } - - @Test - public void testStatusGet99() { - base().get("/status/99") - .then() - .statusCode(500) - .body("body", is("Unknown status code: 99"), - bodyMatchers("GET")); - } - - @Test - public void testStatusGet100() { - base().get("/status/100") - .then() - .statusCode(500) - .body("body", - is("Informational responses are not supported: 100"), - bodyMatchers("GET")); - } - - @Test - public void testStatusGet199() { - base().get("/status/199") - .then() - .statusCode(500) - .body("body", - is("Informational responses are not supported: 199"), - bodyMatchers("GET")); - } - - @Test - public void testStatusGet200() { - base().get("/status/200") - .then() - .statusCode(200) - .body("body", nullValue(), - bodyMatchers("GET")); - } - - @Test - public void testStatusGet204() { - base().get("/status/204") - .then() - .statusCode(204) - .body(is("")); - } - - @Test - public void testStatusGet205() { - base().get("/status/205") - .then() - .statusCode(205) - .headers("content-length", "0") - .body(is("")); - } - - @Test - public void testStatusGet304() { - base().get("/status/304") - .then() - .statusCode(304) - .body(is("")); - } - - @Test - public void testStatusGet599() { - base().get("/status/599") - .then() - .statusCode(599) - .body("body", nullValue(), - bodyMatchers("GET")); - } - - @Test - public void testStatusGet600() { - base().get("/status/600") - .then() - .statusCode(500) - .body("body", is("Unknown status code: 600"), - bodyMatchers("GET")); - } - -} diff --git a/src/test/java/com/testainers/StatusResourceHeadResourceTest.java b/src/test/java/com/testainers/StatusResourceHeadResourceTest.java deleted file mode 100644 index aabc5a1..0000000 --- a/src/test/java/com/testainers/StatusResourceHeadResourceTest.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusTest; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.CoreMatchers.*; - -/** - * @author Eduardo Folly - */ -@QuarkusTest -public class StatusResourceHeadResourceTest extends BaseResourceTest { - - @Test - public void testStatusHeadString() { - base().head("/status/a") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testStatusHeadDouble() { - base().head("/status/1.8") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testStatusHeadNegative() { - base().head("/status/-1") - .then() - .statusCode(500) - .body(is("")); - } - - @Test - public void testStatusHead0() { - base().head("/status/0") - .then() - .statusCode(500) - .body(is("")); - } - - @Test - public void testStatusHead99() { - base().head("/status/99") - .then() - .statusCode(500) - .body(is("")); - } - - @Test - public void testStatusHead100() { - base().head("/status/100") - .then() - .statusCode(500) - .body(is("")); - } - - @Test - public void testStatusHead199() { - base().head("/status/199") - .then() - .statusCode(500) - .body(is("")); - } - - @Test - public void testStatusHead200() { - base().head("/status/200") - .then() - .statusCode(200) - .body(is("")); - } - - @Test - public void testStatusHead204() { - base().head("/status/204") - .then() - .statusCode(204) - .body(is("")); - } - - @Test - public void testStatusHead205() { - base().head("/status/205") - .then() - .statusCode(205) - .headers("content-length", "0") - .body(is("")); - } - - @Test - public void testStatusHead304() { - base().head("/status/304") - .then() - .statusCode(304) - .body(is("")); - } - - @Test - public void testStatusHead599() { - base().head("/status/599") - .then() - .statusCode(599) - .body(is("")); - } - - @Test - public void testStatusHead600() { - base().head("/status/600") - .then() - .statusCode(500) - .body(is("")); - } - -} diff --git a/src/test/java/com/testainers/StatusResourcePatchResourceTest.java b/src/test/java/com/testainers/StatusResourcePatchResourceTest.java deleted file mode 100644 index 289936d..0000000 --- a/src/test/java/com/testainers/StatusResourcePatchResourceTest.java +++ /dev/null @@ -1,130 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusTest; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.Matchers.*; - -/** - * @author Eduardo Folly - */ -@QuarkusTest -public class StatusResourcePatchResourceTest extends BaseResourceTest { - - @Test - public void testStatusPatchString() { - base().patch("/status/a") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testStatusPatchDouble() { - base().patch("/status/1.8") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testStatusPatchNegative() { - json().patch("/status/-1") - .then() - .statusCode(500) - .body("body", is("Unknown status code: -1"), - bodyMatchers("PATCH")) - ; - } - - @Test - public void testStatusPatch0() { - json().patch("/status/0") - .then() - .statusCode(500) - .body("body", is("Unknown status code: 0"), - bodyMatchers("PATCH")); - } - - @Test - public void testStatusPatch99() { - json().patch("/status/99") - .then() - .statusCode(500) - .body("body", is("Unknown status code: 99"), - bodyMatchers("PATCH")); - } - - @Test - public void testStatusPatch100() { - json().patch("/status/100") - .then() - .statusCode(500) - .body("body", - is("Informational responses are not supported: 100"), - bodyMatchers("PATCH")); - } - - @Test - public void testStatusPatch199() { - json().patch("/status/199") - .then() - .statusCode(500) - .body("body", - is("Informational responses are not supported: 199"), - bodyMatchers("PATCH")); - } - - @Test - public void testStatusPatch200() { - json().patch("/status/200") - .then() - .statusCode(200) - .body("body", is(BODY), - bodyMatchers("PATCH")); - } - - @Test - public void testStatusPatch204() { - json().patch("/status/204") - .then() - .statusCode(204) - .body(is("")); - } - - @Test - public void testStatusPatch205() { - json().patch("/status/205") - .then() - .statusCode(205) - .headers("content-length", "0") - .body(is("")); - } - - @Test - public void testStatusPatch304() { - json().patch("/status/304") - .then() - .statusCode(304) - .body(is("")); - } - - @Test - public void testStatusPatch599() { - json().patch("/status/599") - .then() - .statusCode(599) - .body("body", is(BODY), - bodyMatchers("PATCH")); - } - - @Test - public void testStatusPatch600() { - json().patch("/status/600") - .then() - .statusCode(500) - .body("body", is("Unknown status code: 600"), - bodyMatchers("PATCH")); - } - -} diff --git a/src/test/java/com/testainers/StatusResourcePostResourceTest.java b/src/test/java/com/testainers/StatusResourcePostResourceTest.java deleted file mode 100644 index ef90b51..0000000 --- a/src/test/java/com/testainers/StatusResourcePostResourceTest.java +++ /dev/null @@ -1,129 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusTest; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.Matchers.*; - -/** - * @author Eduardo Folly - */ -@QuarkusTest -public class StatusResourcePostResourceTest extends BaseResourceTest { - - @Test - public void testStatusPostString() { - base().post("/status/a") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testStatusPostDouble() { - base().post("/status/1.8") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testStatusPostNegative() { - json().post("/status/-1") - .then() - .statusCode(500) - .body("body", is("Unknown status code: -1"), - bodyMatchers("POST")); - } - - @Test - public void testStatusPost0() { - json().post("/status/0") - .then() - .statusCode(500) - .body("body", is("Unknown status code: 0"), - bodyMatchers("POST")); - } - - @Test - public void testStatusPost99() { - json().post("/status/99") - .then() - .statusCode(500) - .body("body", is("Unknown status code: 99"), - bodyMatchers("POST")); - } - - @Test - public void testStatusPost100() { - json().post("/status/100") - .then() - .statusCode(500) - .body("body", - is("Informational responses are not supported: 100"), - bodyMatchers("POST")); - } - - @Test - public void testStatusPost199() { - json().post("/status/199") - .then() - .statusCode(500) - .body("body", - is("Informational responses are not supported: 199"), - bodyMatchers("POST")); - } - - @Test - public void testStatusPost200() { - json().post("/status/200") - .then() - .statusCode(200) - .body("body", is(BODY), - bodyMatchers("POST")); - } - - @Test - public void testStatusPost204() { - json().post("/status/204") - .then() - .statusCode(204) - .body(is("")); - } - - @Test - public void testStatusPost205() { - json().post("/status/205") - .then() - .statusCode(205) - .headers("content-length", "0") - .body(is("")); - } - - @Test - public void testStatusPost304() { - json().post("/status/304") - .then() - .statusCode(304) - .body(is("")); - } - - @Test - public void testStatusPost599() { - json().post("/status/599") - .then() - .statusCode(599) - .body("body", is(BODY), - bodyMatchers("POST")); - } - - @Test - public void testStatusPost600() { - json().post("/status/600") - .then() - .statusCode(500) - .body("body", is("Unknown status code: 600"), - bodyMatchers("POST")); - } - -} diff --git a/src/test/java/com/testainers/StatusResourcePutResourceTest.java b/src/test/java/com/testainers/StatusResourcePutResourceTest.java deleted file mode 100644 index 4089413..0000000 --- a/src/test/java/com/testainers/StatusResourcePutResourceTest.java +++ /dev/null @@ -1,129 +0,0 @@ -package com.testainers; - -import io.quarkus.test.junit.QuarkusTest; -import org.junit.jupiter.api.Test; - -import static org.hamcrest.Matchers.*; - -/** - * @author Eduardo Folly - */ -@QuarkusTest -public class StatusResourcePutResourceTest extends BaseResourceTest { - - @Test - public void testStatusPutString() { - base().put("/status/a") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testStatusPutDouble() { - base().put("/status/1.8") - .then() - .statusCode(404) - .statusLine(containsStringIgnoringCase("Not Found")); - } - - @Test - public void testStatusPutNegative() { - json().put("/status/-1") - .then() - .statusCode(500) - .body("body", is("Unknown status code: -1"), - bodyMatchers("PUT")); - } - - @Test - public void testStatusPut0() { - json().put("/status/0") - .then() - .statusCode(500) - .body("body", is("Unknown status code: 0"), - bodyMatchers("PUT")); - } - - @Test - public void testStatusPut99() { - json().put("/status/99") - .then() - .statusCode(500) - .body("body", is("Unknown status code: 99"), - bodyMatchers("PUT")); - } - - @Test - public void testStatusPut100() { - json().put("/status/100") - .then() - .statusCode(500) - .body("body", - is("Informational responses are not supported: 100"), - bodyMatchers("PUT")); - } - - @Test - public void testStatusPut199() { - json().put("/status/199") - .then() - .statusCode(500) - .body("body", - is("Informational responses are not supported: 199"), - bodyMatchers("PUT")); - } - - @Test - public void testStatusPut200() { - json().put("/status/200") - .then() - .statusCode(200) - .body("body", is(BODY), - bodyMatchers("PUT")); - } - - @Test - public void testStatusPut204() { - json().put("/status/204") - .then() - .statusCode(204) - .body(is("")); - } - - @Test - public void testStatusPut205() { - json().put("/status/205") - .then() - .statusCode(205) - .headers("content-length", "0") - .body(is("")); - } - - @Test - public void testStatusPut304() { - json().put("/status/304") - .then() - .statusCode(304) - .body(is("")); - } - - @Test - public void testStatusPut599() { - json().put("/status/599") - .then() - .statusCode(599) - .body("body", is(BODY), - bodyMatchers("PUT")); - } - - @Test - public void testStatusPut600() { - json().put("/status/600") - .then() - .statusCode(500) - .body("body", is("Unknown status code: 600"), - bodyMatchers("PUT")); - } - -} diff --git a/src/test/java/com/testainers/StatusResourceTest.java b/src/test/java/com/testainers/StatusResourceTest.java new file mode 100644 index 0000000..db1d3ef --- /dev/null +++ b/src/test/java/com/testainers/StatusResourceTest.java @@ -0,0 +1,160 @@ +package com.testainers; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.http.Method; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.*; + +/** + * @author Eduardo Folly + */ +@QuarkusTest +public class StatusResourceTest extends BaseResourceTest { + + @Test + public void statusString() { + for (Method method : METHODS) { + base().request(method, "/status/a") + .then() + .statusCode(404) + .statusLine(containsStringIgnoringCase("Not Found")); + } + } + + @Test + public void statusDouble() { + for (Method method : METHODS) { + base().request(method, "/status/1.8") + .then() + .statusCode(404) + .statusLine(containsStringIgnoringCase("Not Found")); + } + } + + @Test + public void statusNegative() { + for (Method method : METHODS) { + json(method).request(method, "/status/-1") + .then() + .statusCode(500) + .body("body", is("Unknown status code: -1"), + bodyMatchers(method)); + } + } + + @Test + public void status0() { + for (Method method : METHODS) { + json(method).request(method, "/status/0") + .then() + .statusCode(500) + .body("body", is("Unknown status code: 0"), + bodyMatchers(method)); + } + } + + @Test + public void status99() { + for (Method method : METHODS) { + json(method).request(method, "/status/99") + .then() + .statusCode(500) + .body("body", is("Unknown status code: 99"), + bodyMatchers(method)); + } + } + + @Test + public void status100() { + for (Method method : METHODS) { + json(method).request(method, "/status/100") + .then() + .statusCode(500) + .body("body", + is("Informational responses are not supported: 100"), + bodyMatchers(method)); + } + } + + @Test + public void status199() { + for (Method method : METHODS) { + json(method) + .request(method, "/status/199") + .then() + .statusCode(500) + .body("body", + is("Informational responses are not supported: 199"), + bodyMatchers(method)); + } + } + + @Test + public void status200() { + for (Method method : METHODS) { + json(method) + .request(method, "/status/200") + .then() + .statusCode(200) + .body("body", + method == Method.GET ? not(BODY) : is(BODY), + bodyMatchers(method)); + } + } + + @Test + public void status204() { + for (Method method : METHODS) { + json(method).request(method, "/status/204") + .then() + .statusCode(204) + .body(is("")); + } + } + + @Test + public void status205() { + for (Method method : METHODS) { + json(method).request(method, "/status/205") + .then() + .statusCode(205) + .headers("content-length", "0") + .body(is("")); + } + } + + @Test + public void status304() { + for (Method method : METHODS) { + json(method).request(method, "/status/304") + .then() + .statusCode(304) + .body(is("")); + } + } + + @Test + public void status599() { + for (Method method : METHODS) { + json(method).request(method, "/status/599") + .then() + .statusCode(599) + .body("body", + method == Method.GET ? not(BODY) : is(BODY), + bodyMatchers(method)); + } + } + + @Test + public void status600() { + for (Method method : METHODS) { + json(method).request(method, "/status/600") + .then() + .statusCode(500) + .body("body", is("Unknown status code: 600"), + bodyMatchers(method)); + } + } + +}