From c17bb4b8dd288092ba945d0574628f3ce1615ea6 Mon Sep 17 00:00:00 2001 From: Tristan Chuine Date: Mon, 10 Jun 2024 21:55:05 +0200 Subject: [PATCH 1/2] [Sonar] Use constant for repetitive value --- .../gridsuite/study/server/LoadFlowTest.java | 22 +- .../study/server/NetworkModificationTest.java | 620 ++++++++---------- .../server/NetworkModificationTreeTest.java | 190 +++--- .../study/server/NonEvacuatedEnergyTest.java | 21 +- .../study/server/SecurityAnalysisTest.java | 11 +- .../study/server/SensitivityAnalysisTest.java | 13 +- .../study/server/ShortCircuitTest.java | 28 +- .../StudyControllerDynamicSimulationTest.java | 2 +- .../org/gridsuite/study/server/StudyTest.java | 338 +++++----- .../study/server/VoltageInitTest.java | 27 +- 10 files changed, 602 insertions(+), 670 deletions(-) diff --git a/src/test/java/org/gridsuite/study/server/LoadFlowTest.java b/src/test/java/org/gridsuite/study/server/LoadFlowTest.java index 13f1bc15c..22439a2d9 100644 --- a/src/test/java/org/gridsuite/study/server/LoadFlowTest.java +++ b/src/test/java/org/gridsuite/study/server/LoadFlowTest.java @@ -121,8 +121,8 @@ public class LoadFlowTest { private static final String LOADFLOW_STATUS_JSON = "{\"status\":\"COMPLETED\"}"; + private static final String USER_ID = "userId"; private static final String VARIANT_ID = "variant_1"; - private static final String VARIANT_ID_2 = "variant_2"; private static final long TIMEOUT = 1000; @@ -372,12 +372,12 @@ public void testLoadFlow() throws Exception { // run a loadflow on root node (not allowed) mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/loadflow/run", studyNameUserIdUuid, rootNodeUuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); //run a loadflow mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/loadflow/run", studyNameUserIdUuid, modificationNode3Uuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.UPDATE_TYPE_LOADFLOW_STATUS); @@ -412,7 +412,7 @@ public void testLoadFlow() throws Exception { // loadflow failed mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/loadflow/run", studyNameUserIdUuid, modificationNode2Uuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.UPDATE_TYPE_LOADFLOW_FAILED); @@ -433,7 +433,7 @@ public void testGetLimitViolations() throws Exception { //run a loadflow mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/loadflow/run?limitReduction=0.7", studyNameUserIdUuid, modificationNode1Uuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()) .andReturn(); @@ -485,7 +485,7 @@ public void testInvalidateStatus() throws Exception { //run a loadflow mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/loadflow/run?limitReduction=0.7", studyNameUserIdUuid, modificationNode1Uuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()) .andReturn(); @@ -496,7 +496,7 @@ public void testInvalidateStatus() throws Exception { // invalidate status mockMvc.perform(put("/v1/studies/{studyUuid}/loadflow/invalidate-status", studyNameUserIdUuid) - .header(HEADER_USER_ID, "userId")).andExpect(status().isOk()); + .header(HEADER_USER_ID, USER_ID)).andExpect(status().isOk()); checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.UPDATE_TYPE_LOADFLOW_STATUS); assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/results/invalidate-status\\?resultUuid=" + LOADFLOW_RESULT_UUID))); } @@ -521,7 +521,7 @@ public void testDeleteLoadFlowResults() throws Exception { //run a loadflow mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/loadflow/run", studyNameUserIdUuid, modificationNode3Uuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.UPDATE_TYPE_LOADFLOW_STATUS); @@ -759,7 +759,7 @@ public void testLoadFlowParameters() throws Exception { JSONAssert.assertEquals(LOADFLOW_DEFAULT_PARAMETERS_JSON, mvcResult.getResponse().getContentAsString(), JSONCompareMode.NON_EXTENSIBLE); - createOrUpdateParametersAndDoChecks(studyNameUserIdUuid, LOADFLOW_DEFAULT_PARAMETERS_JSON, "userId", HttpStatus.OK); + createOrUpdateParametersAndDoChecks(studyNameUserIdUuid, LOADFLOW_DEFAULT_PARAMETERS_JSON, USER_ID, HttpStatus.OK); //checking update is registered mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/loadflow/parameters", studyNameUserIdUuid)).andExpectAll( @@ -773,7 +773,7 @@ public void testLoadFlowParameters() throws Exception { studyNameUserIdUuid = studyEntity2.getId(); - createOrUpdateParametersAndDoChecks(studyNameUserIdUuid, LOADFLOW_DEFAULT_PARAMETERS_JSON, "userId", HttpStatus.OK); + createOrUpdateParametersAndDoChecks(studyNameUserIdUuid, LOADFLOW_DEFAULT_PARAMETERS_JSON, USER_ID, HttpStatus.OK); //get initial loadFlow parameters mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/loadflow/parameters", studyNameUserIdUuid)).andExpectAll( @@ -825,7 +825,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU jsonObject.put("modificationGroupUuid", modificationGroupUuid); mnBodyJson = jsonObject.toString(); - mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, "userId")) + mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); var mess = output.receive(TIMEOUT, studyUpdateDestination); assertNotNull(mess); diff --git a/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java b/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java index a8c9a57eb..28f6ad421 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java @@ -103,6 +103,7 @@ public class NetworkModificationTest { private static final UUID CASE_2_UUID = UUID.fromString(CASE_2_UUID_STRING); private static final UUID CASE_3_UUID = UUID.fromString(CASE_3_UUID_STRING); + private static final String USER_ID = "userId"; private static final String VARIANT_ID = "variant_1"; private static final String VARIANT_ID_2 = "variant_2"; private static final String VARIANT_ID_3 = "variant_3"; @@ -368,7 +369,7 @@ public void testBuildFailed() throws Exception { UUID modificationGroupUuid1 = UUID.randomUUID(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyUuid, rootNodeUuid, - modificationGroupUuid1, "variant_1", "node 1", "userId"); + modificationGroupUuid1, "variant_1", "node 1", USER_ID); testBuildFailedWithNodeUuid(studyUuid, modificationNode.getId()); } @@ -380,32 +381,31 @@ public void testBuildError() throws Exception { UUID rootNodeUuid = getRootNode(studyUuid).getId(); UUID modificationGroupUuid1 = UUID.randomUUID(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyUuid, rootNodeUuid, - modificationGroupUuid1, "variant_1", "node 1", "userId"); + modificationGroupUuid1, "variant_1", "node 1", USER_ID); testBuildErrorWithNodeUuid(studyUuid, modificationNode.getId()); } @Test public void testBuild() throws Exception { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); UUID modificationGroupUuid1 = UUID.randomUUID(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, - modificationGroupUuid1, "variant_1", "node 1", userId); + modificationGroupUuid1, "variant_1", "node 1", USER_ID); UUID modificationGroupUuid2 = UUID.randomUUID(); NetworkModificationNode modificationNode2 = createNetworkModificationNode(studyNameUserIdUuid, - modificationNode1.getId(), modificationGroupUuid2, "variant_2", "node 2", userId); + modificationNode1.getId(), modificationGroupUuid2, "variant_2", "node 2", USER_ID); UUID modificationGroupUuid3 = UUID.randomUUID(); NetworkModificationNode modificationNode3 = createNetworkModificationNode(studyNameUserIdUuid, - modificationNode2.getId(), modificationGroupUuid3, "variant_3", "node 3", userId); + modificationNode2.getId(), modificationGroupUuid3, "variant_3", "node 3", USER_ID); UUID modificationGroupUuid4 = UUID.randomUUID(); NetworkModificationNode modificationNode4 = createNetworkModificationNode(studyNameUserIdUuid, - modificationNode3.getId(), modificationGroupUuid4, "variant_4", "node 4", userId); + modificationNode3.getId(), modificationGroupUuid4, "variant_4", "node 4", USER_ID); UUID modificationGroupUuid5 = UUID.randomUUID(); NetworkModificationNode modificationNode5 = createNetworkModificationNode(studyNameUserIdUuid, - modificationNode4.getId(), modificationGroupUuid5, "variant_5", "node 5", userId); + modificationNode4.getId(), modificationGroupUuid5, "variant_5", "node 5", USER_ID); /* root @@ -427,8 +427,8 @@ public void testBuild() throws Exception { assertEquals(List.of(modificationGroupUuid1, modificationGroupUuid2, modificationGroupUuid3, modificationGroupUuid4, modificationGroupUuid5), buildInfos.getModificationGroupUuids()); modificationNode3.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILT)); // mark node modificationNode3 as built - networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode3, userId); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode3, USER_ID); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); buildInfos = networkModificationTreeService.getBuildInfos(modificationNode4.getId()); @@ -438,16 +438,16 @@ public void testBuild() throws Exception { assertEquals(List.of(modificationGroupUuid4), buildInfos.getModificationGroupUuids()); modificationNode2.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.NOT_BUILT)); // mark node modificationNode2 as not built - networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode2, userId); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode2, USER_ID); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); modificationNode4.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.NOT_BUILT)); // mark node modificationNode4 as built invalid - networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode4, userId); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode4, USER_ID); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); modificationNode5.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILT)); // mark node modificationNode5 as built - networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode5, userId); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode5, USER_ID); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); // build modificationNode2 and stop build @@ -458,8 +458,8 @@ public void testBuild() throws Exception { assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode5.getId()).getGlobalBuildStatus()); modificationNode3.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.NOT_BUILT)); // mark node modificationNode3 as built - networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode3, userId); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode3, USER_ID); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); // build modificationNode3 and stop build @@ -474,9 +474,8 @@ public void testLocalBuildValue() throws Exception { StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); - String userId = "userId"; NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, - UUID.randomUUID(), VARIANT_ID, "node 1", userId); + UUID.randomUUID(), VARIANT_ID, "node 1", USER_ID); UUID modificationNodeUuid = modificationNode.getId(); Map createLoadInfos = Map.of("type", ModificationType.LOAD_CREATION, "equipmentId", "loadId"); @@ -485,12 +484,12 @@ public void testLocalBuildValue() throws Exception { // Mark the node status as built modificationNode.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILT)); - networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode, userId); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode, USER_ID); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); NetworkModificationNode modificationNode2 = createNetworkModificationNode(studyNameUserIdUuid, modificationNodeUuid, - UUID.randomUUID(), VARIANT_ID, "node 2", userId); + UUID.randomUUID(), VARIANT_ID, "node 2", USER_ID); UUID modificationNode2Uuid = modificationNode2.getId(); // Create network modification on BUILT modification node @@ -504,11 +503,11 @@ public void testLocalBuildValue() throws Exception { stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkEquipmentMessagesReceived(studyNameUserIdUuid, modificationNodeUuid, expectedPayload); checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); @@ -522,11 +521,11 @@ public void testLocalBuildValue() throws Exception { stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNode2Uuid)); checkEquipmentMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid, expectedPayload); checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNode2Uuid)); @@ -542,19 +541,14 @@ public void testLocalBuildValue() throws Exception { @Test public void testNetworkModificationSwitch() throws Exception { - - MvcResult mvcResult; - String resultAsString; - String userId = "userId"; - StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, - UUID.randomUUID(), VARIANT_ID, "node 1", userId); + UUID.randomUUID(), VARIANT_ID, "node 1", USER_ID); UUID modificationNode1Uuid = modificationNode1.getId(); NetworkModificationNode modificationNode2 = createNetworkModificationNode(studyNameUserIdUuid, - modificationNode1Uuid, UUID.randomUUID(), VARIANT_ID_2, "node 2", userId); + modificationNode1Uuid, UUID.randomUUID(), VARIANT_ID_2, "node 2", USER_ID); UUID modificationNode2Uuid = modificationNode2.getId(); Map body = Map.of( @@ -569,27 +563,27 @@ public void testNetworkModificationSwitch() throws Exception { // update switch on root node (not allowed) mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); // update switch on first modification node UUID stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode1Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubId, bodyJson, NETWORK_UUID_STRING, VARIANT_ID); - mvcResult = mockMvc.perform(get("/v1/studies").header(HEADER_USER_ID, userId)).andExpectAll( - status().isOk(), - content().contentType(MediaType.APPLICATION_JSON)) - .andReturn(); - resultAsString = mvcResult.getResponse().getContentAsString(); + MvcResult mvcResult = mockMvc.perform(get("/v1/studies").header(HEADER_USER_ID, USER_ID)).andExpectAll( + status().isOk(), + content().contentType(MediaType.APPLICATION_JSON)) + .andReturn(); + String resultAsString = mvcResult.getResponse().getContentAsString(); List csbiListResult = mapper.readValue(resultAsString, new TypeReference>() { }); assertThat(csbiListResult.get(0), createMatcherCreatedStudyBasicInfos(studyNameUserIdUuid, "UCTE")); @@ -597,24 +591,24 @@ public void testNetworkModificationSwitch() throws Exception { // update switch on second modification node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode2Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubId, bodyJson, NETWORK_UUID_STRING, VARIANT_ID_2); // test build status on switch modification modificationNode1.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILT)); // mark modificationNode1 as built - networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, userId); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, USER_ID); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); modificationNode2.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILT)); // mark modificationNode2 as built - networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode2, userId); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode2, USER_ID); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); Optional networkModificationResult = @@ -622,12 +616,12 @@ public void testNetworkModificationSwitch() throws Exception { stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); Set substationsSet = ImmutableSet.of("s3", "s1", "s2"); NetworkImpactsInfos expectedPayload = NetworkImpactsInfos.builder().impactedSubstationsIds(substationsSet).build(); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); checkSwitchModificationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode1Uuid, modificationNode2Uuid), expectedPayload); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); @@ -645,17 +639,14 @@ public void testNetworkModificationSwitch() throws Exception { @Test public void testNetworkModificationEquipment() throws Exception { - MvcResult mvcResult; - String resultAsString; - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); - NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node 1", userId); + NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node 1", USER_ID); UUID modificationNodeUuid = modificationNode.getId(); NetworkModificationNode modificationNode2 = createNetworkModificationNode(studyNameUserIdUuid, - modificationNodeUuid, VARIANT_ID_2, "node 2", userId); + modificationNodeUuid, VARIANT_ID_2, "node 2", USER_ID); UUID modificationNodeUuid2 = modificationNode2.getId(); Map body = Map.of( @@ -667,14 +658,14 @@ public void testNetworkModificationEquipment() throws Exception { //update equipment on root node (not allowed) mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); //update equipment UUID stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); @@ -682,11 +673,11 @@ public void testNetworkModificationEquipment() throws Exception { checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); wireMockUtils.verifyNetworkModificationPost(stubId, bodyJson, NETWORK_UUID_STRING); - mvcResult = mockMvc.perform(get("/v1/studies").header(HEADER_USER_ID, "userId").header(HEADER_USER_ID, "userId")).andExpectAll( + MvcResult mvcResult = mockMvc.perform(get("/v1/studies").header(HEADER_USER_ID, USER_ID).header(HEADER_USER_ID, USER_ID)).andExpectAll( status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); - resultAsString = mvcResult.getResponse().getContentAsString(); + String resultAsString = mvcResult.getResponse().getContentAsString(); List csbiListResponse = mapper.readValue(resultAsString, new TypeReference>() { }); @@ -695,28 +686,27 @@ public void testNetworkModificationEquipment() throws Exception { // update equipment on second modification node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid2) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid2); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNodeUuid2)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid2); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid2); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubId, bodyJson, NETWORK_UUID_STRING, VARIANT_ID_2); } @Test public void testCreateGenerator() throws Exception { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, - UUID.randomUUID(), VARIANT_ID, "node 1", userId); + UUID.randomUUID(), VARIANT_ID, "node 1", USER_ID); UUID modificationNode1Uuid = modificationNode1.getId(); NetworkModificationNode modificationNode2 = createNetworkModificationNode(studyNameUserIdUuid, - modificationNode1Uuid, UUID.randomUUID(), VARIANT_ID_2, "node 2", userId); + modificationNode1Uuid, UUID.randomUUID(), VARIANT_ID_2, "node 2", USER_ID); UUID modificationNode2Uuid = modificationNode2.getId(); Map body = new HashMap<>(); @@ -738,32 +728,32 @@ public void testCreateGenerator() throws Exception { // create generator on root node (not allowed) mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(bodyJsonCreate).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); // create generator on first modification node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreate).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode1Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, bodyJsonCreate, NETWORK_UUID_STRING, VARIANT_ID); // create generator on second modification node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(bodyJsonCreate).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode2Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, bodyJsonCreate, NETWORK_UUID_STRING, VARIANT_ID_2); // update generator creation @@ -776,12 +766,12 @@ public void testCreateGenerator() throws Exception { String bodyJsonUpdate = mapper.writeValueAsString(body); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNode1Uuid, MODIFICATION_UUID) .content(bodyJsonUpdate).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkUpdateEquipmentCreationMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPut(stubPutId, MODIFICATION_UUID, bodyJsonUpdate); // create generator on building node @@ -792,23 +782,22 @@ public void testCreateGenerator() throws Exception { body.replace("maxActivePower", "200.0"); String bodyJsonCreateBis = mapper.writeValueAsString(body); modificationNode1.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILDING)); - networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, userId); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, USER_ID); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreateBis).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); } @Test public void testCreateShuntsCompensator() throws Exception { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, - UUID.randomUUID(), VARIANT_ID, "node 1", userId); + UUID.randomUUID(), VARIANT_ID, "node 1", USER_ID); UUID modificationNode1Uuid = modificationNode1.getId(); String createShuntCompensatorAttributes = "{\"type\":\"" + ModificationType.SHUNT_COMPENSATOR_CREATION + "\",\"shuntCompensatorId\":\"shuntCompensatorId1\",\"shuntCompensatorName\":\"shuntCompensatorName1\",\"voltageLevelId\":\"idVL1\",\"busOrBusbarSectionId\":\"idBus1\"}"; @@ -816,20 +805,20 @@ public void testCreateShuntsCompensator() throws Exception { // create shuntCompensator on root node (not allowed) mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(createShuntCompensatorAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); // create shuntCompensator on modification node child of root node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createShuntCompensatorAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode1Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createShuntCompensatorAttributes, NETWORK_UUID_STRING, VARIANT_ID); // update shunt compensator creation @@ -837,37 +826,36 @@ public void testCreateShuntsCompensator() throws Exception { String shuntCompensatorAttributesUpdated = "{\"type\":\"" + ModificationType.SHUNT_COMPENSATOR_CREATION + "\",\"shuntCompensatorId\":\"shuntCompensatorId2\",\"shuntCompensatorName\":\"shuntCompensatorName2\",\"voltageLevelId\":\"idVL2\",\"busOrBusbarSectionId\":\"idBus1\"}"; mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNode1Uuid, MODIFICATION_UUID) .content(shuntCompensatorAttributesUpdated).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkUpdateEquipmentCreationMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPut(stubPutId, MODIFICATION_UUID, shuntCompensatorAttributesUpdated); String createShuntCompensatorAttributes2 = "{\"type\":\"" + ModificationType.SHUNT_COMPENSATOR_CREATION + "\",\"shuntCompensatorId\":\"shuntCompensatorId3\",\"shuntCompensatorName\":\"shuntCompensatorName3\",\"voltageLevelId\":\"idVL1\",\"busOrBusbarSectionId\":\"idBus1\"}"; modificationNode1.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILDING)); - networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, userId); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, USER_ID); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); // create shunt compensator on building node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createShuntCompensatorAttributes2).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); } @Test public void testCreateLine() throws Exception { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, - UUID.randomUUID(), VARIANT_ID, "node 1", userId); + UUID.randomUUID(), VARIANT_ID, "node 1", USER_ID); UUID modificationNode1Uuid = modificationNode1.getId(); NetworkModificationNode modificationNode2 = createNetworkModificationNode(studyNameUserIdUuid, - modificationNode1Uuid, UUID.randomUUID(), VARIANT_ID_2, "node 2", userId); + modificationNode1Uuid, UUID.randomUUID(), VARIANT_ID_2, "node 2", USER_ID); UUID modificationNode2Uuid = modificationNode2.getId(); String createLineAttributes = "{\"type\":\"" + ModificationType.LINE_CREATION @@ -881,32 +869,32 @@ public void testCreateLine() throws Exception { // create line on root node (not allowed) mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(createLineAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); // create line on first modification node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createLineAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode1Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createLineAttributes, NETWORK_UUID_STRING, VARIANT_ID); // create line on second modification node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(createLineAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode2Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createLineAttributes, NETWORK_UUID_STRING, VARIANT_ID_2); // update line creation @@ -920,12 +908,12 @@ public void testCreateLine() throws Exception { UUID stubPutId = wireMockUtils.stubNetworkModificationPut(MODIFICATION_UUID); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNode1Uuid, MODIFICATION_UUID) .content(lineAttributesUpdated).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkUpdateEquipmentCreationMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPut(stubPutId, MODIFICATION_UUID, lineAttributesUpdated); String createLineAttributes2 = "{\"type\":\"" + ModificationType.LINE_CREATION @@ -936,27 +924,26 @@ public void testCreateLine() throws Exception { + "\"voltageLevelId1\":\"idVL1\"," + "\"busOrBusbarSectionId1\":\"idBus1\"," + "\"voltageLevelId2\":\"idVL2\"," + "\"busOrBusbarSectionId2\":\"idBus2\"}"; modificationNode1.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILDING)); - networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, userId); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, USER_ID); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); // create line on building node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createLineAttributes2).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); } @Test public void testCreateTwoWindingsTransformer() throws Exception { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, - UUID.randomUUID(), VARIANT_ID, "node 1", userId); + UUID.randomUUID(), VARIANT_ID, "node 1", USER_ID); UUID modificationNode1Uuid = modificationNode1.getId(); NetworkModificationNode modificationNode2 = createNetworkModificationNode(studyNameUserIdUuid, - modificationNode1Uuid, UUID.randomUUID(), VARIANT_ID_2, "node 2", userId); + modificationNode1Uuid, UUID.randomUUID(), VARIANT_ID_2, "node 2", USER_ID); UUID modificationNode2Uuid = modificationNode2.getId(); String createTwoWindingsTransformerAttributes = "{\"type\":\"" + ModificationType.TWO_WINDINGS_TRANSFORMER_CREATION + "\",\"equipmentId\":\"2wtId\",\"equipmentName\":\"2wtName\",\"seriesResistance\":\"10\",\"seriesReactance\":\"10\",\"magnetizingConductance\":\"100\",\"magnetizingSusceptance\":\"100\",\"ratedVoltage1\":\"480\",\"ratedVoltage2\":\"380\",\"voltageLevelId1\":\"CHOO5P6\",\"busOrBusbarSectionId1\":\"CHOO5P6_1\",\"voltageLevelId2\":\"CHOO5P6\",\"busOrBusbarSectionId2\":\"CHOO5P6_1\"}"; @@ -964,32 +951,32 @@ public void testCreateTwoWindingsTransformer() throws Exception { // create 2WT on root node (not allowed) mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(createTwoWindingsTransformerAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); // create 2WT on first modification node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createTwoWindingsTransformerAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode1Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createTwoWindingsTransformerAttributes, NETWORK_UUID_STRING, VARIANT_ID); // create 2WT on second modification node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(createTwoWindingsTransformerAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode2Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createTwoWindingsTransformerAttributes, NETWORK_UUID_STRING, VARIANT_ID_2); // update Two Windings Transformer creation @@ -997,48 +984,47 @@ public void testCreateTwoWindingsTransformer() throws Exception { UUID stubPutId = wireMockUtils.stubNetworkModificationPut(MODIFICATION_UUID); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNode1Uuid, MODIFICATION_UUID) .content(twoWindingsTransformerAttributesUpdated).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkUpdateEquipmentCreationMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPut(stubPutId, MODIFICATION_UUID, twoWindingsTransformerAttributesUpdated); String createTwoWindingsTransformerAttributes2 = "{\"type\":\"" + ModificationType.TWO_WINDINGS_TRANSFORMER_CREATION + "\",\"equipmentId\":\"2wtId3\",\"equipmentName\":\"2wtName3\",\"seriesResistance\":\"10\",\"seriesReactance\":\"10\",\"magnetizingConductance\":\"100\",\"magnetizingSusceptance\":\"100\",\"ratedVoltage1\":\"480\",\"ratedVoltage2\":\"380\",\"voltageLevelId1\":\"CHOO5P6\",\"busOrBusbarSectionId1\":\"CHOO5P6_1\",\"voltageLevelId2\":\"CHOO5P6\",\"busOrBusbarSectionId2\":\"CHOO5P6_1\"}"; modificationNode1.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILDING)); - networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, userId); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, USER_ID); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); // create Two Windings Transformer on building node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createTwoWindingsTransformerAttributes2).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); } @Test public void testChangeModificationActiveState() throws Exception { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyUuid).getId(); UUID modificationGroupUuid1 = UUID.randomUUID(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyUuid, rootNodeUuid, - modificationGroupUuid1, "variant_1", "node 1", "userId"); + modificationGroupUuid1, "variant_1", "node 1", USER_ID); UUID modificationUuid = UUID.randomUUID(); UUID nodeNotFoundUuid = UUID.randomUUID(); // deactivate modification on modificationNode mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network_modifications/{modificationUuid}?active=false", - studyUuid, nodeNotFoundUuid, modificationUuid).header(HEADER_USER_ID, "userId") - .header(HEADER_USER_ID, userId)) + studyUuid, nodeNotFoundUuid, modificationUuid).header(HEADER_USER_ID, USER_ID) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isNotFound()); mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network_modifications/{modificationUuid}?active=false", - studyUuid, modificationNode1.getId(), modificationUuid).header(HEADER_USER_ID, "userId") - .header(HEADER_USER_ID, userId)) + studyUuid, modificationNode1.getId(), modificationUuid).header(HEADER_USER_ID, USER_ID) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); AtomicReference node = new AtomicReference<>(); @@ -1051,8 +1037,8 @@ public void testChangeModificationActiveState() throws Exception { // reactivate modification mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network_modifications/{modificationUuid}?active=true", - studyUuid, modificationNode1.getId(), modificationUuid).header(HEADER_USER_ID, "userId") - .header(HEADER_USER_ID, userId)) + studyUuid, modificationNode1.getId(), modificationUuid).header(HEADER_USER_ID, USER_ID) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); node.set(networkModificationTreeService.getNode(modificationNode1.getId())); @@ -1065,16 +1051,15 @@ public void testChangeModificationActiveState() throws Exception { @Test public void deleteModificationRequest() throws Exception { - String userId = "userId"; UUID stubId = wireMockServer.stubFor(WireMock.delete(WireMock.urlPathMatching("/v1/network-modifications")).willReturn(WireMock.ok())).getId(); StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyUuid).getId(); - NetworkModificationNode modificationNode = createNetworkModificationNode(studyUuid, rootNodeUuid, VARIANT_ID, "node 1", userId); - createNetworkModificationNode(studyUuid, rootNodeUuid, VARIANT_ID_2, "node 2", userId); - NetworkModificationNode node3 = createNetworkModificationNode(studyUuid, modificationNode.getId(), "variant_3", "node 3", userId); + NetworkModificationNode modificationNode = createNetworkModificationNode(studyUuid, rootNodeUuid, VARIANT_ID, "node 1", USER_ID); + createNetworkModificationNode(studyUuid, rootNodeUuid, VARIANT_ID_2, "node 2", USER_ID); + NetworkModificationNode node3 = createNetworkModificationNode(studyUuid, modificationNode.getId(), "variant_3", "node 3", USER_ID); /* root / \ node modification node @@ -1085,7 +1070,7 @@ public void deleteModificationRequest() throws Exception { UUID studyUuid1 = UUID.randomUUID(); mockMvc.perform(delete(URI_NETWORK_MODIF, studyUuid1, modificationNode.getId()) .queryParam("uuids", node3.getId().toString()) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); checkEquipmentDeletingMessagesReceived(studyUuid1, modificationNode.getId()); checkEquipmentDeletingFinishedMessagesReceived(studyUuid1, modificationNode.getId()); @@ -1093,7 +1078,7 @@ public void deleteModificationRequest() throws Exception { UUID modificationUuid = UUID.randomUUID(); mockMvc.perform(delete(URI_NETWORK_MODIF, studyUuid, modificationNode.getId()) .queryParam("uuids", modificationUuid.toString()) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); wireMockUtils.verifyDeleteRequest(stubId, "/v1/network-modifications", false, Map.of("uuids", WireMock.equalTo(modificationUuid.toString()))); checkEquipmentDeletingMessagesReceived(studyUuid, modificationNode.getId()); @@ -1106,7 +1091,7 @@ public void deleteModificationRequest() throws Exception { ).getId(); mockMvc.perform(delete("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modifications", studyUuid, modificationNode.getId()) .queryParam("uuids", modificationUuid.toString()) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isBadRequest()); wireMockUtils.verifyDeleteRequest(stubId, "/v1/network-modifications", false, Map.of("uuids", WireMock.equalTo(modificationUuid.toString()))); checkEquipmentDeletingMessagesReceived(studyUuid, modificationNode.getId()); @@ -1115,15 +1100,14 @@ public void deleteModificationRequest() throws Exception { @Test public void testUpdateLines() throws Exception { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, - UUID.randomUUID(), VARIANT_ID, "node 1", userId); + UUID.randomUUID(), VARIANT_ID, "node 1", USER_ID); UUID modificationNode1Uuid = modificationNode1.getId(); NetworkModificationNode modificationNode2 = createNetworkModificationNode(studyNameUserIdUuid, - modificationNode1Uuid, UUID.randomUUID(), VARIANT_ID_2, "node 2", userId); + modificationNode1Uuid, UUID.randomUUID(), VARIANT_ID_2, "node 2", USER_ID); UUID modificationNode2Uuid = modificationNode2.getId(); HashMap bodyLineInfos = new HashMap<>(); @@ -1136,19 +1120,19 @@ public void testUpdateLines() throws Exception { UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(bodyJsonCreate1).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); // lockout line mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreate1).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode1Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPost(stubPostId, bodyJsonCreate1, NETWORK_UUID_STRING); bodyLineInfos.put("equipmentId", "lineFailedId"); @@ -1156,7 +1140,7 @@ public void testUpdateLines() throws Exception { stubPostId = wireMockUtils.stubNetworkModificationPostWithError(bodyJsonCreate2); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreate2).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isBadRequest()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); @@ -1169,13 +1153,13 @@ public void testUpdateLines() throws Exception { stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreate3).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode1Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPost(stubPostId, bodyJsonCreate3, NETWORK_UUID_STRING); bodyLineInfos.put("equipmentId", "lineFailedId"); @@ -1183,7 +1167,7 @@ public void testUpdateLines() throws Exception { stubPostId = wireMockUtils.stubNetworkModificationPostWithError(bodyJsonCreate4); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreate4).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isBadRequest()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); @@ -1196,13 +1180,13 @@ public void testUpdateLines() throws Exception { stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreate5).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode1Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPost(stubPostId, bodyJsonCreate5, NETWORK_UUID_STRING); bodyLineInfos.put("equipmentId", "lineFailedId"); @@ -1210,7 +1194,7 @@ public void testUpdateLines() throws Exception { stubPostId = wireMockUtils.stubNetworkModificationPostWithError(bodyJsonCreate6); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreate6).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isBadRequest()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); @@ -1223,13 +1207,13 @@ public void testUpdateLines() throws Exception { stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreate7).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode1Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPost(stubPostId, bodyJsonCreate7, NETWORK_UUID_STRING); bodyLineInfos.put("equipmentId", "lineFailedId"); @@ -1237,7 +1221,7 @@ public void testUpdateLines() throws Exception { stubPostId = wireMockUtils.stubNetworkModificationPostWithError(bodyJsonCreate8); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreate8).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isBadRequest()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); @@ -1248,30 +1232,29 @@ public void testUpdateLines() throws Exception { stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(bodyJsonCreate9).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode2Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, bodyJsonCreate9, NETWORK_UUID_STRING, VARIANT_ID_2); } @Test public void testCreateLoad() throws Exception { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, - UUID.randomUUID(), VARIANT_ID, "node 1", userId); + UUID.randomUUID(), VARIANT_ID, "node 1", USER_ID); UUID modificationNode1Uuid = modificationNode1.getId(); NetworkModificationNode modificationNode2 = createNetworkModificationNode(studyNameUserIdUuid, - modificationNode1Uuid, UUID.randomUUID(), VARIANT_ID_2, "node 2", userId); + modificationNode1Uuid, UUID.randomUUID(), VARIANT_ID_2, "node 2", USER_ID); UUID modificationNode2Uuid = modificationNode2.getId(); NetworkModificationNode modificationNode3 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, - UUID.randomUUID(), VARIANT_ID, "node 3", userId); + UUID.randomUUID(), VARIANT_ID, "node 3", USER_ID); UUID modificationNode3Uuid = modificationNode3.getId(); String createLoadAttributes = "{\"type\":\"" + ModificationType.LOAD_CREATION + "\",\"loadId\":\"loadId1\",\"loadName\":\"loadName1\",\"loadType\":\"UNDEFINED\",\"activePower\":\"100.0\",\"reactivePower\":\"50.0\",\"voltageLevelId\":\"idVL1\",\"busId\":\"idBus1\"}"; @@ -1279,32 +1262,32 @@ public void testCreateLoad() throws Exception { // create load on root node (not allowed) mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(createLoadAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); // create load on first modification node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createLoadAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode1Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createLoadAttributes, NETWORK_UUID_STRING, VARIANT_ID); // create load on second modification node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(createLoadAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode2Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createLoadAttributes, NETWORK_UUID_STRING, VARIANT_ID_2); // update load creation @@ -1312,38 +1295,37 @@ public void testCreateLoad() throws Exception { stubPostId = wireMockUtils.stubNetworkModificationPutWithBody(MODIFICATION_UUID, loadAttributesUpdated); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNode1Uuid, MODIFICATION_UUID) .content(loadAttributesUpdated).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkUpdateEquipmentCreationMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPut(stubPostId, MODIFICATION_UUID, loadAttributesUpdated); String createLoadAttributes2 = "{\"type\":\"" + ModificationType.LOAD_CREATION + "\",\"loadId\":\"loadId3\",\"loadName\":\"loadName3\",\"loadType\":\"UNDEFINED\",\"activePower\":\"100.0\",\"reactivePower\":\"50.0\",\"voltageLevelId\":\"idVL1\",\"busId\":\"idBus1\"}"; modificationNode3.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILDING)); - networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode3, userId); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode3, USER_ID); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); // create load on building node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode3Uuid) .content(createLoadAttributes2).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); } @Test public void testModifyLoad() throws Exception { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, - UUID.randomUUID(), VARIANT_ID, "node 1", userId); + UUID.randomUUID(), VARIANT_ID, "node 1", USER_ID); UUID modificationNodeUuid = modificationNode.getId(); NetworkModificationNode modificationNode2 = createNetworkModificationNode(studyNameUserIdUuid, - modificationNodeUuid, UUID.randomUUID(), VARIANT_ID_2, "node 2", userId); + modificationNodeUuid, UUID.randomUUID(), VARIANT_ID_2, "node 2", USER_ID); UUID modificationNodeUuid2 = modificationNode2.getId(); String loadModificationAttributes = "{\"type\":\"" + ModificationType.LOAD_MODIFICATION + "\",\"equipmentId\":\"loadId1\",\"loadName\":\"loadName1\",\"loadType\":\"AUXILIARY\",\"activePower\":\"100.0\"}"; @@ -1351,32 +1333,32 @@ public void testModifyLoad() throws Exception { // modify load on root node (not allowed) mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(loadModificationAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); // modify load on first modification node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(loadModificationAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, loadModificationAttributes, NETWORK_UUID_STRING, VARIANT_ID); // modify load on second modification node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid2) .content(loadModificationAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid2); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNodeUuid2)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid2); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid2); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, loadModificationAttributes, NETWORK_UUID_STRING, VARIANT_ID_2); // update load modification @@ -1384,56 +1366,55 @@ public void testModifyLoad() throws Exception { String loadAttributesUpdated = "{\"type\":\"" + ModificationType.LOAD_MODIFICATION + "\",\"loadId\":\"loadId1\",\"loadType\":\"FICTITIOUS\",\"activePower\":\"70.0\"}"; mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNodeUuid, MODIFICATION_UUID) .content(loadAttributesUpdated).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkUpdateEquipmentModificationMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPut(stubPutId, MODIFICATION_UUID, loadAttributesUpdated); } @Test public void testModifyEquipment() throws Exception { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); - NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", userId); + NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", USER_ID); UUID modificationNodeUuid = modificationNode.getId(); - NetworkModificationNode modificationNode2 = createNetworkModificationNode(studyNameUserIdUuid, modificationNodeUuid, UUID.randomUUID(), VARIANT_ID_2, "node 2", userId); + NetworkModificationNode modificationNode2 = createNetworkModificationNode(studyNameUserIdUuid, modificationNodeUuid, UUID.randomUUID(), VARIANT_ID_2, "node 2", USER_ID); UUID modificationNodeUuid2 = modificationNode2.getId(); // modify generator on root node (not allowed) String equipmentModificationAttribute = "{\"type\":\"" + ModificationType.GENERATOR_MODIFICATION + "\",\"equipmentId\":\"equipmentId\"}"; mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(equipmentModificationAttribute).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); // modify generator on first modification node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(equipmentModificationAttribute).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, equipmentModificationAttribute, NETWORK_UUID_STRING, VARIANT_ID); // modify generator on second modification node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid2) .content(equipmentModificationAttribute).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid2); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNodeUuid2)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid2); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid2); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, equipmentModificationAttribute, NETWORK_UUID_STRING, VARIANT_ID_2); // update generator modification @@ -1441,26 +1422,25 @@ public void testModifyEquipment() throws Exception { UUID stubPutId = wireMockUtils.stubNetworkModificationPutWithBody(MODIFICATION_UUID, generatorAttributesUpdated); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNodeUuid, MODIFICATION_UUID) .content(generatorAttributesUpdated).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkUpdateEquipmentModificationMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPut(stubPutId, MODIFICATION_UUID, generatorAttributesUpdated); } @Test public void testCreateSubstation() throws Exception { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, - UUID.randomUUID(), VARIANT_ID, "node 1", userId); + UUID.randomUUID(), VARIANT_ID, "node 1", USER_ID); UUID modificationNode1Uuid = modificationNode1.getId(); NetworkModificationNode modificationNode2 = createNetworkModificationNode(studyNameUserIdUuid, - modificationNode1Uuid, UUID.randomUUID(), VARIANT_ID_2, "node 2", userId); + modificationNode1Uuid, UUID.randomUUID(), VARIANT_ID_2, "node 2", USER_ID); UUID modificationNode2Uuid = modificationNode2.getId(); String createSubstationAttributes = "{\"type\":\"" + ModificationType.SUBSTATION_CREATION + "\",\"substationId\":\"substationId1\",\"substationName\":\"substationName1\",\"country\":\"AD\"}"; @@ -1468,32 +1448,32 @@ public void testCreateSubstation() throws Exception { // create substation on root node (not allowed) mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(createSubstationAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); // create substation on first modification node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createSubstationAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode1Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createSubstationAttributes, NETWORK_UUID_STRING, VARIANT_ID); // create substation on second modification node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(createSubstationAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode2Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createSubstationAttributes, NETWORK_UUID_STRING, VARIANT_ID_2); // update substation creation @@ -1501,36 +1481,35 @@ public void testCreateSubstation() throws Exception { String substationAttributesUpdated = "{\"type\":\"" + ModificationType.SUBSTATION_CREATION + "\",\"substationId\":\"substationId2\",\"substationName\":\"substationName2\",\"country\":\"FR\"}"; mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNode1Uuid, MODIFICATION_UUID) .content(substationAttributesUpdated).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkUpdateEquipmentCreationMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPut(stubPutId, MODIFICATION_UUID, substationAttributesUpdated); String createSubstationAttributes2 = "{\"type\":\"" + ModificationType.SUBSTATION_CREATION + "\",\"substationId\":\"substationId2\",\"substationName\":\"substationName2\",\"country\":\"AD\"}"; modificationNode1.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILDING)); - networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, userId); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, USER_ID); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); // create substation on building node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createSubstationAttributes2).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); } @Test public void testCreateVoltageLevel() throws Exception { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); - NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node 1", userId); + NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node 1", USER_ID); UUID modificationNode1Uuid = modificationNode1.getId(); NetworkModificationNode modificationNode2 = createNetworkModificationNode(studyNameUserIdUuid, - modificationNode1Uuid, UUID.randomUUID(), VARIANT_ID_2, "node 2", userId); + modificationNode1Uuid, UUID.randomUUID(), VARIANT_ID_2, "node 2", USER_ID); UUID modificationNode2Uuid = modificationNode2.getId(); String createVoltageLevelAttributes = "{\"type\":\"" + ModificationType.VOLTAGE_LEVEL_CREATION + "\",\"voltageLevelId\":\"voltageLevelId1\",\"voltageLevelName\":\"voltageLevelName1\"" @@ -1539,32 +1518,32 @@ public void testCreateVoltageLevel() throws Exception { // create voltage level on root node (not allowed) mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(createVoltageLevelAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); // create voltage level UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createVoltageLevelAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode1Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createVoltageLevelAttributes, NETWORK_UUID_STRING, VARIANT_ID); // create voltage level on second modification node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(createVoltageLevelAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode2Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createVoltageLevelAttributes, NETWORK_UUID_STRING, VARIANT_ID_2); // update voltage level creation @@ -1573,35 +1552,34 @@ public void testCreateVoltageLevel() throws Exception { + ",\"nominalVoltage\":\"379.1\", \"substationId\":\"s2\"}"; mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNode1Uuid, MODIFICATION_UUID) .content(voltageLevelAttributesUpdated).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkUpdateEquipmentCreationMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPut(stubPutId, MODIFICATION_UUID, voltageLevelAttributesUpdated); String createVoltageLevelAttributes2 = "{\"type\":\"" + ModificationType.VOLTAGE_LEVEL_CREATION + "\",\"voltageLevelId\":\"voltageLevelId3\",\"voltageLevelName\":\"voltageLevelName3\"" + ",\"nominalVoltage\":\"379.1\", \"substationId\":\"s2\"}"; modificationNode1.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILDING)); - networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, userId); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, USER_ID); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); // create voltage level on building node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createVoltageLevelAttributes2).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); } @SneakyThrows @Test public void testLineSplitWithVoltageLevel() { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); - NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", "userId"); + NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", USER_ID); UUID modificationNodeUuid = modificationNode.getId(); VoltageLevelCreationInfos vl1 = VoltageLevelCreationInfos.builder() @@ -1620,24 +1598,24 @@ public void testLineSplitWithVoltageLevel() { UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(lineSplitWoVLasJSON).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPost(stubPostId, lineSplitWoVLasJSON, NETWORK_UUID_STRING); UUID stubPutId = wireMockUtils.stubNetworkModificationPutWithBody(MODIFICATION_UUID, lineSplitWoVLasJSON); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNodeUuid, MODIFICATION_UUID) .content(lineSplitWoVLasJSON).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkUpdateEquipmentModificationMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPut(stubPutId, MODIFICATION_UUID, lineSplitWoVLasJSON); String badBody = "{\"type\":\"" + ModificationType.LINE_SPLIT_WITH_VOLTAGE_LEVEL + "\",\"bogus\":\"bogus\"}"; @@ -1645,7 +1623,7 @@ public void testLineSplitWithVoltageLevel() { stubPutId = wireMockUtils.stubNetworkModificationPutWithBodyAndError(MODIFICATION_UUID, badBody); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(badBody).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpectAll( status().isBadRequest(), content().string("400 BAD_REQUEST")); @@ -1653,7 +1631,7 @@ public void testLineSplitWithVoltageLevel() { checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNodeUuid, MODIFICATION_UUID) .content(badBody).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpectAll( status().isBadRequest(), content().string("400 BAD_REQUEST")); @@ -1666,11 +1644,10 @@ public void testLineSplitWithVoltageLevel() { @SneakyThrows @Test public void testLineAttachToVoltageLevel() { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); - NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", "userId"); + NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", USER_ID); UUID modificationNodeUuid = modificationNode.getId(); String createVoltageLevelAttributes = "{\"voltageLevelId\":\"vl1\",\"voltageLevelName\":\"voltageLevelName1\"" @@ -1682,59 +1659,58 @@ public void testLineAttachToVoltageLevel() { UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(createLineAttachToVoltageLevelAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPost(stubPostId, createLineAttachToVoltageLevelAttributes, NETWORK_UUID_STRING); UUID stubPutId = wireMockUtils.stubNetworkModificationPutWithBody(MODIFICATION_UUID, createLineAttachToVoltageLevelAttributes); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNodeUuid, MODIFICATION_UUID) .content(createLineAttachToVoltageLevelAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkUpdateEquipmentModificationMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPut(stubPutId, MODIFICATION_UUID, createLineAttachToVoltageLevelAttributes); } @SneakyThrows @Test public void testLinesAttachToSplitLines() { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); - NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", "userId"); + NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", USER_ID); UUID modificationNodeUuid = modificationNode.getId(); String createLinesAttachToSplitLinesAttributes = "{\"type\":\"" + ModificationType.LINES_ATTACH_TO_SPLIT_LINES + "\",\"lineToAttachTo1Id\":\"line1\",\"lineToAttachTo2Id\":\"line2\",\"attachedLineId\":\"line3\",\"voltageLevelId\":\"vl1\",\"bbsBusId\":\"v1bbs\",\"replacingLine1Id\":\"replacingLine1Id\",\"replacingLine1Name\":\"replacingLine1Name\",\"replacingLine2Id\":\"replacingLine2Id\",\"replacingLine2Name\":\"replacingLine2Name\"}"; UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(createLinesAttachToSplitLinesAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPost(stubPostId, createLinesAttachToSplitLinesAttributes, NETWORK_UUID_STRING); UUID stubPutId = wireMockUtils.stubNetworkModificationPutWithBody(MODIFICATION_UUID, createLinesAttachToSplitLinesAttributes); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNodeUuid, MODIFICATION_UUID) .content(createLinesAttachToSplitLinesAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkUpdateEquipmentModificationMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPut(stubPutId, MODIFICATION_UUID, createLinesAttachToSplitLinesAttributes); String badBody = "{\"type\":\"" + ModificationType.LINES_ATTACH_TO_SPLIT_LINES + "\",\"bogus\":\"bogus\"}"; @@ -1742,13 +1718,13 @@ public void testLinesAttachToSplitLines() { stubPutId = wireMockUtils.stubNetworkModificationPutWithBodyAndError(MODIFICATION_UUID, badBody); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(badBody).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isBadRequest()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNodeUuid, MODIFICATION_UUID) .content(badBody).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isBadRequest()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); @@ -1764,44 +1740,43 @@ public void testScaling() { } private void checkScaling(ModificationType scalingType) throws Exception { - String userId = "userId"; ModificationInfos modificationInfos = ModificationInfos.builder().type(scalingType).substationIds(Set.of("s1")).build(); String requestBody = mapper.writeValueAsString(modificationInfos); StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); - NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", "userId"); + NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", USER_ID); UUID modificationNodeUuid = modificationNode.getId(); UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(requestBody).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPost(stubPostId, requestBody, NETWORK_UUID_STRING); UUID stubPutId = wireMockUtils.stubNetworkModificationPutWithBody(MODIFICATION_UUID, requestBody); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNodeUuid, MODIFICATION_UUID) .content(requestBody).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkUpdateEquipmentModificationMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPut(stubPutId, MODIFICATION_UUID, requestBody); // test with errors stubPostId = wireMockUtils.stubNetworkModificationPostWithBodyAndError(requestBody); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(requestBody).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().is4xxClientError()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); @@ -1810,7 +1785,7 @@ private void checkScaling(ModificationType scalingType) throws Exception { stubPutId = wireMockUtils.stubNetworkModificationPutWithBodyAndError(MODIFICATION_UUID, requestBody); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNodeUuid, MODIFICATION_UUID) .content(requestBody).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().is4xxClientError()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); @@ -1820,11 +1795,10 @@ private void checkScaling(ModificationType scalingType) throws Exception { @SneakyThrows @Test public void testDeleteVoltageLevelOnline() { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); - NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", "userId"); + NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", USER_ID); UUID modificationNodeUuid = modificationNode.getId(); String createDeleteVoltageLevelOnlineAttributes = "{\"type\":\"" + ModificationType.DELETE_VOLTAGE_LEVEL_ON_LINE + "\",\"lineToAttachTo1Id\":\"line1\",\"lineToAttachTo2Id\":\"line2\",\"replacingLine1Id\":\"replacingLine1Id\",\"replacingLine1Name\":\"replacingLine1Name\"}"; @@ -1832,7 +1806,7 @@ public void testDeleteVoltageLevelOnline() { UUID stubIdPost = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(createDeleteVoltageLevelOnlineAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); @@ -1843,7 +1817,7 @@ public void testDeleteVoltageLevelOnline() { UUID stubIdPut = wireMockUtils.stubNetworkModificationPutWithBody(MODIFICATION_UUID, createDeleteVoltageLevelOnlineAttributes); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNodeUuid, MODIFICATION_UUID) .content(createDeleteVoltageLevelOnlineAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkUpdateEquipmentModificationMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); @@ -1853,7 +1827,7 @@ public void testDeleteVoltageLevelOnline() { String badBody = "{\"type\":\"" + ModificationType.DELETE_VOLTAGE_LEVEL_ON_LINE + "\",\"bogus\":\"bogus\"}"; UUID stubIdPostErr = wireMockUtils.stubNetworkModificationPostWithBodyAndError(badBody); UUID stubIdPutErr = wireMockUtils.stubNetworkModificationPutWithBodyAndError(MODIFICATION_UUID, badBody); - mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid).header(HEADER_USER_ID, userId) + mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid).header(HEADER_USER_ID, USER_ID) .content(badBody).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isBadRequest()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); @@ -1861,7 +1835,7 @@ public void testDeleteVoltageLevelOnline() { wireMockUtils.verifyNetworkModificationPost(stubIdPostErr, badBody, NETWORK_UUID_STRING); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNodeUuid, MODIFICATION_UUID) - .header(HEADER_USER_ID, userId) + .header(HEADER_USER_ID, USER_ID) .content(badBody).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isBadRequest()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); @@ -1872,18 +1846,17 @@ public void testDeleteVoltageLevelOnline() { @SneakyThrows @Test public void testDeleteAttachingline() { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); - NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", "userId"); + NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, VARIANT_ID, "node", USER_ID); UUID modificationNodeUuid = modificationNode.getId(); String createDeleteAttachingLineAttributes = "{\"type\":\"" + ModificationType.DELETE_ATTACHING_LINE + "\",\"lineToAttachTo1Id\":\"line1\",\"lineToAttachTo2Id\":\"line2\",\"attachedLineId\":\"line3\",\"replacingLine1Id\":\"replacingLine1Id\",\"replacingLine1Name\":\"replacingLine1Name\"}"; UUID stubIdPost = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(createDeleteAttachingLineAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); @@ -1893,7 +1866,7 @@ public void testDeleteAttachingline() { UUID stubIdPut = wireMockUtils.stubNetworkModificationPutWithBody(MODIFICATION_UUID, createDeleteAttachingLineAttributes); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNodeUuid, MODIFICATION_UUID) - .header(HEADER_USER_ID, userId) + .header(HEADER_USER_ID, USER_ID) .content(createDeleteAttachingLineAttributes).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); @@ -1906,7 +1879,7 @@ public void testDeleteAttachingline() { UUID stubIdPutErr = wireMockUtils.stubNetworkModificationPutWithBodyAndError(MODIFICATION_UUID, badBody); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(badBody).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isBadRequest()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); @@ -1914,7 +1887,7 @@ public void testDeleteAttachingline() { mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNodeUuid, MODIFICATION_UUID) .content(badBody).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isBadRequest()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); @@ -1923,12 +1896,11 @@ public void testDeleteAttachingline() { @Test public void testReorderModification() throws Exception { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, - UUID.randomUUID(), VARIANT_ID, "node", userId); + UUID.randomUUID(), VARIANT_ID, "node", USER_ID); UUID modificationNodeUuid = modificationNode.getId(); UUID modification1 = UUID.randomUUID(); @@ -1943,13 +1915,13 @@ public void testReorderModification() throws Exception { // switch the 2 modifications order (modification1 is set at the end, after modification2) mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modification/{modificationID}", - studyNameUserIdUuid, modificationNodeUuid, modification1).header(HEADER_USER_ID, "userId")) + studyNameUserIdUuid, modificationNodeUuid, modification1).header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); List modificationUuidList = Collections.singletonList(modification1); String expectedBody = mapper.writeValueAsString(modificationUuidList); @@ -1966,13 +1938,13 @@ public void testReorderModification() throws Exception { // switch back the 2 modifications order (modification1 is set before modification2) mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modification/{modificationID}?beforeUuid={modificationID2}", - studyNameUserIdUuid, modificationNodeUuid, modification1, modification2).header(HEADER_USER_ID, "userId")) + studyNameUserIdUuid, modificationNodeUuid, modification1, modification2).header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); url = "/v1/groups/" + modificationNode.getModificationGroupUuid(); wireMockUtils.verifyPutRequestWithUrlMatching(groupStubId, url, Map.of( "action", WireMock.equalTo("MOVE"), @@ -1988,12 +1960,11 @@ public void testReorderModification() throws Exception { @Test public void testReorderModificationErrorCase() throws Exception { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, - UUID.randomUUID(), VARIANT_ID, "node", userId); + UUID.randomUUID(), VARIANT_ID, "node", USER_ID); UUID modificationNodeUuid = modificationNode.getId(); UUID modification1 = UUID.randomUUID(); @@ -2002,13 +1973,13 @@ public void testReorderModificationErrorCase() throws Exception { UUID nodeIdUuid1 = UUID.randomUUID(); mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modification/{modificationID}?beforeUuid={modificationID2}", - studyNameUserIdUuid, nodeIdUuid1, modification1, modification2).header(HEADER_USER_ID, "userId")) + studyNameUserIdUuid, nodeIdUuid1, modification1, modification2).header(HEADER_USER_ID, USER_ID)) .andExpect(status().isNotFound()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, nodeIdUuid1); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, nodeIdUuid1); mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modification/{modificationID}?beforeUuid={modificationID2}", - studyNameUserIdUuid1, modificationNodeUuid, modification1, modification2).header(HEADER_USER_ID, "userId")) + studyNameUserIdUuid1, modificationNodeUuid, modification1, modification2).header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid1, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid1, modificationNodeUuid); @@ -2016,12 +1987,11 @@ public void testReorderModificationErrorCase() throws Exception { @Test public void testDuplicateModification() throws Exception { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyUuid).getId(); NetworkModificationNode node1 = createNetworkModificationNode(studyUuid, rootNodeUuid, - UUID.randomUUID(), VARIANT_ID, "New node 1", "userId"); + UUID.randomUUID(), VARIANT_ID, "New node 1", USER_ID); UUID nodeUuid1 = node1.getId(); UUID modification1 = UUID.randomUUID(); UUID modification2 = UUID.randomUUID(); @@ -2038,13 +2008,13 @@ public void testDuplicateModification() throws Exception { studyUuid, nodeUuid1) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyUuid, nodeUuid1); checkNodesBuildStatusUpdatedMessageReceived(studyUuid, List.of(nodeUuid1)); checkUpdateModelsStatusMessagesReceived(studyUuid, nodeUuid1); checkEquipmentUpdatingFinishedMessagesReceived(studyUuid, nodeUuid1); - checkElementUpdatedMessageSent(studyUuid, userId); + checkElementUpdatedMessageSent(studyUuid, USER_ID); List expectedList = List.of(modification1, modification2); String expectedBody = mapper.writeValueAsString(expectedList); @@ -2059,8 +2029,8 @@ public void testDuplicateModification() throws Exception { // now we do the same but on a built node node1.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILT)); // mark node1 as built - networkModificationTreeService.updateNode(studyUuid, node1, userId); - checkElementUpdatedMessageSent(studyUuid, userId); + networkModificationTreeService.updateNode(studyUuid, node1, USER_ID); + checkElementUpdatedMessageSent(studyUuid, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); groupStubId = wireMockServer.stubFor(WireMock.any(WireMock.urlPathMatching("/v1/groups/.*")) @@ -2073,12 +2043,12 @@ public void testDuplicateModification() throws Exception { studyUuid, nodeUuid1) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); NetworkImpactsInfos expectedPayload = NetworkImpactsInfos.builder().build(); checkEquipmentUpdatingMessagesReceived(studyUuid, nodeUuid1); - checkElementUpdatedMessageSent(studyUuid, userId); + checkElementUpdatedMessageSent(studyUuid, USER_ID); checkEquipmentMessagesReceived(studyUuid, List.of(nodeUuid1), expectedPayload); checkNodesBuildStatusUpdatedMessageReceived(studyUuid, List.of(nodeUuid1)); checkUpdateModelsStatusMessagesReceived(studyUuid, nodeUuid1); @@ -2098,12 +2068,11 @@ public void testDuplicateModification() throws Exception { @Test public void testDuplicateModificationErrorCase() throws Exception { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyUuid).getId(); NetworkModificationNode node1 = createNetworkModificationNode(studyUuid, rootNodeUuid, - UUID.randomUUID(), VARIANT_ID, "New node 1", "userId"); + UUID.randomUUID(), VARIANT_ID, "New node 1", USER_ID); UUID nodeUuid1 = node1.getId(); UUID modification1 = UUID.randomUUID(); UUID modification2 = UUID.randomUUID(); @@ -2114,7 +2083,7 @@ public void testDuplicateModificationErrorCase() throws Exception { UUID.randomUUID(), rootNodeUuid) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isNotFound()); // Random/bad nodeId error case @@ -2122,22 +2091,21 @@ public void testDuplicateModificationErrorCase() throws Exception { studyUuid, UUID.randomUUID()) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isNotFound()); } @Test public void testCutAndPasteModification() throws Exception { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyUuid).getId(); NetworkModificationNode node1 = createNetworkModificationNode(studyUuid, rootNodeUuid, - UUID.randomUUID(), VARIANT_ID, "New node 1", userId); + UUID.randomUUID(), VARIANT_ID, "New node 1", USER_ID); UUID nodeUuid1 = node1.getId(); NetworkModificationNode node2 = createNetworkModificationNode(studyUuid, rootNodeUuid, - UUID.randomUUID(), VARIANT_ID, "New node 2", userId); + UUID.randomUUID(), VARIANT_ID, "New node 2", USER_ID); UUID nodeUuid2 = node2.getId(); UUID modification1 = UUID.randomUUID(); UUID modification2 = UUID.randomUUID(); @@ -2154,7 +2122,7 @@ public void testCutAndPasteModification() throws Exception { studyUuid, nodeUuid1, nodeUuid1) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyUuid, nodeUuid1); checkNodesBuildStatusUpdatedMessageReceived(studyUuid, List.of(nodeUuid1)); @@ -2179,7 +2147,7 @@ public void testCutAndPasteModification() throws Exception { studyUuid, nodeUuid2, nodeUuid1) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyUuid, nodeUuid2); checkEquipmentUpdatingMessagesReceived(studyUuid, nodeUuid1); @@ -2189,8 +2157,8 @@ public void testCutAndPasteModification() throws Exception { checkUpdateModelsStatusMessagesReceived(studyUuid, nodeUuid1); checkEquipmentUpdatingFinishedMessagesReceived(studyUuid, nodeUuid2); checkEquipmentUpdatingFinishedMessagesReceived(studyUuid, nodeUuid1); - checkElementUpdatedMessageSent(studyUuid, userId); - checkElementUpdatedMessageSent(studyUuid, userId); + checkElementUpdatedMessageSent(studyUuid, USER_ID); + checkElementUpdatedMessageSent(studyUuid, USER_ID); expectedList = List.of(modification1, modification2); expectedBody = mapper.writeValueAsString(expectedList); @@ -2210,21 +2178,20 @@ public void testCutAndPasteModification() throws Exception { studyUuid, nodeUuid1) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isBadRequest()); } @Test public void testCutAndPasteModificationErrorCase() throws Exception { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyUuid).getId(); NetworkModificationNode node1 = createNetworkModificationNode(studyUuid, rootNodeUuid, - UUID.randomUUID(), VARIANT_ID, "New node 1", userId); + UUID.randomUUID(), VARIANT_ID, "New node 1", USER_ID); UUID nodeUuid1 = node1.getId(); NetworkModificationNode node2 = createNetworkModificationNode(studyUuid, rootNodeUuid, - UUID.randomUUID(), VARIANT_ID, "New node 2", userId); + UUID.randomUUID(), VARIANT_ID, "New node 2", USER_ID); UUID nodeUuid2 = node2.getId(); UUID modification1 = UUID.randomUUID(); UUID modification2 = UUID.randomUUID(); @@ -2235,7 +2202,7 @@ public void testCutAndPasteModificationErrorCase() throws Exception { UUID.randomUUID(), rootNodeUuid, UUID.randomUUID()) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isNotFound()); // Random/bad nodeId error case @@ -2243,21 +2210,20 @@ public void testCutAndPasteModificationErrorCase() throws Exception { studyUuid, UUID.randomUUID(), UUID.randomUUID()) .contentType(MediaType.APPLICATION_JSON) .content(modificationUuidListBody) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isNotFound()); } @Test public void testDeleteEquipment() throws Exception { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, - UUID.randomUUID(), VARIANT_ID, "node 1", userId); + UUID.randomUUID(), VARIANT_ID, "node 1", USER_ID); UUID modificationNode1Uuid = modificationNode1.getId(); NetworkModificationNode modificationNode2 = createNetworkModificationNode(studyNameUserIdUuid, - modificationNode1Uuid, UUID.randomUUID(), VARIANT_ID_2, "node 2", userId); + modificationNode1Uuid, UUID.randomUUID(), VARIANT_ID_2, "node 2", USER_ID); UUID modificationNode2Uuid = modificationNode2.getId(); Map body = Map.of( @@ -2270,58 +2236,57 @@ public void testDeleteEquipment() throws Exception { // delete equipment on root node (not allowed) mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, rootNodeUuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); // delete equipment on first modification node UUID stubPostId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode1Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, bodyJson, NETWORK_UUID_STRING, VARIANT_ID); // delete equipment on second modification node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode2Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, bodyJson, NETWORK_UUID_STRING, VARIANT_ID_2); // update equipment deletion UUID stubPutId = wireMockUtils.stubNetworkModificationPut(MODIFICATION_UUID); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNode1Uuid, MODIFICATION_UUID) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkUpdateEquipmentCreationMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPut(stubPutId, MODIFICATION_UUID, bodyJson); } @Test public void testNodesInvalidation() throws Exception { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); - NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", BuildStatus.BUILT, userId); + NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", BuildStatus.BUILT, USER_ID); UUID modificationNode1Uuid = modificationNode1.getId(); - NetworkModificationNode modificationNode2 = createNetworkModificationNode(studyNameUserIdUuid, modificationNode1Uuid, UUID.randomUUID(), VARIANT_ID_2, "node 2", BuildStatus.BUILT, userId); + NetworkModificationNode modificationNode2 = createNetworkModificationNode(studyNameUserIdUuid, modificationNode1Uuid, UUID.randomUUID(), VARIANT_ID_2, "node 2", BuildStatus.BUILT, USER_ID); UUID modificationNode2Uuid = modificationNode2.getId(); - NetworkModificationNode modificationNode3 = createNetworkModificationNode(studyNameUserIdUuid, modificationNode2Uuid, UUID.randomUUID(), VARIANT_ID_3, "node 3", BuildStatus.BUILT, userId); + NetworkModificationNode modificationNode3 = createNetworkModificationNode(studyNameUserIdUuid, modificationNode2Uuid, UUID.randomUUID(), VARIANT_ID_3, "node 3", BuildStatus.BUILT, USER_ID); UUID modificationNode3Uuid = modificationNode3.getId(); modificationNode1.setReportUuid(UUID.randomUUID()); @@ -2334,11 +2299,11 @@ public void testNodesInvalidation() throws Exception { modificationNode2.setReportUuid(UUID.randomUUID()); modificationNode3.setReportUuid(UUID.randomUUID()); - networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, userId); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, USER_ID); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); - networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode3, userId); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode3, USER_ID); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); // Update a network modification on node 1 (already built) -> build invalidation of all nodes @@ -2346,13 +2311,13 @@ public void testNodesInvalidation() throws Exception { UUID stubUuid = wireMockUtils.stubNetworkModificationPutWithBody(MODIFICATION_UUID, generatorAttributesUpdated); mockMvc.perform(put(URI_NETWORK_MODIF_WITH_ID, studyNameUserIdUuid, modificationNode1Uuid, MODIFICATION_UUID) .content(generatorAttributesUpdated).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentUpdatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode1Uuid, modificationNode2Uuid, modificationNode3Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPut(stubUuid, MODIFICATION_UUID, generatorAttributesUpdated); var requests = TestUtils.getRequestsWithBodyDone(15, server); @@ -2366,8 +2331,8 @@ public void testNodesInvalidation() throws Exception { // Mark the node 3 status as built modificationNode3.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILT)); - networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode3, userId); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode3, USER_ID); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); // Create a network modification on node 2 (not built) -> build invalidation of node 3 @@ -2376,13 +2341,13 @@ public void testNodesInvalidation() throws Exception { stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode2Uuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode2Uuid, modificationNode3Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode2Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNode3Uuid).getGlobalBuildStatus()); wireMockUtils.verifyNetworkModificationPost(stubUuid, jsonCreateLoadInfos, NETWORK_UUID_STRING); @@ -2392,11 +2357,10 @@ public void testNodesInvalidation() throws Exception { @Test public void testRemoveLoadFlowComputationReport() throws Exception { - String userId = "userId"; StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); - NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", BuildStatus.BUILT, userId); + NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 1", BuildStatus.BUILT, USER_ID); UUID modificationNode1Uuid = modificationNode1.getId(); // In this node, let's say we have all computations results final UUID reportUuid = UUID.randomUUID(); @@ -2408,8 +2372,8 @@ public void testRemoveLoadFlowComputationReport() throws Exception { modificationNode1.setShortCircuitAnalysisResultUuid(UUID.fromString(SHORTCIRCUIT_ANALYSIS_RESULT_UUID)); modificationNode1.setOneBusShortCircuitAnalysisResultUuid(UUID.fromString(ONE_BUS_SHORTCIRCUIT_ANALYSIS_RESULT_UUID)); modificationNode1.setVoltageInitResultUuid(UUID.fromString(VOLTAGE_INIT_RESULT_UUID)); - networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, userId); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, USER_ID); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); // A modification body @@ -2426,13 +2390,13 @@ public void testRemoveLoadFlowComputationReport() throws Exception { UUID stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJson).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNode1Uuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode1Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubId, bodyJson, NETWORK_UUID_STRING, VARIANT_ID); var requests = TestUtils.getRequestsDone(21, server); // 3 x 7 computations @@ -2453,9 +2417,8 @@ public void testUpdateOfBuildStatus() { StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); - String userId = "userId"; NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, - UUID.randomUUID(), VARIANT_ID, "node 1", userId); + UUID.randomUUID(), VARIANT_ID, "node 1", USER_ID); UUID modificationNodeUuid = modificationNode.getId(); Map createLoadInfos = Map.of("type", ModificationType.LOAD_CREATION, "equipmentId", "loadId"); @@ -2465,21 +2428,21 @@ public void testUpdateOfBuildStatus() { UUID stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); assertEquals(BuildStatus.NOT_BUILT, networkModificationTreeService.getNodeBuildStatus(modificationNodeUuid).getGlobalBuildStatus()); wireMockUtils.verifyNetworkModificationPostWithVariant(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING, VARIANT_ID); // Mark the node status as built modificationNode.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILT)); - networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode, userId); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode, USER_ID); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); // Create network modification on BUILT modification node @@ -2488,11 +2451,11 @@ public void testUpdateOfBuildStatus() { stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); NetworkImpactsInfos expectedPayload = NetworkImpactsInfos.builder().impactedSubstationsIds(ImmutableSet.of("s1")).deletedEquipments(ImmutableSet.of()).build(); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); checkEquipmentMessagesReceived(studyNameUserIdUuid, modificationNodeUuid, expectedPayload); checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); @@ -2505,10 +2468,10 @@ public void testUpdateOfBuildStatus() { stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkEquipmentMessagesReceived(studyNameUserIdUuid, modificationNodeUuid, expectedPayload); checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); @@ -2522,10 +2485,10 @@ public void testUpdateOfBuildStatus() { stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(networkModificationResult)); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkEquipmentMessagesReceived(studyNameUserIdUuid, modificationNodeUuid, expectedPayload); checkNodesBuildStatusUpdatedMessageReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); @@ -2832,9 +2795,8 @@ public void testCreateModificationWithErrors() { StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE"); UUID studyNameUserIdUuid = studyEntity.getId(); UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId(); - String userId = "userId"; NetworkModificationNode modificationNode = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, - UUID.randomUUID(), VARIANT_ID, "node 1", userId); + UUID.randomUUID(), VARIANT_ID, "node 1", USER_ID); UUID modificationNodeUuid = modificationNode.getId(); Map createLoadInfos = Map.of("type", ModificationType.LOAD_CREATION, "equipmentId", "loadId"); @@ -2844,13 +2806,13 @@ public void testCreateModificationWithErrors() { UUID stubId = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkNodesInvalidationMessagesReceived(studyNameUserIdUuid, List.of(modificationNodeUuid)); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubId, jsonCreateLoadInfos, NETWORK_UUID_STRING, VARIANT_ID); // String message error @@ -2858,7 +2820,7 @@ public void testCreateModificationWithErrors() { stubId = wireMockUtils.stubNetworkModificationPostWithError(jsonCreateLoadInfos); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpectAll(status().isBadRequest(), content().string(errorMessage)); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); @@ -2868,7 +2830,7 @@ public void testCreateModificationWithErrors() { stubId = wireMockUtils.stubNetworkModificationPostWithError(jsonCreateLoadInfos, String.format("{\"message\" : \"%s\"}", errorMessage)); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpectAll(status().isBadRequest(), content().string(errorMessage)); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); @@ -2879,7 +2841,7 @@ public void testCreateModificationWithErrors() { stubId = wireMockUtils.stubNetworkModificationPostWithError(jsonCreateLoadInfos, errorMessage); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNodeUuid) .content(jsonCreateLoadInfos).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpectAll(status().isBadRequest(), content().string(errorMessage)); checkEquipmentCreatingMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNodeUuid); diff --git a/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java b/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java index a2251617d..ee2ae09fa 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java @@ -88,9 +88,9 @@ @DisableElasticsearch @ContextConfigurationWithTestChannel public class NetworkModificationTreeTest { - private static final Logger LOGGER = LoggerFactory.getLogger(NetworkModificationTreeTest.class); - public static final String NODE_UPDATED = "nodeUpdated"; + private static final String NODE_UPDATED = "nodeUpdated"; + private static final String USER_ID = "userId"; @Autowired private MockMvc mockMvc; @@ -346,7 +346,7 @@ public void testGetRoot() throws Exception { mockMvc.perform(get("/v1/studies/{studyUuid}/tree", study.getId())) .andExpect(status().isOk()); - mockMvc.perform(delete("/v1/studies/{studyUuid}/tree/nodes/{id}?deleteChildren={delete}", study.getId(), root.getId(), false).header(HEADER_USER_ID, "userId")) + mockMvc.perform(delete("/v1/studies/{studyUuid}/tree/nodes/{id}?deleteChildren={delete}", study.getId(), root.getId(), false).header(HEADER_USER_ID, USER_ID)) .andExpect(status().is4xxClientError()); } @@ -371,11 +371,10 @@ private RootNode getRootNode(UUID study) throws Exception { @Test public void testNodeCreation() throws Exception { - String userId = "userId"; RootNode root = createRoot(); // Check build status initialized to NOT_BUILT if null final NetworkModificationNode node1 = buildNetworkModificationNode("not_built", "not built node", MODIFICATION_GROUP_UUID_2, VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); - createNode(root.getStudyId(), root, node1, userId); + createNode(root.getStudyId(), root, node1, USER_ID); root = getRootNode(root.getStudyId()); List children = root.getChildren(); assertEquals(1, children.size()); @@ -383,10 +382,10 @@ public void testNodeCreation() throws Exception { assertEquals(false, networkModificationNode.getNodeBuildStatus().isBuilt()); assertEquals("not_built", networkModificationNode.getName()); assertEquals("not built node", networkModificationNode.getDescription()); - deleteNode(root.getStudyId(), children, false, Set.of(children.get(0)), true, userId); + deleteNode(root.getStudyId(), children, false, Set.of(children.get(0)), true, USER_ID); // Check built status correctly initialized final NetworkModificationNode node2 = buildNetworkModificationNode("built", "built node", MODIFICATION_GROUP_UUID, VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.BUILT); - createNode(root.getStudyId(), root, node2, userId); + createNode(root.getStudyId(), root, node2, USER_ID); root = getRootNode(root.getStudyId()); children = root.getChildren(); assertEquals(1, children.size()); @@ -394,18 +393,17 @@ public void testNodeCreation() throws Exception { assertEquals(true, networkModificationNode.getNodeBuildStatus().isBuilt()); assertEquals("built", networkModificationNode.getName()); assertEquals("built node", networkModificationNode.getDescription()); - deleteNode(root.getStudyId(), children, false, Set.of(children.get(0)), userId); + deleteNode(root.getStudyId(), children, false, Set.of(children.get(0)), USER_ID); } @Test public void testNodeStashAndRestore() throws Exception { - String userId = "userId"; RootNode root = createRoot(); UUID studyId = root.getStudyId(); // Check build status initialized to NOT_BUILT if null final NetworkModificationNode node1 = buildNetworkModificationNode("not_built", "not built node", MODIFICATION_GROUP_UUID_2, VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); - createNode(root.getStudyId(), root, node1, userId); + createNode(root.getStudyId(), root, node1, USER_ID); root = getRootNode(root.getStudyId()); List children = root.getChildren(); assertEquals(1, children.size()); @@ -415,7 +413,7 @@ public void testNodeStashAndRestore() throws Exception { assertEquals("not built node", networkModificationNode.getDescription()); //stash 1 node and do the checks - stashNode(root.getStudyId(), children.get(0), false, Set.of(children.get(0)), userId); + stashNode(root.getStudyId(), children.get(0), false, Set.of(children.get(0)), USER_ID); var stashedNode = nodeRepository.findById(children.get(0).getId()).orElseThrow(); assertTrue(stashedNode.isStashed()); assertNull(stashedNode.getParentNode()); @@ -429,18 +427,18 @@ public void testNodeStashAndRestore() throws Exception { // / \ // n2 n3 final NetworkModificationNode n1 = buildNetworkModificationNode("n1", "n1", UUID.randomUUID(), "variant1", UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); - createNode(studyId, root, n1, userId); + createNode(studyId, root, n1, USER_ID); final NetworkModificationNode n2 = buildNetworkModificationNode("n2", "n2", UUID.randomUUID(), "variant2", UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); - createNode(studyId, n1, n2, userId); + createNode(studyId, n1, n2, USER_ID); final NetworkModificationNode n3 = buildNetworkModificationNode("n3", "n3", UUID.randomUUID(), "variant3", UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); - createNode(studyId, n1, n3, userId); + createNode(studyId, n1, n3, USER_ID); final NetworkModificationNode n4 = buildNetworkModificationNode("n4", "n4", UUID.randomUUID(), "variant4", UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); - createNode(studyId, root, n4, userId); + createNode(studyId, root, n4, USER_ID); //Try to stash the node n1 so it should stash n1 and its subtree (n2 and n3) - stashNode(root.getStudyId(), n1, true, Set.of(n1, n2, n3), userId); - stashNode(root.getStudyId(), n4, true, Set.of(n4), userId); + stashNode(root.getStudyId(), n1, true, Set.of(n1, n2, n3), USER_ID); + stashNode(root.getStudyId(), n4, true, Set.of(n4), USER_ID); var stashedNode1 = nodeRepository.findById(n1.getId()).orElseThrow(); assertTrue(stashedNode1.isStashed()); @@ -464,7 +462,7 @@ public void testNodeStashAndRestore() throws Exception { assertNotNull(stashedNode4.getStashDate()); var result = mockMvc.perform(get("/v1/studies/{studyUuid}/tree/nodes/stash", root.getStudyId()) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()) .andReturn(); @@ -475,7 +473,7 @@ public void testNodeStashAndRestore() throws Exception { assertTrue(result.getResponse().getContentAsString().contains(n4.getId().toString())); //And now we restore the tree we just stashed - restoreNode(studyId, List.of(stashedNode1.getIdNode(), stashedNode4.getIdNode()), root.getId(), Set.of(n1.getId(), n2.getId(), n3.getId(), n4.getId()), userId); + restoreNode(studyId, List.of(stashedNode1.getIdNode(), stashedNode4.getIdNode()), root.getId(), Set.of(n1.getId(), n2.getId(), n3.getId(), n4.getId()), USER_ID); var restoredNode1 = nodeRepository.findById(n1.getId()).orElseThrow(); assertFalse(restoredNode1.isStashed()); @@ -498,7 +496,7 @@ public void testNodeStashAndRestore() throws Exception { assertNull(restoredNode4.getStashDate()); result = mockMvc.perform(get("/v1/studies/{studyUuid}/tree/nodes/stash", root.getStudyId()) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()) .andReturn(); //Only the first level nodes should appear @@ -516,13 +514,12 @@ private UUID createNodeTree() throws Exception { / \ n3 n4 */ - String userId = "userId"; RootNode root = createRoot(); UUID rootId = root.getId(); final NetworkModificationNode node1 = buildNetworkModificationNode("n1", "zzz", MODIFICATION_GROUP_UUID, VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); final NetworkModificationNode node2 = buildNetworkModificationNode("n2", "", MODIFICATION_GROUP_UUID_2, VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); - createNode(root.getStudyId(), root, node1, userId); - createNode(root.getStudyId(), root, node2, userId); + createNode(root.getStudyId(), root, node1, USER_ID); + createNode(root.getStudyId(), root, node2, USER_ID); // need to re-access to see the whole tree root = getRootNode(root.getStudyId()); List children = root.getChildren(); @@ -532,8 +529,8 @@ private UUID createNodeTree() throws Exception { // add 2 children to n2 node2.setName("n3"); node1.setName("n4"); - createNode(root.getStudyId(), children.get(1), node2, userId); - createNode(root.getStudyId(), children.get(1), node1, userId); + createNode(root.getStudyId(), children.get(1), node2, USER_ID); + createNode(root.getStudyId(), children.get(1), node1, USER_ID); // need to re-access to see the whole tree root = getRootNode(root.getStudyId()); children = root.getChildren(); @@ -599,13 +596,12 @@ public void testNodeAncestor() throws Exception { @Test public void testNodeManipulation() throws Exception { - String userId = "userId"; RootNode root = createRoot(); final NetworkModificationNode node1 = buildNetworkModificationNode("hypo 1", "potamus", MODIFICATION_GROUP_UUID, VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); final NetworkModificationNode node2 = buildNetworkModificationNode("loadflow", "dance", MODIFICATION_GROUP_UUID_2, VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); final NetworkModificationNode node4 = buildNetworkModificationNode("hypo 2", "potamus", MODIFICATION_GROUP_UUID_3, VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); - createNode(root.getStudyId(), root, node1, userId); - createNode(root.getStudyId(), root, node2, userId); + createNode(root.getStudyId(), root, node1, USER_ID); + createNode(root.getStudyId(), root, node2, USER_ID); root = getRootNode(root.getStudyId()); List children = root.getChildren(); @@ -619,8 +615,8 @@ public void testNodeManipulation() throws Exception { node2.setName("niark"); node1.setName("condriak"); node1.setModificationGroupUuid(UUID.randomUUID()); - createNode(root.getStudyId(), children.get(1), node2, userId); - createNode(root.getStudyId(), children.get(1), node1, userId); + createNode(root.getStudyId(), children.get(1), node2, USER_ID); + createNode(root.getStudyId(), children.get(1), node1, USER_ID); /* expected root @@ -640,7 +636,7 @@ public void testNodeManipulation() throws Exception { children = child.getChildren(); assertChildrenEquals(Set.of(node1, node2), children); - deleteNode(root.getStudyId(), List.of(child), false, Set.of(child), true, userId); + deleteNode(root.getStudyId(), List.of(child), false, Set.of(child), true, USER_ID); /* expected root @@ -651,9 +647,9 @@ public void testNodeManipulation() throws Exception { root = getRootNode(root.getStudyId()); assertEquals(3, root.getChildren().size()); child = root.getChildren().get(0); - createNode(root.getStudyId(), child, node4, userId); + createNode(root.getStudyId(), child, node4, USER_ID); - deleteNode(root.getStudyId(), List.of(child), true, Set.of(child, node4), userId); + deleteNode(root.getStudyId(), List.of(child), true, Set.of(child, node4), USER_ID); /* expected root @@ -665,7 +661,7 @@ public void testNodeManipulation() throws Exception { assertEquals(3, nodeRepository.findAll().size()); NetworkModificationNode node3 = buildNetworkModificationNode("loadflow", "dance", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); - createNode(root.getStudyId(), root, node3, userId); + createNode(root.getStudyId(), root, node3, USER_ID); networkModificationTreeService.doDeleteTree(root.getStudyId()); assertEquals(0, nodeRepository.findAll().size()); @@ -673,7 +669,7 @@ public void testNodeManipulation() throws Exception { mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", root.getStudyId(), UUID.randomUUID()) .contentType(MediaType.APPLICATION_JSON) .content(objectWriter.writeValueAsString(node1)) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isNotFound()); } @@ -689,7 +685,7 @@ private void deleteNode(UUID studyUuid, List child, boolean delete .toList(); String deleteNodeUuid = child.stream().map(AbstractNode::getId).map(UUID::toString).reduce("", (a1, a2) -> a1 + "," + a2).substring(1); - mockMvc.perform(delete("/v1/studies/{studyUuid}/tree/nodes?deleteChildren={delete}", studyUuid, deleteChildren).header(HEADER_USER_ID, "userId") + mockMvc.perform(delete("/v1/studies/{studyUuid}/tree/nodes?deleteChildren={delete}", studyUuid, deleteChildren).header(HEADER_USER_ID, USER_ID) .queryParam("ids", deleteNodeUuid)) .andExpect(status().isOk()); @@ -717,7 +713,7 @@ private void deleteNode(UUID studyUuid, List child, boolean delete } private void stashNode(UUID studyUuid, AbstractNode child, boolean stashChildren, Set expectedStash, String userId) throws Exception { - mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}/stash?stashChildren={stash}", studyUuid, child.getId(), stashChildren).header(HEADER_USER_ID, "userId")) + mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}/stash?stashChildren={stash}", studyUuid, child.getId(), stashChildren).header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkElementUpdatedMessageSent(studyUuid, userId); @@ -737,7 +733,7 @@ private void restoreNode(UUID studyUuid, List nodeId, UUID anchorNodeId, S String param = nodeId.stream().map(UUID::toString).reduce("", (a1, a2) -> a1 + "," + a2).substring(1); - mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/restore?anchorNodeId={anchorNodeId}", studyUuid, anchorNodeId).header(HEADER_USER_ID, "userId") + mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/restore?anchorNodeId={anchorNodeId}", studyUuid, anchorNodeId).header(HEADER_USER_ID, USER_ID) .queryParam("ids", param)) .andExpect(status().isOk()); @@ -759,7 +755,6 @@ private void assertChildrenEquals(Set original, List @Test public void testNodeInsertion() throws Exception { - String userId = "userId"; RootNode root = createRoot(); final NetworkModificationNode networkModification1 = buildNetworkModificationNode("hypo 1", "potamus", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); final NetworkModificationNode networkModification2 = buildNetworkModificationNode("hypo 2", "potamus", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); @@ -769,11 +764,11 @@ public void testNodeInsertion() throws Exception { mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}?mode=BEFORE", root.getStudyId(), root.getId()) .contentType(MediaType.APPLICATION_JSON) .content(objectWriter.writeValueAsString(networkModification1)) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().is4xxClientError()); - createNode(root.getStudyId(), root, networkModification1, userId); - createNode(root.getStudyId(), root, networkModification2, userId); + createNode(root.getStudyId(), root, networkModification1, USER_ID); + createNode(root.getStudyId(), root, networkModification2, USER_ID); root = getRootNode(root.getStudyId()); /* root / \ @@ -781,7 +776,7 @@ public void testNodeInsertion() throws Exception { */ AbstractNode unchangedNode = root.getChildren().get(0); AbstractNode willBeMoved = root.getChildren().get(1); - insertNode(root.getStudyId(), willBeMoved, networkModification3, InsertMode.BEFORE, root, userId); + insertNode(root.getStudyId(), willBeMoved, networkModification3, InsertMode.BEFORE, root, USER_ID); /* root / \ n3 n2 @@ -796,23 +791,22 @@ public void testNodeInsertion() throws Exception { mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", root.getStudyId(), UUID.randomUUID()) .contentType(MediaType.APPLICATION_JSON) .content(objectWriter.writeValueAsString(networkModification1)) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isNotFound()); } @Test public void testInsertAfter() throws Exception { - String userId = "userId"; RootNode root = createRoot(); final NetworkModificationNode node1 = buildNetworkModificationNode("hypo", "potamus", null, VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); final NetworkModificationNode node2 = buildNetworkModificationNode("loadflow 1", "dance", null, VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.BUILT); final NetworkModificationNode node3 = buildNetworkModificationNode("loadflow 2", "dance", null, VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.BUILT); - createNode(root.getStudyId(), root, node2, userId); - createNode(root.getStudyId(), root, node3, userId); + createNode(root.getStudyId(), root, node2, USER_ID); + createNode(root.getStudyId(), root, node3, USER_ID); root = getRootNode(root.getStudyId()); var originalChildren = root.getChildren().stream().map(AbstractNode::getId).collect(Collectors.toSet()); - insertNode(root.getStudyId(), root, node1, InsertMode.AFTER, root, userId); + insertNode(root.getStudyId(), root, node1, InsertMode.AFTER, root, USER_ID); root = getRootNode(root.getStudyId()); assertEquals(1, root.getChildren().size()); var grandChildren = getRootNode(root.getStudyId()).getChildren().get(0).getChildren().stream().map(AbstractNode::getId).collect(Collectors.toSet()); @@ -830,10 +824,9 @@ public void testInsertAfter() throws Exception { @Test public void testNodeUpdate() throws Exception { - String userId = "userId"; RootNode root = createRoot(); final NetworkModificationNode node1 = buildNetworkModificationNode("hypo", "potamus", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); - createNode(root.getStudyId(), root, node1, userId); + createNode(root.getStudyId(), root, node1, USER_ID); node1.setName("grunt"); node1.setModificationGroupUuid(UUID.randomUUID()); root = getRootNode(root.getStudyId()); @@ -841,10 +834,10 @@ public void testNodeUpdate() throws Exception { mockMvc.perform(put("/v1/studies/{studyUuid}/tree/nodes", root.getStudyId()) .contentType(MediaType.APPLICATION_JSON) .content(objectWriter.writeValueAsString(node1)) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); - checkElementUpdatedMessageSent(root.getStudyId(), userId); + checkElementUpdatedMessageSent(root.getStudyId(), USER_ID); root = getRootNode(root.getStudyId()); assertEquals(1, root.getChildren().size()); assertNodeEquals(node1, root.getChildren().get(0)); @@ -865,10 +858,10 @@ public void testNodeUpdate() throws Exception { mockMvc.perform(put("/v1/studies/{studyUuid}/tree/nodes", root.getStudyId()) .contentType(MediaType.APPLICATION_JSON) .content(objectWriter.writeValueAsString(justANameUpdate)) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); assertEquals(NODE_RENAMED, output.receive(TIMEOUT, studyUpdateDestination).getHeaders().get(HEADER_UPDATE_TYPE)); - checkElementUpdatedMessageSent(root.getStudyId(), userId); + checkElementUpdatedMessageSent(root.getStudyId(), USER_ID); var newNode = getNode(root.getStudyId(), node1.getId()); node1.setName(justANameUpdate.getName()); @@ -878,7 +871,7 @@ public void testNodeUpdate() throws Exception { mockMvc.perform(put("/v1/studies/{studyUuid}/tree/nodes", root.getStudyId()) .contentType(MediaType.APPLICATION_JSON) .content(objectWriter.writeValueAsString(node1)) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isNotFound()); } @@ -887,10 +880,9 @@ public void testNodeUpdate() throws Exception { // If it's not the case or if this test causes problems feel free to update it / remove it as needed @Test public void testNodeDescriptionUpdate() throws Exception { - String userId = "userId"; RootNode root = createRoot(); final NetworkModificationNode node1 = buildNetworkModificationNode("hypo", "potamus", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); - createNode(root.getStudyId(), root, node1, userId); + createNode(root.getStudyId(), root, node1, USER_ID); var nodeDescriptionUpdate = NetworkModificationNode.builder() .description("My taylor is rich!").id(node1.getId()).build(); @@ -898,30 +890,28 @@ public void testNodeDescriptionUpdate() throws Exception { mockMvc.perform(put("/v1/studies/{studyUuid}/tree/nodes", root.getStudyId()) .contentType(MediaType.APPLICATION_JSON) .content(objectWriter.writeValueAsString(nodeDescriptionUpdate)) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); assertEquals(NODE_UPDATED, output.receive(TIMEOUT, studyUpdateDestination).getHeaders().get(HEADER_UPDATE_TYPE)); - checkElementUpdatedMessageSent(root.getStudyId(), userId); + checkElementUpdatedMessageSent(root.getStudyId(), USER_ID); } @SneakyThrows @Test public void testLightNode() { - String userId = "userId"; RootNode root = createRoot(); final NetworkModificationNode hypo = buildNetworkModificationNode("hypo", "potamus", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); final NetworkModificationNode hypo2 = buildNetworkModificationNode("hypo 2", "potamus", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); final NetworkModificationNode hypo3 = buildNetworkModificationNode("hypo 3", "potamus", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); - createNode(root.getStudyId(), root, hypo, userId); - createNode(root.getStudyId(), root, hypo2, userId); - createNode(root.getStudyId(), root, hypo3, userId); + createNode(root.getStudyId(), root, hypo, USER_ID); + createNode(root.getStudyId(), root, hypo2, USER_ID); + createNode(root.getStudyId(), root, hypo3, USER_ID); AbstractNode node = getNode(root.getStudyId(), root.getId()); assertEquals(3, node.getChildrenIds().size()); } @Test public void testGetParentNode() throws Exception { - String userId = "userId"; RootNode root = createRoot(); UUID rootId = root.getId(); final NetworkModificationNode node1 = buildNetworkModificationNode("hypo", "potamus", null, VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); @@ -931,12 +921,12 @@ public void testGetParentNode() throws Exception { final NetworkModificationNode node5 = buildNetworkModificationNode("loadflow 2", "dance", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.BUILT); final NetworkModificationNode node6 = buildNetworkModificationNode("loadflow 3", "dance", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.BUILT); - createNode(root.getStudyId(), root, node1, userId); - createNode(root.getStudyId(), node1, node3, userId); - createNode(root.getStudyId(), node3, node2, userId); - createNode(root.getStudyId(), node2, node4, userId); - createNode(root.getStudyId(), node4, node5, userId); - createNode(root.getStudyId(), node5, node6, userId); + createNode(root.getStudyId(), root, node1, USER_ID); + createNode(root.getStudyId(), node1, node3, USER_ID); + createNode(root.getStudyId(), node3, node2, USER_ID); + createNode(root.getStudyId(), node2, node4, USER_ID); + createNode(root.getStudyId(), node4, node5, USER_ID); + createNode(root.getStudyId(), node5, node6, USER_ID); assertEquals(node5.getId(), networkModificationTreeService.getParentNode(node6.getId(), NodeType.NETWORK_MODIFICATION)); assertEquals(node3.getId(), networkModificationTreeService.getParentNode(node2.getId(), NodeType.NETWORK_MODIFICATION)); @@ -950,7 +940,6 @@ public void testGetParentNode() throws Exception { @Test public void testGetLastParentNodeBuilt() throws Exception { - String userId = "userId"; RootNode root = createRoot(); final NetworkModificationNode node1 = buildNetworkModificationNode("hypo 1", "potamus", null, VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); final NetworkModificationNode node2 = buildNetworkModificationNode("hypo 2", "potamus", null, VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); @@ -963,16 +952,16 @@ public void testGetLastParentNodeBuilt() throws Exception { final NetworkModificationNode node9 = buildNetworkModificationNode("loadflow 6", "dance", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); final NetworkModificationNode node10 = buildNetworkModificationNode("loadflow 7", "dance", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); - createNode(root.getStudyId(), root, node1, userId); - createNode(root.getStudyId(), node1, node4, userId); - createNode(root.getStudyId(), node4, node2, userId); - createNode(root.getStudyId(), node2, node5, userId); - createNode(root.getStudyId(), node5, node6, userId); - createNode(root.getStudyId(), node6, node7, userId); - createNode(root.getStudyId(), node7, node8, userId); - createNode(root.getStudyId(), node8, node3, userId); - createNode(root.getStudyId(), node3, node10, userId); - createNode(root.getStudyId(), node10, node9, userId); + createNode(root.getStudyId(), root, node1, USER_ID); + createNode(root.getStudyId(), node1, node4, USER_ID); + createNode(root.getStudyId(), node4, node2, USER_ID); + createNode(root.getStudyId(), node2, node5, USER_ID); + createNode(root.getStudyId(), node5, node6, USER_ID); + createNode(root.getStudyId(), node6, node7, USER_ID); + createNode(root.getStudyId(), node7, node8, USER_ID); + createNode(root.getStudyId(), node8, node3, USER_ID); + createNode(root.getStudyId(), node3, node10, USER_ID); + createNode(root.getStudyId(), node10, node9, USER_ID); assertEquals(node7.getId(), networkModificationTreeService.doGetLastParentNodeBuiltUuid(node7.getId())); assertEquals(node7.getId(), networkModificationTreeService.doGetLastParentNodeBuiltUuid(node9.getId())); @@ -1018,7 +1007,7 @@ private void insertNode(UUID studyUuid, AbstractNode parentNode, NetworkModifica mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}?mode={mode}", studyUuid, parentNode.getId(), mode) .contentType(MediaType.APPLICATION_JSON) .content(newNodeBodyJson) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkElementUpdatedMessageSent(studyUuid, userId); @@ -1089,21 +1078,20 @@ private void assertModificationNodeEquals(AbstractNode expected, AbstractNode cu @Test public void testNodeName() throws Exception { - String userId = "userId"; RootNode root = createRoot(); String nodeName = "node 1"; final NetworkModificationNode node = buildNetworkModificationNode(nodeName, "potamus", null, VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.BUILT); UUID studyUuid = root.getStudyId(); - createNode(studyUuid, root, node, userId); + createNode(studyUuid, root, node, USER_ID); createNodeFail(studyUuid, root, root); createNodeFail(studyUuid, root, node); node.setName("node 2"); - createNode(studyUuid, root, node, userId); + createNode(studyUuid, root, node, USER_ID); String nodeName1 = getNodeName(studyUuid); final NetworkModificationNode node1 = buildNetworkModificationNode(nodeName1, "potamus", null, VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.BUILT); - createNode(studyUuid, root, node1, userId); + createNode(studyUuid, root, node1, USER_ID); String nodeName2 = getNodeName(studyUuid); assertNotEquals(nodeName, nodeName1); @@ -1115,7 +1103,7 @@ private void createNodeFail(UUID studyUuid, AbstractNode parentNode, AbstractNod mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNode.getId()) .contentType(MediaType.APPLICATION_JSON) .content(objectWriter.writeValueAsString(newNode)) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); } @@ -1129,10 +1117,9 @@ private String getNodeName(UUID studyUuid) throws Exception { @Test public void testGetNetworkModificationsNode() throws Exception { - String userId = "userId"; RootNode root = createRoot(); NetworkModificationNode node = buildNetworkModificationNode("modification node 1", "", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.BUILT); - createNode(root.getStudyId(), root, node, userId); + createNode(root.getStudyId(), root, node, USER_ID); String bodyError = mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modifications", root.getStudyId(), node.getId())) .andExpect(status().isInternalServerError()) @@ -1145,7 +1132,7 @@ public void testGetNetworkModificationsNode() throws Exception { .andExpect(status().isNotFound()); node = buildNetworkModificationNode("modification node 2", "", MODIFICATION_GROUP_UUID, VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.BUILT); - createNode(root.getStudyId(), root, node, userId); + createNode(root.getStudyId(), root, node, USER_ID); mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modifications", root.getStudyId(), node.getId())) .andExpect(status().isOk()) .andReturn().getResponse().getContentAsString(); @@ -1153,10 +1140,9 @@ public void testGetNetworkModificationsNode() throws Exception { @Test public void testGetNetworkModificationsToRestoreByNode() throws Exception { - String userId = "userId"; RootNode root = createRoot(); NetworkModificationNode node = buildNetworkModificationNode("modification node 1", "", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.BUILT); - createNode(root.getStudyId(), root, node, userId); + createNode(root.getStudyId(), root, node, USER_ID); String bodyError = mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modifications", root.getStudyId(), node.getId(), true)) .andExpect(status().isInternalServerError()) @@ -1169,9 +1155,9 @@ public void testGetNetworkModificationsToRestoreByNode() throws Exception { .andExpect(status().isNotFound()); node = buildNetworkModificationNode("modification node 3", "", UUID.fromString(MODIFICATION_GROUP_UUID_STRING), VARIANT_ID, null, null, null, null, null, null, BuildStatus.BUILT); - createNode(root.getStudyId(), root, node, userId); + createNode(root.getStudyId(), root, node, USER_ID); mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modifications?uuids={modificationID1}&stashed=false", root.getStudyId(), node.getId(), MODIFICATION1_UUID_STRING) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); @@ -1190,10 +1176,9 @@ public void testGetNetworkModificationsToRestoreByNode() throws Exception { @Test public void testGetNetworkModificationsToStashByNode() throws Exception { - String userId = "userId"; RootNode root = createRoot(); NetworkModificationNode node = buildNetworkModificationNode("modification node 1", "", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.BUILT); - createNode(root.getStudyId(), root, node, userId); + createNode(root.getStudyId(), root, node, USER_ID); String bodyError = mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modifications", root.getStudyId(), node.getId(), false)) .andExpect(status().isInternalServerError()) @@ -1206,9 +1191,9 @@ public void testGetNetworkModificationsToStashByNode() throws Exception { .andExpect(status().isNotFound()); node = buildNetworkModificationNode("modification node 3", "", UUID.fromString(MODIFICATION_GROUP_UUID_STRING), VARIANT_ID, null, null, null, null, null, null, BuildStatus.BUILT); - createNode(root.getStudyId(), root, node, userId); + createNode(root.getStudyId(), root, node, USER_ID); mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modifications?uuids={modificationID1}&stashed=true", root.getStudyId(), node.getId(), MODIFICATION1_UUID_STRING) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); @@ -1296,16 +1281,15 @@ public void testUpdateApplicationStatus() { */ @SneakyThrows private Pair createTreeForBuildStatus() { - String userId = "userId"; RootNode root = createRoot(); final NetworkModificationNode node1 = buildNetworkModificationNode("built_with_error", "not built node", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.BUILT_WITH_ERROR); final NetworkModificationNode node2 = buildNetworkModificationNode("built_with_warning", "not built node", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.BUILT_WITH_WARNING); final NetworkModificationNode node3 = buildNetworkModificationNode("not_built", "not built node", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT); final NetworkModificationNode node4 = buildNetworkModificationNode("building", "not built node", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.BUILDING); - createNode(root.getStudyId(), root, node1, userId); - createNode(root.getStudyId(), node1, node2, userId); - createNode(root.getStudyId(), node2, node3, userId); - createNode(root.getStudyId(), node3, node4, userId); + createNode(root.getStudyId(), root, node1, USER_ID); + createNode(root.getStudyId(), node1, node2, USER_ID); + createNode(root.getStudyId(), node2, node3, USER_ID); + createNode(root.getStudyId(), node3, node4, USER_ID); return Pair.of(root.getStudyId(), node4); } diff --git a/src/test/java/org/gridsuite/study/server/NonEvacuatedEnergyTest.java b/src/test/java/org/gridsuite/study/server/NonEvacuatedEnergyTest.java index edcbd04f0..b22d55cc0 100644 --- a/src/test/java/org/gridsuite/study/server/NonEvacuatedEnergyTest.java +++ b/src/test/java/org/gridsuite/study/server/NonEvacuatedEnergyTest.java @@ -107,6 +107,7 @@ public class NonEvacuatedEnergyTest { private static final String CASE_3_UUID_STRING = "790769f9-bd31-43be-be46-e50296951e32"; private static final UUID CASE_3_UUID = UUID.fromString(CASE_3_UUID_STRING); + private static final String USER_ID = "userId"; private static final String VARIANT_ID = "variant_1"; private static final String VARIANT_ID_2 = "variant_2"; private static final String VARIANT_ID_3 = "variant_3"; @@ -196,14 +197,14 @@ public MockResponse dispatch(RecordedRequest request) { String resultUuid = path.matches(".*variantId=" + VARIANT_ID_3 + ".*") ? NON_EVACUATED_ENERGY_OTHER_NODE_RESULT_UUID : NON_EVACUATED_ENERGY_RESULT_UUID; input.send(MessageBuilder.withPayload("") .setHeader("resultUuid", resultUuid) - .setHeader(HEADER_USER_ID, "userId") + .setHeader(HEADER_USER_ID, USER_ID) .setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D") .build(), nonEvacuatedEnergyResultDestination); return new MockResponse().setResponseCode(200).setBody("\"" + resultUuid + "\"") .addHeader("Content-Type", "application/json; charset=utf-8"); } else if (path.matches("/v1/networks/" + NETWORK_UUID_2_STRING + "/non-evacuated-energy.*")) { input.send(MessageBuilder.withPayload("") - .setHeader(HEADER_USER_ID, "userId") + .setHeader(HEADER_USER_ID, USER_ID) .setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D") .build(), nonEvacuatedEnergyFailedDestination); return new MockResponse().setResponseCode(200).setBody("\"" + NON_EVACUATED_ENERGY_ERROR_NODE_RESULT_UUID + "\"") @@ -269,7 +270,7 @@ private void testNonEvacuatedEnergyWithNodeUuid(UUID studyUuid, UUID nodeUuid, U // run sensitivity analysis non evacuated energy mvcResult = mockMvc.perform(post("/v1/studies/{studyUuid}/nodes/{nodeUuid}/non-evacuated-energy/run", studyUuid, nodeUuid) - .contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, "userId")).andExpect(status().isOk()) + .contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, USER_ID)).andExpect(status().isOk()) .andReturn(); resultAsString = mvcResult.getResponse().getContentAsString(); UUID uuidResponse = mapper.readValue(resultAsString, UUID.class); @@ -331,7 +332,7 @@ public void testNonEvacuatedEnergy() throws Exception { // run sensitivity analysis non evacuated energy on root node (not allowed) mockMvc.perform(post("/v1/studies/{studyUuid}/nodes/{nodeUuid}/non-evacuated-energy/run", studyNameUserIdUuid, rootNodeUuid) - .contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, "userId")) + .contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); testNonEvacuatedEnergyWithNodeUuid(studyNameUserIdUuid, modificationNode1Uuid, UUID.fromString(NON_EVACUATED_ENERGY_RESULT_UUID)); @@ -343,7 +344,7 @@ public void testNonEvacuatedEnergy() throws Exception { // run additional sensitivity analysis non evacuated energy for deletion test mockMvc.perform(post("/v1/studies/{studyUuid}/nodes/{nodeUuid}/non-evacuated-energy/run", studyNameUserIdUuid, modificationNode2Uuid) - .contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, "userId")).andExpect(status().isOk()) + .contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, USER_ID)).andExpect(status().isOk()) .andReturn(); Message sensitivityAnalysisStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); @@ -439,7 +440,7 @@ public void testResetUuidResultWhenNonEvacuatedEnergyFailed() { input.send(MessageBuilder.withPayload("").setHeader(HEADER_RECEIVER, resultUuidJson).build(), nonEvacuatedEnergyFailedDestination); return resultUuid; }).when(studyService).runNonEvacuatedEnergy(any(), any(), any()); - studyService.runNonEvacuatedEnergy(studyEntity.getId(), modificationNode.getId(), "userId"); + studyService.runNonEvacuatedEnergy(studyEntity.getId(), modificationNode.getId(), USER_ID); Message message = output.receive(TIMEOUT, studyUpdateDestination); assertEquals(studyEntity.getId(), message.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); @@ -461,7 +462,7 @@ public void testNonEvacuatedEnergyFailedForNotification() throws Exception { // run failing sensitivity analysis non evacuated energy (because in network 2) mvcResult = mockMvc.perform(post("/v1/studies/{studyUuid}/nodes/{nodeUuid}/non-evacuated-energy/run", studyUuid, modificationNode1Uuid) - .contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, "userId")) + .contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()).andReturn(); resultAsString = mvcResult.getResponse().getContentAsString(); String uuidResponse = mapper.readValue(resultAsString, String.class); @@ -492,7 +493,7 @@ public void testNonEvacuatedEnergyFailedForNotification() throws Exception { UUID modificationNode1Uuid2 = modificationNode2.getId(); mockMvc.perform(post("/v1/studies/{studyUuid}/nodes/{nodeUuid}/non-evacuated-energy/run", studyUuid2, modificationNode1Uuid2) - .contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, "userId")) + .contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); // failed sensitivity analysis non evacuated energy without receiver -> no failure message sent to frontend @@ -546,7 +547,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU jsonObject.put("modificationGroupUuid", modificationGroupUuid); mnBodyJson = jsonObject.toString(); - mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, "userId")) + mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); var mess = output.receive(TIMEOUT, studyUpdateDestination); assertNotNull(mess); @@ -655,7 +656,7 @@ public void testNonEvacuatedEnergyParameters() throws Exception { mockMvc.perform( post("/v1/studies/{studyUuid}/non-evacuated-energy/parameters", studyNameUserIdUuid) - .header(HEADER_USER_ID, "userId") + .header(HEADER_USER_ID, USER_ID) .contentType(MediaType.APPLICATION_JSON) .content(myBodyJson)).andExpect( status().isOk()); diff --git a/src/test/java/org/gridsuite/study/server/SecurityAnalysisTest.java b/src/test/java/org/gridsuite/study/server/SecurityAnalysisTest.java index 63124f79f..5f906329b 100644 --- a/src/test/java/org/gridsuite/study/server/SecurityAnalysisTest.java +++ b/src/test/java/org/gridsuite/study/server/SecurityAnalysisTest.java @@ -115,6 +115,7 @@ public class SecurityAnalysisTest { private static final String CASE_3_UUID_STRING = "790769f9-bd31-43be-be46-e50296951e32"; private static final UUID CASE_3_UUID = UUID.fromString(CASE_3_UUID_STRING); + private static final String USER_ID = "userId"; private static final String VARIANT_ID = "variant_1"; private static final String VARIANT_ID_2 = "variant_2"; private static final String VARIANT_ID_3 = "variant_3"; @@ -551,7 +552,7 @@ private void testSecurityAnalysisWithNodeUuid(UUID studyUuid, UUID nodeUuid, UUI assertTrue(TestUtils.getRequestsDone(1, server).contains(String.format("/v1/results/%s/status", resultUuid))); // stop security analysis - mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/security-analysis/stop", studyUuid, nodeUuid).header(HEADER_USER_ID, "userId")).andExpect(status().isOk()); + mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/security-analysis/stop", studyUuid, nodeUuid).header(HEADER_USER_ID, USER_ID)).andExpect(status().isOk()); securityAnalysisStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); assertEquals(studyUuid, securityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); @@ -620,7 +621,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU jsonObject.put("modificationGroupUuid", modificationGroupUuid); mnBodyJson = jsonObject.toString(); - mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, "userId")) + mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); var mess = output.receive(TIMEOUT, studyUpdateDestination); assertNotNull(mess); @@ -649,7 +650,7 @@ public void testSecurityAnalysisParameters() throws Exception { //update the parameters mockMvc.perform( post("/v1/studies/{studyUuid}/security-analysis/parameters", studyNameUserIdUuid) - .header(HEADER_USER_ID, "userId") + .header(HEADER_USER_ID, USER_ID) .contentType(MediaType.APPLICATION_JSON) .content(mnBodyJson)).andExpect( status().isOk()); @@ -665,7 +666,7 @@ public void testSecurityAnalysisParameters() throws Exception { //same with set parameters mockMvc.perform( post("/v1/studies/{studyUuid}/security-analysis/parameters", studyNameUserIdUuid) - .header(HEADER_USER_ID, "userId") + .header(HEADER_USER_ID, USER_ID) .contentType(MediaType.APPLICATION_JSON) .content(mnBodyJson)).andExpect( status().isOk()); @@ -683,7 +684,7 @@ public void testCreateSecurityAnalysisParameters() throws Exception { //test update parameters without having already created parameters -> should call create instead of update mockMvc.perform(post("/v1/studies/{studyUuid}/security-analysis/parameters", studyUuid) - .header(HEADER_USER_ID, "userId") + .header(HEADER_USER_ID, USER_ID) .contentType(MediaType.APPLICATION_JSON) .content(mnBodyJson)) .andExpect(status().isOk()); diff --git a/src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java b/src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java index ea752302b..67e5a7b6c 100644 --- a/src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java +++ b/src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java @@ -112,6 +112,7 @@ public class SensitivityAnalysisTest { private static final List CONTINGENCIES_FILTERS_UUID = List.of(UUID.randomUUID()); private static final SensitivityFactorsIdsByGroup IDS = SensitivityFactorsIdsByGroup.builder().ids(Map.of("0", MONITORED_BRANCHES_FILTERS_UUID, "1", INJECTIONS_FILTERS_UUID, "2", CONTINGENCIES_FILTERS_UUID)).build(); + private static final String USER_ID = "userId"; private static final String VARIANT_ID = "variant_1"; private static final String VARIANT_ID_2 = "variant_2"; private static final String VARIANT_ID_3 = "variant_3"; @@ -297,7 +298,7 @@ private void testSensitivityAnalysisWithNodeUuid(UUID studyUuid, UUID nodeUuid, // run sensitivity analysis mockMvc.perform(post("/v1/studies/{studyUuid}/nodes/{nodeUuid}/sensitivity-analysis/run", studyUuid, nodeUuid) - .header(HEADER_USER_ID, "userId")).andExpect(status().isOk()); + .header(HEADER_USER_ID, USER_ID)).andExpect(status().isOk()); Message sensitivityAnalysisStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); assertEquals(studyUuid, sensitivityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); @@ -343,13 +344,13 @@ private void testSensitivityAnalysisWithNodeUuid(UUID studyUuid, UUID nodeUuid, mockMvc.perform(post("/v1/studies/{studyUuid}/nodes/{nodeUuid}/sensitivity-analysis/result/csv", studyUuid, UUID.randomUUID()) .contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, "userId") + .header(HEADER_USER_ID, USER_ID) .content(content)) .andExpectAll(status().isNotFound(), content().string("\"SENSITIVITY_ANALYSIS_NOT_FOUND\"")); mockMvc.perform(post("/v1/studies/{studyUuid}/nodes/{nodeUuid}/sensitivity-analysis/result/csv", studyUuid, nodeUuid) .contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, "userId") + .header(HEADER_USER_ID, USER_ID) .content(content)) .andExpectAll(status().isOk(), content().bytes(SENSITIVITY_RESULTS_AS_CSV)); @@ -603,7 +604,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU jsonObject.put("modificationGroupUuid", modificationGroupUuid); mnBodyJson = jsonObject.toString(); - mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, "userId")) + mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); var mess = output.receive(TIMEOUT, studyUpdateDestination); assertNotNull(mess); @@ -701,7 +702,7 @@ public void testGetSensitivityAnalysisFactorsCount() throws Exception { MockHttpServletRequestBuilder requestBuilder = get("/v1/studies/{studyUuid}/sensitivity-analysis/factors-count", studyNameUserIdUuid); IDS.getIds().forEach((key, list) -> requestBuilder.queryParam(String.format("ids[%s]", key), list.stream().map(UUID::toString).toArray(String[]::new))); - String resultAsString = mockMvc.perform(requestBuilder.header(HEADER_USER_ID, "userId")) + String resultAsString = mockMvc.perform(requestBuilder.header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()) .andReturn() .getResponse() @@ -714,7 +715,7 @@ public void testGetSensitivityAnalysisFactorsCount() throws Exception { private void setParametersAndDoChecks(UUID studyNameUserIdUuid, String parameters) throws Exception { mockMvc.perform( post("/v1/studies/{studyUuid}/sensitivity-analysis/parameters", studyNameUserIdUuid) - .header(HEADER_USER_ID, "userId") + .header(HEADER_USER_ID, USER_ID) .contentType(MediaType.APPLICATION_JSON) .content(parameters)).andExpect( status().isOk()); diff --git a/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java b/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java index e7983c730..7d0859d9b 100644 --- a/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java +++ b/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java @@ -83,7 +83,6 @@ @DisableElasticsearch @ContextConfigurationWithTestChannel public class ShortCircuitTest { - private static final Logger LOGGER = LoggerFactory.getLogger(ShortCircuitTest.class); private static final String CASE_SHORT_CIRCUIT_UUID_STRING = "11a91c11-2c2d-83bb-b45f-20b83e4ef00c"; @@ -113,12 +112,11 @@ public class ShortCircuitTest { private static final byte[] SHORT_CIRCUIT_ANALYSIS_CSV_RESULT = {0x00, 0x11}; private static final String SHORT_CIRCUIT_ANALYSIS_STATUS_JSON = "{\"status\":\"COMPLETED\"}"; - private static final String VARIANT_ID = "variant_1"; + private static final String USER_ID = "userId"; + private static final String VARIANT_ID = "variant_1"; private static final String VARIANT_ID_2 = "variant_2"; - private static final String VARIANT_ID_3 = "variant_3"; - private static final String VARIANT_ID_4 = "variant_4"; private static final long TIMEOUT = 1000; @@ -352,12 +350,12 @@ public void testAllBusesShortCircuit() throws Exception { // run a short circuit analysis on root node (not allowed) mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/shortcircuit/run", studyNameUserIdUuid, rootNodeUuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); //run an all-buses short circuit analysis mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/shortcircuit/run", studyNameUserIdUuid, modificationNode3Uuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.UPDATE_TYPE_SHORT_CIRCUIT_STATUS); @@ -455,11 +453,11 @@ public void testGetShortCircuitAnalysisCsvResultNotFound() throws Exception { UUID modificationNode4Uuid = modificationNode4.getId(); mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/shortcircuit/run", studyNameUserIdUuid, rootNodeUuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/shortcircuit/run", studyNameUserIdUuid, modificationNode4Uuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.UPDATE_TYPE_SHORT_CIRCUIT_STATUS); @@ -492,7 +490,7 @@ public void testPagedShortCircuit() throws Exception { //run a short circuit analysis mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/shortcircuit/run", studyNameUserIdUuid, modificationNode1Uuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.UPDATE_TYPE_SHORT_CIRCUIT_STATUS); @@ -562,13 +560,13 @@ public void testOneBusShortCircuit() throws Exception { // run a one bus short circuit analysis on root node (not allowed) mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/shortcircuit/run", studyNameUserIdUuid, rootNodeUuid) .param("busId", "BUS_TEST_ID") - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); //run a one bus short circuit analysis mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/shortcircuit/run", studyNameUserIdUuid, modificationNode3Uuid) .param("busId", "BUS_TEST_ID") - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.UPDATE_TYPE_ONE_BUS_SHORT_CIRCUIT_STATUS); @@ -726,7 +724,7 @@ public void testInvalidateShortCircuitStatus() throws Exception { //run a short circuit analysis mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/shortcircuit/run", studyNameUserIdUuid, modificationNode3Uuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()) .andReturn(); @@ -740,7 +738,7 @@ public void testInvalidateShortCircuitStatus() throws Exception { //run a one bus short circuit analysis mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/shortcircuit/run", studyNameUserIdUuid, modificationNode3Uuid) .param("busId", "BUS_TEST_ID") - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()) .andReturn(); @@ -754,7 +752,7 @@ public void testInvalidateShortCircuitStatus() throws Exception { // invalidate status mockMvc.perform(put("/v1/studies/{studyUuid}/short-circuit/invalidate-status", studyNameUserIdUuid) - .header(HEADER_USER_ID, "userId")).andExpect(status().isOk()); + .header(HEADER_USER_ID, USER_ID)).andExpect(status().isOk()); checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.UPDATE_TYPE_SHORT_CIRCUIT_STATUS); checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.UPDATE_TYPE_ONE_BUS_SHORT_CIRCUIT_STATUS); assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/results/invalidate-status\\?resultUuid=" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID + "&resultUuid=" + SHORT_CIRCUIT_ANALYSIS_RESULT_UUID))); @@ -800,7 +798,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU jsonObject.put("modificationGroupUuid", modificationGroupUuid); mnBodyJson = jsonObject.toString(); - mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, "userId")) + mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); var mess = output.receive(TIMEOUT, studyUpdateDestination); assertNotNull(mess); diff --git a/src/test/java/org/gridsuite/study/server/StudyControllerDynamicSimulationTest.java b/src/test/java/org/gridsuite/study/server/StudyControllerDynamicSimulationTest.java index c47a172b0..908f28e28 100644 --- a/src/test/java/org/gridsuite/study/server/StudyControllerDynamicSimulationTest.java +++ b/src/test/java/org/gridsuite/study/server/StudyControllerDynamicSimulationTest.java @@ -244,7 +244,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU jsonObject.put("modificationGroupUuid", modificationGroupUuid); mnBodyJson = jsonObject.toString(); - studyClient.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, "userId")) + studyClient.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, HEADER_USER_ID_VALUE)) .andExpect(status().isOk()); var mess = output.receive(TIMEOUT, studyUpdateDestination); assertThat(mess).isNotNull(); diff --git a/src/test/java/org/gridsuite/study/server/StudyTest.java b/src/test/java/org/gridsuite/study/server/StudyTest.java index 61d81b922..5c9e9dfe9 100644 --- a/src/test/java/org/gridsuite/study/server/StudyTest.java +++ b/src/test/java/org/gridsuite/study/server/StudyTest.java @@ -116,8 +116,9 @@ @DisableElasticsearch @ContextConfigurationWithTestChannel public class StudyTest { - private static final Logger LOGGER = LoggerFactory.getLogger(StudyTest.class); + private static final String USER_ID = "userId"; + private static final String USER_ID_2 = "userId2"; @Autowired private MockMvc mockMvc; @@ -283,7 +284,7 @@ private void initMockBeans(Network network) { CreatedStudyBasicInfos.builder().id(UUID.fromString("11888888-0000-0000-0000-111111111112")).userId("userId1").caseFormat("UCTE").build() ); - when(studyInfosService.search(String.format("userId:%s", "userId"))) + when(studyInfosService.search(String.format("userId:%s", USER_ID))) .then((Answer>) invocation -> studiesInfos); when(equipmentInfosService.searchEquipments(any(), any(), any(), any(), any())).thenCallRealMethod(); @@ -689,11 +690,11 @@ private UUID getRootNodeUuid(UUID studyUuid) { public void testSearch() throws Exception { MvcResult mvcResult; String resultAsString; - UUID studyUuid = createStudy("userId", CASE_UUID); + UUID studyUuid = createStudy(USER_ID, CASE_UUID); UUID rootNodeId = getRootNodeUuid(studyUuid); mvcResult = mockMvc - .perform(get("/v1/search?q={request}", String.format("userId:%s", "userId")).header(HEADER_USER_ID, "userId")) + .perform(get("/v1/search?q={request}", String.format("userId:%s", USER_ID)).header(HEADER_USER_ID, USER_ID)) .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)).andReturn(); resultAsString = mvcResult.getResponse().getContentAsString(); List createdStudyBasicInfosList = mapper.readValue(resultAsString, @@ -703,7 +704,7 @@ public void testSearch() throws Exception { mvcResult = mockMvc .perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/search?userInput={request}&fieldSelector=NAME", - studyUuid, rootNodeId, "B").header(HEADER_USER_ID, "userId")) + studyUuid, rootNodeId, "B").header(HEADER_USER_ID, USER_ID)) .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)).andReturn(); resultAsString = mvcResult.getResponse().getContentAsString(); List equipmentInfos = mapper.readValue(resultAsString, @@ -713,7 +714,7 @@ public void testSearch() throws Exception { mvcResult = mockMvc .perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/search?userInput={request}&fieldSelector=NAME", - studyUuid, rootNodeId, "B").header(HEADER_USER_ID, "userId")) + studyUuid, rootNodeId, "B").header(HEADER_USER_ID, USER_ID)) .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)).andReturn(); resultAsString = mvcResult.getResponse().getContentAsString(); equipmentInfos = mapper.readValue(resultAsString, new TypeReference>() { @@ -722,7 +723,7 @@ public void testSearch() throws Exception { mvcResult = mockMvc .perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/search?userInput={request}&fieldSelector=ID", - studyUuid, rootNodeId, "B").header(HEADER_USER_ID, "userId")) + studyUuid, rootNodeId, "B").header(HEADER_USER_ID, USER_ID)) .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)).andReturn(); resultAsString = mvcResult.getResponse().getContentAsString(); equipmentInfos = mapper.readValue(resultAsString, new TypeReference>() { @@ -730,7 +731,7 @@ public void testSearch() throws Exception { assertThat(equipmentInfos, new MatcherJson<>(mapper, linesInfos)); mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/search?userInput={request}&fieldSelector=bogus", - studyUuid, rootNodeId, "B").header(HEADER_USER_ID, "userId")) + studyUuid, rootNodeId, "B").header(HEADER_USER_ID, USER_ID)) .andExpectAll(status().isBadRequest(), content().string("Enum unknown entry 'bogus' should be among NAME, ID")) .andReturn(); @@ -738,40 +739,36 @@ public void testSearch() throws Exception { @Test public void test() throws Exception { - MvcResult result; - String resultAsString; - String userId = "userId"; - //empty list - mockMvc.perform(get("/v1/studies").header(HEADER_USER_ID, "userId")).andExpectAll(status().isOk(), + mockMvc.perform(get("/v1/studies").header(HEADER_USER_ID, USER_ID)).andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON), content().string("[]")); //empty list - mockMvc.perform(get("/v1/study_creation_requests").header(HEADER_USER_ID, "userId")).andExpectAll(status().isOk(), + mockMvc.perform(get("/v1/study_creation_requests").header(HEADER_USER_ID, USER_ID)).andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON), content().string("[]")); //insert a study - UUID studyUuid = createStudy("userId", CASE_UUID); + UUID studyUuid = createStudy(USER_ID, CASE_UUID); // check the study - result = mockMvc.perform(get("/v1/studies/{studyUuid}", studyUuid).header(HEADER_USER_ID, "userId")) - .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)).andReturn(); + MvcResult result = mockMvc.perform(get("/v1/studies/{studyUuid}", studyUuid).header(HEADER_USER_ID, USER_ID)) + .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)).andReturn(); - resultAsString = result.getResponse().getContentAsString(); + String resultAsString = result.getResponse().getContentAsString(); StudyInfos infos = mapper.readValue(resultAsString, StudyInfos.class); assertThat(infos, createMatcherStudyInfos(studyUuid, "UCTE")); //insert a study with a non existing case and except exception result = mockMvc.perform(post("/v1/studies/cases/{caseUuid}", - NOT_EXISTING_CASE_UUID, "false").header(HEADER_USER_ID, "userId").param(CASE_FORMAT, "XIIDM")) + NOT_EXISTING_CASE_UUID, "false").header(HEADER_USER_ID, USER_ID).param(CASE_FORMAT, "XIIDM")) .andExpectAll(status().isFailedDependency(), content().contentType(MediaType.valueOf("text/plain;charset=UTF-8"))).andReturn(); assertEquals("The case '" + NOT_EXISTING_CASE_UUID + "' does not exist", result.getResponse().getContentAsString()); assertTrue(TestUtils.getRequestsDone(1, server) .contains(String.format("/v1/cases/%s/exists", NOT_EXISTING_CASE_UUID))); - result = mockMvc.perform(get("/v1/studies").header(HEADER_USER_ID, "userId")) + result = mockMvc.perform(get("/v1/studies").header(HEADER_USER_ID, USER_ID)) .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)).andReturn(); resultAsString = result.getResponse().getContentAsString(); @@ -783,9 +780,9 @@ public void test() throws Exception { //insert the same study but with another user (should work) //even with the same name should work - studyUuid = createStudy("userId2", CASE_UUID); + studyUuid = createStudy(USER_ID_2, CASE_UUID); - resultAsString = mockMvc.perform(get("/v1/studies").header(HEADER_USER_ID, "userId2")) + resultAsString = mockMvc.perform(get("/v1/studies").header(HEADER_USER_ID, USER_ID_2)) .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)).andReturn().getResponse().getContentAsString(); createdStudyBasicInfosList = mapper.readValue(resultAsString, @@ -797,7 +794,7 @@ public void test() throws Exception { UUID randomUuid = UUID.randomUUID(); //get a non existing study -> 404 not found - mockMvc.perform(get("/v1/studies/{studyUuid}", randomUuid).header(HEADER_USER_ID, "userId")) + mockMvc.perform(get("/v1/studies/{studyUuid}", randomUuid).header(HEADER_USER_ID, USER_ID)) .andExpectAll(status().isNotFound(), content().contentType(MediaType.APPLICATION_JSON), jsonPath("$").value(STUDY_NOT_FOUND.name())); @@ -832,16 +829,16 @@ public void test() throws Exception { .andExpect(status().isOk()); TestUtils.getRequestsDone(1, server); // just consume it - NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 3", userId); + NetworkModificationNode modificationNode1 = createNetworkModificationNode(studyNameUserIdUuid, rootNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 3", USER_ID); UUID modificationNode1Uuid = modificationNode1.getId(); mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/export-network/{format}", studyNameUserIdUuid, modificationNode1Uuid, "XIIDM")) .andExpect(status().isInternalServerError()); modificationNode1.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILT)); - networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, userId); + networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); - checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/export-network/{format}", studyNameUserIdUuid, modificationNode1Uuid, "XIIDM")) .andExpect(status().isOk()); @@ -856,7 +853,7 @@ public void testCreateStudyWithImportParameters() throws Exception { randomListParam.add("paramValue1"); randomListParam.add("paramValue2"); importParameters.put("param1", randomListParam); - UUID studyUuid = createStudyWithImportParameters("userId", CASE_UUID, "UCTE", importParameters); + UUID studyUuid = createStudyWithImportParameters(USER_ID, CASE_UUID, "UCTE", importParameters); StudyEntity studyEntity = studyRepository.findById(studyUuid).get(); assertEquals(studyUuid, studyEntity.getId()); @@ -864,18 +861,18 @@ public void testCreateStudyWithImportParameters() throws Exception { @Test public void testCreateStudyWithDuplicateCase() throws Exception { - createStudyWithDuplicateCase("userId", CASE_UUID); + createStudyWithDuplicateCase(USER_ID, CASE_UUID); } @Test public void testDeleteStudy() throws Exception { - UUID studyUuid = createStudy("userId", CASE_UUID); + UUID studyUuid = createStudy(USER_ID, CASE_UUID); StudyEntity studyEntity = studyRepository.findById(studyUuid).orElseThrow(); studyEntity.setVoltageInitParametersUuid(UUID.randomUUID()); // does not have default params studyRepository.save(studyEntity); UUID stubUuid = wireMockUtils.stubNetworkModificationDeleteGroup(); - mockMvc.perform(delete("/v1/studies/{studyUuid}", studyUuid).header(HEADER_USER_ID, "userId")) + mockMvc.perform(delete("/v1/studies/{studyUuid}", studyUuid).header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); assertTrue(studyRepository.findById(studyUuid).isEmpty()); @@ -894,7 +891,7 @@ public void testDeleteStudy() throws Exception { @Test public void testDeleteStudyWithError() throws Exception { - UUID studyUuid = createStudy("userId", CASE_UUID); + UUID studyUuid = createStudy(USER_ID, CASE_UUID); StudyEntity studyEntity = studyRepository.findById(studyUuid).orElseThrow(); studyEntity.setLoadFlowParametersUuid(null); studyEntity.setSecurityAnalysisParametersUuid(null); @@ -907,7 +904,7 @@ public void testDeleteStudyWithError() throws Exception { }).when(caseService).deleteCase(any()); UUID stubUuid = wireMockUtils.stubNetworkModificationDeleteGroup(); - mockMvc.perform(delete("/v1/studies/{studyUuid}", studyUuid).header(HEADER_USER_ID, "userId")) + mockMvc.perform(delete("/v1/studies/{studyUuid}", studyUuid).header(HEADER_USER_ID, USER_ID)) .andExpectAll(status().isInternalServerError(), content().string(InterruptedException.class.getName())); wireMockUtils.verifyNetworkModificationDeleteGroup(stubUuid); @@ -919,7 +916,7 @@ public void testDeleteStudyWithError() throws Exception { @Test public void testDeleteStudyWithNonExistingCase() throws Exception { - UUID studyUuid = createStudy("userId", CASE_UUID); + UUID studyUuid = createStudy(USER_ID, CASE_UUID); UUID stubUuid = wireMockUtils.stubNetworkModificationDeleteGroup(); @@ -930,7 +927,7 @@ public void testDeleteStudyWithNonExistingCase() throws Exception { studyEntity.setCaseUuid(nonExistingCaseUuid); studyRepository.save(studyEntity); - mockMvc.perform(delete("/v1/studies/{studyUuid}", studyUuid).header(HEADER_USER_ID, "userId")) + mockMvc.perform(delete("/v1/studies/{studyUuid}", studyUuid).header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); assertTrue(studyRepository.findById(studyUuid).isEmpty()); @@ -946,15 +943,15 @@ public void testDeleteStudyWithNonExistingCase() throws Exception { @Test public void testMetadata() throws Exception { - UUID studyUuid = createStudy("userId", CASE_UUID); + UUID studyUuid = createStudy(USER_ID, CASE_UUID); UUID oldStudyUuid = studyUuid; - studyUuid = createStudy("userId2", CASE_UUID); + studyUuid = createStudy(USER_ID_2, CASE_UUID); MvcResult mvcResult = mockMvc .perform(get("/v1/studies/metadata?ids=" + Stream.of(oldStudyUuid, studyUuid).map(Object::toString).collect(Collectors.joining(","))) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpectAll(status().isOk(), content().contentType(MediaType.APPLICATION_JSON)).andReturn(); String resultAsString = mvcResult.getResponse().getContentAsString(); List createdStudyBasicInfosList = mapper.readValue(resultAsString, @@ -976,21 +973,21 @@ public void testMetadata() throws Exception { public void testNotifyStudyMetadataUpdated() throws Exception { UUID studyUuid = UUID.randomUUID(); mockMvc.perform(post("/v1/studies/{studyUuid}/notification?type=metadata_updated", studyUuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkStudyMetadataUpdatedMessagesReceived(); mockMvc.perform(post("/v1/studies/{studyUuid}/notification?type=NOT_EXISTING_TYPE", UUID.randomUUID()) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isBadRequest()); } @Test public void testLogsReport() throws Exception { - UUID studyUuid = createStudy("userId", CASE_UUID); + UUID studyUuid = createStudy(USER_ID, CASE_UUID); UUID rootNodeUuid = getRootNodeUuid(studyUuid); - MvcResult mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/parent-nodes-report?reportType=NETWORK_MODIFICATION", studyUuid, rootNodeUuid).header(HEADER_USER_ID, "userId")) + MvcResult mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/parent-nodes-report?reportType=NETWORK_MODIFICATION", studyUuid, rootNodeUuid).header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()).andReturn(); String resultAsString = mvcResult.getResponse().getContentAsString(); List reporterModel = mapper.readValue(resultAsString, new TypeReference>() { }); @@ -1151,9 +1148,8 @@ public void testGetNullNetwork() { @Test public void testCreateStudyWithErrorDuringCaseImport() throws Exception { - String userId = "userId"; mockMvc.perform(post("/v1/studies/cases/{caseUuid}", CASE_UUID_CAUSING_IMPORT_ERROR) - .header(HEADER_USER_ID, userId) + .header(HEADER_USER_ID, USER_ID) .param(CASE_FORMAT, "UCTE")) .andExpect(status().is5xxServerError()); @@ -1161,10 +1157,10 @@ public void testCreateStudyWithErrorDuringCaseImport() throws Exception { Message message = output.receive(TIMEOUT, "study.update"); MessageHeaders headers = message.getHeaders(); - assertEquals(userId, headers.get(HEADER_USER_ID)); + assertEquals(USER_ID, headers.get(HEADER_USER_ID)); assertEquals(NotificationService.UPDATE_TYPE_STUDIES, headers.get(HEADER_UPDATE_TYPE)); - MvcResult mvcResult = mockMvc.perform(get("/v1/study_creation_requests").header(HEADER_USER_ID, "userId")).andExpectAll( + MvcResult mvcResult = mockMvc.perform(get("/v1/study_creation_requests").header(HEADER_USER_ID, USER_ID)).andExpectAll( status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); @@ -1181,22 +1177,21 @@ public void testCreateStudyWithErrorDuringCaseImport() throws Exception { @Test public void testCreateStudyCreationFailedWithoutErrorMessage() throws Exception { - String userId = "userId"; mockMvc.perform(post("/v1/studies/cases/{caseUuid}", CASE_UUID_CAUSING_CONVERSION_ERROR) - .header(HEADER_USER_ID, userId) + .header(HEADER_USER_ID, USER_ID) .param(CASE_FORMAT, "XIIDM")) .andExpect(status().isOk()); // assert that the broker message has been sent a study creation request message Message message = output.receive(TIMEOUT, "study.update"); MessageHeaders headers = message.getHeaders(); - assertEquals(userId, headers.get(HEADER_USER_ID)); + assertEquals(USER_ID, headers.get(HEADER_USER_ID)); assertEquals(NotificationService.UPDATE_TYPE_STUDIES, headers.get(HEADER_UPDATE_TYPE)); // checks that the error message has a default value set message = output.receive(TIMEOUT, "study.update"); headers = message.getHeaders(); - assertEquals(userId, headers.get(HEADER_USER_ID)); + assertEquals(USER_ID, headers.get(HEADER_USER_ID)); assertEquals(NotificationService.UPDATE_TYPE_STUDIES, headers.get(HEADER_UPDATE_TYPE)); assertEquals(DEFAULT_ERROR_MESSAGE, headers.get(NotificationService.HEADER_ERROR)); @@ -1205,22 +1200,21 @@ public void testCreateStudyCreationFailedWithoutErrorMessage() throws Exception @Test public void testCreateStudyWithErrorDuringStudyCreation() throws Exception { - String userId = "userId"; mockMvc.perform(post("/v1/studies/cases/{caseUuid}", CASE_UUID_CAUSING_STUDY_CREATION_ERROR) - .header(HEADER_USER_ID, userId) + .header(HEADER_USER_ID, USER_ID) .param(CASE_FORMAT, "UCTE")) .andExpect(status().isOk()); // assert that the broker message has been sent a study creation request message Message message = output.receive(TIMEOUT, "study.update"); MessageHeaders headers = message.getHeaders(); - assertEquals(userId, headers.get(HEADER_USER_ID)); + assertEquals(USER_ID, headers.get(HEADER_USER_ID)); assertEquals(NotificationService.UPDATE_TYPE_STUDIES, headers.get(HEADER_UPDATE_TYPE)); // study error message message = output.receive(TIMEOUT, "study.update"); headers = message.getHeaders(); - assertEquals(userId, headers.get(HEADER_USER_ID)); + assertEquals(USER_ID, headers.get(HEADER_USER_ID)); assertEquals(NotificationService.UPDATE_TYPE_STUDIES, headers.get(HEADER_UPDATE_TYPE)); assertEquals(STUDY_CREATION_ERROR_MESSAGE, headers.get(NotificationService.HEADER_ERROR)); @@ -1235,7 +1229,7 @@ public void testGetStudyCreationRequests() throws Exception { String resultAsString; countDownLatch = new CountDownLatch(1); - mvcResult = mockMvc.perform(get("/v1/study_creation_requests").header(HEADER_USER_ID, "userId")).andExpectAll( + mvcResult = mockMvc.perform(get("/v1/study_creation_requests").header(HEADER_USER_ID, USER_ID)).andExpectAll( status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); @@ -1254,7 +1248,7 @@ public void testGetStudyCreationRequests() throws Exception { // drop the broker message for study creation request (deletion) output.receive(TIMEOUT, studyUpdateDestination); - mvcResult = mockMvc.perform(get("/v1/study_creation_requests").header(HEADER_USER_ID, "userId")).andExpectAll( + mvcResult = mockMvc.perform(get("/v1/study_creation_requests").header(HEADER_USER_ID, USER_ID)).andExpectAll( status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); @@ -1264,7 +1258,7 @@ public void testGetStudyCreationRequests() throws Exception { assertEquals(List.of(), bsiListResult); - mvcResult = mockMvc.perform(get("/v1/studies").header(HEADER_USER_ID, "userId")).andExpectAll( + mvcResult = mockMvc.perform(get("/v1/studies").header(HEADER_USER_ID, USER_ID)).andExpectAll( status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); @@ -1276,7 +1270,7 @@ public void testGetStudyCreationRequests() throws Exception { //insert a study mvcResult = mockMvc.perform(post("/v1/studies/cases/{caseUuid}", NEW_STUDY_CASE_UUID, "false") - .header(HEADER_USER_ID, "userId") + .header(HEADER_USER_ID, USER_ID) .param(CASE_FORMAT, "XIIDM")) .andExpect(status().isOk()) .andReturn(); @@ -1287,7 +1281,7 @@ public void testGetStudyCreationRequests() throws Exception { assertThat(bsiResult, createMatcherStudyBasicInfos(studyCreationRequestRepository.findAll().get(0).getId())); mvcResult = mockMvc.perform(get("/v1/study_creation_requests", NEW_STUDY_CASE_UUID, "false") - .header(HEADER_USER_ID, "userId")).andExpectAll( + .header(HEADER_USER_ID, USER_ID)).andExpectAll( status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); @@ -1307,7 +1301,7 @@ public void testGetStudyCreationRequests() throws Exception { output.receive(TIMEOUT, studyUpdateDestination); mvcResult = mockMvc.perform(get("/v1/study_creation_requests") - .header(HEADER_USER_ID, "userId")).andExpectAll( + .header(HEADER_USER_ID, USER_ID)).andExpectAll( status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); @@ -1318,7 +1312,7 @@ public void testGetStudyCreationRequests() throws Exception { assertEquals(List.of(), bsiListResult); mvcResult = mockMvc.perform(get("/v1/studies") - .header(HEADER_USER_ID, "userId")).andExpectAll( + .header(HEADER_USER_ID, USER_ID)).andExpectAll( status().isOk(), content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); @@ -1415,7 +1409,7 @@ private void checkEquipmentCreationMessagesReceived(UUID studyNameUserIdUuid, UU @Test public void testCreateStudyWithDefaultLoadflow() throws Exception { - createStudy("userId", CASE_UUID); + createStudy(USER_ID, CASE_UUID); StudyEntity study = studyRepository.findAll().get(0); assertEquals(study.getNonEvacuatedEnergyProvider(), defaultNonEvacuatedEnergyProvider); } @@ -1436,11 +1430,10 @@ public void testCreateStudyWithDefaultLoadflowUserHasValidParamsInProfile() thro } private void testDuplicateStudy(UUID study1Uuid) throws Exception { - String userId = "userId"; RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); - NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", userId); - NetworkModificationNode node2 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID_2, "node2", userId); + NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", USER_ID); + NetworkModificationNode node2 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID_2, "node2", USER_ID); // add modification on node "node1" String createTwoWindingsTransformerAttributes = "{\"type\":\"" + ModificationType.TWO_WINDINGS_TRANSFORMER_CREATION + "\",\"equipmentId\":\"2wtId\",\"equipmentName\":\"2wtName\",\"seriesResistance\":\"10\",\"seriesReactance\":\"10\",\"magnetizingConductance\":\"100\",\"magnetizingSusceptance\":\"100\",\"ratedVoltage1\":\"480\",\"ratedVoltage2\":\"380\",\"voltageLevelId1\":\"CHOO5P6\",\"busOrBusbarSectionId1\":\"CHOO5P6_1\",\"voltageLevelId2\":\"CHOO5P6\",\"busOrBusbarSectionId2\":\"CHOO5P6_1\"}"; @@ -1449,13 +1442,13 @@ private void testDuplicateStudy(UUID study1Uuid) throws Exception { mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node1.getId()) .contentType(MediaType.APPLICATION_JSON) .content(createTwoWindingsTransformerAttributes) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(study1Uuid, node1.getId()); checkNodeBuildStatusUpdatedMessageReceived(study1Uuid, List.of(node1.getId())); checkUpdateModelsStatusMessagesReceived(study1Uuid, node1.getId()); checkEquipmentUpdatingFinishedMessagesReceived(study1Uuid, node1.getId()); - checkElementUpdatedMessageSent(study1Uuid, userId); + checkElementUpdatedMessageSent(study1Uuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createTwoWindingsTransformerAttributes, NETWORK_UUID_STRING, VARIANT_ID); // add modification on node "node2" @@ -1465,13 +1458,13 @@ private void testDuplicateStudy(UUID study1Uuid) throws Exception { mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId()) .contentType(MediaType.APPLICATION_JSON) .content(createLoadAttributes) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(study1Uuid, node2.getId()); checkNodeBuildStatusUpdatedMessageReceived(study1Uuid, List.of(node2.getId())); checkUpdateModelsStatusMessagesReceived(study1Uuid, node2.getId()); checkEquipmentUpdatingFinishedMessagesReceived(study1Uuid, node2.getId()); - checkElementUpdatedMessageSent(study1Uuid, userId); + checkElementUpdatedMessageSent(study1Uuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubPostId, createLoadAttributes, NETWORK_UUID_STRING, VARIANT_ID_2); node2.setSecurityAnalysisResultUuid(UUID.randomUUID()); @@ -1481,23 +1474,23 @@ private void testDuplicateStudy(UUID study1Uuid) throws Exception { node2.setDynamicSimulationResultUuid(UUID.randomUUID()); node2.setVoltageInitResultUuid(UUID.randomUUID()); node2.setSecurityAnalysisResultUuid(UUID.randomUUID()); - networkModificationTreeService.updateNode(study1Uuid, node2, userId); + networkModificationTreeService.updateNode(study1Uuid, node2, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); - checkElementUpdatedMessageSent(study1Uuid, userId); + checkElementUpdatedMessageSent(study1Uuid, USER_ID); // duplicate the study - StudyEntity duplicatedStudy = duplicateStudy(study1Uuid, userId, "UCTE"); + StudyEntity duplicatedStudy = duplicateStudy(study1Uuid, USER_ID, "UCTE"); assertNotEquals(study1Uuid, duplicatedStudy.getId()); //Test duplication from a non existing source study mockMvc.perform(post(STUDIES_URL + "?duplicateFrom={studyUuid}", UUID.randomUUID()) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isNotFound()); } @Test public void testDuplicateStudyWithParametersUuid() throws Exception { - UUID study1Uuid = createStudy("userId", CASE_UUID); + UUID study1Uuid = createStudy(USER_ID, CASE_UUID); StudyEntity studyEntity = studyRepository.findById(study1Uuid).orElseThrow(); studyEntity.setLoadFlowParametersUuid(UUID.randomUUID()); studyEntity.setSecurityAnalysisParametersUuid(UUID.randomUUID()); @@ -1509,7 +1502,7 @@ public void testDuplicateStudyWithParametersUuid() throws Exception { @Test public void testDuplicateStudyWithoutParametersUuid() throws Exception { - UUID study1Uuid = createStudy("userId", CASE_UUID); + UUID study1Uuid = createStudy(USER_ID, CASE_UUID); StudyEntity studyEntity = studyRepository.findById(study1Uuid).orElseThrow(); studyEntity.setLoadFlowParametersUuid(null); studyEntity.setSecurityAnalysisParametersUuid(null); @@ -1520,7 +1513,7 @@ public void testDuplicateStudyWithoutParametersUuid() throws Exception { @Test public void testDuplicateStudyWithErrorDuringCaseDuplication() throws Exception { - UUID studyUuid = createStudy("userId", CASE_UUID); + UUID studyUuid = createStudy(USER_ID, CASE_UUID); StudyEntity studyEntity = studyRepository.findById(studyUuid).orElseThrow(); studyRepository.save(studyEntity); @@ -1530,7 +1523,7 @@ public void testDuplicateStudyWithErrorDuringCaseDuplication() throws Exception String response = mockMvc.perform(post(STUDIES_URL + "?duplicateFrom={studyUuid}", studyUuid) .param(CASE_FORMAT, "XIIDM") - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()).andReturn().getResponse().getContentAsString(); ObjectMapper mapper = new ObjectMapper(); @@ -1543,7 +1536,7 @@ public void testDuplicateStudyWithErrorDuringCaseDuplication() throws Exception private StudyEntity duplicateStudy(UUID studyUuid, String userId, String caseFormat) throws Exception { UUID stubUuid = wireMockUtils.stubDuplicateModificationGroup(); String response = mockMvc.perform(post(STUDIES_URL + "?duplicateFrom={studyUuid}", studyUuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()).andReturn().getResponse().getContentAsString(); ObjectMapper mapper = new ObjectMapper(); String newUuid = mapper.readValue(response, String.class); @@ -1632,13 +1625,12 @@ private StudyEntity duplicateStudy(UUID studyUuid, String userId, String caseFor @Test public void testCutAndPasteNode() throws Exception { - String userId = "userId"; - UUID study1Uuid = createStudy("userId", CASE_UUID); + UUID study1Uuid = createStudy(USER_ID, CASE_UUID); RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); - NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", userId); - NetworkModificationNode node2 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID_2, "node2", userId); - NetworkModificationNode emptyNode = createNetworkModificationNode(study1Uuid, rootNode.getId(), EMPTY_MODIFICATION_GROUP_UUID, VARIANT_ID_2, "emptyNode", userId); + NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", USER_ID); + NetworkModificationNode node2 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID_2, "node2", USER_ID); + NetworkModificationNode emptyNode = createNetworkModificationNode(study1Uuid, rootNode.getId(), EMPTY_MODIFICATION_GROUP_UUID, VARIANT_ID_2, "emptyNode", USER_ID); /* * rootNode @@ -1654,13 +1646,13 @@ public void testCutAndPasteNode() throws Exception { UUID stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node1.getId()) .content(createTwoWindingsTransformerAttributes).contentType(MediaType.APPLICATION_JSON) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(study1Uuid, node1.getId()); checkNodeBuildStatusUpdatedMessageReceived(study1Uuid, List.of(node1.getId())); checkUpdateModelsStatusMessagesReceived(study1Uuid, node1.getId()); checkEquipmentUpdatingFinishedMessagesReceived(study1Uuid, node1.getId()); - checkElementUpdatedMessageSent(study1Uuid, userId); + checkElementUpdatedMessageSent(study1Uuid, USER_ID); wireMockUtils.verifyNetworkModificationPost(stubUuid, createTwoWindingsTransformerAttributes, NETWORK_UUID_STRING); // add modification on node "node2" @@ -1669,27 +1661,27 @@ public void testCutAndPasteNode() throws Exception { mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId()) .contentType(MediaType.APPLICATION_JSON) .content(createLoadAttributes) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(study1Uuid, node2.getId()); checkNodeBuildStatusUpdatedMessageReceived(study1Uuid, List.of(node2.getId())); checkUpdateModelsStatusMessagesReceived(study1Uuid, node2.getId()); checkEquipmentUpdatingFinishedMessagesReceived(study1Uuid, node2.getId()); - checkElementUpdatedMessageSent(study1Uuid, userId); + checkElementUpdatedMessageSent(study1Uuid, USER_ID); wireMockUtils.verifyNetworkModificationPost(stubUuid, createLoadAttributes, NETWORK_UUID_STRING); node2.setLoadFlowResultUuid(UUID.randomUUID()); node2.setSecurityAnalysisResultUuid(UUID.randomUUID()); - networkModificationTreeService.updateNode(study1Uuid, node2, userId); + networkModificationTreeService.updateNode(study1Uuid, node2, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); - checkElementUpdatedMessageSent(study1Uuid, userId); + checkElementUpdatedMessageSent(study1Uuid, USER_ID); // node2 should not have any child List allNodes = networkModificationTreeService.getAllNodes(study1Uuid); assertEquals(0, allNodes.stream().filter(nodeEntity -> nodeEntity.getParentNode() != null && nodeEntity.getParentNode().getIdNode().equals(node2.getId())).count()); // cut the node1 and paste it after node2 - cutAndPasteNode(study1Uuid, node1, node2.getId(), InsertMode.AFTER, 0, userId); + cutAndPasteNode(study1Uuid, node1, node2.getId(), InsertMode.AFTER, 0, USER_ID); /* * rootNode @@ -1719,7 +1711,7 @@ public void testCutAndPasteNode() throws Exception { .collect(Collectors.toList())); // cut and paste the node2 before emptyNode - cutAndPasteNode(study1Uuid, node2, emptyNode.getId(), InsertMode.BEFORE, 1, userId); + cutAndPasteNode(study1Uuid, node2, emptyNode.getId(), InsertMode.BEFORE, 1, USER_ID); allNodes = networkModificationTreeService.getAllNodes(study1Uuid); /* @@ -1755,7 +1747,7 @@ public void testCutAndPasteNode() throws Exception { .collect(Collectors.toList())); //cut and paste node2 in a new branch starting from modificationNode - cutAndPasteNode(study1Uuid, node2, modificationNodeUuid, InsertMode.CHILD, 1, userId); + cutAndPasteNode(study1Uuid, node2, modificationNodeUuid, InsertMode.CHILD, 1, USER_ID); allNodes = networkModificationTreeService.getAllNodes(study1Uuid); /* @@ -1785,11 +1777,10 @@ public void testCutAndPasteNode() throws Exception { @Test public void testCutAndPasteNodeAroundItself() throws Exception { - String userId = "userId"; - UUID study1Uuid = createStudy(userId, CASE_UUID); + UUID study1Uuid = createStudy(USER_ID, CASE_UUID); RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); - NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", userId); + NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", USER_ID); UUID stubGetCountUuid = wireMockUtils.stubNetworkModificationCountGet(node1.getModificationGroupUuid().toString(), 0); @@ -1797,7 +1788,7 @@ public void testCutAndPasteNodeAroundItself() throws Exception { mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/nodes?nodeToCutUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}", study1Uuid, node1.getId(), node1.getId(), InsertMode.BEFORE) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); wireMockUtils.verifyNetworkModificationCountsGet(stubGetCountUuid, node1.getModificationGroupUuid().toString()); @@ -1805,7 +1796,7 @@ public void testCutAndPasteNodeAroundItself() throws Exception { mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/nodes?nodeToCutUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}", study1Uuid, node1.getId(), node1.getId(), InsertMode.AFTER) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); wireMockUtils.verifyNetworkModificationCountsGet(stubGetCountUuid, node1.getModificationGroupUuid().toString()); @@ -1813,23 +1804,22 @@ public void testCutAndPasteNodeAroundItself() throws Exception { mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/nodes?nodeToCutUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}", study1Uuid, node1.getId(), node1.getId(), InsertMode.CHILD) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); wireMockUtils.verifyNetworkModificationCountsGet(stubGetCountUuid, node1.getModificationGroupUuid().toString()); } @Test public void testCutAndPasteNodeWithoutModification() throws Exception { - String userId = "userId"; - UUID study1Uuid = createStudy(userId, CASE_UUID); + UUID study1Uuid = createStudy(USER_ID, CASE_UUID); RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); - NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, UUID.randomUUID(), VARIANT_ID, "node1", BuildStatus.BUILT, userId); + NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, UUID.randomUUID(), VARIANT_ID, "node1", BuildStatus.BUILT, USER_ID); - NetworkModificationNode emptyNode = createNetworkModificationNode(study1Uuid, rootNode.getId(), EMPTY_MODIFICATION_GROUP_UUID, VARIANT_ID_2, "emptyNode", BuildStatus.BUILT, userId); - NetworkModificationNode emptyNodeChild = createNetworkModificationNode(study1Uuid, emptyNode.getId(), UUID.randomUUID(), VARIANT_ID_3, "emptyNodeChild", BuildStatus.BUILT, userId); + NetworkModificationNode emptyNode = createNetworkModificationNode(study1Uuid, rootNode.getId(), EMPTY_MODIFICATION_GROUP_UUID, VARIANT_ID_2, "emptyNode", BuildStatus.BUILT, USER_ID); + NetworkModificationNode emptyNodeChild = createNetworkModificationNode(study1Uuid, emptyNode.getId(), UUID.randomUUID(), VARIANT_ID_3, "emptyNodeChild", BuildStatus.BUILT, USER_ID); - cutAndPasteNode(study1Uuid, emptyNode, node1.getId(), InsertMode.BEFORE, 1, userId); + cutAndPasteNode(study1Uuid, emptyNode, node1.getId(), InsertMode.BEFORE, 1, USER_ID); Set request = TestUtils.getRequestsDone(1, server); assertTrue(request.stream().allMatch(r -> r.matches("/v1/reports/.*"))); @@ -1841,16 +1831,15 @@ public void testCutAndPasteNodeWithoutModification() throws Exception { @Test public void testCutAndPasteNodeWithModification() throws Exception { - String userId = "userId"; - UUID study1Uuid = createStudy(userId, CASE_UUID); + UUID study1Uuid = createStudy(USER_ID, CASE_UUID); RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); - NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, UUID.randomUUID(), VARIANT_ID, "node1", BuildStatus.BUILT, userId); + NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, UUID.randomUUID(), VARIANT_ID, "node1", BuildStatus.BUILT, USER_ID); - NetworkModificationNode notEmptyNode = createNetworkModificationNode(study1Uuid, rootNode.getId(), UUID.randomUUID(), VARIANT_ID_2, "notEmptyNode", BuildStatus.BUILT, userId); - NetworkModificationNode notEmptyNodeChild = createNetworkModificationNode(study1Uuid, notEmptyNode.getId(), UUID.randomUUID(), VARIANT_ID_3, "notEmptyNodeChild", BuildStatus.BUILT, userId); + NetworkModificationNode notEmptyNode = createNetworkModificationNode(study1Uuid, rootNode.getId(), UUID.randomUUID(), VARIANT_ID_2, "notEmptyNode", BuildStatus.BUILT, USER_ID); + NetworkModificationNode notEmptyNodeChild = createNetworkModificationNode(study1Uuid, notEmptyNode.getId(), UUID.randomUUID(), VARIANT_ID_3, "notEmptyNodeChild", BuildStatus.BUILT, USER_ID); - cutAndPasteNode(study1Uuid, notEmptyNode, node1.getId(), InsertMode.BEFORE, 1, userId); + cutAndPasteNode(study1Uuid, notEmptyNode, node1.getId(), InsertMode.BEFORE, 1, USER_ID); Set request = TestUtils.getRequestsDone(3, server); assertTrue(request.stream().allMatch(r -> r.matches("/v1/reports/.*"))); @@ -1862,24 +1851,23 @@ public void testCutAndPasteNodeWithModification() throws Exception { @Test public void testCutAndPastErrors() throws Exception { - String userId = "userId"; - UUID study1Uuid = createStudy("userId", CASE_UUID); + UUID study1Uuid = createStudy(USER_ID, CASE_UUID); RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); - NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", userId); + NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", USER_ID); //try cut non existing node and expect not found mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/nodes?nodeToCutUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}", study1Uuid, UUID.randomUUID(), node1.getId(), InsertMode.AFTER) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isNotFound()); //try to cut to a non existing position and expect not found mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/nodes?nodeToCutUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}", study1Uuid, node1.getId(), UUID.randomUUID(), InsertMode.AFTER) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isNotFound()); //try to cut and paste to before the root node and expect forbidden @@ -1887,7 +1875,7 @@ public void testCutAndPastErrors() throws Exception { mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/nodes?nodeToCutUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}", study1Uuid, node1.getId(), rootNode.getId(), InsertMode.BEFORE) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); wireMockUtils.verifyNetworkModificationCountsGet(stubUuid, node1.getModificationGroupUuid().toString()); @@ -1895,25 +1883,24 @@ public void testCutAndPastErrors() throws Exception { @Test public void testCutAndPasteSubtree() throws Exception { - String userId = "userId"; - UUID study1Uuid = createStudy(userId, CASE_UUID); + UUID study1Uuid = createStudy(USER_ID, CASE_UUID); RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); - NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, UUID.randomUUID(), VARIANT_ID, "node1", BuildStatus.BUILT, userId); + NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, UUID.randomUUID(), VARIANT_ID, "node1", BuildStatus.BUILT, USER_ID); - NetworkModificationNode emptyNode = createNetworkModificationNode(study1Uuid, rootNode.getId(), EMPTY_MODIFICATION_GROUP_UUID, VARIANT_ID_2, "emptyNode", BuildStatus.BUILT, userId); - NetworkModificationNode emptyNodeChild = createNetworkModificationNode(study1Uuid, emptyNode.getId(), UUID.randomUUID(), VARIANT_ID_3, "emptyNodeChild", BuildStatus.BUILT, userId); + NetworkModificationNode emptyNode = createNetworkModificationNode(study1Uuid, rootNode.getId(), EMPTY_MODIFICATION_GROUP_UUID, VARIANT_ID_2, "emptyNode", BuildStatus.BUILT, USER_ID); + NetworkModificationNode emptyNodeChild = createNetworkModificationNode(study1Uuid, emptyNode.getId(), UUID.randomUUID(), VARIANT_ID_3, "emptyNodeChild", BuildStatus.BUILT, USER_ID); mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/subtrees?subtreeToCutParentNodeUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}", study1Uuid, emptyNode.getId(), emptyNodeChild.getId()) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/subtrees?subtreeToCutParentNodeUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}", study1Uuid, emptyNode.getId(), node1.getId()) - .header(HEADER_USER_ID, userId)) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkNodeBuildStatusUpdatedMessageReceived(study1Uuid, List.of(emptyNode.getId(), emptyNodeChild.getId())); @@ -1936,7 +1923,7 @@ public void testCutAndPasteSubtree() throws Exception { assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); checkSubtreeMovedMessageSent(study1Uuid, emptyNode.getId(), node1.getId()); - checkElementUpdatedMessageSent(study1Uuid, userId); + checkElementUpdatedMessageSent(study1Uuid, USER_ID); var request = TestUtils.getRequestsDone(2, server); assertTrue(request.stream().allMatch(r -> r.matches("/v1/reports/.*"))); @@ -1948,24 +1935,23 @@ public void testCutAndPasteSubtree() throws Exception { mockMvc.perform(get(STUDIES_URL + "/{studyUuid}/subtree?parentNodeUuid={parentSubtreeNode}", study1Uuid, emptyNode.getId()) - .header(HEADER_USER_ID, "userId")).andExpect(status().isOk()); + .header(HEADER_USER_ID, USER_ID)).andExpect(status().isOk()); mockMvc.perform(get(STUDIES_URL + "/{studyUuid}/subtree?parentNodeUuid={parentSubtreeNode}", study1Uuid, UUID.randomUUID()) - .header(HEADER_USER_ID, "userId")).andExpect(status().isNotFound()); + .header(HEADER_USER_ID, USER_ID)).andExpect(status().isNotFound()); } @Test public void testDuplicateNode() throws Exception { - String userId = "userId"; - UUID study1Uuid = createStudy(userId, CASE_UUID); + UUID study1Uuid = createStudy(USER_ID, CASE_UUID); RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); - NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", userId); - NetworkModificationNode node2 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID_2, "node2", userId); - NetworkModificationNode node3 = createNetworkModificationNode(study1Uuid, rootNode.getId(), UUID.randomUUID(), VARIANT_ID, "node3", BuildStatus.BUILT, userId); - NetworkModificationNode emptyNode = createNetworkModificationNode(study1Uuid, rootNode.getId(), EMPTY_MODIFICATION_GROUP_UUID, VARIANT_ID_2, "emptyNode", userId); + NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", USER_ID); + NetworkModificationNode node2 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID_2, "node2", USER_ID); + NetworkModificationNode node3 = createNetworkModificationNode(study1Uuid, rootNode.getId(), UUID.randomUUID(), VARIANT_ID, "node3", BuildStatus.BUILT, USER_ID); + NetworkModificationNode emptyNode = createNetworkModificationNode(study1Uuid, rootNode.getId(), EMPTY_MODIFICATION_GROUP_UUID, VARIANT_ID_2, "emptyNode", USER_ID); // add modification on node "node1" String createTwoWindingsTransformerAttributes = "{\"type\":\"" + ModificationType.TWO_WINDINGS_TRANSFORMER_CREATION + "\",\"equipmentId\":\"2wtId\",\"equipmentName\":\"2wtName\",\"seriesResistance\":\"10\",\"seriesReactance\":\"10\",\"magnetizingConductance\":\"100\",\"magnetizingSusceptance\":\"100\",\"ratedVoltage1\":\"480\",\"ratedVoltage2\":\"380\",\"voltageLevelId1\":\"CHOO5P6\",\"busOrBusbarSectionId1\":\"CHOO5P6_1\",\"voltageLevelId2\":\"CHOO5P6\",\"busOrBusbarSectionId2\":\"CHOO5P6_1\"}"; @@ -1973,13 +1959,13 @@ public void testDuplicateNode() throws Exception { mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node1.getId()) .contentType(MediaType.APPLICATION_JSON) .content(createTwoWindingsTransformerAttributes) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(study1Uuid, node1.getId()); checkNodeBuildStatusUpdatedMessageReceived(study1Uuid, List.of(node1.getId())); checkUpdateModelsStatusMessagesReceived(study1Uuid, node1.getId()); checkEquipmentUpdatingFinishedMessagesReceived(study1Uuid, node1.getId()); - checkElementUpdatedMessageSent(study1Uuid, userId); + checkElementUpdatedMessageSent(study1Uuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubUuid, createTwoWindingsTransformerAttributes, NETWORK_UUID_STRING, VARIANT_ID); // add modification on node "node2" @@ -1988,27 +1974,27 @@ public void testDuplicateNode() throws Exception { mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId()) .contentType(MediaType.APPLICATION_JSON) .content(createLoadAttributes) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(study1Uuid, node2.getId()); checkNodeBuildStatusUpdatedMessageReceived(study1Uuid, List.of(node2.getId())); checkUpdateModelsStatusMessagesReceived(study1Uuid, node2.getId()); checkEquipmentUpdatingFinishedMessagesReceived(study1Uuid, node2.getId()); - checkElementUpdatedMessageSent(study1Uuid, userId); + checkElementUpdatedMessageSent(study1Uuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubUuid, createLoadAttributes, NETWORK_UUID_STRING, VARIANT_ID_2); node2.setLoadFlowResultUuid(UUID.randomUUID()); node2.setSecurityAnalysisResultUuid(UUID.randomUUID()); - networkModificationTreeService.updateNode(study1Uuid, node2, userId); + networkModificationTreeService.updateNode(study1Uuid, node2, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); - checkElementUpdatedMessageSent(study1Uuid, userId); + checkElementUpdatedMessageSent(study1Uuid, USER_ID); //node2 should not have any child List allNodes = networkModificationTreeService.getAllNodes(study1Uuid); assertEquals(0, allNodes.stream().filter(nodeEntity -> nodeEntity.getParentNode() != null && nodeEntity.getParentNode().getIdNode().equals(node2.getId())).count()); // duplicate the node1 after node2 - UUID duplicatedNodeUuid = duplicateNode(study1Uuid, study1Uuid, node1, node2.getId(), InsertMode.AFTER, userId); + UUID duplicatedNodeUuid = duplicateNode(study1Uuid, study1Uuid, node1, node2.getId(), InsertMode.AFTER, USER_ID); //node2 should now have 1 child allNodes = networkModificationTreeService.getAllNodes(study1Uuid); @@ -2019,7 +2005,7 @@ public void testDuplicateNode() throws Exception { .count()); // duplicate the node2 before node1 - UUID duplicatedNodeUuid2 = duplicateNode(study1Uuid, study1Uuid, node2, node1.getId(), InsertMode.BEFORE, userId); + UUID duplicatedNodeUuid2 = duplicateNode(study1Uuid, study1Uuid, node2, node1.getId(), InsertMode.BEFORE, USER_ID); allNodes = networkModificationTreeService.getAllNodes(study1Uuid); assertEquals(1, allNodes.stream() .filter(nodeEntity -> nodeEntity.getParentNode() != null @@ -2029,7 +2015,7 @@ public void testDuplicateNode() throws Exception { //now the tree looks like root -> modificationNode -> duplicatedNode2 -> node1 -> node2 -> duplicatedNode1 //duplicate node1 in a new branch starting from duplicatedNode2 - UUID duplicatedNodeUuid3 = duplicateNode(study1Uuid, study1Uuid, node1, duplicatedNodeUuid2, InsertMode.CHILD, userId); + UUID duplicatedNodeUuid3 = duplicateNode(study1Uuid, study1Uuid, node1, duplicatedNodeUuid2, InsertMode.CHILD, USER_ID); allNodes = networkModificationTreeService.getAllNodes(study1Uuid); //expect to have modificationNode as a parent assertEquals(1, allNodes.stream() @@ -2044,39 +2030,38 @@ public void testDuplicateNode() throws Exception { mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/nodes?nodeToCopyUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}&sourceStudyUuid={sourceStudyUuid}", study1Uuid, UUID.randomUUID(), node1.getId(), InsertMode.AFTER, study1Uuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isNotFound()); //try to copy to a non existing position and expect not found mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/nodes?nodeToCopyUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}&sourceStudyUuid={sourceStudyUuid}", study1Uuid, node1.getId(), UUID.randomUUID(), InsertMode.AFTER, study1Uuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isNotFound()); //try to copy to before the root node and expect forbidden mockMvc.perform(post(STUDIES_URL + "/{studyUuid}/tree/nodes?nodeToCopyUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}&sourceStudyUuid={sourceStudyUuid}", study1Uuid, node1.getId(), rootNode.getId(), InsertMode.BEFORE, study1Uuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); // Test Built status when duplicating an empty node assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(node3.getId()).getGlobalBuildStatus()); - duplicateNode(study1Uuid, study1Uuid, emptyNode, node3.getId(), InsertMode.BEFORE, userId); + duplicateNode(study1Uuid, study1Uuid, emptyNode, node3.getId(), InsertMode.BEFORE, USER_ID); assertEquals(BuildStatus.BUILT, networkModificationTreeService.getNodeBuildStatus(node3.getId()).getGlobalBuildStatus()); } @Test public void testDuplicateSubtree() throws Exception { - String userId = "userId"; - UUID study1Uuid = createStudy(userId, CASE_UUID); + UUID study1Uuid = createStudy(USER_ID, CASE_UUID); RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); - NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", userId); - NetworkModificationNode node2 = createNetworkModificationNode(study1Uuid, node1.getId(), VARIANT_ID_2, "node2", userId); - NetworkModificationNode node3 = createNetworkModificationNode(study1Uuid, node2.getId(), UUID.randomUUID(), VARIANT_ID, "node3", BuildStatus.BUILT, userId); - NetworkModificationNode node4 = createNetworkModificationNode(study1Uuid, rootNode.getId(), EMPTY_MODIFICATION_GROUP_UUID, VARIANT_ID_2, "emptyNode", userId); + NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", USER_ID); + NetworkModificationNode node2 = createNetworkModificationNode(study1Uuid, node1.getId(), VARIANT_ID_2, "node2", USER_ID); + NetworkModificationNode node3 = createNetworkModificationNode(study1Uuid, node2.getId(), UUID.randomUUID(), VARIANT_ID, "node3", BuildStatus.BUILT, USER_ID); + NetworkModificationNode node4 = createNetworkModificationNode(study1Uuid, rootNode.getId(), EMPTY_MODIFICATION_GROUP_UUID, VARIANT_ID_2, "emptyNode", USER_ID); /*tree state root @@ -2093,13 +2078,13 @@ public void testDuplicateSubtree() throws Exception { mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node1.getId()) .contentType(MediaType.APPLICATION_JSON) .content(createTwoWindingsTransformerAttributes) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(study1Uuid, node1.getId()); checkNodeBuildStatusUpdatedMessageReceived(study1Uuid, List.of(node1.getId(), node3.getId())); checkUpdateModelsStatusMessagesReceived(study1Uuid, node1.getId()); checkEquipmentUpdatingFinishedMessagesReceived(study1Uuid, node1.getId()); - checkElementUpdatedMessageSent(study1Uuid, userId); + checkElementUpdatedMessageSent(study1Uuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubUuid, createTwoWindingsTransformerAttributes, NETWORK_UUID_STRING, VARIANT_ID); // Invalidation node 3 @@ -2113,21 +2098,21 @@ public void testDuplicateSubtree() throws Exception { mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId()) .contentType(MediaType.APPLICATION_JSON) .content(createLoadAttributes) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(study1Uuid, node2.getId()); checkNodeBuildStatusUpdatedMessageReceived(study1Uuid, List.of(node2.getId())); checkUpdateModelsStatusMessagesReceived(study1Uuid, node2.getId()); checkEquipmentUpdatingFinishedMessagesReceived(study1Uuid, node2.getId()); - checkElementUpdatedMessageSent(study1Uuid, userId); + checkElementUpdatedMessageSent(study1Uuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubUuid, createLoadAttributes, NETWORK_UUID_STRING, VARIANT_ID_2); node2.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILT)); node2.setLoadFlowResultUuid(UUID.randomUUID()); node2.setSecurityAnalysisResultUuid(UUID.randomUUID()); - networkModificationTreeService.updateNode(study1Uuid, node2, userId); + networkModificationTreeService.updateNode(study1Uuid, node2, USER_ID); output.receive(TIMEOUT, studyUpdateDestination); - checkElementUpdatedMessageSent(study1Uuid, userId); + checkElementUpdatedMessageSent(study1Uuid, USER_ID); //node 4 should not have any children List allNodes = networkModificationTreeService.getAllNodes(study1Uuid); @@ -2140,7 +2125,7 @@ public void testDuplicateSubtree() throws Exception { mockMvc.perform(post(STUDIES_URL + "/{study1Uuid}/tree/subtrees?subtreeToCopyParentNodeUuid={parentNodeToCopy}&referenceNodeUuid={referenceNodeUuid}&sourceStudyUuid={sourceStudyUuid}", study1Uuid, node1.getId(), node4.getId(), study1Uuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); List nodesAfterDuplication = networkModificationTreeService.getAllNodes(study1Uuid).stream().map(NodeEntity::getIdNode).collect(Collectors.toList()); @@ -2148,7 +2133,7 @@ public void testDuplicateSubtree() throws Exception { assertEquals(3, nodesAfterDuplication.size()); checkSubtreeCreatedMessageSent(study1Uuid, nodesAfterDuplication.get(0), node4.getId()); - checkElementUpdatedMessageSent(study1Uuid, userId); + checkElementUpdatedMessageSent(study1Uuid, USER_ID); wireMockUtils.verifyDuplicateModificationGroup(stubDuplicateUuid, 3); /*tree state @@ -2166,12 +2151,12 @@ public void testDuplicateSubtree() throws Exception { mockMvc.perform(get(STUDIES_URL + "/{studyUuid}/subtree?parentNodeUuid={parentSubtreeNode}", study1Uuid, nodesAfterDuplication.get(0)) - .header(HEADER_USER_ID, "userId")).andExpect(status().isOk()); + .header(HEADER_USER_ID, USER_ID)).andExpect(status().isOk()); mockMvc.perform(get(STUDIES_URL + "/{studyUuid}/subtree?parentNodeUuid={parentSubtreeNode}", study1Uuid, UUID.randomUUID()) - .header(HEADER_USER_ID, "userId")).andExpect(status().isNotFound()); + .header(HEADER_USER_ID, USER_ID)).andExpect(status().isNotFound()); allNodes = networkModificationTreeService.getAllNodes(study1Uuid); @@ -2198,30 +2183,29 @@ public void testDuplicateSubtree() throws Exception { mockMvc.perform(post(STUDIES_URL + "/{targetStudyUuid}/tree/subtrees?subtreeToCopyParentNodeUuid={parentNodeToCopy}&referenceNodeUuid={referenceNodeUuid}&sourceStudyUuid={sourceStudyUuid}", study1Uuid, UUID.randomUUID(), node1.getId(), study1Uuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isNotFound()); //try to copy to a non existing position and expect not found mockMvc.perform(post(STUDIES_URL + "/{targetStudyUuid}/tree/subtrees?subtreeToCopyParentNodeUuid={parentNodeToCopy}&referenceNodeUuid={referenceNodeUuid}&sourceStudyUuid={sourceStudyUuid}", study1Uuid, node1.getId(), UUID.randomUUID(), study1Uuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isNotFound()); } @Test public void testDuplicateNodeBetweenStudies() throws Exception { - String userId = "userId"; - UUID study1Uuid = createStudy(userId, CASE_UUID); + UUID study1Uuid = createStudy(USER_ID, CASE_UUID); RootNode rootNode = networkModificationTreeService.getStudyTree(study1Uuid); UUID modificationNodeUuid = rootNode.getChildren().get(0).getId(); - NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", userId); - NetworkModificationNode node2 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID_2, "node2", userId); + NetworkModificationNode node1 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID, "node1", USER_ID); + NetworkModificationNode node2 = createNetworkModificationNode(study1Uuid, modificationNodeUuid, VARIANT_ID_2, "node2", USER_ID); - UUID study2Uuid = createStudy(userId, CASE_UUID); + UUID study2Uuid = createStudy(USER_ID, CASE_UUID); RootNode study2RootNode = networkModificationTreeService.getStudyTree(study2Uuid); UUID study2ModificationNodeUuid = study2RootNode.getChildren().get(0).getId(); - NetworkModificationNode study2Node2 = createNetworkModificationNode(study2Uuid, study2ModificationNodeUuid, VARIANT_ID_2, "node2", userId); + NetworkModificationNode study2Node2 = createNetworkModificationNode(study2Uuid, study2ModificationNodeUuid, VARIANT_ID_2, "node2", USER_ID); // add modification on study 1 node "node1" UUID stubUuid = wireMockUtils.stubNetworkModificationPost(mapper.writeValueAsString(Optional.empty())); @@ -2229,13 +2213,13 @@ public void testDuplicateNodeBetweenStudies() throws Exception { mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node1.getId()) .contentType(MediaType.APPLICATION_JSON) .content(createTwoWindingsTransformerAttributes) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(study1Uuid, node1.getId()); checkNodeBuildStatusUpdatedMessageReceived(study1Uuid, List.of(node1.getId())); checkUpdateModelsStatusMessagesReceived(study1Uuid, node1.getId()); checkEquipmentUpdatingFinishedMessagesReceived(study1Uuid, node1.getId()); - checkElementUpdatedMessageSent(study1Uuid, userId); + checkElementUpdatedMessageSent(study1Uuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubUuid, createTwoWindingsTransformerAttributes, NETWORK_UUID_STRING, VARIANT_ID); // add modification on node "node2" @@ -2244,13 +2228,13 @@ public void testDuplicateNodeBetweenStudies() throws Exception { mockMvc.perform(post(URI_NETWORK_MODIF, study1Uuid, node2.getId()) .contentType(MediaType.APPLICATION_JSON) .content(createLoadAttributes) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkEquipmentCreatingMessagesReceived(study1Uuid, node2.getId()); checkNodeBuildStatusUpdatedMessageReceived(study1Uuid, List.of(node2.getId())); checkUpdateModelsStatusMessagesReceived(study1Uuid, node2.getId()); checkEquipmentUpdatingFinishedMessagesReceived(study1Uuid, node2.getId()); - checkElementUpdatedMessageSent(study1Uuid, userId); + checkElementUpdatedMessageSent(study1Uuid, USER_ID); wireMockUtils.verifyNetworkModificationPostWithVariant(stubUuid, createLoadAttributes, NETWORK_UUID_STRING, VARIANT_ID_2); //study 2 node2 should not have any child @@ -2258,7 +2242,7 @@ public void testDuplicateNodeBetweenStudies() throws Exception { assertEquals(0, allNodes.stream().filter(nodeEntity -> nodeEntity.getParentNode() != null && nodeEntity.getParentNode().getIdNode().equals(study2Node2.getId())).count()); // duplicate the node1 from study 1 after node2 from study 2 - UUID duplicatedNodeUuid = duplicateNode(study1Uuid, study2Uuid, node1, study2Node2.getId(), InsertMode.AFTER, userId); + UUID duplicatedNodeUuid = duplicateNode(study1Uuid, study2Uuid, node1, study2Node2.getId(), InsertMode.AFTER, USER_ID); //node2 should now have 1 child allNodes = networkModificationTreeService.getAllNodes(study2Uuid); @@ -2358,13 +2342,13 @@ private UUID duplicateNode(UUID sourceStudyUuid, UUID targetStudyUuid, NetworkMo mockMvc.perform(post(STUDIES_URL + "/{targetStudyUuid}/tree/nodes?nodeToCopyUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}", targetStudyUuid, nodeToCopy.getId(), referenceNodeUuid, insertMode) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); } else { mockMvc.perform(post(STUDIES_URL + "/{targetStudyUuid}/tree/nodes?nodeToCopyUuid={nodeUuid}&referenceNodeUuid={referenceNodeUuid}&insertMode={insertMode}&sourceStudyUuid={sourceStudyUuid}", targetStudyUuid, nodeToCopy.getId(), referenceNodeUuid, insertMode, sourceStudyUuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); } @@ -2437,7 +2421,7 @@ public void reindexStudyTest() throws Exception { mockMvc.perform(get("/v1/studies/{studyUuid}/indexation/status", UUID.randomUUID())) .andExpectAll(status().isNotFound()); - UUID notExistingNetworkStudyUuid = createStudy("userId", NOT_EXISTING_NETWORK_CASE_UUID); + UUID notExistingNetworkStudyUuid = createStudy(USER_ID, NOT_EXISTING_NETWORK_CASE_UUID); mockMvc.perform(post("/v1/studies/{studyUuid}/reindex-all", notExistingNetworkStudyUuid)) .andExpect(status().isInternalServerError()); @@ -2453,7 +2437,7 @@ public void reindexStudyTest() throws Exception { requests = TestUtils.getRequestsWithBodyDone(1, server); assertEquals(1, requests.stream().filter(r -> r.getPath().contains("/v1/networks/" + NOT_EXISTING_NETWORK_UUID + "/indexed-equipments")).count()); - UUID study1Uuid = createStudy("userId", CASE_UUID); + UUID study1Uuid = createStudy(USER_ID, CASE_UUID); mockMvc.perform(get("/v1/studies/{studyUuid}/indexation/status", study1Uuid)) .andExpectAll(status().isOk(), diff --git a/src/test/java/org/gridsuite/study/server/VoltageInitTest.java b/src/test/java/org/gridsuite/study/server/VoltageInitTest.java index 72ebc824e..26bc85a12 100644 --- a/src/test/java/org/gridsuite/study/server/VoltageInitTest.java +++ b/src/test/java/org/gridsuite/study/server/VoltageInitTest.java @@ -144,8 +144,9 @@ public class VoltageInitTest { private static final String VOLTAGE_INIT_PREVIEW_MODIFICATION_LIST = "[{\"type\": \"VOLTAGE_INIT_MODIFICATION\",\"uuid\": \"254a3b85-14ad-4436-bf62-3e60af831dd1\",\"date\": \"2023-09-18T10:58:32.582239Z\",\"stashed\": false,\"generators\": [],\"transformers\": [],\"staticVarCompensators\": [],\"vscConverterStations\": [],\"shuntCompensators\": []}]"; private static final String VOLTAGE_INIT_STATUS_JSON = "{\"status\":\"COMPLETED\"}"; - private static final String VARIANT_ID = "variant_1"; + private static final String USER_ID = "userId"; + private static final String VARIANT_ID = "variant_1"; private static final String VARIANT_ID_2 = "variant_2"; private static final long TIMEOUT = 1000; @@ -327,7 +328,7 @@ private void initMockBeans(Network network) { private void createOrUpdateParametersAndDoChecks(UUID studyNameUserIdUuid, StudyVoltageInitParameters parameters) throws Exception { mockMvc.perform( post("/v1/studies/{studyUuid}/voltage-init/parameters", studyNameUserIdUuid) - .header(HEADER_USER_ID, "userId") + .header(HEADER_USER_ID, USER_ID) .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(parameters))).andExpect( status().isOk()); @@ -391,7 +392,7 @@ public void testUpdatingParametersWithSameComputationParametersDoesNotInvalidate mockMvc.perform( post("/v1/studies/{studyUuid}/voltage-init/parameters", studyEntity.getId()) - .header(HEADER_USER_ID, "userId") + .header(HEADER_USER_ID, USER_ID) .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(studyVoltageInitParameters))).andExpect( status().isOk()); @@ -415,7 +416,7 @@ public void testApplyModificationsWhenParameterIsActivated() throws Exception { UUID.randomUUID(), VARIANT_ID_2, "node 1"); //run a voltage init analysis mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/voltage-init/run", studyEntity.getId(), modificationNode1.getId()) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); // Running the computation @@ -453,12 +454,12 @@ public void testVoltageInit() throws Exception { // run a voltage init on root node (not allowed) mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/voltage-init/run", studyNameUserIdUuid, rootNodeUuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isForbidden()); //run a voltage init analysis mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/voltage-init/run", studyNameUserIdUuid, modificationNode3Uuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.UPDATE_TYPE_VOLTAGE_INIT_STATUS); @@ -486,7 +487,7 @@ public void testVoltageInit() throws Exception { mockMvc.perform( post("/v1/studies/{studyUuid}/voltage-init/parameters", studyNameUserIdUuid) - .header(HEADER_USER_ID, "userId") + .header(HEADER_USER_ID, USER_ID) .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(createStudyVoltageInitParameters(false, VOLTAGE_INIT_PARAMETERS_INFOS_2)))).andExpect( status().isOk()); @@ -507,7 +508,7 @@ public void testVoltageInit() throws Exception { assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/results/" + VOLTAGE_INIT_RESULT_UUID + "/stop\\?receiver=.*nodeUuid.*"))); mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/voltage-init/run", studyNameUserIdUuid, modificationNode2Uuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.UPDATE_TYPE_VOLTAGE_INIT_FAILED); @@ -537,7 +538,7 @@ public void testCopyVoltageInitModifications() throws Exception { // run a voltage init analysis mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/voltage-init/run", studyNameUserIdUuid, modificationNode3Uuid) - .header(HEADER_USER_ID, "userId")) + .header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.UPDATE_TYPE_VOLTAGE_INIT_STATUS); @@ -548,7 +549,7 @@ public void testCopyVoltageInitModifications() throws Exception { // just retrieve modifications list from modificationNode3Uuid mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/voltage-init/modifications", studyNameUserIdUuid, modificationNode3Uuid) - .header(HEADER_USER_ID, "userId")).andExpect(status().isOk()); + .header(HEADER_USER_ID, USER_ID)).andExpect(status().isOk()); assertTrue(TestUtils.getRequestsDone(2, server).stream().allMatch(r -> r.matches("/v1/groups/" + MODIFICATIONS_GROUP_UUID + "/network-modifications\\?errorOnGroupNotFound=false&onlyStashed=false&onlyMetadata=false") || r.matches("/v1/results/" + VOLTAGE_INIT_RESULT_UUID + "/modifications-group-uuid") @@ -556,7 +557,7 @@ public void testCopyVoltageInitModifications() throws Exception { // clone and copy modifications to modificationNode3Uuid mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/voltage-init/modifications", studyNameUserIdUuid, modificationNode3Uuid) - .header(HEADER_USER_ID, "userId")).andExpect(status().isOk()); + .header(HEADER_USER_ID, USER_ID)).andExpect(status().isOk()); assertTrue(TestUtils.getRequestsDone(4, server).stream().allMatch(r -> r.matches("/v1/results/" + VOLTAGE_INIT_RESULT_UUID + "/modifications-group-uuid") || r.matches("/v1/results/" + VOLTAGE_INIT_RESULT_UUID + "/status") || @@ -570,7 +571,7 @@ public void testCopyVoltageInitModifications() throws Exception { checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.NODE_BUILD_STATUS_UPDATED); checkUpdateModelsStatusMessagesReceived(studyNameUserIdUuid); checkEquipmentUpdatingFinishedMessagesReceived(studyNameUserIdUuid, modificationNode3Uuid); - checkElementUpdatedMessageSent(studyNameUserIdUuid, "userId"); + checkElementUpdatedMessageSent(studyNameUserIdUuid, USER_ID); } private void checkUpdateModelsStatusMessagesReceived(UUID studyUuid) { @@ -750,7 +751,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU jsonObject.put("modificationGroupUuid", modificationGroupUuid); mnBodyJson = jsonObject.toString(); - mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, "userId")) + mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, USER_ID)) .andExpect(status().isOk()); var mess = output.receive(TIMEOUT, studyUpdateDestination); assertNotNull(mess); From 7a0c91dbf2944c05cb47a5f28184a3934288988d Mon Sep 17 00:00:00 2001 From: Tristan Chuine Date: Mon, 10 Jun 2024 22:14:30 +0200 Subject: [PATCH 2/2] fix --- src/test/java/org/gridsuite/study/server/StudyTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/gridsuite/study/server/StudyTest.java b/src/test/java/org/gridsuite/study/server/StudyTest.java index 5c9e9dfe9..2750a7f9c 100644 --- a/src/test/java/org/gridsuite/study/server/StudyTest.java +++ b/src/test/java/org/gridsuite/study/server/StudyTest.java @@ -117,8 +117,6 @@ @ContextConfigurationWithTestChannel public class StudyTest { private static final Logger LOGGER = LoggerFactory.getLogger(StudyTest.class); - private static final String USER_ID = "userId"; - private static final String USER_ID_2 = "userId2"; @Autowired private MockMvc mockMvc; @@ -170,6 +168,8 @@ public class StudyTest { private static final String STUDY_CREATION_ERROR_MESSAGE = "Une erreur est survenue lors de la création de l'étude"; private static final String URI_NETWORK_MODIF = "/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-modifications"; private static final String CASE_FORMAT = "caseFormat"; + private static final String USER_ID = "userId"; + private static final String USER_ID_2 = "userId2"; private static final String NO_PARAMS_IN_PROFILE_USER_ID = "noParamInProfileUser"; private static final String USER_PROFILE_NO_PARAMS_JSON = "{\"id\":\"97bb1890-a90c-43c3-a004-e631246d42d6\",\"name\":\"Profile No params\"}"; private static final String INVALID_PARAMS_IN_PROFILE_USER_ID = "invalidParamInProfileUser"; @@ -1325,7 +1325,7 @@ public void testGetStudyCreationRequests() throws Exception { assertTrue(requests.stream().anyMatch(r -> r.matches("/v1/networks\\?caseUuid=" + NEW_STUDY_CASE_UUID + "&variantId=" + FIRST_VARIANT_ID + "&reportUuid=.*"))); assertTrue(requests.contains(String.format("/v1/cases/%s/disableExpiration", NEW_STUDY_CASE_UUID))); assertTrue(requests.contains("/v1/parameters/default")); - assertTrue(requests.stream().anyMatch(r -> r.equals("/v1/users/userId/profile"))); + assertTrue(requests.stream().anyMatch(r -> r.equals("/v1/users/" + USER_ID + "/profile"))); } private void checkUpdateModelStatusMessagesReceived(UUID studyUuid, UUID nodeUuid, String updateType) {