-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #178 from jsmrcka/resteasy-reactive
Add RESTEasy Reactive JAX-RS scenario
- Loading branch information
Showing
21 changed files
with
276 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?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.ts.qe</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<relativePath>../..</relativePath> | ||
</parent> | ||
<artifactId>jaxrs-reactive</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Quarkus QE TS: HTTP: jaxrs-reactive</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-reactive</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
23 changes: 23 additions & 0 deletions
23
http/jaxrs-reactive/src/main/java/io/quarkus/ts/jaxrs/reactive/MultipartBody.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.quarkus.ts.jaxrs.reactive; | ||
|
||
import java.io.File; | ||
|
||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.jboss.resteasy.reactive.PartType; | ||
import org.jboss.resteasy.reactive.RestForm; | ||
|
||
public class MultipartBody { | ||
|
||
@RestForm("text") | ||
@PartType(MediaType.TEXT_PLAIN) | ||
public String text; | ||
|
||
@RestForm("image") | ||
@PartType("image/png") | ||
public File image; | ||
|
||
@RestForm("data") | ||
@PartType(MediaType.APPLICATION_OCTET_STREAM) | ||
public File data; | ||
} |
55 changes: 55 additions & 0 deletions
55
http/jaxrs-reactive/src/main/java/io/quarkus/ts/jaxrs/reactive/MultipartResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package io.quarkus.ts.jaxrs.reactive; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.jboss.resteasy.reactive.MultipartForm; | ||
|
||
@Path("/multipart") | ||
public class MultipartResource { | ||
|
||
@POST | ||
@Consumes(MediaType.MULTIPART_FORM_DATA) | ||
@Produces(MediaType.MULTIPART_FORM_DATA) | ||
public MultipartBody postForm(@MultipartForm MultipartBody multipartBody) { | ||
return multipartBody; | ||
} | ||
|
||
@POST | ||
@Path("/text") | ||
@Consumes(MediaType.MULTIPART_FORM_DATA) | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String postFormReturnText(@MultipartForm MultipartBody multipartBody) { | ||
return multipartBody.text; | ||
} | ||
|
||
@POST | ||
@Path("/image") | ||
@Consumes(MediaType.MULTIPART_FORM_DATA) | ||
@Produces(MediaType.APPLICATION_OCTET_STREAM) | ||
public byte[] postFormReturnFile(@MultipartForm MultipartBody multipartBody) throws IOException { | ||
return IOUtils.toByteArray(multipartBody.image.toURI()); | ||
} | ||
|
||
@POST | ||
@Path("/data") | ||
@Consumes(MediaType.MULTIPART_FORM_DATA) | ||
@Produces(MediaType.APPLICATION_OCTET_STREAM) | ||
public byte[] postFormReturnData(@MultipartForm MultipartBody multipartBody) throws IOException { | ||
return IOUtils.toByteArray(multipartBody.data.toURI()); | ||
} | ||
|
||
@POST | ||
@Path("/echo") | ||
@Consumes(MediaType.MULTIPART_FORM_DATA) | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String echo(String requestBody) { | ||
return requestBody; | ||
} | ||
} |
Empty file.
43 changes: 43 additions & 0 deletions
43
http/jaxrs-reactive/src/test/java/io/quarkus/ts/jaxrs/reactive/AsciiMultipartResourceIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.quarkus.ts.jaxrs.reactive; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.not; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.bootstrap.RestService; | ||
import io.quarkus.test.scenarios.QuarkusScenario; | ||
import io.quarkus.test.services.QuarkusApplication; | ||
import io.restassured.builder.MultiPartSpecBuilder; | ||
import io.restassured.http.ContentType; | ||
import io.restassured.specification.MultiPartSpecification; | ||
|
||
@QuarkusScenario | ||
public class AsciiMultipartResourceIT { | ||
|
||
public static final String TEXT_WITH_DIACRITICS = "Přikrášlený žloťoučký kůň úpěl ďábelské ódy."; | ||
private static final String EXPECTED_ASCII_TEXT = new String(TEXT_WITH_DIACRITICS.getBytes(StandardCharsets.UTF_8), | ||
StandardCharsets.US_ASCII); | ||
|
||
@QuarkusApplication | ||
static RestService app = new RestService().withProperties("us-asscii.properties"); | ||
|
||
@Test | ||
public void testMultipartText() { | ||
MultiPartSpecification multiPartSpecification = new MultiPartSpecBuilder(TEXT_WITH_DIACRITICS) | ||
.controlName("text") | ||
.header("Content-Type", "text/plain") | ||
.charset(StandardCharsets.UTF_8) | ||
.build(); | ||
|
||
app.given().multiPart(multiPartSpecification) | ||
.post("/multipart/text") | ||
.then() | ||
.statusCode(200) | ||
.contentType(ContentType.TEXT) | ||
.body(not(equalTo(TEXT_WITH_DIACRITICS))) | ||
.body(equalTo(EXPECTED_ASCII_TEXT)); | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
http/jaxrs-reactive/src/test/java/io/quarkus/ts/jaxrs/reactive/MultipartResourceIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package io.quarkus.ts.jaxrs.reactive; | ||
|
||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Random; | ||
|
||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.scenarios.QuarkusScenario; | ||
import io.restassured.RestAssured; | ||
import io.restassured.builder.MultiPartSpecBuilder; | ||
import io.restassured.http.ContentType; | ||
import io.restassured.response.ValidatableResponse; | ||
import io.restassured.specification.MultiPartSpecification; | ||
|
||
@QuarkusScenario | ||
public class MultipartResourceIT { | ||
|
||
private static final String IMAGE_FILE_NAME = "/quarkus.png"; | ||
private static final String TEXT_WITH_DIACRITICS = "Přikrášlený žloťoučký kůň úpěl ďábelské ódy."; | ||
private static byte[] randomBytes = new byte[120]; | ||
private static File imageFile; | ||
private static byte[] imageBytes; | ||
|
||
@BeforeAll | ||
public static void beforeAll() throws IOException { | ||
imageFile = new File(MultipartResourceIT.class.getResource(IMAGE_FILE_NAME).getFile()); | ||
imageBytes = IOUtils.toByteArray(MultipartResourceIT.class.getResourceAsStream(IMAGE_FILE_NAME)); | ||
new Random().nextBytes(randomBytes); | ||
} | ||
|
||
@Test | ||
public void testMultipartIsSendAndReceived() { | ||
whenSendMultipartData("/multipart") | ||
.contentType("multipart/form-data"); | ||
} | ||
|
||
@Test | ||
public void testTextVersionOfMultipart() { | ||
whenSendMultipartData("/multipart/echo") | ||
.contentType(ContentType.TEXT) | ||
.body( | ||
containsString("Content-Disposition: form-data; name=\"text\""), | ||
containsString("Content-Disposition: form-data; name=\"data\"; filename=\"random.dat\""), | ||
containsString("Content-Disposition: form-data; name=\"image\"; filename=\"quarkus.png\""), | ||
containsString(TEXT_WITH_DIACRITICS)); | ||
} | ||
|
||
@Test | ||
public void testTextPartFromMultipart() { | ||
whenSendMultipartData("/multipart/text") | ||
.contentType(ContentType.TEXT) | ||
.body(equalTo(TEXT_WITH_DIACRITICS)); | ||
} | ||
|
||
@Test | ||
public void testImagePartFromMultipart() { | ||
byte[] receivedBytes = whenSendMultipartData("/multipart/image") | ||
.contentType(MediaType.APPLICATION_OCTET_STREAM) | ||
.extract().asByteArray(); | ||
assertThat(receivedBytes, equalTo(imageBytes)); | ||
} | ||
|
||
@Test | ||
public void testDataPartFromMultipart() { | ||
byte[] receivedBytes = whenSendMultipartData("/multipart/data") | ||
.contentType(MediaType.APPLICATION_OCTET_STREAM) | ||
.extract().asByteArray(); | ||
assertThat(receivedBytes, equalTo(randomBytes)); | ||
} | ||
|
||
private ValidatableResponse whenSendMultipartData(String path) { | ||
MultiPartSpecification textSpec = new MultiPartSpecBuilder(TEXT_WITH_DIACRITICS) | ||
.controlName("text") | ||
.mimeType("text/plain") | ||
.charset(StandardCharsets.UTF_8) | ||
.build(); | ||
MultiPartSpecification dataSpec = new MultiPartSpecBuilder(randomBytes) | ||
.controlName("data") | ||
.fileName("random.dat") | ||
.header("Content-Type", "application/octet-stream") | ||
.build(); | ||
MultiPartSpecification imageSpec = new MultiPartSpecBuilder(imageFile) | ||
.controlName("image") | ||
.fileName("quarkus.png") | ||
.mimeType("image/png") | ||
.build(); | ||
|
||
return RestAssured.given() | ||
.contentType("multipart/form-data") | ||
.multiPart(textSpec) | ||
.multiPart(imageSpec) | ||
.multiPart(dataSpec) | ||
.post(path) | ||
.then() | ||
.statusCode(200); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...xrs-reactive/src/test/java/io/quarkus/ts/jaxrs/reactive/OpenShiftMultipartResourceIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.quarkus.ts.jaxrs.reactive; | ||
|
||
import io.quarkus.test.scenarios.OpenShiftScenario; | ||
|
||
@OpenShiftScenario | ||
public class OpenShiftMultipartResourceIT extends MultipartResourceIT { | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
quarkus.resteasy-reactive.multipart.input-part.default-charset=us-ascii |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.