diff --git a/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java b/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java index d5bc286b0..c84d8019c 100644 --- a/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java +++ b/src/main/java/org/gridsuite/modification/server/NetworkModificationController.java @@ -11,13 +11,13 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; -import org.apache.commons.lang3.tuple.Pair; import org.gridsuite.modification.NetworkModificationException; import org.gridsuite.modification.dto.ModificationInfos; import org.gridsuite.modification.server.dto.*; import org.gridsuite.modification.server.dto.catalog.LineTypeInfos; import org.gridsuite.modification.server.service.LineTypesCatalogService; import org.gridsuite.modification.server.service.NetworkModificationService; +import org.springframework.data.util.Pair; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -78,7 +78,7 @@ public ResponseEntity duplicateGroup(@RequestParam("groupUuid") UUID group return ResponseEntity.ok().build(); } - @PutMapping(value = "/groups/{groupUuid}", produces = MediaType.APPLICATION_JSON_VALUE) + @PutMapping(value = "/groups/{groupUuid}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @Operation(summary = "For a list of network modifications passed in body, Move them before another one or at the end of the list, or Duplicate them at the end of the list") @ApiResponse(responseCode = "200", description = "The modification list of the group has been updated.") public ResponseEntity>> handleNetworkModifications(@Parameter(description = "updated group UUID, where modifications are pasted") @PathVariable("groupUuid") UUID targetGroupUuid, @@ -89,16 +89,16 @@ public ResponseEntity>> handleNetworkMo @RequestBody Pair, List> modificationContextInfos) { return switch (action) { case COPY -> - ResponseEntity.ok().body(networkModificationService.duplicateModifications(targetGroupUuid, modificationContextInfos.getLeft(), modificationContextInfos.getRight())); + ResponseEntity.ok().body(networkModificationService.duplicateModifications(targetGroupUuid, modificationContextInfos.getFirst(), modificationContextInfos.getSecond())); case INSERT -> - ResponseEntity.ok().body(networkModificationService.insertCompositeModifications(targetGroupUuid, modificationContextInfos.getLeft(), modificationContextInfos.getRight())); + ResponseEntity.ok().body(networkModificationService.insertCompositeModifications(targetGroupUuid, modificationContextInfos.getFirst(), modificationContextInfos.getSecond())); case MOVE -> { UUID sourceGroupUuid = originGroupUuid == null ? targetGroupUuid : originGroupUuid; boolean canBuildNode = build; if (sourceGroupUuid.equals(targetGroupUuid)) { canBuildNode = false; } - yield ResponseEntity.ok().body(networkModificationService.moveModifications(targetGroupUuid, sourceGroupUuid, beforeModificationUuid, modificationContextInfos.getLeft(), modificationContextInfos.getRight(), canBuildNode)); + yield ResponseEntity.ok().body(networkModificationService.moveModifications(targetGroupUuid, sourceGroupUuid, beforeModificationUuid, modificationContextInfos.getFirst(), modificationContextInfos.getSecond(), canBuildNode)); } }; } @@ -161,8 +161,8 @@ public ResponseEntity> getModificationGroups() { public ResponseEntity>> createNetworkModification( @Parameter(description = "Group UUID") @RequestParam(name = "groupUuid") UUID groupUuid, @RequestBody Pair> modificationContextInfos) { - modificationContextInfos.getLeft().check(); - return ResponseEntity.ok().body(networkModificationService.createNetworkModification(groupUuid, modificationContextInfos.getLeft(), modificationContextInfos.getRight())); + modificationContextInfos.getFirst().check(); + return ResponseEntity.ok().body(networkModificationService.createNetworkModification(groupUuid, modificationContextInfos.getFirst(), modificationContextInfos.getSecond())); } /** diff --git a/src/main/java/org/gridsuite/modification/server/dto/ModificationApplicationContext.java b/src/main/java/org/gridsuite/modification/server/dto/ModificationApplicationContext.java index 52addfe2c..a67c4cfa0 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/ModificationApplicationContext.java +++ b/src/main/java/org/gridsuite/modification/server/dto/ModificationApplicationContext.java @@ -8,4 +8,4 @@ import java.util.UUID; -public record ModificationApplicationContext(UUID networkUuid, String variantId, UUID reportUuid, UUID nodeUuid) { } +public record ModificationApplicationContext(UUID networkUuid, String variantId, UUID reportUuid, UUID reporterId) { } diff --git a/src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java b/src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java index 837401429..b3c920b61 100644 --- a/src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java +++ b/src/main/java/org/gridsuite/modification/server/repositories/NetworkModificationRepository.java @@ -62,13 +62,13 @@ public void deleteAll() { // This method should be package-private and not used as API of the service as it uses ModificationEntity and // we want to encapsulate the use of Entity related objects to this service. // Nevertheless We have to keep it public for transactional annotation. - public List saveModifications(UUID groupUuid, List modifications) { + public List saveModifications(UUID groupUuid, List modifications) { return saveModificationsNonTransactional(groupUuid, modifications); } @Transactional // To have all create in the same transaction (atomic) // TODO Remove transaction when errors will no longer be sent to the front - public List saveModificationInfos(UUID groupUuid, List modifications) { + public List saveModificationInfos(UUID groupUuid, List modifications) { List entities = modifications.stream().map(ModificationEntity::fromDTO).toList(); return saveModificationsNonTransactional(groupUuid, entities); @@ -85,7 +85,7 @@ public UUID createNetworkCompositeModification(@NonNull List modificationU return modificationRepository.save(compositeEntity).getId(); } - private List saveModificationsNonTransactional(UUID groupUuid, List modifications) { + private List saveModificationsNonTransactional(UUID groupUuid, List modifications) { int order = modificationRepository.countByGroupIdAndStashed(groupUuid, false); var modificationGroupEntity = this.modificationGroupRepository .findById(groupUuid) diff --git a/src/main/java/org/gridsuite/modification/server/service/NetworkModificationService.java b/src/main/java/org/gridsuite/modification/server/service/NetworkModificationService.java index 6d6e4b4b1..2918041ef 100644 --- a/src/main/java/org/gridsuite/modification/server/service/NetworkModificationService.java +++ b/src/main/java/org/gridsuite/modification/server/service/NetworkModificationService.java @@ -153,8 +153,8 @@ public List> createNetworkModification(@NonN } /** - * TODO : Remove this endpoint after the final integration of root networks - * Need to use tne new endpoint with ModificationApplicationContext DTO (see above) + * TODO : Remove this method after the final integration of root networks + * Need to use tne new method with ModificationApplicationContext DTO (see above) */ public Optional createNetworkModification(@NonNull UUID networkUuid, String variantId, @NonNull UUID groupUuid, @NonNull ReportInfos reportInfos, @@ -175,7 +175,7 @@ private List> applyModifications(List applyModifications(modificationApplicationContext.networkUuid(), modificationApplicationContext.variantId(), - new ReportInfos(modificationApplicationContext.reportUuid(), modificationApplicationContext.nodeUuid()), + new ReportInfos(modificationApplicationContext.reportUuid(), modificationApplicationContext.reporterId()), modifications) ).toList(); } @@ -253,7 +253,7 @@ public void deleteNetworkModifications(UUID groupUuid, List modificationsU } @Transactional - public List> moveModifications(@NonNull UUID destinationGroupUuid, @NonNull UUID originGroupUuid, @NonNull UUID beforeModificationUuid, + public List> moveModifications(@NonNull UUID destinationGroupUuid, @NonNull UUID originGroupUuid, UUID beforeModificationUuid, @NonNull List modificationsToMoveUuids, @NonNull List applicationContexts, boolean canBuildNode) { // update origin/destinations groups to cut and paste all modificationsToMove @@ -265,8 +265,8 @@ public List> moveModifications(@NonNull UUID } /** - * TODO : Remove this endpoint after the final integration of root networks - * Need to use the new endpoint with ModificationApplicationContext DTO (see above) + * TODO : Remove this method after the final integration of root networks + * Need to use the new method with ModificationApplicationContext DTO (see above) */ @Transactional public Optional moveModifications(UUID destinationGroupUuid, UUID originGroupUuid, @@ -332,8 +332,8 @@ public List> duplicateModifications(@NonNull } /** - * TODO : Remove this endpoint after the final integration of root networks - * Need to use the new endpoint with ModificationApplicationContext DTO (see above) + * TODO : Remove this method after the final integration of root networks + * Need to use the new method with ModificationApplicationContext DTO (see above) */ @Transactional public Optional duplicateModifications(UUID targetGroupUuid, @@ -352,8 +352,8 @@ public List> insertCompositeModifications(@N } /** - * TODO : Remove this endpoint after the final integration of root networks (used only for move) - * Need to use the new endpoint with ModificationApplicationContext DTO (see above) + * TODO : Remove this method after the final integration of root networks (used only for move) + * Need to use the new method with ModificationApplicationContext DTO (see above) */ @Transactional public Optional insertCompositeModifications(UUID targetGroupUuid, diff --git a/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java b/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java index 46f00237f..ce2883410 100644 --- a/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java +++ b/src/test/java/org/gridsuite/modification/server/ModificationControllerTest.java @@ -24,6 +24,7 @@ import org.gridsuite.modification.NetworkModificationException; import org.gridsuite.modification.dto.*; import org.gridsuite.modification.dto.LoadCreationInfos.LoadCreationInfosBuilder; +import org.gridsuite.modification.server.dto.ModificationApplicationContext; import org.gridsuite.modification.server.dto.ModificationMetadata; import org.gridsuite.modification.server.dto.NetworkModificationResult; import org.gridsuite.modification.server.dto.catalog.LineTypeInfos; @@ -177,6 +178,17 @@ private boolean existTombstonedEquipmentInfos(String equipmentId, UUID networkUu return tombstonedEquipmentInfosRepository.findAllByNetworkUuidAndVariantId(networkUuid, variantId).stream().anyMatch(t -> t.getId().equals(equipmentId)); } + private void assertApplicationStatusOKNew(MvcResult mvcResult) throws Exception { + List> networkModificationResult = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { }); + assertEquals(1, networkModificationResult.size()); + assertTrue(networkModificationResult.get(0).isPresent()); + assertNotEquals(NetworkModificationResult.ApplicationStatus.WITH_ERRORS, networkModificationResult.get(0).get().getApplicationStatus()); + } + + /** + * TODO : Remove this method after the final integration of root networks + * Need to use the new endpoint with modificationContextInfos DTO (see above) + */ private void assertApplicationStatusOK(MvcResult mvcResult) throws Exception { Optional networkModificationResult = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { }); assertTrue(networkModificationResult.isPresent()); @@ -474,13 +486,14 @@ private List createSomeSwitchModifications(UUID groupId, int .equipmentId("v1b1") .build(); MvcResult mvcResult; + ModificationApplicationContext applicationContext = new ModificationApplicationContext(TEST_NETWORK_ID, NetworkCreation.VARIANT_ID, TEST_REPORT_ID, UUID.randomUUID()); for (int i = 0; i < number; i++) { switchStatusModificationInfos.setEquipmentAttributeValue(openStates.get(i % 2)); - String switchStatusModificationInfosJson = objectWriter.writeValueAsString(switchStatusModificationInfos); - mvcResult = mockMvc.perform(post(URI_NETWORK_MODIF_BASE + "?networkUuid=" + TEST_NETWORK_ID + "&groupUuid=" + groupId + "&reportUuid=" + TEST_REPORT_ID + "&reporterId=" + UUID.randomUUID()) - .content(switchStatusModificationInfosJson).contentType(MediaType.APPLICATION_JSON)) + String bodyJson = objectWriter.writeValueAsString(org.springframework.data.util.Pair.of(switchStatusModificationInfos, List.of(applicationContext))); + mvcResult = mockMvc.perform(post(URI_NETWORK_MODIF_BASE + "?groupUuid=" + groupId) + .content(bodyJson).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()).andReturn(); - assertApplicationStatusOK(mvcResult); + assertApplicationStatusOKNew(mvcResult); } var modificationList = modificationRepository.getModifications(groupId, false, true); assertEquals(number, modificationList.size()); @@ -508,6 +521,94 @@ void testCopyModification() throws Exception { List modificationList = createSomeSwitchModifications(TEST_GROUP_ID, 3); List modificationUuidList = modificationList.stream().map(ModificationInfos::getUuid).collect(Collectors.toList()); + // Duplicate [0] and [1], and append them at the end of the group modification list. + List duplicateModificationUuidList = new ArrayList<>(modificationUuidList.subList(0, 2)); + List badModificationUuidList = List.of(UUID.randomUUID(), UUID.randomUUID()); + duplicateModificationUuidList.addAll(badModificationUuidList); + ModificationApplicationContext applicationContext = new ModificationApplicationContext(TEST_NETWORK_ID, NetworkCreation.VARIANT_ID, TEST_REPORT_ID, UUID.randomUUID()); + String bodyJson = objectWriter.writeValueAsString(org.springframework.data.util.Pair.of(duplicateModificationUuidList, List.of(applicationContext))); + MvcResult mvcResult = mockMvc.perform( + put("/v1/groups/" + TEST_GROUP_ID + "?action=COPY") + .content(bodyJson) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()).andReturn(); + assertApplicationStatusOKNew(mvcResult); + + var newModificationList = modificationRepository.getModifications(TEST_GROUP_ID, false, true); + List newModificationUuidList = newModificationList.stream().map(ModificationInfos::getUuid).collect(Collectors.toList()); + // now 5 modifications: first 0-1-2 are still the same, last 3-4 are new (duplicates of 0-1) + assertEquals(5, newModificationList.size()); + assertEquals(modificationUuidList, newModificationUuidList.subList(0, 3)); + // compare duplicates 0 and 3 (same data except uuid) + assertThat(newModificationList.get(3)).recursivelyEquals(modificationList.get(0)); + + // compare duplicates 1 and 4 (same data except uuid) + assertThat(newModificationList.get(4)).recursivelyEquals(modificationList.get(1)); + + // bad request error case: wrong action param + mockMvc.perform( + put("/v1/groups/" + TEST_GROUP_ID + "?action=XXXXXXX") + .content(bodyJson) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isBadRequest()); + + // create 1 modification in another group + UUID otherGroupId = UUID.randomUUID(); + List modificationListOtherGroup = createSomeSwitchModifications(otherGroupId, 1); + List modificationUuidListOtherGroup = modificationListOtherGroup.stream().map(ModificationInfos::getUuid).collect(Collectors.toList()); + + // Duplicate the same modifications, and append them at the end of this new group modification list. + duplicateModificationUuidList = new ArrayList<>(modificationUuidList.subList(0, 2)); + bodyJson = objectWriter.writeValueAsString(org.springframework.data.util.Pair.of(duplicateModificationUuidList, List.of(applicationContext))); + mvcResult = mockMvc.perform( + put("/v1/groups/" + otherGroupId + "?action=COPY") + .content(bodyJson) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()).andReturn(); + assertApplicationStatusOKNew(mvcResult); + + var newModificationListOtherGroup = modificationRepository.getModifications(otherGroupId, false, true); + List newModificationUuidListOtherGroup = newModificationListOtherGroup.stream().map(ModificationInfos::getUuid).collect(Collectors.toList()); + // now 3 modifications in new group: first 0 is still the same, last 1-2 are new (duplicates of 0-1 from first group) + assertEquals(3, newModificationListOtherGroup.size()); + assertEquals(modificationUuidListOtherGroup, newModificationUuidListOtherGroup.subList(0, 1)); + // compare duplicates + assertThat(newModificationListOtherGroup.get(1)).recursivelyEquals(modificationList.get(0)); + assertThat(newModificationListOtherGroup.get(2)).recursivelyEquals(modificationList.get(1)); + + // Duplicate all modifications in TEST_GROUP_ID, and append them at the end of otherGroupId + mvcResult = mockMvc.perform( + put("/v1/groups/" + otherGroupId + "/duplications" + + "?networkUuid=" + TEST_NETWORK_ID + + "&reportUuid=" + TEST_REPORT_ID + + "&reporterId=" + UUID.randomUUID() + + "&variantId=" + NetworkCreation.VARIANT_ID + + "&duplicateFrom=" + TEST_GROUP_ID) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()).andReturn(); + assertApplicationStatusOK(mvcResult); + + newModificationListOtherGroup = modificationRepository.getModifications(otherGroupId, true, true); + // now 8 modifications in new group: first 3 are still the same, 5 last are new duplicates from first group + assertEquals(8, newModificationListOtherGroup.size()); + + // compare duplicates + modificationList = modificationRepository.getModifications(TEST_GROUP_ID, true, true); + for (int i = 3; i < 8; ++i) { + assertThat(newModificationListOtherGroup.get(i)).recursivelyEquals(modificationList.get(i - 3)); + } + } + + /** + * TODO : Remove this test after the final integration of root networks + * Need to use tne new test with modificationContextInfos DTO (see above) + */ + @Test + void testCopyModificationOld() throws Exception { + // create 3 modifications + List modificationList = createSomeSwitchModifications(TEST_GROUP_ID, 3); + List modificationUuidList = modificationList.stream().map(ModificationInfos::getUuid).collect(Collectors.toList()); + // Duplicate [0] and [1], and append them at the end of the group modification list. List duplicateModificationUuidList = new ArrayList<>(modificationUuidList.subList(0, 2)); List badModificationUuidList = List.of(UUID.randomUUID(), UUID.randomUUID()); @@ -679,14 +780,11 @@ void testMoveModificationInSameGroup() throws Exception { stream().map(ModificationInfos::getUuid).collect(Collectors.toList()); // swap modifications: move [1] before [0] - List movingModificationUuidList = Collections.singletonList(modificationUuidList.get(1)); - String url = "/v1/groups/" + TEST_GROUP_ID + "?action=MOVE" - + "&networkUuid=" + TEST_NETWORK_ID - + "&reportUuid=" + TEST_REPORT_ID - + "&reporterId=" + UUID.randomUUID() - + "&variantId=" + NetworkCreation.VARIANT_ID - + "&before=" + modificationUuidList.get(0); - mockMvc.perform(put(url).content(objectWriter.writeValueAsString(movingModificationUuidList)) + List movingModificationUuidList = List.of(modificationUuidList.get(1)); + ModificationApplicationContext applicationContext = new ModificationApplicationContext(TEST_NETWORK_ID, NetworkCreation.VARIANT_ID, TEST_REPORT_ID, UUID.randomUUID()); + String bodyJson = objectWriter.writeValueAsString(org.springframework.data.util.Pair.of(movingModificationUuidList, List.of(applicationContext))); + String url = "/v1/groups/" + TEST_GROUP_ID + "?action=MOVE" + "&before=" + modificationUuidList.get(0); + mockMvc.perform(put(url).content(bodyJson) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); @@ -704,6 +802,68 @@ void testNetworkCompositeModification() throws Exception { List modificationList = createSomeSwitchModifications(TEST_GROUP_ID, modificationsNumber); assertEquals(modificationsNumber, modificationRepository.getModifications(TEST_GROUP_ID, true, true).size()); + // Create a composite modification with the switch modification + List modificationUuids = modificationList.stream().map(ModificationInfos::getUuid).toList(); + MvcResult mvcResult; + mvcResult = mockMvc.perform(post(URI_COMPOSITE_NETWORK_MODIF_BASE) + .content(mapper.writeValueAsString(modificationUuids)).contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()).andReturn(); + ModificationInfos compositeModificationInfos = CompositeModificationInfos.builder() + .modifications(modificationList) + .build(); + UUID compositeModificationUuid = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { }); + assertThat(modificationRepository.getModificationInfo(compositeModificationUuid)).recursivelyEquals(compositeModificationInfos); + assertEquals(modificationsNumber, modificationRepository.getModifications(TEST_GROUP_ID, true, true).size()); + + // get the composite modification (metadata only) + mvcResult = mockMvc.perform(get(URI_GET_COMPOSITE_NETWORK_MODIF_CONTENT + compositeModificationUuid + "/network-modifications")) + .andExpect(status().isOk()).andReturn(); + List compositeModificationContent = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { }); + assertEquals(modificationsNumber, compositeModificationContent.size()); + assertNotNull(compositeModificationContent.get(0).getMessageType()); + assertNotNull(compositeModificationContent.get(0).getMessageValues()); + assertNull(((EquipmentAttributeModificationInfos) compositeModificationContent.get(0)).getEquipmentAttributeName()); + assertNull(((EquipmentAttributeModificationInfos) compositeModificationContent.get(0)).getEquipmentAttributeValue()); + assertNull(((EquipmentAttributeModificationInfos) compositeModificationContent.get(0)).getEquipmentType()); + assertNull(((EquipmentAttributeModificationInfos) compositeModificationContent.get(0)).getEquipmentId()); + + // get the composite modification (complete data) + mvcResult = mockMvc.perform(get(URI_GET_COMPOSITE_NETWORK_MODIF_CONTENT + compositeModificationUuid + "/network-modifications?onlyMetadata=false")) + .andExpect(status().isOk()).andReturn(); + compositeModificationContent = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { }); + assertEquals("open", ((EquipmentAttributeModificationInfos) compositeModificationContent.get(0)).getEquipmentAttributeName()); + assertEquals(Boolean.TRUE, ((EquipmentAttributeModificationInfos) compositeModificationContent.get(0)).getEquipmentAttributeValue()); + assertEquals(IdentifiableType.SWITCH, ((EquipmentAttributeModificationInfos) compositeModificationContent.get(0)).getEquipmentType()); + assertEquals("v1b1", ((EquipmentAttributeModificationInfos) compositeModificationContent.get(0)).getEquipmentId()); + + // Insert the composite modification in the group + ModificationApplicationContext applicationContext = new ModificationApplicationContext(TEST_NETWORK_ID, NetworkCreation.VARIANT_ID, TEST_REPORT_ID, UUID.randomUUID()); + String bodyJson = objectWriter.writeValueAsString(org.springframework.data.util.Pair.of(List.of(compositeModificationUuid), List.of(applicationContext))); + mvcResult = mockMvc.perform( + put("/v1/groups/" + TEST_GROUP_ID + "?action=INSERT") + .content(bodyJson) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()).andReturn(); + assertApplicationStatusOKNew(mvcResult); + + List newModificationList = modificationRepository.getModifications(TEST_GROUP_ID, false, true); + assertEquals(modificationsNumber * 2, newModificationList.size()); + List newModificationUuidList = newModificationList.stream().map(ModificationInfos::getUuid).toList(); + assertEquals(modificationUuids.get(0), newModificationUuidList.get(0)); + assertThat(modificationList.get(0)).recursivelyEquals(newModificationList.get(modificationsNumber)); + } + + /** + * TODO : Remove this test after the final integration of root networks + * Need to use tne new test with modificationContextInfos DTO (see above) + */ + @Test + void testNetworkCompositeModificationOld() throws Exception { + // Insert some switch modifications in the group + int modificationsNumber = 2; + List modificationList = createSomeSwitchModifications(TEST_GROUP_ID, modificationsNumber); + assertEquals(modificationsNumber, modificationRepository.getModifications(TEST_GROUP_ID, true, true).size()); + // Create a composite modification with the switch modification List modificationUuids = modificationList.stream().map(ModificationInfos::getUuid).toList(); MvcResult mvcResult; @@ -773,24 +933,20 @@ void testMoveModificationBetweenTwoGroups() throws Exception { UUID originSingleModification = createDeletionModification(TEST_GROUP2_ID, IdentifiableType.LOAD, "v1load").getUuid(); // cut origin[0] and append to destination - List movingModificationUuidList = Collections.singletonList(originSingleModification); - String url = "/v1/groups/" + TEST_GROUP_ID + "?action=MOVE" - + "&networkUuid=" + TEST_NETWORK_ID - + "&reportUuid=" + TEST_REPORT_ID - + "&reporterId=" + UUID.randomUUID() - + "&variantId=" + NetworkCreation.VARIANT_ID - + "&originGroupUuid=" + TEST_GROUP2_ID - + "&build=true"; - - MvcResult mvcResult = mockMvc.perform(put(url).content(objectWriter.writeValueAsString(movingModificationUuidList)) + List movingModificationUuidList = List.of(originSingleModification); + ModificationApplicationContext applicationContext = new ModificationApplicationContext(TEST_NETWORK_ID, NetworkCreation.VARIANT_ID, TEST_REPORT_ID, UUID.randomUUID()); + String bodyJson = objectWriter.writeValueAsString(org.springframework.data.util.Pair.of(movingModificationUuidList, List.of(applicationContext))); + String url = "/v1/groups/" + TEST_GROUP_ID + "?action=MOVE" + "&originGroupUuid=" + TEST_GROUP2_ID + "&build=true"; + MvcResult mvcResult = mockMvc.perform(put(url).content(bodyJson) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andReturn(); // incremental build: deletion impacts expected, all related to the moved load deletion (dealing with "s1" substation) - Optional networkModificationResult = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { }); - assertTrue(networkModificationResult.isPresent()); - networkModificationResult.get().getNetworkImpacts().forEach(i -> { + List> networkModificationResult = mapper.readValue(mvcResult.getResponse().getContentAsString(), new TypeReference<>() { }); + assertEquals(1, networkModificationResult.size()); + assertTrue(networkModificationResult.get(0).isPresent()); + networkModificationResult.get(0).get().getNetworkImpacts().forEach(i -> { assertTrue(i.isSimple()); SimpleElementImpact simpleImpact = (SimpleElementImpact) i; assertEquals(Set.of(substationS1), simpleImpact.getSubstationIds());