Skip to content

Commit

Permalink
Fix split packages (#156)
Browse files Browse the repository at this point in the history
Fixes #149.
  • Loading branch information
jpraet authored Jan 8, 2025
1 parent 51d1be4 commit 1b1b614
Show file tree
Hide file tree
Showing 82 changed files with 204 additions and 190 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.belgif.rest.problem;
package io.github.belgif.rest.problem.it;

import static org.assertj.core.api.Assertions.*;

Expand All @@ -15,14 +15,17 @@
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.cfg.PackageVersion;

import io.github.belgif.rest.problem.BadRequestProblem;
import io.github.belgif.rest.problem.DefaultProblem;
import io.github.belgif.rest.problem.ProblemModule;
import io.github.belgif.rest.problem.TooManyRequestsProblem;
import io.github.belgif.rest.problem.api.InEnum;
import io.github.belgif.rest.problem.api.Input;
import io.github.belgif.rest.problem.api.InputValidationIssue;
import io.github.belgif.rest.problem.api.InputValidationIssues;
import io.github.belgif.rest.problem.api.Problem;
import io.github.belgif.rest.problem.registry.TestProblemTypeRegistry;

abstract class AbstractJacksonSerializationTest {
public abstract class AbstractJacksonSerializationTest {

private ObjectMapper mapper;

Expand All @@ -32,7 +35,7 @@ static void printJacksonVersion() {
}

@BeforeEach
void setUp() {
public void setUp() {
mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
TestProblemTypeRegistry registry = new TestProblemTypeRegistry();
Expand All @@ -41,37 +44,37 @@ void setUp() {
}

@Test
void badRequestProblem() throws JsonProcessingException {
public void badRequestProblem() throws JsonProcessingException {
BadRequestProblem problem = new BadRequestProblem();
problem.setDetail("my detail message");
problem.setAdditionalProperty("additional", "property");
assertSerializationRoundtrip(problem);
}

@Test
void customProblem() throws JsonProcessingException {
public void customProblem() throws JsonProcessingException {
CustomProblem problem = new CustomProblem("custom");
problem.setAdditionalProperty("additional", "property");
assertSerializationRoundtrip(problem);
}

@Test
void retryAfterProblem() throws JsonProcessingException {
public void retryAfterProblem() throws JsonProcessingException {
TooManyRequestsProblem problem = new TooManyRequestsProblem();
problem.setRetryAfterSec(60L);
problem.setAdditionalProperty("additional", "property");
assertSerializationRoundtrip(problem);
}

@Test
void badRequestProblemReplacedSsin() throws JsonProcessingException {
public void badRequestProblemReplacedSsin() throws JsonProcessingException {
BadRequestProblem problem = new BadRequestProblem(
InputValidationIssues.replacedSsin(InEnum.BODY, "parent[1].ssin", "12345678901", "23456789012"));
assertSerializationRoundtrip(problem);
}

@Test
void badRequestProblemMultipleInputs() throws JsonProcessingException {
public void badRequestProblemMultipleInputs() throws JsonProcessingException {
BadRequestProblem problem = new BadRequestProblem();
problem.setDetail("my detail message");
InputValidationIssue issue = new InputValidationIssue();
Expand All @@ -85,7 +88,7 @@ void badRequestProblemMultipleInputs() throws JsonProcessingException {
}

@Test
void badRequestProblemWithInNameValueAndInputsArray() throws JsonProcessingException {
public void badRequestProblemWithInNameValueAndInputsArray() throws JsonProcessingException {
String json = "{\n"
+ " \"type\": \"urn:problem-type:belgif:badRequest\",\n"
+ " \"href\": \"https://www.belgif.be/specification/rest/api-guide/problems/badRequest.html\",\n"
Expand Down Expand Up @@ -116,7 +119,7 @@ void badRequestProblemWithInNameValueAndInputsArray() throws JsonProcessingExcep
}

@Test
void badRequestProblemWithInputsArrayAndInNameValue() throws JsonProcessingException {
public void badRequestProblemWithInputsArrayAndInNameValue() throws JsonProcessingException {
String json = "{\n"
+ " \"type\": \"urn:problem-type:belgif:badRequest\",\n"
+ " \"href\": \"https://www.belgif.be/specification/rest/api-guide/problems/badRequest.html\",\n"
Expand Down Expand Up @@ -146,7 +149,7 @@ void badRequestProblemWithInputsArrayAndInNameValue() throws JsonProcessingExcep
}

@Test
void unmappedProblem() throws JsonProcessingException {
public void unmappedProblem() throws JsonProcessingException {
mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);

Expand All @@ -161,7 +164,7 @@ void unmappedProblem() throws JsonProcessingException {
}

@Test
void legacyInvalidParamProblem() throws JsonProcessingException {
public void legacyInvalidParamProblem() throws JsonProcessingException {
String json = "{\n"
+ " \"type\": \"urn:problem-type:belgif:badRequest\",\n"
+ " \"href\": \"https://www.belgif.be/specification/rest/api-guide/problems/badRequest.html\",\n"
Expand All @@ -184,7 +187,7 @@ void legacyInvalidParamProblem() throws JsonProcessingException {
}

@Test
void unknownProblemWithMessage() throws JsonProcessingException {
public void unknownProblemWithMessage() throws JsonProcessingException {
String json = "{\n"
+ " \"id\" : \"08eb8aa6-d4a5-44fc-b25d-007b9f6a272a\",\n"
+ " \"code\" : \"Bad Request\",\n"
Expand All @@ -203,7 +206,7 @@ void unknownProblemWithMessage() throws JsonProcessingException {
}

@Test
void additionalExceptionProperties() throws JsonProcessingException {
public void additionalExceptionProperties() throws JsonProcessingException {
BadRequestProblem problem = new BadRequestProblem();
problem.setAdditionalProperty("cause", "cause");
problem.setAdditionalProperty("stackTrace", "stackTrace");
Expand All @@ -214,7 +217,7 @@ void additionalExceptionProperties() throws JsonProcessingException {
}

@Test
void issueWithStatusAndInstance() throws JsonProcessingException {
public void issueWithStatusAndInstance() throws JsonProcessingException {
BadRequestProblem problem = new BadRequestProblem();
problem.setDetail("my detail message");
InputValidationIssue issue = new InputValidationIssue().detail("test");
Expand All @@ -225,7 +228,7 @@ void issueWithStatusAndInstance() throws JsonProcessingException {
}

@Test
void issueWithNullValue() throws JsonProcessingException {
public void issueWithNullValue() throws JsonProcessingException {
BadRequestProblem problem = new BadRequestProblem(
new InputValidationIssue(InEnum.BODY, "id", null));
String json = mapper.writeValueAsString(problem);
Expand All @@ -234,15 +237,15 @@ void issueWithNullValue() throws JsonProcessingException {
}

@Test
void issueWithNullInputValue() throws JsonProcessingException {
public void issueWithNullInputValue() throws JsonProcessingException {
BadRequestProblem problem = new BadRequestProblem(new InputValidationIssue()
.inputs(Input.body("a", null), Input.body("b", null)));
String json = mapper.writeValueAsString(problem);
assertThat(json).doesNotContain("null");
assertSerializationRoundtrip(problem);
}

void assertSerializationRoundtrip(Problem problem) throws JsonProcessingException {
protected void assertSerializationRoundtrip(Problem problem) throws JsonProcessingException {
String json = mapper.writeValueAsString(problem);
print(json);
Problem result = mapper.readValue(json, Problem.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.belgif.rest.problem;
package io.github.belgif.rest.problem.it;

import static org.hamcrest.Matchers.*;

Expand All @@ -7,29 +7,29 @@
import io.restassured.http.ContentType;
import io.restassured.specification.RequestSpecification;

abstract class AbstractOpenApiValidationSpringBootIT {
public abstract class AbstractOpenApiValidationSpringBootIT {

private static final String BAD_REQUEST_URN = "urn:problem-type:belgif:badRequest";
private static final String SCHEMA_VIOLATION_URN = "urn:problem-type:belgif:input-validation:schemaViolation";

protected abstract RequestSpecification getSpec();

@Test
void validPathParamWorksTest() {
public void validPathParamWorksTest() {
getSpec().when().get("/myFirstPath/abc1234567").then().assertThat()
.statusCode(200)
.body(equalTo("All good!"));
}

@Test
void notFound() {
public void notFound() {
getSpec().when().get("/not/found").then().assertThat()
.statusCode(404)
.body("type", equalTo("urn:problem-type:belgif:resourceNotFound"));
}

@Test
void unknownQueryParamTest() {
public void unknownQueryParamTest() {
getSpec().when().queryParam("myUnknownParam", 123).get("/myFirstPath").then().assertThat()
.statusCode(400)
.body("type", equalTo(BAD_REQUEST_URN))
Expand All @@ -43,7 +43,7 @@ void unknownQueryParamTest() {
}

@Test
void missingQueryParamTest() {
public void missingQueryParamTest() {
getSpec().when().get("/myQueryPath").then().assertThat()
.statusCode(400)
.body("type", equalTo(BAD_REQUEST_URN))
Expand All @@ -57,7 +57,7 @@ void missingQueryParamTest() {
}

@Test
void invalidPathParamTest() {
public void invalidPathParamTest() {
getSpec().when().get("/myFirstPath/a1a1234567").then().assertThat()
.statusCode(400)
.body("type", equalTo(BAD_REQUEST_URN))
Expand All @@ -71,7 +71,7 @@ void invalidPathParamTest() {
}

@Test
void pathParamTooShortTest() {
public void pathParamTooShortTest() {
getSpec().when().get("/myFirstPath/abc").then().assertThat()
.statusCode(400)
.body("type", equalTo(BAD_REQUEST_URN))
Expand All @@ -85,14 +85,14 @@ void pathParamTooShortTest() {
}

@Test
void validQueryParamWorksTest() {
public void validQueryParamWorksTest() {
getSpec().when().queryParam("myParam", "abc1234567").get("/myFirstPath").then().assertThat()
.statusCode(200)
.body(equalTo("All good!"));
}

@Test
void invalidQueryParamTest() {
public void invalidQueryParamTest() {
getSpec().when().queryParam("myParam", "a1a1234567").get("/myFirstPath").then().assertThat()
.statusCode(400)
.body("type", equalTo(BAD_REQUEST_URN))
Expand All @@ -106,7 +106,7 @@ void invalidQueryParamTest() {
}

@Test
void queryParamTooShortTest() {
public void queryParamTooShortTest() {
getSpec().when().queryParam("myParam", "abc").get("/myFirstPath").then().assertThat()
.statusCode(400)
.body("type", equalTo(BAD_REQUEST_URN))
Expand All @@ -120,7 +120,7 @@ void queryParamTooShortTest() {
}

@Test
void absentHeaderParamTest() {
public void absentHeaderParamTest() {
getSpec().when().get("/myHeaderPath").then().assertThat()
.statusCode(400)
.body("type", equalTo(BAD_REQUEST_URN))
Expand All @@ -134,7 +134,7 @@ void absentHeaderParamTest() {
}

@Test
void headerParamTooShortTest() {
public void headerParamTooShortTest() {
getSpec().when().header("MyHeader", "abc").get("/myHeaderPath").then().assertThat()
.statusCode(400)
.body("type", equalTo(BAD_REQUEST_URN))
Expand All @@ -148,7 +148,7 @@ void headerParamTooShortTest() {
}

@Test
void requestBodyJsonParseErrorTest() {
public void requestBodyJsonParseErrorTest() {
getSpec().contentType(ContentType.JSON).body("{" +
"\"name\" ; this is my name" +
"}").when().post("/myFirstPath").then().assertThat()
Expand All @@ -163,7 +163,7 @@ void requestBodyJsonParseErrorTest() {
}

@Test
void missingRequestBodyTest() {
public void missingRequestBodyTest() {
getSpec().contentType(ContentType.JSON).when().post("/myFirstPath").then().assertThat()
.statusCode(400)
.body("type", equalTo(BAD_REQUEST_URN))
Expand All @@ -176,7 +176,7 @@ void missingRequestBodyTest() {
}

@Test
void invalidRequestBodyTest() {
public void invalidRequestBodyTest() {
getSpec().contentType(ContentType.JSON).body("{" +
"\"myFirstProperty\": \"yes\"," +
"\"myInnerObject\": {" +
Expand All @@ -195,7 +195,7 @@ void invalidRequestBodyTest() {
}

@Test
void missingPropertiesInRequestBodyNestedSchemaTest() {
public void missingPropertiesInRequestBodyNestedSchemaTest() {
getSpec().contentType(ContentType.JSON).body("{" +
"\"myInnerObject\": {" +
"\"nonExistingParam\": \"abc\"" +
Expand All @@ -218,7 +218,7 @@ void missingPropertiesInRequestBodyNestedSchemaTest() {
}

@Test
void missingPropertiesInRequestBodyTest() {
public void missingPropertiesInRequestBodyTest() {
getSpec().contentType(ContentType.JSON).body("{" +
"}").when().post("/myFirstPath").then().assertThat()
.statusCode(400)
Expand All @@ -234,7 +234,7 @@ void missingPropertiesInRequestBodyTest() {
}

@Test
void nonCompliantRegexInAllOfRequestBodyTest() {
public void nonCompliantRegexInAllOfRequestBodyTest() {
getSpec().contentType(ContentType.JSON).body("{\n" +
" \"myFirstProperty\": \"yes\",\n" +
" \"myInnerObject\": {\n" +
Expand All @@ -261,7 +261,7 @@ void nonCompliantRegexInAllOfRequestBodyTest() {
}

@Test
void missingPropertiesInAllOfRequestBodyTest() {
public void missingPropertiesInAllOfRequestBodyTest() {
getSpec().contentType(ContentType.JSON).body("{\n" +
" \"myFirstProperty\": \"yes\",\n" +
" \"myInnerObject\": {\n" +
Expand All @@ -284,7 +284,7 @@ void missingPropertiesInAllOfRequestBodyTest() {
}

@Test
void missingPropertiesInOneOfRequestBodyTest() {
public void missingPropertiesInOneOfRequestBodyTest() {
getSpec().contentType(ContentType.JSON).body("{\n" +
" \"myFirstProperty\": \"yes\",\n" +
" \"myInnerObject\": {\n" +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.github.belgif.rest.problem;
package io.github.belgif.rest.problem.it;

import static org.hamcrest.Matchers.*;

import org.junit.jupiter.api.Test;

abstract class AbstractRestProblemEEIT extends AbstractRestProblemIT {
public abstract class AbstractRestProblemEEIT extends AbstractRestProblemIT {

@Test
void ejb() {
public void ejb() {
getSpec().when()
.get("/ejb").then().assertThat()
.statusCode(400)
Expand Down
Loading

0 comments on commit 1b1b614

Please sign in to comment.