Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.github.belgif.rest.problem.it;

import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.TestInstance.Lifecycle.*;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

import io.github.belgif.rest.problem.config.ProblemConfig;
import io.restassured.specification.RequestSpecification;

@TestInstance(PER_CLASS)
// PER_CLASS because otherwise @MethodSource("getClients") requires a static getClients() method
public abstract class AbstractRestProblemDisabledIT {

protected abstract RequestSpecification getSpec();

@AfterAll
static void afterAll() {
ProblemConfig.reset();
}

@Test
public void ping() {
getSpec().when().get("/ping").then().assertThat()
.statusCode(200)
.body(is("pong"));
}

@Test
public void badRequest() {
getSpec().when().get("/badRequest").then().log().all().assertThat()
.statusCode(500)
.body(not(containsString("urn:problem-type:belgif:badRequest")));
}

@Test
public void runtime() {
getSpec().when().get("/runtime").then().log().all().assertThat()
.statusCode(500)
.body(not(containsString("urn:problem-type:belgif:internalServerError")));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,11 @@ public void notFound() {
.body("detail", equalTo("No resource /frontend/not/found found"));
}

@Test
public void disabled() {
getSpec().basePath("/spring/disabled").when().get("/runtime").then().log().all().assertThat()
.statusCode(500)
.body(not(containsString("urn:problem-type:belgif:internalServerError")));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
<name>${project.groupId}:${project.artifactId}</name>
<packaging>war</packaging>

<properties>
<maven.compiler.release>17</maven.compiler.release>
</properties>

<build>
<finalName>belgif-rest-problem-jakarta-ee-it</finalName>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.github.belgif.rest.enabled;

import jakarta.enterprise.context.RequestScoped;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Response;

@RequestScoped
@Path("/")
public class Enabled {

@GET
@Path("/runtime")
public Response runtime() {
throw new RuntimeException("oops");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.github.belgif.rest.enabled;

import java.util.Set;

import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;

import io.github.belgif.rest.problem.ee.jaxrs.ProblemFeature;

@ApplicationPath("/enabled")
public class RESTConfig extends Application {

@Override
public Set<Class<?>> getClasses() {
return Set.of(Enabled.class);
}

@Override
public Set<Object> getSingletons() {
return Set.of(new ProblemFeature());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.github.belgif.rest.problem;

import static org.hamcrest.Matchers.*;

import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

import io.github.belgif.rest.problem.config.ProblemConfig;
import io.github.belgif.rest.problem.it.AbstractRestProblemDisabledIT;
import io.restassured.RestAssured;
import io.restassured.specification.RequestSpecification;

@Testcontainers
class RestProblemJakartaEeDisabledIT extends AbstractRestProblemDisabledIT {

@Container
@SuppressWarnings("rawtypes")
public static final GenericContainer JBOSS_CONTAINER = RestProblemJakartaEeIT.createContainer()
.withEnv(ProblemConfig.PROPERTY_SERVER_SIDE_ENABLED, "false");

@Override
protected RequestSpecification getSpec() {
return RestAssured.with().baseUri("http://" + JBOSS_CONTAINER.getHost())
.port(JBOSS_CONTAINER.getMappedPort(8080))
.basePath("/rest-problem/frontend");
}

@Test
void enabled() {
getSpec().basePath("/rest-problem/enabled").when()
.get("/runtime").then()
.assertThat()
.statusCode(500)
.body("type", equalTo("urn:problem-type:belgif:internalServerError"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<packaging>war</packaging>

<properties>
<maven.compiler.release>17</maven.compiler.release>
<docker.image>registry.redhat.io/jboss-eap-7/eap-xp4-openjdk17-openshift-rhel8:4.0-49</docker.image>
</properties>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.github.belgif.rest.enabled;

import javax.enterprise.context.RequestScoped;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;

@RequestScoped
@Path("/")
public class Enabled {

@GET
@Path("/runtime")
public Response runtime() {
throw new RuntimeException("oops");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.github.belgif.rest.enabled;

import java.util.Set;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

import io.github.belgif.rest.problem.ee.jaxrs.ProblemFeature;

@ApplicationPath("/enabled")
public class RESTConfig extends Application {

@Override
public Set<Class<?>> getClasses() {
return Set.of(Enabled.class);
}

@Override
public Set<Object> getSingletons() {
return Set.of(new ProblemFeature());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.github.belgif.rest.problem;

import static org.hamcrest.Matchers.*;

import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

import io.github.belgif.rest.problem.config.ProblemConfig;
import io.github.belgif.rest.problem.it.AbstractRestProblemDisabledIT;
import io.restassured.RestAssured;
import io.restassured.specification.RequestSpecification;

@Testcontainers
class RestProblemJavaEeDisabledIT extends AbstractRestProblemDisabledIT {

@Container
@SuppressWarnings("rawtypes")
public static final GenericContainer JBOSS_CONTAINER = RestProblemJavaEeIT.createContainer()
.withEnv(ProblemConfig.PROPERTY_SERVER_SIDE_ENABLED, "false");

@Override
protected RequestSpecification getSpec() {
return RestAssured.with().baseUri("http://" + JBOSS_CONTAINER.getHost())
.port(JBOSS_CONTAINER.getMappedPort(8080))
.basePath("/rest-problem/frontend");
}

@Test
void enabled() {
getSpec().basePath("/rest-problem/enabled").when()
.get("/runtime").then()
.assertThat()
.statusCode(500)
.body("type", equalTo("urn:problem-type:belgif:internalServerError"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.github.belgif.rest.problem.server-side-enabled=false
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.github.belgif.rest.problem.quarkus.it;

import io.github.belgif.rest.problem.it.AbstractRestProblemDisabledIT;
import io.quarkus.test.common.http.TestHTTPEndpoint;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
import io.restassured.RestAssured;
import io.restassured.specification.RequestSpecification;

@QuarkusTest
@TestProfile(RestProblemQuarkusDisabledIT.class)
@TestHTTPEndpoint(Frontend.class)
public class RestProblemQuarkusDisabledIT extends AbstractRestProblemDisabledIT implements QuarkusTestProfile {

@Override
public String getConfigProfile() {
return "disabled";
}

@Override
protected RequestSpecification getSpec() {
return RestAssured.given();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.github.belgif.rest.problem;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.github.belgif.rest.problem.config.DisableProblems;

@DisableProblems
@RestController
@RequestMapping("/disabled")
public class ProblemsDisabledController {

@GetMapping("/runtime")
public void runtime() {
throw new RuntimeException("oops");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.github.belgif.rest.problem;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.github.belgif.rest.problem.config.EnableProblems;

@EnableProblems
@RestController
@RequestMapping("/enabled")
public class ProblemsEnabledController {

@GetMapping("/runtime")
public void runtime() {
throw new RuntimeException("oops");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.github.belgif.rest.problem.server-side-enabled=false
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.github.belgif.rest.problem;

import static org.hamcrest.Matchers.*;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;

import io.github.belgif.rest.problem.it.AbstractRestProblemDisabledIT;
import io.restassured.RestAssured;
import io.restassured.specification.RequestSpecification;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("disabled")
@DirtiesContext
class RestProblemSpringBoot3DisabledIT extends AbstractRestProblemDisabledIT {

@LocalServerPort
private int port;

@Override
protected RequestSpecification getSpec() {
return RestAssured.with().baseUri("http://localhost").port(port).basePath("/spring/frontend");
}

@Test
void enabled() {
getSpec().basePath("/spring/enabled").when().get("/runtime").then().assertThat()
.statusCode(500)
.body("type", equalTo("urn:problem-type:belgif:internalServerError"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.github.belgif.rest.problem;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.github.belgif.rest.problem.config.DisableProblems;

@DisableProblems
@RestController
@RequestMapping("/disabled")
public class ProblemsDisabledController {

@GetMapping("/runtime")
public void runtime() {
throw new RuntimeException("oops");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.github.belgif.rest.problem;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.github.belgif.rest.problem.config.EnableProblems;

@EnableProblems
@RestController
@RequestMapping("/enabled")
public class ProblemsEnabledController {

@GetMapping("/runtime")
public void runtime() {
throw new RuntimeException("oops");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.github.belgif.rest.problem.server-side-enabled=false
Loading