diff --git a/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java b/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java index 6ad7fff9..c77129e0 100644 --- a/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java +++ b/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java @@ -135,7 +135,7 @@ private static final class ShortCircuitAnalysisResultMock { static final ShortCircuitAnalysisResult RESULT_BASIC = new ShortCircuitAnalysisResult(List.of(FAULT_RESULT_BASIC_1, FAULT_RESULT_BASIC_2, FAULT_RESULT_BASIC_3)); } - private static class ShortCircuitAnalysisProviderMock implements ShortCircuitAnalysisProvider { + private static final class ShortCircuitAnalysisProviderMock implements ShortCircuitAnalysisProvider { @Override public String getName() { return "ShortCircuitAnalysisMock"; @@ -180,21 +180,14 @@ public String getVersion() { private Network nodeBreakerNetwork; - private static void assertResultsEquals(ShortCircuitAnalysisResult result, org.gridsuite.shortcircuit.server.dto.ShortCircuitAnalysisResult resultDto) { - assertEquals(result.getFaultResults().size(), resultDto.getFaults().size()); - List orderedFaultResults = result.getFaultResults().stream().sorted(Comparator.comparing(fr -> fr.getFault().getId())).collect(Collectors.toList()); - List orderedFaultResultsDto = resultDto.getFaults().stream().sorted(Comparator.comparing(fr -> fr.getFault().getId())).collect(Collectors.toList()); - assertFaultResultsEquals(orderedFaultResults, orderedFaultResultsDto); - } - - private static void assertPagedFaultResultsEquals(ShortCircuitAnalysisResult result, List faultResults) { + private static void assertFaultResultsEquals(ShortCircuitAnalysisResult result, List faultResults) { assertEquals(result.getFaultResults().size(), faultResults.size()); List orderedFaultResults = result.getFaultResults().stream().sorted(Comparator.comparing(fr -> fr.getFault().getId())).toList(); List orderedFaultResultsDto = faultResults.stream().sorted(Comparator.comparing(fr -> fr.getFault().getId())).toList(); assertFaultResultsEquals(orderedFaultResults, orderedFaultResultsDto); } - private static void assertPagedFaultResultsEqualsSorted(ShortCircuitAnalysisResult result, List faultResults) { + private static void assertSortedFaultResultsEquals(ShortCircuitAnalysisResult result, List faultResults) { assertEquals(result.getFaultResults().size(), faultResults.size()); assertFaultResultsEquals(result.getFaultResults(), faultResults); } @@ -322,7 +315,7 @@ public void runTest() throws Exception { .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); org.gridsuite.shortcircuit.server.dto.ShortCircuitAnalysisResult resultDto = mapper.readValue(result.getResponse().getContentAsString(), org.gridsuite.shortcircuit.server.dto.ShortCircuitAnalysisResult.class); - assertResultsEquals(ShortCircuitAnalysisResultMock.RESULT_WITH_LIMIT_VIOLATIONS, resultDto); + assertFaultResultsEquals(ShortCircuitAnalysisResultMock.RESULT_WITH_LIMIT_VIOLATIONS, resultDto.getFaults()); // BASIC mode result = mockMvc.perform(get( @@ -332,7 +325,7 @@ public void runTest() throws Exception { .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); org.gridsuite.shortcircuit.server.dto.ShortCircuitAnalysisResult resultDtoBasic = mapper.readValue(result.getResponse().getContentAsString(), org.gridsuite.shortcircuit.server.dto.ShortCircuitAnalysisResult.class); - assertResultsEquals(ShortCircuitAnalysisResultMock.RESULT_BASIC, resultDtoBasic); + assertFaultResultsEquals(ShortCircuitAnalysisResultMock.RESULT_BASIC, resultDtoBasic.getFaults()); // FULL mode result = mockMvc.perform(get( @@ -342,7 +335,7 @@ public void runTest() throws Exception { .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); org.gridsuite.shortcircuit.server.dto.ShortCircuitAnalysisResult resultDtoFull = mapper.readValue(result.getResponse().getContentAsString(), org.gridsuite.shortcircuit.server.dto.ShortCircuitAnalysisResult.class); - assertResultsEquals(ShortCircuitAnalysisResultMock.RESULT_MAGNITUDE_FULL, resultDtoFull); + assertFaultResultsEquals(ShortCircuitAnalysisResultMock.RESULT_MAGNITUDE_FULL, resultDtoFull.getFaults()); result = mockMvc.perform(get( "/" + VERSION + "/results/{resultUuid}/fault_results/paged", RESULT_UUID) @@ -358,7 +351,7 @@ public void runTest() throws Exception { JsonNode faultResultsPageNode = mapper.readTree(result.getResponse().getContentAsString()); ObjectReader faultResultsReader = mapper.readerFor(new TypeReference>() { }); List faultResultsPageDto0 = faultResultsReader.readValue(faultResultsPageNode.get("content")); - assertPagedFaultResultsEquals(ShortCircuitAnalysisResultMock.RESULT_WITH_LIMIT_VIOLATIONS, faultResultsPageDto0); + assertFaultResultsEquals(ShortCircuitAnalysisResultMock.RESULT_WITH_LIMIT_VIOLATIONS, faultResultsPageDto0); result = mockMvc.perform(get( "/" + VERSION + "/results/{resultUuid}/fault_results/paged", RESULT_UUID) @@ -371,7 +364,7 @@ public void runTest() throws Exception { .andReturn(); JsonNode faultResultsPageNode0 = mapper.readTree(result.getResponse().getContentAsString()); List faultResultsPageDto0Full = faultResultsReader.readValue(faultResultsPageNode0.get("content")); - assertPagedFaultResultsEqualsSorted(ShortCircuitAnalysisResultMock.RESULT_SORTED_PAGE_0, faultResultsPageDto0Full); + assertSortedFaultResultsEquals(ShortCircuitAnalysisResultMock.RESULT_SORTED_PAGE_0, faultResultsPageDto0Full); result = mockMvc.perform(get( "/" + VERSION + "/results/{resultUuid}/fault_results/paged", RESULT_UUID) @@ -384,7 +377,7 @@ public void runTest() throws Exception { .andReturn(); JsonNode faultResultsPageNode1 = mapper.readTree(result.getResponse().getContentAsString()); List faultResultsPageDto1Full = faultResultsReader.readValue(faultResultsPageNode1.get("content")); - assertPagedFaultResultsEqualsSorted(ShortCircuitAnalysisResultMock.RESULT_SORTED_PAGE_1, faultResultsPageDto1Full); + assertSortedFaultResultsEquals(ShortCircuitAnalysisResultMock.RESULT_SORTED_PAGE_1, faultResultsPageDto1Full); // should throw not found if result does not exist mockMvc.perform(get("/" + VERSION + "/results/{resultUuid}", OTHER_RESULT_UUID)) @@ -439,7 +432,7 @@ public void runWithBusIdTest() throws Exception { .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); org.gridsuite.shortcircuit.server.dto.ShortCircuitAnalysisResult resultDto = mapper.readValue(result.getResponse().getContentAsString(), org.gridsuite.shortcircuit.server.dto.ShortCircuitAnalysisResult.class); - assertResultsEquals(ShortCircuitAnalysisResultMock.RESULT_FORTESCUE_FULL, resultDto); + assertFaultResultsEquals(ShortCircuitAnalysisResultMock.RESULT_FORTESCUE_FULL, resultDto.getFaults()); // paged results (more deeply tested in unit tests) result = mockMvc.perform(get( @@ -455,7 +448,7 @@ public void runWithBusIdTest() throws Exception { List feederResults = reader.readValue(feederResultsPage.get("content")); // we update the fault result with the feeders we just get to be able to use the assertion org.gridsuite.shortcircuit.server.dto.FaultResult formattedFaultResult = new org.gridsuite.shortcircuit.server.dto.FaultResult(faultResult.getFault(), faultResult.getCurrent(), faultResult.getPositiveMagnitude(), faultResult.getShortCircuitPower(), faultResult.getLimitViolations(), feederResults, faultResult.getShortCircuitLimits()); - assertPagedFaultResultsEquals(ShortCircuitAnalysisResultMock.RESULT_FORTESCUE_FULL, List.of(formattedFaultResult)); + assertFaultResultsEquals(ShortCircuitAnalysisResultMock.RESULT_FORTESCUE_FULL, List.of(formattedFaultResult)); } } @@ -499,7 +492,7 @@ public void runWithBusBarSectionIdTest() throws Exception { .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); org.gridsuite.shortcircuit.server.dto.ShortCircuitAnalysisResult resultDto = mapper.readValue(result.getResponse().getContentAsString(), org.gridsuite.shortcircuit.server.dto.ShortCircuitAnalysisResult.class); - assertResultsEquals(ShortCircuitAnalysisResultMock.RESULT_FORTESCUE_FULL, resultDto); + assertFaultResultsEquals(ShortCircuitAnalysisResultMock.RESULT_FORTESCUE_FULL, resultDto.getFaults()); } }