Fix crash due to JSON parsing on "Finishing up" tab (#132)
The seemingly unused library `jersey-hk2` that got removed in #118 is used, if present, internally by the Jersey client to find and register Jackson modules (such as those that provide `java.time` support). ## How to test 1. Turn on the `DAISY-INTEGRATION` Maven profile (alongside `DEV`) 2. Configure some projects and their authors to have a Daisy connection 3. Log in as the supervisor 4. Go to the "Finishing up" tab in the project 5. See that it works compared to `develop` branch Reviewed-on: #132 Reviewed-by: Nico Athanassiadis <nico@dsv.su.se> Co-authored-by: Andreas Svanberg <andreass@dsv.su.se> Co-committed-by: Andreas Svanberg <andreass@dsv.su.se>
This commit is contained in:
parent
de18f200a7
commit
9ede262e7b
core
@ -32,6 +32,10 @@
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-json-jackson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.inject</groupId>
|
||||
<artifactId>jersey-hk2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
|
@ -6,7 +6,11 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import jakarta.inject.Inject;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.util.*;
|
||||
@ -15,6 +19,9 @@ import org.junit.jupiter.api.Test;
|
||||
import se.su.dsv.scipro.finalseminar.FinalSeminar;
|
||||
import se.su.dsv.scipro.finalseminar.FinalSeminarOpposition;
|
||||
import se.su.dsv.scipro.finalseminar.OppositionApprovedEvent;
|
||||
import se.su.dsv.scipro.grading.GetGradeError;
|
||||
import se.su.dsv.scipro.grading.GradingServiceImpl;
|
||||
import se.su.dsv.scipro.grading.Result;
|
||||
import se.su.dsv.scipro.project.Project;
|
||||
import se.su.dsv.scipro.security.auth.roles.Roles;
|
||||
import se.su.dsv.scipro.system.DegreeType;
|
||||
@ -149,6 +156,44 @@ public class GradingReportServiceImplIntegrationTest extends IntegrationTest {
|
||||
assertNull(oppositionCriterion.getFeedback());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_json_deserialization() throws IOException {
|
||||
String json =
|
||||
"""
|
||||
{
|
||||
"grade": "A",
|
||||
"reported": "2021-01-01"
|
||||
}
|
||||
""";
|
||||
HttpServer httpServer = startHttpServerWithJsonResponse(json);
|
||||
|
||||
int port = httpServer.getAddress().getPort();
|
||||
|
||||
GradingServiceImpl gradingService = new GradingServiceImpl("http://localhost:" + port);
|
||||
Either<GetGradeError, Optional<Result>> result = gradingService.getResult("token", 1, 2, 3);
|
||||
|
||||
Optional<Result> right = result.right();
|
||||
assertTrue(right.isPresent());
|
||||
assertEquals(LocalDate.of(2021, 1, 1), right.get().reported());
|
||||
|
||||
httpServer.stop(0);
|
||||
}
|
||||
|
||||
private static HttpServer startHttpServerWithJsonResponse(String json) throws IOException {
|
||||
HttpServer httpServer = HttpServer.create();
|
||||
httpServer.createContext("/", exchange -> {
|
||||
try (exchange) {
|
||||
byte[] response = json.getBytes(StandardCharsets.UTF_8);
|
||||
exchange.getResponseHeaders().add("Content-Type", "application/json");
|
||||
exchange.sendResponseHeaders(200, response.length);
|
||||
exchange.getResponseBody().write(response);
|
||||
}
|
||||
});
|
||||
httpServer.bind(new InetSocketAddress("localhost", 0), 0);
|
||||
httpServer.start();
|
||||
return httpServer;
|
||||
}
|
||||
|
||||
private void addOppositionCriterion() {
|
||||
gradingReportTemplate = createOppositionCriteria(gradingReportTemplate, 2);
|
||||
gradingReport = createGradingReport(project, student);
|
||||
|
Loading…
x
Reference in New Issue
Block a user