Skip to content
Open
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
Binary file added Report.docx
Binary file not shown.
1 change: 1 addition & 0 deletions jackson-datatype-problem/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
requires transitive com.fasterxml.jackson.core;
requires transitive com.fasterxml.jackson.databind;
requires transitive org.zalando.problem;
requires org.checkerframework.checker.qual;
exports org.zalando.problem.jackson;
provides com.fasterxml.jackson.databind.Module with org.zalando.problem.jackson.ProblemModule;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package org.zalando.problem.jackson;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.zalando.problem.Status;
import org.zalando.problem.StatusType;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;

public class MyTest {

@Test
@DisplayName("11.1 Input Status Code is in the Map")
void TestDeserializeWithKnownStatusCode() throws IOException {
Map<Integer, StatusType> statusMap = new HashMap<>();
statusMap.put(400, Status.BAD_REQUEST);

StatusTypeDeserializer deserializer = new StatusTypeDeserializer(statusMap);
ObjectMapper mapper = new ObjectMapper();

SimpleModule module = new SimpleModule();
module.addDeserializer(StatusType.class, deserializer);
mapper.registerModule(module);

StatusType result = mapper.readValue("400", StatusType.class);

assertEquals(Status.BAD_REQUEST, result);
assertEquals(400, result.getStatusCode());
assertEquals("Bad Request", result.getReasonPhrase());
}

@Test
@DisplayName("11.2 Multiple Input Status Code is in the Map")
void TestDeserializeWithMultipleKnownStatusCodes() throws IOException {
Map<Integer, StatusType> statusMap = new HashMap<>();
statusMap.put(200, Status.OK);
statusMap.put(402, Status.PAYMENT_REQUIRED);
statusMap.put(500, Status.INTERNAL_SERVER_ERROR);

StatusTypeDeserializer deserializer = new StatusTypeDeserializer(statusMap);
ObjectMapper mapper = new ObjectMapper();

SimpleModule module = new SimpleModule();
module.addDeserializer(StatusType.class, deserializer);
mapper.registerModule(module);

StatusType result200 = mapper.readValue("200", StatusType.class);
assertEquals(Status.OK, result200);
assertEquals(200, result200.getStatusCode());
assertEquals("OK", result200.getReasonPhrase());

StatusType result402 = mapper.readValue("402", StatusType.class);
assertEquals(Status.PAYMENT_REQUIRED, result402);
assertEquals(402, result402.getStatusCode());
assertEquals("Payment Required", result402.getReasonPhrase());

StatusType result500 = mapper.readValue("500", StatusType.class);
assertEquals(Status.INTERNAL_SERVER_ERROR, result500);
assertEquals(500, result500.getStatusCode());
assertEquals("Internal Server Error", result500.getReasonPhrase());
}


@Test
@DisplayName("11.3 Input Status Code is not in the Map")
void TestDeserializeWithUnknownStatusCode() throws IOException {
Map<Integer, StatusType> statusMap = new HashMap<>();
statusMap.put(400, Status.BAD_REQUEST);

StatusTypeDeserializer deserializer = new StatusTypeDeserializer(statusMap);
ObjectMapper mapper = new ObjectMapper();

SimpleModule module = new SimpleModule();
module.addDeserializer(StatusType.class, deserializer);
mapper.registerModule(module);

StatusType result1 = mapper.readValue("404", StatusType.class);
StatusType result2 = mapper.readValue("500", StatusType.class);

assertEquals(404, result1.getStatusCode());
assertEquals("Unknown", result1.getReasonPhrase());
assertInstanceOf(UnknownStatus.class, result1);
assertEquals(500, result2.getStatusCode());
assertEquals("Unknown", result2.getReasonPhrase());
assertInstanceOf(UnknownStatus.class, result2);
}

@Test
@DisplayName("11.4 The Map is empty")
void TestDeserializeWithEmptyMap() throws IOException {
Map<Integer, StatusType> emptyMap = new HashMap<>();

StatusTypeDeserializer deserializer = new StatusTypeDeserializer(emptyMap);
ObjectMapper mapper = new ObjectMapper();

SimpleModule module = new SimpleModule();
module.addDeserializer(StatusType.class, deserializer);
mapper.registerModule(module);

StatusType result = mapper.readValue("200", StatusType.class);

assertEquals(200, result.getStatusCode());
assertEquals("Unknown", result.getReasonPhrase());
assertInstanceOf(UnknownStatus.class, result);
}
}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
</distributionManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>23</maven.compiler.source>
<maven.compiler.target>23</maven.compiler.target>
<junit-jupiter.version>5.8.2</junit-jupiter.version>
</properties>
<dependencyManagement>
Expand Down
8 changes: 8 additions & 0 deletions problem/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@
</parent>
<artifactId>problem</artifactId>
<description>An implementation of the application/problem+json draft.</description>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
2 changes: 2 additions & 0 deletions problem/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
requires static org.apiguardian.api;
requires transitive com.google.gson;
exports org.zalando.problem;
requires org.checkerframework.checker.qual;
uses org.zalando.problem.spi.StackTraceProcessor;
}
Loading