Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TU: Use the new spring boot treeToValue method to parse a Page #42

Closed
wants to merge 1 commit into from
Closed
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
Expand Up @@ -7,9 +7,7 @@
package org.gridsuite.shortcircuit.server;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.powsybl.commons.extensions.AbstractExtension;
import com.powsybl.commons.reporter.Reporter;
import com.powsybl.computation.ComputationManager;
Expand Down Expand Up @@ -341,12 +339,7 @@ public void runTest() throws Exception {
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andReturn();
// It's not easy to deserialize into a Page implementation
// ( e.g. https://stackoverflow.com/questions/52490399/spring-boot-page-deserialization-pageimpl-no-constructor ),
// but for tests we care only about the content so we deserialize to DTOs only the content subfield using the jackson treemodel api
JsonNode faultResultsPageNode = mapper.readTree(result.getResponse().getContentAsString());
ObjectReader reader = mapper.readerFor(new TypeReference<List<org.gridsuite.shortcircuit.server.dto.FaultResult>>() { });
List<org.gridsuite.shortcircuit.server.dto.FaultResult> faultResultsPageDto0 = reader.readValue(faultResultsPageNode.get("content"));
List<org.gridsuite.shortcircuit.server.dto.FaultResult> faultResultsPageDto0 = mapper.treeToValue(mapper.readTree(result.getResponse().getContentAsString()).get("content"), mapper.constructType(new TypeReference<List<org.gridsuite.shortcircuit.server.dto.FaultResult>>() { }));
assertPagedResultsEquals(ShortCircuitAnalysisResultMock.RESULT, faultResultsPageDto0);

result = mockMvc.perform(get(
Expand All @@ -358,8 +351,8 @@ public void runTest() throws Exception {
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andReturn();
JsonNode faultResultsPageNode0 = mapper.readTree(result.getResponse().getContentAsString());
List<org.gridsuite.shortcircuit.server.dto.FaultResult> faultResultsPageDto0Full = reader.readValue(faultResultsPageNode0.get("content"));

List<org.gridsuite.shortcircuit.server.dto.FaultResult> faultResultsPageDto0Full = mapper.treeToValue(mapper.readTree(result.getResponse().getContentAsString()).get("content"), mapper.constructType(new TypeReference<List<org.gridsuite.shortcircuit.server.dto.FaultResult>>() { }));
assertPagedResultsEquals(ShortCircuitAnalysisResultMock.RESULT_SORTED_PAGE_0, faultResultsPageDto0Full);

result = mockMvc.perform(get(
Expand All @@ -371,8 +364,8 @@ public void runTest() throws Exception {
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andReturn();
JsonNode faultResultsPageNode1 = mapper.readTree(result.getResponse().getContentAsString());
List<org.gridsuite.shortcircuit.server.dto.FaultResult> faultResultsPageDto1Full = reader.readValue(faultResultsPageNode1.get("content"));

List<org.gridsuite.shortcircuit.server.dto.FaultResult> faultResultsPageDto1Full = mapper.treeToValue(mapper.readTree(result.getResponse().getContentAsString()).get("content"), mapper.constructType(new TypeReference<List<org.gridsuite.shortcircuit.server.dto.FaultResult>>() { }));
assertPagedResultsEquals(ShortCircuitAnalysisResultMock.RESULT_SORTED_PAGE_1, faultResultsPageDto1Full);

// should throw not found if result does not exist
Expand Down
Loading