-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
WithFormBodyTest.java
64 lines (53 loc) · 1.96 KB
/
WithFormBodyTest.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
62
63
64
package io.quarkus.resteasy.reactive.server.test.customproviders;
import java.util.function.Supplier;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.hamcrest.Matchers;
import org.jboss.resteasy.reactive.RestForm;
import org.jboss.resteasy.reactive.server.WithFormRead;
import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext;
import org.jboss.resteasy.reactive.server.spi.ServerRequestContext;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;
public class WithFormBodyTest {
@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.setArchiveProducer(new Supplier<>() {
@Override
public JavaArchive get() {
return ShrinkWrap.create(JavaArchive.class)
.addClasses(HelloResource.class);
}
});
@Test
public void testMethodWithBody() {
RestAssured.with()
.formParam("name", "Quarkus")
.post("/hello")
.then().body(Matchers.equalTo("hello Quarkus"));
}
@Test
public void testMethodWithUndeclaredBody() {
RestAssured.with()
.formParam("name", "Quarkus")
.post("/hello/empty")
.then().body(Matchers.equalTo("hello Quarkus"));
}
@Path("hello")
public static class HelloResource {
@POST
public String helloPost(@RestForm String name) {
return "hello " + name;
}
@WithFormRead
@Path("empty")
@POST
public String helloEmptyPost(ServerRequestContext requestContext) {
return "hello " + ((ResteasyReactiveRequestContext) requestContext).getFormParameter("name", true, false);
}
}
}