diff --git a/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java b/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java index 155f01991..d83f52ae9 100644 --- a/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java +++ b/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java @@ -21,7 +21,6 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; import java.util.*; import java.util.concurrent.CompletableFuture; @@ -222,23 +221,6 @@ public ResponseEntity getOneLineTypeWithLimits(@PathVariable UUID return ResponseEntity.ok().body(test); } - @PostMapping(value = "/network-modifications/catalog/line_types", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - @Operation(summary = "Create or add a line types catalog") - @ApiResponse(responseCode = "200", description = "The line types catalog is created or added") - public ResponseEntity addLineTypes(@RequestParam("file") MultipartFile file) { - lineTypesCatalogService.addLineTypes(file); - return ResponseEntity.ok().build(); - } - - // TODO : delete this endpoint - @DeleteMapping(value = "/network-modifications/catalog/line_types", produces = MediaType.APPLICATION_JSON_VALUE) - @Operation(summary = "Delete line types catalog") - @ApiResponse(responseCode = "200", description = "The line types catalog is deleted") - public ResponseEntity deleteLineTypesCatalog() { - lineTypesCatalogService.deleteLineTypesCatalog(); - return ResponseEntity.ok().build(); - } - @PutMapping(value = "/network-modifications", produces = MediaType.APPLICATION_JSON_VALUE, params = "stashed") @Operation(summary = "stash or unstash network modifications") @ApiResponse(responseCode = "200", description = "The network modifications were stashed") diff --git a/src/main/java/org/gridsuite/modification/server/SupervisionController.java b/src/main/java/org/gridsuite/modification/server/SupervisionController.java index 31df9180c..7b317080e 100644 --- a/src/main/java/org/gridsuite/modification/server/SupervisionController.java +++ b/src/main/java/org/gridsuite/modification/server/SupervisionController.java @@ -12,10 +12,12 @@ import io.swagger.v3.oas.annotations.tags.Tag; import org.apache.http.HttpHost; import org.elasticsearch.client.RestClient; +import org.gridsuite.modification.server.service.LineTypesCatalogService; import org.gridsuite.modification.server.service.SupervisionService; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import java.util.List; import java.util.UUID; @@ -29,11 +31,14 @@ public class SupervisionController { private final SupervisionService supervisionService; + private final LineTypesCatalogService lineTypesCatalogService; + private final RestClient restClient; - public SupervisionController(SupervisionService supervisionService, + public SupervisionController(SupervisionService supervisionService, LineTypesCatalogService lineTypesCatalogService, RestClient restClient) { this.supervisionService = supervisionService; + this.lineTypesCatalogService = lineTypesCatalogService; this.restClient = restClient; } @@ -94,4 +99,20 @@ public ResponseEntity getModificationsToReindexCount() { public ResponseEntity getModificationsIndexName() { return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN).body(supervisionService.getModificationIndexName()); } + + @PostMapping(value = "/network-modifications/catalog/line_types", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + @Operation(summary = "Create or add a line types catalog") + @ApiResponse(responseCode = "200", description = "The line types catalog is created or added") + public ResponseEntity addLineTypes(@RequestParam("file") MultipartFile file) { + lineTypesCatalogService.addLineTypes(file); + return ResponseEntity.ok().build(); + } + + @DeleteMapping(value = "/network-modifications/catalog/line_types", produces = MediaType.APPLICATION_JSON_VALUE) + @Operation(summary = "Delete line types catalog") + @ApiResponse(responseCode = "200", description = "The line types catalog is deleted") + public ResponseEntity deleteLineTypesCatalog() { + lineTypesCatalogService.deleteLineTypesCatalog(); + return ResponseEntity.ok().build(); + } } diff --git a/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java b/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java index 863cc947c..26f6a81d7 100644 --- a/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java +++ b/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java @@ -25,9 +25,6 @@ import org.gridsuite.modification.dto.*; import org.gridsuite.modification.dto.LoadCreationInfos.LoadCreationInfosBuilder; import org.gridsuite.modification.server.dto.*; -import org.gridsuite.modification.server.dto.catalog.AerialLineTypeInfos; -import org.gridsuite.modification.server.dto.catalog.LineTypeInfos; -import org.gridsuite.modification.server.dto.catalog.UndergroundLineTypeInfos; import org.gridsuite.modification.server.elasticsearch.EquipmentInfosRepository; import org.gridsuite.modification.server.elasticsearch.EquipmentInfosService; import org.gridsuite.modification.server.elasticsearch.TombstonedEquipmentInfosRepository; @@ -51,19 +48,16 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; -import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; -import org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder; -import java.io.IOException; -import java.io.InputStream; import java.time.Instant; import java.util.*; import java.util.stream.Collectors; -import static org.gridsuite.modification.ModificationType.*; +import static org.gridsuite.modification.ModificationType.EQUIPMENT_ATTRIBUTE_MODIFICATION; +import static org.gridsuite.modification.ModificationType.LINE_MODIFICATION; import static org.gridsuite.modification.NetworkModificationException.Type.*; import static org.gridsuite.modification.dto.OperationalLimitsGroupInfos.Applicability.SIDE1; import static org.gridsuite.modification.dto.OperationalLimitsGroupInfos.Applicability.SIDE2; @@ -71,7 +65,8 @@ import static org.gridsuite.modification.server.elasticsearch.EquipmentInfosService.getIndexedEquipmentTypes; import static org.gridsuite.modification.server.impacts.TestImpactUtils.*; import static org.gridsuite.modification.server.report.NetworkModificationServerReportResourceBundle.ERROR_MESSAGE_KEY; -import static org.gridsuite.modification.server.utils.TestUtils.*; +import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage; +import static org.gridsuite.modification.server.utils.TestUtils.runRequestAsync; import static org.gridsuite.modification.server.utils.assertions.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; @@ -103,11 +98,6 @@ class ModificationControllerTest { private static final UUID TEST_REPORT_ID = UUID.randomUUID(); private static final String URI_NETWORK_MODIF_BASE = "/v1/network-modifications"; - private static final String URI_LINE_CATALOG = URI_NETWORK_MODIF_BASE + "/catalog/line_types"; - private static final String LINE_TYPES_CATALOG_JSON_FILE_1 = "/lines-catalog.json.gz"; - private static final String LINE_TYPES_CATALOG_JSON_FILE_2 = "/line_types_catalog_2.json.gz"; - private static final String LINE_TYPES_CATALOG_JSON_FILE_3 = "/line_types_catalog_3.json.gz"; - private static final String NOT_EXISTING_JSON_FILE = "/not_existing_file.json.gz"; private static final String NETWORK_MODIFICATION_URI = URI_NETWORK_MODIF_BASE + "?groupUuid=" + TEST_GROUP_ID; @Autowired @@ -1406,186 +1396,6 @@ void testGetPositionAfterAndBefore() { assertEquals(0, ModificationUtils.getInstance().getPosition("bbs1", testNetwork, v1)); } - @Test - void testGetLineTypesCatalog() throws Exception { - MvcResult mvcResult; - String resultAsString; - - // Check if the catalog is empty - mvcResult = mockMvc - .perform(get(URI_LINE_CATALOG).contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn(); - resultAsString = mvcResult.getResponse().getContentAsString(); - List emptyLineTypes = mapper.readValue(resultAsString, new TypeReference<>() { }); - assertEquals(0, emptyLineTypes.size()); - - // Create the catalog with some line types - mockMvc.perform(multipart(URI_LINE_CATALOG) - .file(createMockMultipartFile(LINE_TYPES_CATALOG_JSON_FILE_1))) - .andExpect(status().isOk()); - - // Check if the catalog is complete avoiding the duplicate entry - mvcResult = mockMvc - .perform(get(URI_LINE_CATALOG).contentType(MediaType.APPLICATION_JSON)) - .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn(); - resultAsString = mvcResult.getResponse().getContentAsString(); - List lineTypes = mapper.readValue(resultAsString, new TypeReference<>() { }); - assertEquals(10, lineTypes.size()); - - // need to delete before adding the new catalog - mockMvc.perform(delete(URI_LINE_CATALOG)) - .andExpect(status().isOk()); - - // Check if catalog is completely updated - mockMvc.perform(multipart(URI_LINE_CATALOG) - .file(createMockMultipartFile(LINE_TYPES_CATALOG_JSON_FILE_2))) - .andExpect(status().isOk()); - - mvcResult = mockMvc - .perform(get(URI_LINE_CATALOG).contentType(MediaType.APPLICATION_JSON)) - .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn(); - resultAsString = mvcResult.getResponse().getContentAsString(); - List lineTypes2 = mapper.readValue(resultAsString, new TypeReference<>() { }); - assertEquals(2, lineTypes2.size()); - - mockMvc.perform(delete(URI_LINE_CATALOG)) - .andExpect(status().isOk()); - - // Check if the catalog is empty - mvcResult = mockMvc - .perform(get(URI_LINE_CATALOG).contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn(); - resultAsString = mvcResult.getResponse().getContentAsString(); - emptyLineTypes = mapper.readValue(resultAsString, new TypeReference<>() { }); - assertEquals(0, emptyLineTypes.size()); - } - - @Test - void testGetLineTypeWithoutLimitsCatalog() throws Exception { - MvcResult mvcResult; - String resultAsString; - - // Check if the catalog is empty - mvcResult = mockMvc - .perform(get(URI_LINE_CATALOG).contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn(); - resultAsString = mvcResult.getResponse().getContentAsString(); - List emptyLineTypes = mapper.readValue(resultAsString, new TypeReference<>() { }); - assertEquals(0, emptyLineTypes.size()); - - // Create the catalog with some line types - mockMvc.perform(multipart(URI_LINE_CATALOG) - .file(createMockMultipartFile(LINE_TYPES_CATALOG_JSON_FILE_3))) - .andExpect(status().isOk()); - - mvcResult = mockMvc - .perform(get(URI_LINE_CATALOG).contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn(); - resultAsString = mvcResult.getResponse().getContentAsString(); - List lineTypes = mapper.readValue(resultAsString, new TypeReference<>() { }); - assertEquals(2, lineTypes.size()); - // getting the whole catalog does not load the limits - assertNull(lineTypes.get(0).getLimitsForLineType()); - assertNull(lineTypes.get(1).getLimitsForLineType()); - - // get one line of the catalog does not load limits too - mvcResult = mockMvc - .perform(get(URI_LINE_CATALOG + "/" + lineTypes.get(0).getId()).contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn(); - resultAsString = mvcResult.getResponse().getContentAsString(); - LineTypeInfos selectedLineType = mapper.readValue(resultAsString, new TypeReference<>() { }); - assertEquals(2, selectedLineType.getLimitsForLineType().size()); - assertNull(selectedLineType.getLimitsForLineType().getFirst().getLimitSetName()); - assertNull(selectedLineType.getLimitsForLineType().getFirst().getPermanentLimit()); - assertNull(selectedLineType.getLimitsForLineType().getFirst().getTemporaryLimits()); - assertEquals("1", selectedLineType.getLimitsForLineType().getFirst().getArea()); - assertEquals("37", selectedLineType.getLimitsForLineType().getFirst().getTemperature()); - mockMvc.perform(delete(URI_LINE_CATALOG)) - .andExpect(status().isOk()); - } - - @Test - void testGetLineTypeWithLimitsCatalog() throws Exception { - // Create the catalog with some line types - mockMvc.perform(multipart(URI_LINE_CATALOG) - .file(createMockMultipartFile(LINE_TYPES_CATALOG_JSON_FILE_3))) - .andExpect(status().isOk()); - - MvcResult mvcResult = mockMvc - .perform(get(URI_LINE_CATALOG).contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn(); - String resultAsString = mvcResult.getResponse().getContentAsString(); - List lineTypes = mapper.readValue(resultAsString, new TypeReference<>() { }); - assertEquals(2, lineTypes.size()); - UUID aerialLineId = lineTypes.get(0) instanceof AerialLineTypeInfos ? lineTypes.get(0).getId() : lineTypes.get(1).getId(); - UUID underGroundLineId = lineTypes.get(0) instanceof UndergroundLineTypeInfos ? lineTypes.get(0).getId() : lineTypes.get(1).getId(); - - // get one aerial line with limits - mvcResult = mockMvc - .perform(get(URI_LINE_CATALOG + "/" + aerialLineId + "/with-limits?area=1&temperature=37").contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn(); - resultAsString = mvcResult.getResponse().getContentAsString(); - LineTypeInfos selectedLineType = mapper.readValue(resultAsString, new TypeReference<>() { }); - - assertEquals(1, selectedLineType.getLimitsForLineType().size()); - assertEquals("LimitSet1", selectedLineType.getLimitsForLineType().getFirst().getLimitSetName()); - assertEquals(10.0, selectedLineType.getLimitsForLineType().getFirst().getPermanentLimit()); - assertEquals(20.0, selectedLineType.getLimitsForLineType().getFirst().getTemporaryLimits().getFirst().getLimitValue()); - assertEquals("TemporaryLimit1", selectedLineType.getLimitsForLineType().getFirst().getTemporaryLimits().getFirst().getName()); - assertEquals(100, selectedLineType.getLimitsForLineType().getFirst().getTemporaryLimits().getFirst().getAcceptableDuration()); - assertEquals("37", selectedLineType.getLimitsForLineType().getFirst().getTemperature()); - assertEquals("1", selectedLineType.getLimitsForLineType().getFirst().getArea()); - - // get one underground line with limits - mvcResult = mockMvc - .perform(get(URI_LINE_CATALOG + "/" + underGroundLineId + "/with-limits?area=1&shapeFactor=0.9").contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andReturn(); - resultAsString = mvcResult.getResponse().getContentAsString(); - selectedLineType = mapper.readValue(resultAsString, new TypeReference<>() { }); - assertEquals(1, selectedLineType.getLimitsForLineType().size()); - assertEquals("LimitSet1", selectedLineType.getLimitsForLineType().getFirst().getLimitSetName()); - assertEquals(11.0, selectedLineType.getLimitsForLineType().getFirst().getPermanentLimit(), 0.01); - assertEquals(22.0, selectedLineType.getLimitsForLineType().getFirst().getTemporaryLimits().getFirst().getLimitValue(), 0.01); - assertEquals("TemporaryLimit1", selectedLineType.getLimitsForLineType().getFirst().getTemporaryLimits().getFirst().getName()); - assertEquals(100, selectedLineType.getLimitsForLineType().getFirst().getTemporaryLimits().getFirst().getAcceptableDuration()); - assertEquals("37", selectedLineType.getLimitsForLineType().getFirst().getTemperature()); - assertEquals("1", selectedLineType.getLimitsForLineType().getFirst().getArea()); - - mockMvc.perform(delete(URI_LINE_CATALOG)) - .andExpect(status().isOk()); - } - - private MockMultipartFile createMockMultipartFile(String fileName) throws IOException { - try (InputStream inputStream = getClass().getResourceAsStream(fileName)) { - return new MockMultipartFile("file", fileName, MediaType.MULTIPART_FORM_DATA_VALUE, inputStream); - } - } - - @Test - void testPostLineTypeWithLimitsCatalogError() throws Exception { - MockMultipartHttpServletRequestBuilder mockMultipartHttpServletRequestBuilder = multipart(URI_LINE_CATALOG) - .file(createMockMultipartFile(NOT_EXISTING_JSON_FILE)); - - mockMvc.perform(mockMultipartHttpServletRequestBuilder) - .andExpect(result -> { - assertNotNull(result.getResolvedException()); - assertEquals("java.io.EOFException", - result.getResolvedException().getMessage()); - }); - } - @Test void testCreateVoltageInitModification() throws Exception { // Create the modification diff --git a/src/test/java/org/gridsuite/modification/server/SupervisionControllerTest.java b/src/test/java/org/gridsuite/modification/server/SupervisionControllerTest.java index 4d91449bc..ce8ae9d38 100644 --- a/src/test/java/org/gridsuite/modification/server/SupervisionControllerTest.java +++ b/src/test/java/org/gridsuite/modification/server/SupervisionControllerTest.java @@ -1,7 +1,18 @@ +/** + * Copyright (c) 2026, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ package org.gridsuite.modification.server; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.http.HttpHost; import org.elasticsearch.client.RestClient; +import org.gridsuite.modification.server.dto.catalog.AerialLineTypeInfos; +import org.gridsuite.modification.server.dto.catalog.LineTypeInfos; +import org.gridsuite.modification.server.dto.catalog.UndergroundLineTypeInfos; +import org.gridsuite.modification.server.service.LineTypesCatalogService; import org.gridsuite.modification.server.service.SupervisionService; import org.gridsuite.modification.server.utils.elasticsearch.DisableElasticsearch; import org.junit.jupiter.api.Test; @@ -9,14 +20,20 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.context.bean.override.mockito.MockitoSpyBean; import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; import java.util.UUID; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.times; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -24,15 +41,28 @@ @SpringBootTest @DisableElasticsearch class SupervisionControllerTest { + + private static final String SUPERVISION_URI_LINE_CATALOG = "/v1/supervision/network-modifications/catalog/line_types"; + private static final String LINE_TYPES_CATALOG_JSON_FILE_1 = "/lines-catalog.json.gz"; + private static final String LINE_TYPES_CATALOG_JSON_FILE_2 = "/line_types_catalog_2.json.gz"; + private static final String LINE_TYPES_CATALOG_JSON_FILE_3 = "/line_types_catalog_3.json.gz"; + private static final String NOT_EXISTING_JSON_FILE = "/not_existing_file.json.gz"; + @MockitoSpyBean private SupervisionService supervisionService; + @Autowired + private LineTypesCatalogService lineTypesCatalogService; + @Autowired MockMvc mockMvc; @Autowired private RestClient restClient; + @Autowired + private ObjectMapper mapper; + @Test void testGetElasticSearchHost() throws Exception { HttpHost httpHost = restClient.getNodes().get(0).getHost(); @@ -102,4 +132,128 @@ void testGetIndexName() throws Exception { content().string("modifications") ); } + + @Test + void testGetLineTypesCatalog() throws Exception { + // Check if the catalog is empty + List emptyLineTypes = lineTypesCatalogService.getAllLineTypes(); + assertEquals(0, emptyLineTypes.size()); + + // Create the catalog with some line types + mockMvc.perform(multipart(SUPERVISION_URI_LINE_CATALOG) + .file(createMockMultipartFile(LINE_TYPES_CATALOG_JSON_FILE_1))) + .andExpect(status().isOk()); + + // Check if the catalog is complete avoiding the duplicate entry + List lineTypes = lineTypesCatalogService.getAllLineTypes(); + assertEquals(10, lineTypes.size()); + + // need to delete before adding the new catalog + mockMvc.perform(delete(SUPERVISION_URI_LINE_CATALOG)) + .andExpect(status().isOk()); + + // Check if catalog is completely updated + mockMvc.perform(multipart(SUPERVISION_URI_LINE_CATALOG) + .file(createMockMultipartFile(LINE_TYPES_CATALOG_JSON_FILE_2))) + .andExpect(status().isOk()); + + List lineTypes2 = lineTypesCatalogService.getAllLineTypes(); + assertEquals(2, lineTypes2.size()); + + mockMvc.perform(delete(SUPERVISION_URI_LINE_CATALOG)) + .andExpect(status().isOk()); + + // Check if the catalog is empty + emptyLineTypes = lineTypesCatalogService.getAllLineTypes(); + assertEquals(0, emptyLineTypes.size()); + } + + @Test + void testGetLineTypeWithLimitsCatalog() throws Exception { + // Create the catalog with some line types + mockMvc.perform(multipart(SUPERVISION_URI_LINE_CATALOG) + .file(createMockMultipartFile(LINE_TYPES_CATALOG_JSON_FILE_3))) + .andExpect(status().isOk()); + + List lineTypes = lineTypesCatalogService.getAllLineTypes(); + assertEquals(2, lineTypes.size()); + UUID aerialLineId = lineTypes.get(0) instanceof AerialLineTypeInfos ? lineTypes.get(0).getId() : lineTypes.get(1).getId(); + UUID underGroundLineId = lineTypes.get(0) instanceof UndergroundLineTypeInfos ? lineTypes.get(0).getId() : lineTypes.get(1).getId(); + + // get one aerial line with limits + LineTypeInfos selectedLineType = lineTypesCatalogService.getLineTypesWithLimits(aerialLineId, "1", "37", null); + + assertEquals(1, selectedLineType.getLimitsForLineType().size()); + assertEquals("LimitSet1", selectedLineType.getLimitsForLineType().getFirst().getLimitSetName()); + assertEquals(10.0, selectedLineType.getLimitsForLineType().getFirst().getPermanentLimit()); + assertEquals(20.0, selectedLineType.getLimitsForLineType().getFirst().getTemporaryLimits().getFirst().getLimitValue()); + assertEquals("TemporaryLimit1", selectedLineType.getLimitsForLineType().getFirst().getTemporaryLimits().getFirst().getName()); + assertEquals(100, selectedLineType.getLimitsForLineType().getFirst().getTemporaryLimits().getFirst().getAcceptableDuration()); + assertEquals("37", selectedLineType.getLimitsForLineType().getFirst().getTemperature()); + assertEquals("1", selectedLineType.getLimitsForLineType().getFirst().getArea()); + + // get one underground line with limits + selectedLineType = lineTypesCatalogService.getLineTypesWithLimits(underGroundLineId, "1", null, "0.9"); + assertEquals(1, selectedLineType.getLimitsForLineType().size()); + assertEquals("LimitSet1", selectedLineType.getLimitsForLineType().getFirst().getLimitSetName()); + assertEquals(11.0, selectedLineType.getLimitsForLineType().getFirst().getPermanentLimit(), 0.01); + assertEquals(22.0, selectedLineType.getLimitsForLineType().getFirst().getTemporaryLimits().getFirst().getLimitValue(), 0.01); + assertEquals("TemporaryLimit1", selectedLineType.getLimitsForLineType().getFirst().getTemporaryLimits().getFirst().getName()); + assertEquals(100, selectedLineType.getLimitsForLineType().getFirst().getTemporaryLimits().getFirst().getAcceptableDuration()); + assertEquals("37", selectedLineType.getLimitsForLineType().getFirst().getTemperature()); + assertEquals("1", selectedLineType.getLimitsForLineType().getFirst().getArea()); + + mockMvc.perform(delete(SUPERVISION_URI_LINE_CATALOG)) + .andExpect(status().isOk()); + } + + @Test + void testPostLineTypeWithLimitsCatalogError() throws Exception { + MockMultipartHttpServletRequestBuilder mockMultipartHttpServletRequestBuilder = multipart(SUPERVISION_URI_LINE_CATALOG) + .file(createMockMultipartFile(NOT_EXISTING_JSON_FILE)); + + mockMvc.perform(mockMultipartHttpServletRequestBuilder) + .andExpect(result -> { + assertNotNull(result.getResolvedException()); + assertEquals("java.io.EOFException", + result.getResolvedException().getMessage()); + }); + } + + @Test + void testGetLineTypeWithoutLimitsCatalog() throws Exception { + // Check if the catalog is empty + List emptyLineTypes = lineTypesCatalogService.getAllLineTypes(); + assertEquals(0, emptyLineTypes.size()); + + // Create the catalog with some line types + mockMvc.perform(multipart(SUPERVISION_URI_LINE_CATALOG) + .file(createMockMultipartFile(LINE_TYPES_CATALOG_JSON_FILE_3))) + .andExpect(status().isOk()); + + List lineTypes = lineTypesCatalogService.getAllLineTypes(); + assertEquals(2, lineTypes.size()); + // getting the whole catalog does not load the limits + assertNull(lineTypes.get(0).getLimitsForLineType()); + assertNull(lineTypes.get(1).getLimitsForLineType()); + + // get one line of the catalog does not load limits too + LineTypeInfos selectedLineType = lineTypesCatalogService.getLineTypesWithAreaTemperatureShapeFactors(lineTypes.get(0).getId()); + assertEquals(2, selectedLineType.getLimitsForLineType().size()); + assertNull(selectedLineType.getLimitsForLineType().getFirst().getLimitSetName()); + assertNull(selectedLineType.getLimitsForLineType().getFirst().getPermanentLimit()); + assertNull(selectedLineType.getLimitsForLineType().getFirst().getTemporaryLimits()); + assertEquals("1", selectedLineType.getLimitsForLineType().getFirst().getArea()); + assertEquals("37", selectedLineType.getLimitsForLineType().getFirst().getTemperature()); + + mockMvc.perform(delete(SUPERVISION_URI_LINE_CATALOG)) + .andExpect(status().isOk()); + } + + private MockMultipartFile createMockMultipartFile(String fileName) throws IOException { + try (InputStream inputStream = getClass().getResourceAsStream(fileName)) { + return new MockMultipartFile("file", fileName, MediaType.MULTIPART_FORM_DATA_VALUE, inputStream); + } + } + }