-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
LocalDateParamTest.java
74 lines (59 loc) · 2.28 KB
/
LocalDateParamTest.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
65
66
67
68
69
70
71
72
73
74
package org.jboss.resteasy.reactive.server.vertx.test.simple;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import jakarta.ws.rs.FormParam;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.QueryParam;
import org.hamcrest.Matchers;
import org.jboss.resteasy.reactive.DateFormat;
import org.jboss.resteasy.reactive.server.vertx.test.framework.ResteasyReactiveUnitTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import io.restassured.RestAssured;
public class LocalDateParamTest {
@RegisterExtension
static ResteasyReactiveUnitTest test = new ResteasyReactiveUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(HelloResource.class, CustomDateTimeFormatterProvider.class));
@Test
public void localDateAsQueryParam() {
RestAssured.get("/hello?date=08-08-1984")
.then().statusCode(200).body(Matchers.equalTo("hello#1984-08-08"));
}
@Test
public void localDateAsPathParam() {
RestAssured.get("/hello/1995-09-21")
.then().statusCode(200).body(Matchers.equalTo("hello@1995-09-21"));
}
@Test
public void localDateAsFormParam() {
RestAssured.given().formParam("date", "1995/09/22").post("/hello")
.then().statusCode(200).body(Matchers.equalTo("hello:1995-09-22"));
}
@Path("hello")
public static class HelloResource {
@GET
public String helloQuery(@QueryParam("date") @DateFormat(pattern = "dd-MM-yyyy") LocalDate date) {
return "hello#" + date;
}
@GET
@Path("{date}")
public String helloPath(@PathParam("date") LocalDate date) {
return "hello@" + date;
}
@POST
public String helloForm(
@FormParam("date") @DateFormat(dateTimeFormatterProvider = CustomDateTimeFormatterProvider.class) LocalDate date) {
return "hello:" + date;
}
}
public static class CustomDateTimeFormatterProvider implements DateFormat.DateTimeFormatterProvider {
@Override
public DateTimeFormatter get() {
return DateTimeFormatter.ofPattern("yyyy/MM/dd");
}
}
}