-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from zalando/feature/custom-constraint-violat…
…ion-type Made problem type configurable
- Loading branch information
Showing
9 changed files
with
90 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...rg/zalando/problem/spring/web/advice/validation/ConstraintViolationProblemModuleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.zalando.problem.spring.web.advice.validation; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.MapperFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.Test; | ||
import org.zalando.problem.ProblemModule; | ||
import org.zalando.problem.validation.ConstraintViolationProblemModule; | ||
|
||
import java.net.URI; | ||
|
||
import static com.jayway.jsonassert.JsonAssert.with; | ||
import static java.util.Collections.emptyList; | ||
import static java.util.Collections.singletonList; | ||
import static javax.ws.rs.core.Response.Status.BAD_REQUEST; | ||
import static org.hamcrest.Matchers.contains; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
@Slf4j | ||
public class ConstraintViolationProblemModuleTest { | ||
|
||
@Test | ||
public void shouldSerializeWithoutAutoDetect() throws JsonProcessingException { | ||
final ObjectMapper mapper = new ObjectMapper() | ||
.disable(MapperFeature.AUTO_DETECT_FIELDS) | ||
.disable(MapperFeature.AUTO_DETECT_GETTERS) | ||
.disable(MapperFeature.AUTO_DETECT_IS_GETTERS) | ||
.registerModule(new ProblemModule()) | ||
.registerModule(new ConstraintViolationProblemModule()); | ||
|
||
final Violation violation = new Violation("bob", "was missing"); | ||
final ConstraintViolationProblem unit = new ConstraintViolationProblem(BAD_REQUEST, singletonList(violation)); | ||
|
||
with(mapper.writeValueAsString(unit)) | ||
.assertThat("status", is(400)) | ||
.assertThat("type", is(ConstraintViolationProblem.TYPE_VALUE)) | ||
.assertThat("title", is("Constraint Violation")) | ||
.assertThat("violations", hasSize(1)) | ||
.assertThat("violations.*.field", contains("bob")) | ||
.assertThat("violations.*.message", contains("was missing")); | ||
} | ||
|
||
@Test | ||
public void shouldSerializeCustomType() throws JsonProcessingException { | ||
final ObjectMapper mapper = new ObjectMapper() | ||
.registerModule(new ProblemModule()) | ||
.registerModule(new ConstraintViolationProblemModule()); | ||
|
||
final URI type = URI.create("foo"); | ||
final ConstraintViolationProblem unit = new ConstraintViolationProblem(type, BAD_REQUEST, emptyList()); | ||
|
||
with(mapper.writeValueAsString(unit)) | ||
.assertThat("type", is("foo")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 0 additions & 48 deletions
48
src/test/java/org/zalando/problem/validation/ConstraintViolationProblemModuleTest.java
This file was deleted.
Oops, something went wrong.