11package io .github .belgif .rest .problem ;
22
3- import static org .hamcrest .Matchers .*;
3+ import java .util .Arrays ;
4+ import java .util .stream .Stream ;
45
56import org .junit .jupiter .api .AfterAll ;
6- import org .junit .jupiter .api .BeforeEach ;
7- import org .junit .jupiter .api .Test ;
8- import org .junit .jupiter .params .ParameterizedTest ;
9- import org .junit .jupiter .params .provider .EnumSource ;
107import org .slf4j .Logger ;
118import org .slf4j .LoggerFactory ;
129import org .testcontainers .containers .GenericContainer ;
2219import io .restassured .specification .RequestSpecification ;
2320
2421@ Testcontainers
25- class RestProblemJakartaEeIT {
22+ class RestProblemJakartaEeIT extends AbstractRestProblemIT {
2623
2724 private static final Logger LOGGER = LoggerFactory .getLogger (RestProblemJakartaEeIT .class );
2825
2926 @ Container
3027 @ SuppressWarnings ({ "rawtypes" , "unchecked" })
31- public static final GenericContainer JBOSS_CONTAINER =
28+ public static final GenericContainer WILDFLY_CONTAINER =
3229 new GenericContainer ("quay.io/wildfly/wildfly:31.0.1.Final-jdk17" )
3330 .withEnv ("PREPEND_JAVA_OPTS" , "-javaagent:/opt/jboss/wildfly/standalone/deployments/jacocoagent.jar"
3431 + "=destfile=/tmp/jacoco-it.exec,includes=io.github.belgif.rest.problem.*" )
@@ -42,117 +39,25 @@ class RestProblemJakartaEeIT {
4239 .waitingFor (Wait .forLogMessage (".*WFLYSRV0025.*" , 1 ))
4340 .withLogConsumer (new Slf4jLogConsumer (LOGGER ));
4441
45- enum Client {
46- MICROPROFILE , JAXRS , JAXRS_ASYNC , RESTEASY , RESTEASY_PROXY
47- }
48-
49- private RequestSpecification spec ;
50-
5142 @ AfterAll
5243 static void dumpJacocoReport () {
53- try (StopContainerCmd stop = JBOSS_CONTAINER .getDockerClient ()
54- .stopContainerCmd (JBOSS_CONTAINER .getContainerId ())) {
44+ try (StopContainerCmd stop = WILDFLY_CONTAINER .getDockerClient ()
45+ .stopContainerCmd (WILDFLY_CONTAINER .getContainerId ())) {
5546 stop .exec ();
56- JBOSS_CONTAINER .copyFileFromContainer ("/tmp/jacoco-it.exec" , "target/jacoco-it.exec" );
47+ WILDFLY_CONTAINER .copyFileFromContainer ("/tmp/jacoco-it.exec" , "target/jacoco-it.exec" );
5748 }
5849 }
5950
60- @ BeforeEach
61- void before () {
62- spec = RestAssured .with ().baseUri ("http://" + JBOSS_CONTAINER .getHost ())
63- .port (JBOSS_CONTAINER .getMappedPort (8080 ))
51+ @ Override
52+ protected RequestSpecification getSpec () {
53+ return RestAssured .with ().baseUri ("http://" + WILDFLY_CONTAINER .getHost ())
54+ .port (WILDFLY_CONTAINER .getMappedPort (8080 ))
6455 .basePath ("/rest-problem/frontend" );
6556 }
6657
67- @ Test
68- void badRequest () {
69- spec .when ().get ("/badRequest" ).then ().assertThat ()
70- .statusCode (400 )
71- .body ("type" , equalTo ("urn:problem-type:belgif:badRequest" ))
72- .body ("detail" , equalTo ("Bad Request from frontend" ));
73- }
74-
75- @ Test
76- void custom () {
77- spec .when ().get ("/custom" ).then ().assertThat ()
78- .statusCode (409 )
79- .body ("type" , equalTo ("urn:problem-type:acme:custom" ))
80- .body ("customField" , equalTo ("value from frontend" ));
81- }
82-
83- @ Test
84- void runtime () {
85- spec .when ().get ("/runtime" ).then ().assertThat ()
86- .statusCode (500 )
87- .body ("type" , equalTo ("urn:problem-type:belgif:internalServerError" ));
88- }
89-
90- @ Test
91- void unmapped () {
92- spec .when ().get ("/unmapped" ).then ().assertThat ()
93- .statusCode (400 )
94- .body ("type" , equalTo ("urn:problem-type:belgif:test:unmapped" ))
95- .body ("detail" , equalTo ("Unmapped problem from frontend" ));
96- }
97-
98- @ Test
99- void retryAfter () {
100- spec .when ().get ("/retryAfter" ).then ().assertThat ()
101- .statusCode (503 )
102- .header ("Retry-After" , "10000" )
103- .body ("type" , equalTo ("urn:problem-type:belgif:serviceUnavailable" ));
104- }
105-
106- @ ParameterizedTest
107- @ EnumSource
108- void badRequestFromBackend (Client client ) {
109- spec .when ().get ("/badRequestFromBackend?client=" + client ).then ().assertThat ()
110- .statusCode (400 )
111- .body ("type" , equalTo ("urn:problem-type:belgif:badRequest" ))
112- .body ("detail" , equalTo ("Bad Request from backend (caught successfully by frontend)" ));
113- }
114-
115- @ ParameterizedTest
116- @ EnumSource
117- void customFromBackend (Client client ) {
118- spec .when ().get ("/customFromBackend?client=" + client ).then ().assertThat ()
119- .statusCode (409 )
120- .body ("type" , equalTo ("urn:problem-type:acme:custom" ))
121- .body ("customField" , equalTo ("value from backend (caught successfully by frontend)" ));
122- }
123-
124- @ ParameterizedTest
125- @ EnumSource
126- void unmappedFromBackend (Client client ) {
127- spec .when ().get ("/unmappedFromBackend?client=" + client ).then ().assertThat ()
128- .statusCode (400 )
129- .body ("type" , equalTo ("urn:problem-type:belgif:test:unmapped" ))
130- .body ("detail" , equalTo ("Unmapped problem from backend (caught successfully by frontend)" ));
131- }
132-
133- @ Test
134- void beanValidation () {
135- spec .when ().get ("/beanValidation?positive=-1" ).then ().assertThat ()
136- .statusCode (400 )
137- .body ("type" , equalTo ("urn:problem-type:belgif:badRequest" ))
138- .body ("issues[0].type" , equalTo ("urn:problem-type:belgif:input-validation:schemaViolation" ))
139- .body ("issues[0].title" , equalTo ("Input value is invalid with respect to the schema" ))
140- .body ("issues[0].detail" , equalTo ("must be greater than 0" ))
141- .body ("issues[0].in" , equalTo ("query" ))
142- .body ("issues[0].name" , equalTo ("positive" ))
143- .body ("issues[0].value" , equalTo (-1 ))
144- .body ("issues[1].type" , equalTo ("urn:problem-type:belgif:input-validation:schemaViolation" ))
145- .body ("issues[1].title" , equalTo ("Input value is invalid with respect to the schema" ))
146- .body ("issues[1].detail" , equalTo ("must not be null" ))
147- .body ("issues[1].in" , equalTo ("query" ))
148- .body ("issues[1].name" , equalTo ("required" ))
149- .body ("issues[1].value" , nullValue ());
150- }
151-
152- @ Test
153- void notFound () {
154- spec .when ().get ("/not/found" ).then ().assertThat ()
155- .statusCode (404 );
58+ @ Override
59+ protected Stream <String > getClients () {
60+ return Arrays .stream (Client .values ()).map (Client ::name );
15661 }
15762
15863}
0 commit comments