forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomHeadersAndWriterInterceptorTest.java
61 lines (51 loc) · 1.92 KB
/
CustomHeadersAndWriterInterceptorTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package org.jboss.resteasy.reactive.server.vertx.test.response;
import static io.restassured.RestAssured.when;
import static org.assertj.core.api.Assertions.*;
import static org.hamcrest.Matchers.is;
import io.restassured.http.Headers;
import java.io.IOException;
import java.util.Date;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;
import javax.ws.rs.ext.WriterInterceptor;
import javax.ws.rs.ext.WriterInterceptorContext;
import org.jboss.resteasy.reactive.server.vertx.test.framework.ResteasyReactiveUnitTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
public class CustomHeadersAndWriterInterceptorTest {
@RegisterExtension
static ResteasyReactiveUnitTest runner = new ResteasyReactiveUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(TestResource.class, DummyWriterInterceptor.class));
@Test
void testResponseHeaders() {
Headers headers = when()
.get("/test")
.then()
.statusCode(200)
.header("etag", is("0"))
.extract().headers();
assertThat(headers.getList("etag")).hasSize(1);
assertThat(headers.getList("Last-Modified")).hasSize(1);
}
@Path("/test")
public static class TestResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public Response hello() {
return Response.ok("123").lastModified(new Date()).header("etag", 0).build();
}
}
@Provider
public static class DummyWriterInterceptor implements WriterInterceptor {
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
context.proceed();
}
}
}