Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow QuarkusTest to override base URL of REST client #10196

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bom/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,11 @@
<artifactId>quarkus-junit5-mockito</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-test-rest-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arquillian</artifactId>
Expand Down
3 changes: 1 addition & 2 deletions integration-tests/rest-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
<!-- Test dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
<artifactId>quarkus-test-rest-client</artifactId>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.it.rest.client;

import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
Expand All @@ -11,11 +12,12 @@

@Path("/echo")
@RegisterRestClient
@ApplicationScoped
public interface MultipartService {

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
String sendMultipartData(@MultipartForm MultipartBody data);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.quarkus.it.rest.client.server;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/another/new")
public class AnotherEchoService {

@Path("/echo")
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
public String echo(String requestBody) throws Exception {
return "another";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.quarkus.it.rest.client.server;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/other/echo")
public class OtherEchoService {

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
public String echo(String requestBody) throws Exception {
return "other";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@
import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.containsString;

import java.net.URI;
import java.net.URISyntaxException;

import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;

import io.quarkus.test.junit.DisabledOnNativeImage;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.restclient.RestClientTestSupport;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@QuarkusTest
public class MultipartResourceTest {

@Order(3) // execute this last to make sure that the reset of the base URL is properly performed automatically
@Test
public void testMultipartDataIsSent() {
given()
Expand All @@ -23,4 +33,30 @@ public void testMultipartDataIsSent() {
containsString("greeting.txt"));
}

@DisabledOnNativeImage
@Order(1)
@Test
public void testCustomEcho() throws URISyntaxException {
RestClientTestSupport.setBaseURI(MultipartService.class, new URI(System.getProperty("test.url") + "/other"));
given()
.header("Content-Type", "text/plain")
.when().post("/client/multipart")
.then()
.statusCode(200)
.body(containsString("other"));
}

@DisabledOnNativeImage
@Order(2)
@Test
public void testAnotherCustomEcho() throws URISyntaxException {
RestClientTestSupport.setBaseURI(MultipartService.class, new URI(System.getProperty("test.url") + "/another/new"));
given()
.header("Content-Type", "text/plain")
.when().post("/client/multipart")
.then()
.statusCode(200)
.body(containsString("another"));
}

}
1 change: 1 addition & 0 deletions test-framework/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<module>maven</module>
<module>vault</module>
<module>ldap</module>
<module>rest-client</module>
</modules>

</project>
57 changes: 57 additions & 0 deletions test-framework/rest-client/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-test-framework</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

<artifactId>quarkus-test-rest-client</artifactId>
<name>Quarkus - Test framework - REST Client</name>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client-microprofile</artifactId>
<exclusions>
<exclusion>
<groupId>org.jboss.spec.javax.interceptor</groupId>
<artifactId>
jboss-interceptors-api_1.2_spec
</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-cdi</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>commons-logging-jboss-logging</artifactId>
</dependency>
</dependencies>

</project>
Loading