From 007d6553f9b7d8c31838a4b61bf5a55a15bd418a Mon Sep 17 00:00:00 2001 From: Tristan Chuine Date: Mon, 10 Jun 2024 22:06:52 +0200 Subject: [PATCH] Fix constants not `static final` --- .../org/gridsuite/study/server/CaseTest.java | 8 +- .../gridsuite/study/server/LoadFlowTest.java | 38 ++-- .../study/server/NetworkModificationTest.java | 94 +++++----- .../server/NetworkModificationTreeTest.java | 107 ++++++----- .../server/NetworkModificationUnitTest.java | 11 +- .../study/server/NonEvacuatedEnergyTest.java | 48 ++--- .../study/server/SecurityAnalysisTest.java | 60 +++---- .../study/server/SensitivityAnalysisTest.java | 70 ++++---- .../study/server/ShortCircuitTest.java | 32 ++-- .../study/server/SingleLineDiagramTest.java | 10 +- .../StudyControllerDynamicSimulationTest.java | 86 ++++----- .../study/server/StudyServiceTest.java | 36 ++-- .../org/gridsuite/study/server/StudyTest.java | 166 +++++++++--------- .../study/server/VoltageInitTest.java | 50 +++--- 14 files changed, 404 insertions(+), 412 deletions(-) diff --git a/src/test/java/org/gridsuite/study/server/CaseTest.java b/src/test/java/org/gridsuite/study/server/CaseTest.java index 4a8be2b75..8db250f3c 100644 --- a/src/test/java/org/gridsuite/study/server/CaseTest.java +++ b/src/test/java/org/gridsuite/study/server/CaseTest.java @@ -62,6 +62,9 @@ public class CaseTest { public static final String POST = "POST"; private static final String CASE_NAME = "DefaultCaseName"; + //output destinations + private static final String STUDY_UPDATE_DESTINATION = "study.update"; + @Autowired private MockMvc mockMvc; @@ -79,9 +82,6 @@ public class CaseTest { @Autowired private StudyRepository studyRepository; - //output destinations - private String studyUpdateDestination = "study.update"; - @Before public void setup() throws IOException { @@ -142,7 +142,7 @@ private void cleanDB() { @After public void tearDown() { - List destinations = List.of(studyUpdateDestination); + List destinations = List.of(STUDY_UPDATE_DESTINATION); cleanDB(); diff --git a/src/test/java/org/gridsuite/study/server/LoadFlowTest.java b/src/test/java/org/gridsuite/study/server/LoadFlowTest.java index e5f7e8bf0..cafe649a3 100644 --- a/src/test/java/org/gridsuite/study/server/LoadFlowTest.java +++ b/src/test/java/org/gridsuite/study/server/LoadFlowTest.java @@ -139,11 +139,11 @@ public class LoadFlowTest { private static String LOADFLOW_PROFILE_PARAMETERS_JSON; //output destinations - private final String studyUpdateDestination = "study.update"; - private final String elementUpdateDestination = "element.update"; - private final String loadflowResultDestination = "loadflow.result"; - private final String loadflowStoppedDestination = "loadflow.stopped"; - private final String loadflowFailedDestination = "loadflow.failed"; + private static final String STUDY_UPDATE_DESTINATION = "study.update"; + private static final String ELEMENT_UPDATE_DESTINATION = "element.update"; + private static final String LOADFLOW_RESULT_DESTINATION = "loadflow.result"; + private static final String LOADFLOW_STOPPED_DESTINATION = "loadflow.stopped"; + private static final String LOADFLOW_FAILED_DESTINATION = "loadflow.failed"; @Autowired private MockMvc mockMvc; @@ -249,14 +249,14 @@ public MockResponse dispatch(RecordedRequest request) { input.send(MessageBuilder.withPayload("") .setHeader("resultUuid", LOADFLOW_RESULT_UUID) .setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D") - .build(), loadflowResultDestination); + .build(), LOADFLOW_RESULT_DESTINATION); return new MockResponse().setResponseCode(200) .setBody(loadFlowResultUuidStr) .addHeader("Content-Type", "application/json; charset=utf-8"); } else if (path.matches("/v1/networks/" + NETWORK_UUID_STRING + "/run-and-save\\?receiver=.*&reportUuid=.*&reporterId=.*&variantId=" + VARIANT_ID)) { input.send(MessageBuilder.withPayload("") .setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D") - .build(), loadflowFailedDestination); + .build(), LOADFLOW_FAILED_DESTINATION); return new MockResponse().setResponseCode(200) .setBody(loadFlowErrorResultUuidStr) .addHeader("Content-Type", "application/json; charset=utf-8"); @@ -289,7 +289,7 @@ public MockResponse dispatch(RecordedRequest request) { input.send(MessageBuilder.withPayload("") .setHeader("resultUuid", resultUuid) .setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D") - .build(), loadflowStoppedDestination); + .build(), LOADFLOW_STOPPED_DESTINATION); return new MockResponse().setResponseCode(200) .addHeader("Content-Type", "application/json; charset=utf-8"); } else if (path.matches("/v1/results")) { @@ -552,7 +552,7 @@ public void testResetUuidResultWhenLFFailed() { StudyService studyService = Mockito.mock(StudyService.class); doAnswer(invocation -> { - input.send(MessageBuilder.withPayload("").setHeader(HEADER_RECEIVER, resultUuidJson).build(), loadflowFailedDestination); + input.send(MessageBuilder.withPayload("").setHeader(HEADER_RECEIVER, resultUuidJson).build(), LOADFLOW_FAILED_DESTINATION); return resultUuid; }).when(studyService).runLoadFlow(any(), any(), any(), any()); studyService.runLoadFlow(studyEntity.getId(), modificationNode.getId(), "", null); @@ -560,14 +560,14 @@ public void testResetUuidResultWhenLFFailed() { // Test reset uuid result in the database assertTrue(networkModificationTreeService.getComputationResultUuid(modificationNode.getId(), LOAD_FLOW).isEmpty()); - Message message = output.receive(TIMEOUT, studyUpdateDestination); + Message message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyEntity.getId(), message.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); String updateType = (String) message.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_LOADFLOW_FAILED, updateType); } private void checkUpdateModelStatusMessagesReceived(UUID studyUuid, String updateTypeToCheck, String otherUpdateTypeToCheck) { - Message loadFlowStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message loadFlowStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, loadFlowStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); String updateType = (String) loadFlowStatusMessage.getHeaders().get(HEADER_UPDATE_TYPE); if (otherUpdateTypeToCheck == null) { @@ -632,19 +632,19 @@ private void createOrUpdateParametersAndDoChecks(UUID studyNameUserIdUuid, Strin .content(parameters)) .andExpect(status().is(status.value())); - Message message = output.receive(TIMEOUT, studyUpdateDestination); + Message message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyNameUserIdUuid, message.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); assertEquals(NotificationService.UPDATE_TYPE_LOADFLOW_STATUS, message.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); - message = output.receive(TIMEOUT, studyUpdateDestination); + message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS, message.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); - message = output.receive(TIMEOUT, studyUpdateDestination); + message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(NotificationService.UPDATE_TYPE_SENSITIVITY_ANALYSIS_STATUS, message.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); - message = output.receive(TIMEOUT, studyUpdateDestination); + message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(NotificationService.UPDATE_TYPE_NON_EVACUATED_ENERGY_STATUS, message.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); - message = output.receive(TIMEOUT, studyUpdateDestination); + message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS, message.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); - message = output.receive(TIMEOUT, elementUpdateDestination); + message = output.receive(TIMEOUT, ELEMENT_UPDATE_DESTINATION); assertEquals(studyNameUserIdUuid, message.getHeaders().get(NotificationService.HEADER_ELEMENT_UUID)); } @@ -828,7 +828,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header("userId", "userId")) .andExpect(status().isOk()); - var mess = output.receive(TIMEOUT, studyUpdateDestination); + var mess = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertNotNull(mess); modificationNode.setId(UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE)))); assertEquals(InsertMode.CHILD.name(), mess.getHeaders().get(NotificationService.HEADER_INSERT_MODE)); @@ -842,7 +842,7 @@ private void cleanDB() { @After public void tearDown() { - List destinations = List.of(studyUpdateDestination, loadflowResultDestination, loadflowStoppedDestination, loadflowFailedDestination); + List destinations = List.of(STUDY_UPDATE_DESTINATION, LOADFLOW_RESULT_DESTINATION, LOADFLOW_STOPPED_DESTINATION, LOADFLOW_FAILED_DESTINATION); cleanDB(); diff --git a/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java b/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java index 3c0ccf498..38927a8c7 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkModificationTest.java @@ -141,6 +141,10 @@ public class NetworkModificationTest { private static final NetworkModificationResult DEFAULT_BUILD_RESULT = createModificationResultWithElementImpact(SimpleImpactType.CREATION, IdentifiableType.LINE, "lineId", Set.of("s1", "s2")).get(); + //output destinations + private static final String STUDY_UPDATE_DESTINATION = "study.update"; + private static final String ELEMENT_UPDATE_DESTINATION = "element.update"; + @Autowired private MockMvc mockMvc; @@ -194,10 +198,6 @@ public class NetworkModificationTest { @Autowired private StudyRepository studyRepository; - //output destinations - private final String studyUpdateDestination = "study.update"; - private final String elementUpdateDestination = "element.update"; - private UUID buildFailedStubId; private UUID buildErrorStubId; private UUID groupStubId; @@ -430,7 +430,7 @@ public void testBuild() throws Exception { modificationNode3.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILT)); // mark node modificationNode3 as built networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode3, userId); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); buildInfos = networkModificationTreeService.getBuildInfos(modificationNode4.getId()); assertEquals("variant_3", buildInfos.getOriginVariantId()); // variant to clone is variant associated to node @@ -441,15 +441,15 @@ public void testBuild() throws Exception { modificationNode2.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.NOT_BUILT)); // mark node modificationNode2 as not built networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode2, userId); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); modificationNode4.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.NOT_BUILT)); // mark node modificationNode4 as built invalid networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode4, userId); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); modificationNode5.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILT)); // mark node modificationNode5 as built networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode5, userId); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); // build modificationNode2 and stop build testBuildWithNodeUuid(studyNameUserIdUuid, modificationNode2.getId(), 1); @@ -461,7 +461,7 @@ public void testBuild() throws Exception { modificationNode3.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.NOT_BUILT)); // mark node modificationNode3 as built networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode3, userId); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); // build modificationNode3 and stop build testBuildWithNodeUuid(studyNameUserIdUuid, modificationNode3.getId(), 1); @@ -488,7 +488,7 @@ public void testLocalBuildValue() throws Exception { modificationNode.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILT)); networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode, userId); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); NetworkModificationNode modificationNode2 = createNetworkModificationNode(studyNameUserIdUuid, modificationNodeUuid, UUID.randomUUID(), VARIANT_ID, "node 2", userId); @@ -612,11 +612,11 @@ public void testNetworkModificationSwitch() throws Exception { modificationNode1.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILT)); // mark modificationNode1 as built networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, userId); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); modificationNode2.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILT)); // mark modificationNode2 as built networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode2, userId); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); Optional networkModificationResult = createModificationResultWithElementImpact(SimpleImpactType.MODIFICATION, IdentifiableType.SWITCH, "switchId", Set.of("s1", "s2", "s3")); @@ -795,7 +795,7 @@ public void testCreateGenerator() throws Exception { modificationNode1.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILDING)); networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, userId); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(bodyJsonCreateBis).contentType(MediaType.APPLICATION_JSON) .header(USER_ID_HEADER, userId)) @@ -850,7 +850,7 @@ public void testCreateShuntsCompensator() throws Exception { modificationNode1.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILDING)); networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, userId); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); // create shunt compensator on building node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createShuntCompensatorAttributes2).contentType(MediaType.APPLICATION_JSON) @@ -939,7 +939,7 @@ public void testCreateLine() throws Exception { modificationNode1.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILDING)); networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, userId); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); // create line on building node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createLineAttributes2).contentType(MediaType.APPLICATION_JSON) @@ -1010,7 +1010,7 @@ public void testCreateTwoWindingsTransformer() throws Exception { modificationNode1.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILDING)); networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, userId); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); // create Two Windings Transformer on building node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createTwoWindingsTransformerAttributes2).contentType(MediaType.APPLICATION_JSON) @@ -1325,7 +1325,7 @@ public void testCreateLoad() throws Exception { modificationNode3.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILDING)); networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode3, userId); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); // create load on building node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode3Uuid) @@ -1514,7 +1514,7 @@ public void testCreateSubstation() throws Exception { modificationNode1.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILDING)); networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, userId); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); // create substation on building node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createSubstationAttributes2).contentType(MediaType.APPLICATION_JSON) @@ -1587,7 +1587,7 @@ public void testCreateVoltageLevel() throws Exception { modificationNode1.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILDING)); networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, userId); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); // create voltage level on building node mockMvc.perform(post(URI_NETWORK_MODIF, studyNameUserIdUuid, modificationNode1Uuid) .content(createVoltageLevelAttributes2).contentType(MediaType.APPLICATION_JSON) @@ -2062,7 +2062,7 @@ public void testDuplicateModification() throws Exception { node1.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILT)); // mark node1 as built networkModificationTreeService.updateNode(studyUuid, node1, userId); checkElementUpdatedMessageSent(studyUuid, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); groupStubId = wireMockServer.stubFor(WireMock.any(WireMock.urlPathMatching("/v1/groups/.*")) .withQueryParam("action", WireMock.equalTo("COPY")) @@ -2337,10 +2337,10 @@ public void testNodesInvalidation() throws Exception { networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, userId); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode3, userId); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); // Update a network modification on node 1 (already built) -> build invalidation of all nodes String generatorAttributesUpdated = "{\"type\":\"" + ModificationType.GENERATOR_MODIFICATION + "\",\"generatorId\":\"generatorId1\",\"generatorType\":\"FICTITIOUS\",\"activePower\":\"70.0\"}"; @@ -2369,7 +2369,7 @@ public void testNodesInvalidation() throws Exception { modificationNode3.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILT)); networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode3, userId); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); // Create a network modification on node 2 (not built) -> build invalidation of node 3 Map createLoadInfos = Map.of("type", ModificationType.LOAD_CREATION, "equipmentId", "loadId"); @@ -2411,7 +2411,7 @@ public void testRemoveLoadFlowComputationReport() throws Exception { modificationNode1.setVoltageInitResultUuid(UUID.fromString(VOLTAGE_INIT_RESULT_UUID)); networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, userId); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); // A modification body Map body = Map.of( @@ -2481,7 +2481,7 @@ public void testUpdateOfBuildStatus() { networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode, userId); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); // Create network modification on BUILT modification node Optional networkModificationResult = @@ -2542,16 +2542,16 @@ private void testBuildWithNodeUuid(UUID studyUuid, UUID nodeUuid, int nbReportEx .andExpect(status().isOk()); // Initial node update -> BUILDING - Message buildStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message buildStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, buildStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); assertEquals(NotificationService.NODE_BUILD_STATUS_UPDATED, buildStatusMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); // Successful -> Node update -> BUILT - buildStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + buildStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, buildStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); assertEquals(NotificationService.NODE_BUILD_STATUS_UPDATED, buildStatusMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); - buildStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + buildStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, buildStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); assertEquals(nodeUuid, buildStatusMessage.getHeaders().get(NotificationService.HEADER_NODE)); assertEquals(NotificationService.UPDATE_TYPE_BUILD_COMPLETED, buildStatusMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); @@ -2569,12 +2569,12 @@ private void testBuildWithNodeUuid(UUID studyUuid, UUID nodeUuid, int nbReportEx mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/build/stop", studyUuid, nodeUuid)) .andExpect(status().isOk()); - buildStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + buildStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, buildStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); assertEquals(NotificationService.NODE_BUILD_STATUS_UPDATED, buildStatusMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); - output.receive(TIMEOUT, studyUpdateDestination); - buildStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); + buildStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, buildStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); assertEquals(nodeUuid, buildStatusMessage.getHeaders().get(NotificationService.HEADER_NODE)); assertEquals(NotificationService.UPDATE_TYPE_BUILD_CANCELLED, buildStatusMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); @@ -2595,17 +2595,17 @@ private void testBuildFailedWithNodeUuid(UUID studyUuid, UUID nodeUuid) throws E .andExpect(status().isOk()); // initial node update -> building - Message buildStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message buildStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, buildStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); assertEquals(NotificationService.NODE_BUILD_STATUS_UPDATED, buildStatusMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); // fail -> second node update -> not built - buildStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + buildStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, buildStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); assertEquals(NotificationService.NODE_BUILD_STATUS_UPDATED, buildStatusMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); // error message sent to frontend - buildStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + buildStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, buildStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); assertEquals(nodeUuid, buildStatusMessage.getHeaders().get(NotificationService.HEADER_NODE)); assertEquals(NotificationService.UPDATE_TYPE_BUILD_FAILED, buildStatusMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); @@ -2623,12 +2623,12 @@ private void testBuildErrorWithNodeUuid(UUID studyUuid, UUID nodeUuid) throws Ex .andExpect(status().isInternalServerError()); // initial node update -> building - Message buildStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message buildStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, buildStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); assertEquals(NotificationService.NODE_BUILD_STATUS_UPDATED, buildStatusMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); // error -> second node update -> not built - buildStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + buildStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, buildStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); assertEquals(NotificationService.NODE_BUILD_STATUS_UPDATED, buildStatusMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); @@ -2639,7 +2639,7 @@ private void testBuildErrorWithNodeUuid(UUID studyUuid, UUID nodeUuid) throws Ex private void checkEquipmentCreatingMessagesReceived(UUID studyNameUserIdUuid, UUID nodeUuid) { // assert that the broker message has been sent for updating study type - Message messageStudyUpdate = output.receive(TIMEOUT, studyUpdateDestination); + Message messageStudyUpdate = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals("", new String(messageStudyUpdate.getPayload())); MessageHeaders headersStudyUpdate = messageStudyUpdate.getHeaders(); assertEquals(studyNameUserIdUuid, headersStudyUpdate.get(NotificationService.HEADER_STUDY_UUID)); @@ -2649,7 +2649,7 @@ private void checkEquipmentCreatingMessagesReceived(UUID studyNameUserIdUuid, UU private void checkUpdateModelStatusMessagesReceived(UUID studyUuid, UUID nodeUuid, String updateType) { // assert that the broker message has been sent for updating model status - Message messageStatus = output.receive(TIMEOUT, studyUpdateDestination); + Message messageStatus = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals("", new String(messageStatus.getPayload())); MessageHeaders headersStatus = messageStatus.getHeaders(); assertEquals(studyUuid, headersStatus.get(NotificationService.HEADER_STUDY_UUID)); @@ -2671,7 +2671,7 @@ private void checkUpdateModelsStatusMessagesReceived(UUID studyUuid, UUID nodeUu } private void checkNodesBuildStatusUpdatedMessageReceived(UUID studyUuid, List nodesUuids) { - Message messageStatus = output.receive(TIMEOUT, studyUpdateDestination); + Message messageStatus = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals("", new String(messageStatus.getPayload())); MessageHeaders headersStatus = messageStatus.getHeaders(); assertEquals(studyUuid, headersStatus.get(NotificationService.HEADER_STUDY_UUID)); @@ -2692,7 +2692,7 @@ private void checkEquipmentMessagesReceived(UUID studyNameUserIdUuid, UUID nodeU private void checkEquipmentMessagesReceived(UUID studyNameUserIdUuid, List nodeUuids, NetworkImpactsInfos expectedPayload) throws Exception { // assert that the broker message has been sent for updating study type - Message messageStudyUpdate = output.receive(TIMEOUT, studyUpdateDestination); + Message messageStudyUpdate = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); NetworkImpactsInfos actualPayload = mapper.readValue(new String(messageStudyUpdate.getPayload()), new TypeReference() { }); assertThat(expectedPayload, new MatcherJson<>(mapper, actualPayload)); @@ -2704,7 +2704,7 @@ private void checkEquipmentMessagesReceived(UUID studyNameUserIdUuid, List private void checkEquipmentDeletingMessagesReceived(UUID studyNameUserIdUuid, UUID nodeUuid) { // assert that the broker message has been sent for updating study type - Message messageStudyUpdate = output.receive(TIMEOUT, studyUpdateDestination); + Message messageStudyUpdate = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals("", new String(messageStudyUpdate.getPayload())); MessageHeaders headersStudyUpdate = messageStudyUpdate.getHeaders(); assertEquals(studyNameUserIdUuid, headersStudyUpdate.get(NotificationService.HEADER_STUDY_UUID)); @@ -2724,7 +2724,7 @@ private void checkSwitchModificationMessagesReceived(UUID studyNameUserIdUuid, L private void checkEquipmentUpdatingMessagesReceived(UUID studyNameUserIdUuid, UUID nodeUuid) { // assert that the broker message has been sent for updating study type - Message messageStudyUpdate = output.receive(TIMEOUT, studyUpdateDestination); + Message messageStudyUpdate = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals("", new String(messageStudyUpdate.getPayload())); MessageHeaders headersStudyUpdate = messageStudyUpdate.getHeaders(); assertEquals(studyNameUserIdUuid, headersStudyUpdate.get(NotificationService.HEADER_STUDY_UUID)); @@ -2747,7 +2747,7 @@ private void checkEquipmentDeletingFinishedMessagesReceived(UUID studyNameUserId private void checkEquipmentFinishedMessagesReceived(UUID studyNameUserIdUuid, UUID nodeUuid, String updateType) { // assert that the broker message has been sent for updating study type - Message messageStudyUpdate = output.receive(TIMEOUT, studyUpdateDestination); + Message messageStudyUpdate = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals("", new String(messageStudyUpdate.getPayload())); MessageHeaders headersStudyUpdate = messageStudyUpdate.getHeaders(); assertEquals(studyNameUserIdUuid, headersStudyUpdate.get(NotificationService.HEADER_STUDY_UUID)); @@ -2757,7 +2757,7 @@ private void checkEquipmentFinishedMessagesReceived(UUID studyNameUserIdUuid, UU private void checkEquipmentDeletedMessagesReceived(UUID studyNameUserIdUuid, UUID nodeUuid, NetworkImpactsInfos expectedPayload) throws Exception { // assert that the broker message has been sent for updating study type - Message messageStudyUpdate = output.receive(TIMEOUT, studyUpdateDestination); + Message messageStudyUpdate = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); NetworkImpactsInfos actualPayload = mapper.readValue(new String(messageStudyUpdate.getPayload()), new TypeReference() { }); assertThat(expectedPayload, new MatcherJson<>(mapper, actualPayload)); @@ -2820,7 +2820,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).header(USER_ID_HEADER, userId).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); checkElementUpdatedMessageSent(studyUuid, userId); - var mess = output.receive(TIMEOUT, studyUpdateDestination); + var mess = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertNotNull(mess); modificationNode.setId(UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE)))); assertEquals(InsertMode.CHILD.name(), mess.getHeaders().get(NotificationService.HEADER_INSERT_MODE)); @@ -2888,7 +2888,7 @@ public void testCreateModificationWithErrors() { } private void checkElementUpdatedMessageSent(UUID elementUuid, String userId) { - Message message = output.receive(TIMEOUT, elementUpdateDestination); + Message message = output.receive(TIMEOUT, ELEMENT_UPDATE_DESTINATION); assertEquals(elementUuid, message.getHeaders().get(NotificationService.HEADER_ELEMENT_UUID)); assertEquals(userId, message.getHeaders().get(NotificationService.HEADER_MODIFIED_BY)); } @@ -2902,7 +2902,7 @@ private void cleanDB() { public void tearDown() throws IOException { cleanDB(); - TestUtils.assertQueuesEmptyThenClear(List.of(studyUpdateDestination), output); + TestUtils.assertQueuesEmptyThenClear(List.of(STUDY_UPDATE_DESTINATION), output); try { TestUtils.assertWiremockServerRequestsEmptyThenShutdown(wireMockServer); diff --git a/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java b/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java index 40738596f..bfca68c43 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkModificationTreeTest.java @@ -88,10 +88,24 @@ @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 NETWORK_UUID_STRING = "38400000-8cf0-11bd-b23e-10b96e4ef00d"; + private static final UUID NETWORK_UUID = UUID.fromString(NETWORK_UUID_STRING); + private static final String VARIANT_ID = "variant_1"; + private static final String VARIANT_ID_2 = "variant_2"; + private static final UUID MODIFICATION_GROUP_UUID = UUID.randomUUID(); + private static final UUID MODIFICATION_GROUP_UUID_2 = UUID.randomUUID(); + private static final UUID MODIFICATION_GROUP_UUID_3 = UUID.randomUUID(); + private static final String MODIFICATION1_UUID_STRING = "38400000-8cf0-11bd-b23e-10b96e4ef00d"; + private static final String MODIFICATION2_UUID_STRING = "38400000-8cf0-11bd-b23e-10b96e4ef111"; + private static final String MODIFICATION_GROUP_UUID_STRING = "38400000-8cf0-11bd-b23e-10b96e4ef222"; + private static final String USER_ID_HEADER = "userId"; + + private static final String STUDY_UPDATE_DESTINATION = "study.update"; + private static final String ELEMENT_UPDATE_DESTINATION = "element.update"; + @Autowired private MockMvc mockMvc; @@ -169,24 +183,9 @@ public class NetworkModificationTreeTest { @MockBean private VariantManager variantManager; - private static final String NETWORK_UUID_STRING = "38400000-8cf0-11bd-b23e-10b96e4ef00d"; - private static final UUID NETWORK_UUID = UUID.fromString(NETWORK_UUID_STRING); - private static final String VARIANT_ID = "variant_1"; - private static final String VARIANT_ID_2 = "variant_2"; - private static final UUID MODIFICATION_GROUP_UUID = UUID.randomUUID(); - private static final UUID MODIFICATION_GROUP_UUID_2 = UUID.randomUUID(); - private static final UUID MODIFICATION_GROUP_UUID_3 = UUID.randomUUID(); - private static final String MODIFICATION1_UUID_STRING = "38400000-8cf0-11bd-b23e-10b96e4ef00d"; - private static final String MODIFICATION2_UUID_STRING = "38400000-8cf0-11bd-b23e-10b96e4ef111"; - private static final String MODIFICATION_GROUP_UUID_STRING = "38400000-8cf0-11bd-b23e-10b96e4ef222"; - private static final String USER_ID_HEADER = "userId"; - @MockBean private Network network; - private String studyUpdateDestination = "study.update"; - private String elementUpdateDestination = "element.update"; - @Before public void setUp() throws IOException { Configuration.defaultConfiguration(); @@ -306,7 +305,7 @@ public MockResponse dispatch(RecordedRequest request) { @After public void cleanDB() { - List destinations = List.of(studyUpdateDestination, elementUpdateDestination); + List destinations = List.of(STUDY_UPDATE_DESTINATION, ELEMENT_UPDATE_DESTINATION); networkModificationNodeInfoRepository.deleteAll(); rootNodeInfoRepository.deleteAll(); nodeRepository.deleteAll(); @@ -696,7 +695,7 @@ private void deleteNode(UUID studyUuid, List child, boolean delete checkElementUpdatedMessageSent(studyUuid, userId); - var mess = output.receive(TIMEOUT, studyUpdateDestination); + var mess = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); if (expectedDeletion != null) { Collection deletedId = (Collection) mess.getHeaders().get(NotificationService.HEADER_NODES); assertNotNull(deletedId); @@ -706,13 +705,13 @@ private void deleteNode(UUID studyUuid, List child, boolean delete } if (nodeWithModification) { - var message = output.receive(TIMEOUT, studyUpdateDestination); + var message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); while (message != null) { Collection updatedIds = NODE_BUILD_STATUS_UPDATED.equals(message.getHeaders().get(HEADER_UPDATE_TYPE)) ? (Collection) message.getHeaders().get(NotificationService.HEADER_NODES) : List.of((UUID) message.getHeaders().get(NotificationService.HEADER_NODE)); updatedIds.forEach(id -> assertTrue(children.contains(id))); - message = output.receive(TIMEOUT, studyUpdateDestination); + message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); } } } @@ -724,9 +723,9 @@ private void stashNode(UUID studyUuid, AbstractNode child, boolean stashChildren checkElementUpdatedMessageSent(studyUuid, userId); //first message is node build status being reset and then is the node deleted - var message = output.receive(TIMEOUT, studyUpdateDestination); + var message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(NODE_BUILD_STATUS_UPDATED, message.getHeaders().get(HEADER_UPDATE_TYPE)); - message = output.receive(TIMEOUT, studyUpdateDestination); + message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); Collection stashedId = (Collection) message.getHeaders().get(NotificationService.HEADER_NODES); assertNotNull(stashedId); assertEquals(expectedStash.size(), stashedId.size()); @@ -743,7 +742,7 @@ private void restoreNode(UUID studyUuid, List nodeId, UUID anchorNodeId, S .andExpect(status().isOk()); for (int i = 0; i < expectedIdRestored.size(); i++) { - var message = output.receive(TIMEOUT, studyUpdateDestination); + var message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertTrue(expectedIdRestored.contains(message.getHeaders().get(HEADER_NEW_NODE))); } } @@ -850,7 +849,7 @@ public void testNodeUpdate() throws Exception { assertEquals(1, root.getChildren().size()); assertNodeEquals(node1, root.getChildren().get(0)); - var mess = output.receive(TIMEOUT, studyUpdateDestination); + var mess = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertNotNull(mess); var header = mess.getHeaders(); assertEquals(root.getStudyId(), header.get(NotificationService.HEADER_STUDY_UUID)); @@ -868,7 +867,7 @@ public void testNodeUpdate() throws Exception { .content(objectWriter.writeValueAsString(justANameUpdate)) .header(USER_ID_HEADER, "userId")) .andExpect(status().isOk()); - assertEquals(NODE_RENAMED, output.receive(TIMEOUT, studyUpdateDestination).getHeaders().get(HEADER_UPDATE_TYPE)); + assertEquals(NODE_RENAMED, output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION).getHeaders().get(HEADER_UPDATE_TYPE)); checkElementUpdatedMessageSent(root.getStudyId(), userId); var newNode = getNode(root.getStudyId(), node1.getId()); @@ -901,7 +900,7 @@ public void testNodeDescriptionUpdate() throws Exception { .content(objectWriter.writeValueAsString(nodeDescriptionUpdate)) .header(USER_ID_HEADER, "userId")) .andExpect(status().isOk()); - assertEquals(NODE_UPDATED, output.receive(TIMEOUT, studyUpdateDestination).getHeaders().get(HEADER_UPDATE_TYPE)); + assertEquals(NODE_UPDATED, output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION).getHeaders().get(HEADER_UPDATE_TYPE)); checkElementUpdatedMessageSent(root.getStudyId(), userId); } @@ -998,7 +997,7 @@ private void createNode(UUID studyUuid, AbstractNode parentNode, NetworkModifica .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); checkElementUpdatedMessageSent(studyUuid, userId); - var mess = output.receive(TIMEOUT, studyUpdateDestination); + var mess = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertNotNull(mess); newNode.setId(UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE)))); assertEquals(InsertMode.CHILD.name(), mess.getHeaders().get(NotificationService.HEADER_INSERT_MODE)); @@ -1024,7 +1023,7 @@ private void insertNode(UUID studyUuid, AbstractNode parentNode, NetworkModifica checkElementUpdatedMessageSent(studyUuid, userId); - var mess = output.receive(TIMEOUT, studyUpdateDestination); + var mess = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(NotificationService.NODE_CREATED, mess.getHeaders().get(HEADER_UPDATE_TYPE)); assertEquals(newParentNode.getId(), mess.getHeaders().get(NotificationService.HEADER_PARENT_NODE)); assertEquals(mode.name(), mess.getHeaders().get(NotificationService.HEADER_INSERT_MODE)); @@ -1175,18 +1174,18 @@ public void testGetNetworkModificationsToRestoreByNode() throws Exception { .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, elementUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, ELEMENT_UPDATE_DESTINATION)); } @Test @@ -1212,18 +1211,18 @@ public void testGetNetworkModificationsToStashByNode() throws Exception { .header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, elementUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, ELEMENT_UPDATE_DESTINATION)); } @@ -1311,13 +1310,13 @@ private Pair createTreeForBuildStatus() { } private void checkElementUpdatedMessageSent(UUID elementUuid, String userId) { - Message message = output.receive(TIMEOUT, elementUpdateDestination); + Message message = output.receive(TIMEOUT, ELEMENT_UPDATE_DESTINATION); assertEquals(elementUuid, message.getHeaders().get(NotificationService.HEADER_ELEMENT_UUID)); assertEquals(userId, message.getHeaders().get(NotificationService.HEADER_MODIFIED_BY)); } private void checkUpdateNodesMessageReceived(UUID studyUuid, List nodesUuids) { - Message messageStatus = output.receive(TIMEOUT, studyUpdateDestination); + Message messageStatus = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals("", new String(messageStatus.getPayload())); MessageHeaders headersStatus = messageStatus.getHeaders(); assertEquals(studyUuid, headersStatus.get(NotificationService.HEADER_STUDY_UUID)); diff --git a/src/test/java/org/gridsuite/study/server/NetworkModificationUnitTest.java b/src/test/java/org/gridsuite/study/server/NetworkModificationUnitTest.java index c6dc651e9..237902b91 100644 --- a/src/test/java/org/gridsuite/study/server/NetworkModificationUnitTest.java +++ b/src/test/java/org/gridsuite/study/server/NetworkModificationUnitTest.java @@ -78,15 +78,16 @@ class NetworkModificationUnitTest { private static final long TIMEOUT = 1000; private static final String VARIANT_1 = "variant_1"; + //output destinations + private static final String STUDY_UPDATE_DESTINATION = "study.update"; + private UUID studyUuid; private UUID node1Uuid; private UUID node2Uuid; private UUID node3Uuid; - //output destinations @Autowired private OutputDestination output; - private final String studyUpdateDestination = "study.update"; @BeforeEach public void setup() { @@ -148,7 +149,7 @@ void unbuildNode() { } private void checkUpdateBuildStateMessageReceived(UUID studyUuid, UUID nodeUuid) { - Message messageStatus = output.receive(TIMEOUT, studyUpdateDestination); + Message messageStatus = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals("", new String(messageStatus.getPayload())); MessageHeaders headersStatus = messageStatus.getHeaders(); @@ -159,7 +160,7 @@ private void checkUpdateBuildStateMessageReceived(UUID studyUuid, UUID nodeUuid) private void checkUpdateModelStatusMessagesReceived(UUID studyUuid, UUID nodeUuid, String updateType) { // assert that the broker message has been sent for updating model status - Message messageStatus = output.receive(TIMEOUT, studyUpdateDestination); + Message messageStatus = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals("", new String(messageStatus.getPayload())); MessageHeaders headersStatus = messageStatus.getHeaders(); assertEquals(studyUuid, headersStatus.get(NotificationService.HEADER_STUDY_UUID)); @@ -199,7 +200,7 @@ private NodeEntity insertNode(StudyEntity study, UUID nodeId, NodeEntity parentN @AfterEach public void tearDown() { - List destinations = List.of(studyUpdateDestination); + List destinations = List.of(STUDY_UPDATE_DESTINATION); assertQueuesEmptyThenClear(destinations); } diff --git a/src/test/java/org/gridsuite/study/server/NonEvacuatedEnergyTest.java b/src/test/java/org/gridsuite/study/server/NonEvacuatedEnergyTest.java index ab8f43d47..9fcaeadbd 100644 --- a/src/test/java/org/gridsuite/study/server/NonEvacuatedEnergyTest.java +++ b/src/test/java/org/gridsuite/study/server/NonEvacuatedEnergyTest.java @@ -113,6 +113,12 @@ public class NonEvacuatedEnergyTest { private static final long TIMEOUT = 1000; + //output destinations + private static final String STUDY_UPDATE_DESTINATION = "study.update"; + private static final String NON_EVACUATED_ENERGY_RESULT_DESTINATION = "nonEvacuatedEnergy.result"; + private static final String NON_EVACUATED_ENERGY_STOPPED_DESTINATION = "nonEvacuatedEnergy.stopped"; + private static final String NON_EVACUATED_ENERGY_FAILED_DESTINATION = "nonEvacuatedEnergy.failed"; + @Autowired private MockMvc mockMvc; @@ -155,12 +161,6 @@ public class NonEvacuatedEnergyTest { @MockBean private LoadFlowService loadFlowService; - //output destinations - private final String studyUpdateDestination = "study.update"; - private final String nonEvacuatedEnergyResultDestination = "nonEvacuatedEnergy.result"; - private final String nonEvacuatedEnergyStoppedDestination = "nonEvacuatedEnergy.stopped"; - private final String nonEvacuatedEnergyFailedDestination = "nonEvacuatedEnergy.failed"; - @Before public void setup() throws IOException { objectWriter = objectMapper.writer().withDefaultPrettyPrinter(); @@ -198,19 +198,19 @@ public MockResponse dispatch(RecordedRequest request) { .setHeader("resultUuid", resultUuid) .setHeader(HEADER_USER_ID, "userId") .setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D") - .build(), nonEvacuatedEnergyResultDestination); + .build(), NON_EVACUATED_ENERGY_RESULT_DESTINATION); 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("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D") - .build(), nonEvacuatedEnergyFailedDestination); + .build(), NON_EVACUATED_ENERGY_FAILED_DESTINATION); return new MockResponse().setResponseCode(200).setBody("\"" + NON_EVACUATED_ENERGY_ERROR_NODE_RESULT_UUID + "\"") .addHeader("Content-Type", "application/json; charset=utf-8"); } else if (path.matches("/v1/networks/" + NETWORK_UUID_3_STRING + "/non-evacuated-energy.*")) { input.send(MessageBuilder.withPayload("") - .build(), nonEvacuatedEnergyFailedDestination); + .build(), NON_EVACUATED_ENERGY_FAILED_DESTINATION); return new MockResponse().setResponseCode(200).setBody("\"" + NON_EVACUATED_ENERGY_ERROR_NODE_RESULT_UUID + "\"") .addHeader("Content-Type", "application/json; charset=utf-8"); } else if (path.matches("/v1/non-evacuated-energy/results/" + NON_EVACUATED_ENERGY_RESULT_UUID + "/stop.*") @@ -219,7 +219,7 @@ public MockResponse dispatch(RecordedRequest request) { input.send(MessageBuilder.withPayload("") .setHeader("resultUuid", resultUuid) .setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D") - .build(), nonEvacuatedEnergyStoppedDestination); + .build(), NON_EVACUATED_ENERGY_STOPPED_DESTINATION); return new MockResponse().setResponseCode(200) .addHeader("Content-Type", "application/json; charset=utf-8"); } else if (path.matches("/v1/non-evacuated-energy/results/" + NON_EVACUATED_ENERGY_OTHER_NODE_RESULT_UUID)) { @@ -275,17 +275,17 @@ private void testNonEvacuatedEnergyWithNodeUuid(UUID studyUuid, UUID nodeUuid, U UUID uuidResponse = mapper.readValue(resultAsString, UUID.class); assertEquals(uuidResponse, resultUuid); - Message sensitivityAnalysisStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message sensitivityAnalysisStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, sensitivityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); String updateType = (String) sensitivityAnalysisStatusMessage.getHeaders().get(HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_NON_EVACUATED_ENERGY_STATUS, updateType); - Message sensitivityAnalysisUpdateMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message sensitivityAnalysisUpdateMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, sensitivityAnalysisUpdateMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) sensitivityAnalysisUpdateMessage.getHeaders().get(HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_NON_EVACUATED_ENERGY_RESULT, updateType); - sensitivityAnalysisStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + sensitivityAnalysisStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, sensitivityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) sensitivityAnalysisStatusMessage.getHeaders().get(HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_NON_EVACUATED_ENERGY_STATUS, updateType); @@ -308,7 +308,7 @@ private void testNonEvacuatedEnergyWithNodeUuid(UUID studyUuid, UUID nodeUuid, U // stop sensitivity analysis non evacuated energy mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/non-evacuated-energy/stop", studyUuid, nodeUuid)).andExpect(status().isOk()); - sensitivityAnalysisStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + sensitivityAnalysisStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, sensitivityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) sensitivityAnalysisStatusMessage.getHeaders().get(HEADER_UPDATE_TYPE); assertTrue(updateType.equals(NotificationService.UPDATE_TYPE_NON_EVACUATED_ENERGY_STATUS) || updateType.equals(NotificationService.UPDATE_TYPE_NON_EVACUATED_ENERGY_RESULT)); @@ -346,17 +346,17 @@ public void testNonEvacuatedEnergy() throws Exception { .contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, "userId")).andExpect(status().isOk()) .andReturn(); - Message sensitivityAnalysisStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message sensitivityAnalysisStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyNameUserIdUuid, sensitivityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); String updateType = (String) sensitivityAnalysisStatusMessage.getHeaders().get(HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_NON_EVACUATED_ENERGY_STATUS, updateType); - Message sensitivityAnalysisUpdateMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message sensitivityAnalysisUpdateMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyNameUserIdUuid, sensitivityAnalysisUpdateMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) sensitivityAnalysisUpdateMessage.getHeaders().get(HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_NON_EVACUATED_ENERGY_RESULT, updateType); - sensitivityAnalysisStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + sensitivityAnalysisStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyNameUserIdUuid, sensitivityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) sensitivityAnalysisStatusMessage.getHeaders().get(HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_NON_EVACUATED_ENERGY_STATUS, updateType); @@ -436,12 +436,12 @@ public void testResetUuidResultWhenNonEvacuatedEnergyFailed() { StudyService studyService = Mockito.mock(StudyService.class); doAnswer(invocation -> { - input.send(MessageBuilder.withPayload("").setHeader(HEADER_RECEIVER, resultUuidJson).build(), nonEvacuatedEnergyFailedDestination); + input.send(MessageBuilder.withPayload("").setHeader(HEADER_RECEIVER, resultUuidJson).build(), NON_EVACUATED_ENERGY_FAILED_DESTINATION); return resultUuid; }).when(studyService).runNonEvacuatedEnergy(any(), any(), any()); studyService.runNonEvacuatedEnergy(studyEntity.getId(), modificationNode.getId(), "userId"); - Message message = output.receive(TIMEOUT, studyUpdateDestination); + Message message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyEntity.getId(), message.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); String updateType = (String) message.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_NON_EVACUATED_ENERGY_FAILED, updateType); @@ -469,13 +469,13 @@ public void testNonEvacuatedEnergyFailedForNotification() throws Exception { assertEquals(NON_EVACUATED_ENERGY_ERROR_NODE_RESULT_UUID, uuidResponse); // failed sensitivity analysis non evacuated energy - Message message = output.receive(TIMEOUT, studyUpdateDestination); + Message message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, message.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); String updateType = (String) message.getHeaders().get(HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_NON_EVACUATED_ENERGY_FAILED, updateType); // message sent by run controller to notify frontend sensitivity analysis non evacuated energy is running and should update status - message = output.receive(TIMEOUT, studyUpdateDestination); + message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, message.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) message.getHeaders().get(HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_NON_EVACUATED_ENERGY_STATUS, updateType); @@ -498,7 +498,7 @@ public void testNonEvacuatedEnergyFailedForNotification() throws Exception { // failed sensitivity analysis non evacuated energy without receiver -> no failure message sent to frontend // message sent by run controller to notify frontend sensitivity analysis non evacuated energy is running and should update status - message = output.receive(TIMEOUT, studyUpdateDestination); + message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid2, message.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) message.getHeaders().get(HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_NON_EVACUATED_ENERGY_STATUS, updateType); @@ -548,7 +548,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, "userId")) .andExpect(status().isOk()); - var mess = output.receive(TIMEOUT, studyUpdateDestination); + var mess = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertNotNull(mess); modificationNode.setId(UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE)))); assertEquals(InsertMode.CHILD.name(), mess.getHeaders().get(NotificationService.HEADER_INSERT_MODE)); @@ -566,7 +566,7 @@ private void cleanDB() { @After public void tearDown() { - List destinations = List.of(studyUpdateDestination, nonEvacuatedEnergyFailedDestination, nonEvacuatedEnergyResultDestination, nonEvacuatedEnergyStoppedDestination); + List destinations = List.of(STUDY_UPDATE_DESTINATION, NON_EVACUATED_ENERGY_FAILED_DESTINATION, NON_EVACUATED_ENERGY_RESULT_DESTINATION, NON_EVACUATED_ENERGY_STOPPED_DESTINATION); cleanDB(); diff --git a/src/test/java/org/gridsuite/study/server/SecurityAnalysisTest.java b/src/test/java/org/gridsuite/study/server/SecurityAnalysisTest.java index c84d4dc70..7e0cb9173 100644 --- a/src/test/java/org/gridsuite/study/server/SecurityAnalysisTest.java +++ b/src/test/java/org/gridsuite/study/server/SecurityAnalysisTest.java @@ -123,6 +123,12 @@ public class SecurityAnalysisTest { private static final long TIMEOUT = 1000; + //output destinations + private static final String STUDY_UPDATE_DESTINATION = "study.update"; + private static final String SA_RESULT_DESTINATION = "sa.result"; + private static final String SA_STOPPED_DESTINATION = "sa.stopped"; + private static final String SA_FAILED_DESTINATION = "sa.failed"; + private static final SecurityAnalysisParameters SECURITY_ANALYSIS_PARAMETERS = new SecurityAnalysisParameters(); @Autowired @@ -165,12 +171,6 @@ public class SecurityAnalysisTest { @Autowired private ReportService reportService; - //output destinations - private final String studyUpdateDestination = "study.update"; - private final String saResultDestination = "sa.result"; - private final String saStoppedDestination = "sa.stopped"; - private final String saFailedDestination = "sa.failed"; - @Before public void setup() throws IOException { objectWriter = objectMapper.writer().withDefaultPrettyPrinter(); @@ -211,7 +211,7 @@ public MockResponse dispatch(RecordedRequest request) { input.send(MessageBuilder.withPayload("") .setHeader("resultUuid", resultUuid) .setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D") - .build(), saResultDestination); + .build(), SA_RESULT_DESTINATION); return new MockResponse().setResponseCode(200).setBody("\"" + resultUuid + "\"") .addHeader("Content-Type", MediaType.APPLICATION_JSON_UTF8); } else if (path.matches("/v1/results/" + SECURITY_ANALYSIS_RESULT_UUID + "/limit-types") @@ -247,7 +247,7 @@ public MockResponse dispatch(RecordedRequest request) { input.send(MessageBuilder.withPayload("") .setHeader("resultUuid", resultUuid) .setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D") - .build(), saStoppedDestination); + .build(), SA_STOPPED_DESTINATION); return new MockResponse().setResponseCode(200) .addHeader("Content-Type", MediaType.APPLICATION_JSON_UTF8); } else if (path.matches("/v1/contingency-lists/" + CONTINGENCY_LIST_NAME + "/export\\?networkUuid=" + NETWORK_UUID_STRING) @@ -273,12 +273,12 @@ public MockResponse dispatch(RecordedRequest request) { } else if (path.matches("/v1/networks/" + NETWORK_UUID_2_STRING + "/run-and-save.*")) { input.send(MessageBuilder.withPayload("") .setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D") - .build(), saFailedDestination); + .build(), SA_FAILED_DESTINATION); return new MockResponse().setResponseCode(200).setBody("\"" + SECURITY_ANALYSIS_ERROR_NODE_RESULT_UUID + "\"") .addHeader("Content-Type", MediaType.APPLICATION_JSON_UTF8); } else if (path.matches("/v1/networks/" + NETWORK_UUID_3_STRING + "/run-and-save.*")) { input.send(MessageBuilder.withPayload("") - .build(), saFailedDestination); + .build(), SA_FAILED_DESTINATION); return new MockResponse().setResponseCode(200).setBody("\"" + SECURITY_ANALYSIS_ERROR_NODE_RESULT_UUID + "\"") .addHeader("Content-Type", MediaType.APPLICATION_JSON_UTF8); } else if ("/v1/results".equals(path)) { @@ -351,17 +351,17 @@ public void testSecurityAnalysis() throws Exception { .header(HEADER_USER_ID, "testUserId"); mockMvc.perform(requestBuilder).andExpect(status().isOk()); - Message securityAnalysisStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message securityAnalysisStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyNameUserIdUuid, securityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); String updateType = (String) securityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS, updateType); - Message securityAnalysisUpdateMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message securityAnalysisUpdateMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyNameUserIdUuid, securityAnalysisUpdateMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) securityAnalysisUpdateMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_RESULT, updateType); - securityAnalysisStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + securityAnalysisStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyNameUserIdUuid, securityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) securityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS, updateType); @@ -403,7 +403,7 @@ public void testResetUuidResultWhenSAFailed() { StudyService studyService = Mockito.mock(StudyService.class); doAnswer(invocation -> { - input.send(MessageBuilder.withPayload("").setHeader(HEADER_RECEIVER, resultUuidJson).build(), saFailedDestination); + input.send(MessageBuilder.withPayload("").setHeader(HEADER_RECEIVER, resultUuidJson).build(), SA_FAILED_DESTINATION); return resultUuid; }).when(studyService).runSecurityAnalysis(any(), any(), any(), any()); studyService.runSecurityAnalysis(studyEntity.getId(), List.of(), modificationNode.getId(), ""); @@ -411,7 +411,7 @@ public void testResetUuidResultWhenSAFailed() { // Test reset uuid result in the database assertTrue(networkModificationTreeService.getComputationResultUuid(modificationNode.getId(), SECURITY_ANALYSIS).isEmpty()); - Message message = output.receive(TIMEOUT, studyUpdateDestination); + Message message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyEntity.getId(), message.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); String updateType = (String) message.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_FAILED, updateType); @@ -436,13 +436,13 @@ public void testSecurityAnalysisFailedForNotification() throws Exception { .andExpect(status().isOk()); // failed security analysis - Message message = output.receive(TIMEOUT, studyUpdateDestination); + Message message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, message.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); String updateType = (String) message.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_FAILED, updateType); // message sent by run and save controller to notify frontend security analysis is running and should update SA status - message = output.receive(TIMEOUT, studyUpdateDestination); + message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, message.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) message.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS, updateType); @@ -466,7 +466,7 @@ public void testSecurityAnalysisFailedForNotification() throws Exception { // failed security analysis without receiver -> no failure message sent to frontend // message sent by run and save controller to notify frontend security analysis is running and should update SA status - message = output.receive(TIMEOUT, studyUpdateDestination); + message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid2, message.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) message.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS, updateType); @@ -491,17 +491,17 @@ private void testSecurityAnalysisWithNodeUuid(UUID studyUuid, UUID nodeUuid, UUI requestBuilder.header(HEADER_USER_ID, "testUserId"); mockMvc.perform(requestBuilder).andExpect(status().isOk()); - Message securityAnalysisStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message securityAnalysisStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, securityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); String updateType = (String) securityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS, updateType); - Message securityAnalysisUpdateMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message securityAnalysisUpdateMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, securityAnalysisUpdateMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) securityAnalysisUpdateMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_RESULT, updateType); - securityAnalysisStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + securityAnalysisStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, securityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) securityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS, updateType); @@ -553,7 +553,7 @@ private void testSecurityAnalysisWithNodeUuid(UUID studyUuid, UUID nodeUuid, UUI // stop security analysis mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/security-analysis/stop", studyUuid, nodeUuid).header("userId", "userId")).andExpect(status().isOk()); - securityAnalysisStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + securityAnalysisStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, securityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) securityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE); assertTrue(updateType.equals(NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS) || updateType.equals(NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_RESULT)); @@ -622,7 +622,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header("userId", "userId")) .andExpect(status().isOk()); - var mess = output.receive(TIMEOUT, studyUpdateDestination); + var mess = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertNotNull(mess); modificationNode.setId(UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE)))); assertEquals(InsertMode.CHILD.name(), mess.getHeaders().get(NotificationService.HEADER_INSERT_MODE)); @@ -708,17 +708,17 @@ public void getResultZippedCsv() throws Exception { mockMvc.perform(post("/v1/studies/{studyUuid}/nodes/{nodeUuid}/security-analysis/run?contingencyListName={contingencyListName}", studyUuid, nodeUuid, CONTINGENCY_LIST_NAME).header(HEADER_USER_ID, "testUserId")).andExpect(status().isOk()); - Message securityAnalysisStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message securityAnalysisStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, securityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); String updateType = (String) securityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS, updateType); - Message securityAnalysisUpdateMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message securityAnalysisUpdateMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, securityAnalysisUpdateMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) securityAnalysisUpdateMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_RESULT, updateType); - securityAnalysisStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + securityAnalysisStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, securityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) securityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS, updateType); @@ -777,17 +777,17 @@ public void getResultZippedCsvNotFound() throws Exception { mockMvc.perform(post("/v1/studies/{studyUuid}/nodes/{nodeUuid}/security-analysis/run?contingencyListName={contingencyListName}", studyUuid, nodeUuid, CONTINGENCY_LIST_NAME).header(HEADER_USER_ID, "testUserId")).andExpect(status().isOk()); - Message securityAnalysisStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message securityAnalysisStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, securityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); String updateType = (String) securityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS, updateType); - Message securityAnalysisUpdateMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message securityAnalysisUpdateMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, securityAnalysisUpdateMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) securityAnalysisUpdateMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_RESULT, updateType); - securityAnalysisStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + securityAnalysisStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, securityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) securityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS, updateType); @@ -814,7 +814,7 @@ private void cleanDB() { @After public void tearDown() { - List destinations = List.of(studyUpdateDestination, saFailedDestination, saResultDestination, saStoppedDestination); + List destinations = List.of(STUDY_UPDATE_DESTINATION, SA_FAILED_DESTINATION, SA_RESULT_DESTINATION, SA_STOPPED_DESTINATION); cleanDB(); diff --git a/src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java b/src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java index 4a9aec36e..32d830e74 100644 --- a/src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java +++ b/src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java @@ -118,6 +118,21 @@ public class SensitivityAnalysisTest { private static final long TIMEOUT = 1000; + //output destinations + private static final String STUDY_UPDATE_DESTINATION = "study.update"; + private static final String ELEMENT_UPDATE_DESTINATION = "element.update"; + private static final String SENSITIVITY_ANALYSIS_RESULT_DESTINATION = "sensitivityanalysis.result"; + private static final String SENSITIVITY_ANALYSIS_STOPPED_DESTINATION = "sensitivityanalysis.stopped"; + private static final String SENSITIVITY_ANALYSIS_FAILED_DESTINATION = "sensitivityanalysis.failed"; + + public static final String SENSITIVITY_ANALYSIS_DEFAULT_PARAMETERS_JSON = "{\"flowFlowSensitivityValueThreshold\":0.0,\"angleFlowSensitivityValueThreshold\":0.0,\"flowVoltageSensitivityValueThreshold\":0.0," + + "\"sensitivityInjectionsSet\":[],\"sensitivityInjection\":[],\"sensitivityHVDC\":[],\"sensitivityPST\":[],\"sensitivityNodes\":[]}"; + public static final String SENSITIVITY_ANALYSIS_UPDATED_PARAMETERS_JSON = "{\"flowFlowSensitivityValueThreshold\":90.0,\"angleFlowSensitivityValueThreshold\":0.6,\"flowVoltageSensitivityValueThreshold\":0.1,\"sensitivityInjectionsSet\":[{\"monitoredBranches\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da322\",\"containerName\":\"identifiable2\"}],\"injections\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da321\",\"containerName\":\"identifiable1\"}],\"distributionType\":\"PROPORTIONAL\",\"contingencies\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da323\",\"containerName\":\"identifiable3\"}],\"activated\":true}],\"sensitivityInjection\":[{\"monitoredBranches\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da321\",\"containerName\":\"identifiable1\"}],\"injections\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da322\",\"containerName\":\"identifiable2\"}],\"contingencies\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da323\",\"containerName\":\"identifiable3\"}],\"activated\":true}],\"sensitivityHVDC\":[{\"monitoredBranches\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da321\",\"containerName\":\"identifiable1\"}],\"sensitivityType\":\"DELTA_MW\",\"hvdcs\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da322\",\"containerName\":\"identifiable2\"}],\"contingencies\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da323\",\"containerName\":\"identifiable3\"}],\"activated\":true}],\"sensitivityPST\":[{\"monitoredBranches\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da322\",\"containerName\":\"identifiable2\"}],\"sensitivityType\":\"DELTA_MW\",\"psts\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da321\",\"containerName\":\"identifiable1\"}],\"contingencies\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da323\",\"containerName\":\"identifiable3\"}],\"activated\":true}],\"sensitivityNodes\":[{\"monitoredVoltageLevels\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da321\",\"containerName\":\"identifiable1\"}],\"equipmentsInVoltageRegulation\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da322\",\"containerName\":\"identifiable2\"}],\"contingencies\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da323\",\"containerName\":\"identifiable3\"}],\"activated\":true}]}"; + + private static final byte[] SENSITIVITY_RESULTS_AS_CSV = {0x00, 0x01}; + + private static final UUID SENSITIVITY_ANALYSIS_PARAMETERS_UUID = UUID.randomUUID(); + @Autowired private MockMvc mockMvc; @@ -160,21 +175,6 @@ public class SensitivityAnalysisTest { @Autowired private ReportService reportService; - //output destinations - private final String studyUpdateDestination = "study.update"; - private final String elementUpdateDestination = "element.update"; - private final String sensitivityAnalysisResultDestination = "sensitivityanalysis.result"; - private final String sensitivityAnalysisStoppedDestination = "sensitivityanalysis.stopped"; - private final String sensitivityAnalysisFailedDestination = "sensitivityanalysis.failed"; - - public static final String SENSITIVITY_ANALYSIS_DEFAULT_PARAMETERS_JSON = "{\"flowFlowSensitivityValueThreshold\":0.0,\"angleFlowSensitivityValueThreshold\":0.0,\"flowVoltageSensitivityValueThreshold\":0.0," + - "\"sensitivityInjectionsSet\":[],\"sensitivityInjection\":[],\"sensitivityHVDC\":[],\"sensitivityPST\":[],\"sensitivityNodes\":[]}"; - public static final String SENSITIVITY_ANALYSIS_UPDATED_PARAMETERS_JSON = "{\"flowFlowSensitivityValueThreshold\":90.0,\"angleFlowSensitivityValueThreshold\":0.6,\"flowVoltageSensitivityValueThreshold\":0.1,\"sensitivityInjectionsSet\":[{\"monitoredBranches\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da322\",\"containerName\":\"identifiable2\"}],\"injections\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da321\",\"containerName\":\"identifiable1\"}],\"distributionType\":\"PROPORTIONAL\",\"contingencies\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da323\",\"containerName\":\"identifiable3\"}],\"activated\":true}],\"sensitivityInjection\":[{\"monitoredBranches\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da321\",\"containerName\":\"identifiable1\"}],\"injections\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da322\",\"containerName\":\"identifiable2\"}],\"contingencies\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da323\",\"containerName\":\"identifiable3\"}],\"activated\":true}],\"sensitivityHVDC\":[{\"monitoredBranches\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da321\",\"containerName\":\"identifiable1\"}],\"sensitivityType\":\"DELTA_MW\",\"hvdcs\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da322\",\"containerName\":\"identifiable2\"}],\"contingencies\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da323\",\"containerName\":\"identifiable3\"}],\"activated\":true}],\"sensitivityPST\":[{\"monitoredBranches\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da322\",\"containerName\":\"identifiable2\"}],\"sensitivityType\":\"DELTA_MW\",\"psts\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da321\",\"containerName\":\"identifiable1\"}],\"contingencies\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da323\",\"containerName\":\"identifiable3\"}],\"activated\":true}],\"sensitivityNodes\":[{\"monitoredVoltageLevels\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da321\",\"containerName\":\"identifiable1\"}],\"equipmentsInVoltageRegulation\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da322\",\"containerName\":\"identifiable2\"}],\"contingencies\":[{\"containerId\":\"cf399ef3-7f14-4884-8c82-1c90300da323\",\"containerName\":\"identifiable3\"}],\"activated\":true}]}"; - - private static final byte[] SENSITIVITY_RESULTS_AS_CSV = {0x00, 0x01}; - - private static final UUID SENSITIVITY_ANALYSIS_PARAMETERS_UUID = UUID.randomUUID(); - @Before public void setup() throws IOException { objectWriter = objectMapper.writer().withDefaultPrettyPrinter(); @@ -216,20 +216,20 @@ public MockResponse dispatch(RecordedRequest request) { .setHeader("resultUuid", resultUuid) .setHeader(HEADER_USER_ID, "testUserId") .setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D") - .build(), sensitivityAnalysisResultDestination); + .build(), SENSITIVITY_ANALYSIS_RESULT_DESTINATION); 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 + "/run-and-save.*")) { input.send(MessageBuilder.withPayload("") .setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D") .setHeader(HEADER_USER_ID, "testUserId") - .build(), sensitivityAnalysisFailedDestination); + .build(), SENSITIVITY_ANALYSIS_FAILED_DESTINATION); return new MockResponse().setResponseCode(200).setBody("\"" + SENSITIVITY_ANALYSIS_ERROR_NODE_RESULT_UUID + "\"") .addHeader("Content-Type", "application/json; charset=utf-8"); } else if (path.matches("/v1/networks/" + NETWORK_UUID_3_STRING + "/run-and-save.*")) { input.send(MessageBuilder.withPayload("") .setHeader(HEADER_USER_ID, "testUserId") - .build(), sensitivityAnalysisFailedDestination); + .build(), SENSITIVITY_ANALYSIS_FAILED_DESTINATION); return new MockResponse().setResponseCode(200).setBody("\"" + SENSITIVITY_ANALYSIS_ERROR_NODE_RESULT_UUID + "\"") .addHeader("Content-Type", "application/json; charset=utf-8"); } else if (path.matches("/v1/results/" + SENSITIVITY_ANALYSIS_RESULT_UUID + "/stop.*") @@ -238,7 +238,7 @@ public MockResponse dispatch(RecordedRequest request) { input.send(MessageBuilder.withPayload("") .setHeader("resultUuid", resultUuid) .setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D") - .build(), sensitivityAnalysisStoppedDestination); + .build(), SENSITIVITY_ANALYSIS_STOPPED_DESTINATION); return new MockResponse().setResponseCode(200) .addHeader("Content-Type", "application/json; charset=utf-8"); } else if (path.matches("/v1/results/" + SENSITIVITY_ANALYSIS_OTHER_NODE_RESULT_UUID)) { @@ -300,17 +300,17 @@ private void testSensitivityAnalysisWithNodeUuid(UUID studyUuid, UUID nodeUuid, .header("userId", "userId") .header(HEADER_USER_ID, "testUserId")).andExpect(status().isOk()); - Message sensitivityAnalysisStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message sensitivityAnalysisStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, sensitivityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); String updateType = (String) sensitivityAnalysisStatusMessage.getHeaders().get(HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SENSITIVITY_ANALYSIS_STATUS, updateType); - Message sensitivityAnalysisUpdateMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message sensitivityAnalysisUpdateMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, sensitivityAnalysisUpdateMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) sensitivityAnalysisUpdateMessage.getHeaders().get(HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SENSITIVITY_ANALYSIS_RESULT, updateType); - sensitivityAnalysisStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + sensitivityAnalysisStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, sensitivityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) sensitivityAnalysisStatusMessage.getHeaders().get(HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SENSITIVITY_ANALYSIS_STATUS, updateType); @@ -358,7 +358,7 @@ private void testSensitivityAnalysisWithNodeUuid(UUID studyUuid, UUID nodeUuid, // stop sensitivity analysis mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/sensitivity-analysis/stop", studyUuid, nodeUuid)).andExpect(status().isOk()); - sensitivityAnalysisStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + sensitivityAnalysisStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, sensitivityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) sensitivityAnalysisStatusMessage.getHeaders().get(HEADER_UPDATE_TYPE); assertTrue(updateType.equals(NotificationService.UPDATE_TYPE_SENSITIVITY_ANALYSIS_STATUS) || updateType.equals(NotificationService.UPDATE_TYPE_SENSITIVITY_ANALYSIS_RESULT)); @@ -400,17 +400,17 @@ public void testSensitivityAnalysis() throws Exception { .header(HEADER_USER_ID, "testUserId")).andExpect(status().isOk()) .andReturn(); - Message sensitivityAnalysisStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message sensitivityAnalysisStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyNameUserIdUuid, sensitivityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); String updateType = (String) sensitivityAnalysisStatusMessage.getHeaders().get(HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SENSITIVITY_ANALYSIS_STATUS, updateType); - Message sensitivityAnalysisUpdateMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message sensitivityAnalysisUpdateMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyNameUserIdUuid, sensitivityAnalysisUpdateMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) sensitivityAnalysisUpdateMessage.getHeaders().get(HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SENSITIVITY_ANALYSIS_RESULT, updateType); - sensitivityAnalysisStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + sensitivityAnalysisStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyNameUserIdUuid, sensitivityAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) sensitivityAnalysisStatusMessage.getHeaders().get(HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SENSITIVITY_ANALYSIS_STATUS, updateType); @@ -509,7 +509,7 @@ public void testResetUuidResultWhenSAFailed() { StudyService studyService = Mockito.mock(StudyService.class); doAnswer(invocation -> { - input.send(MessageBuilder.withPayload("").setHeader(HEADER_RECEIVER, resultUuidJson).build(), sensitivityAnalysisFailedDestination); + input.send(MessageBuilder.withPayload("").setHeader(HEADER_RECEIVER, resultUuidJson).build(), SENSITIVITY_ANALYSIS_FAILED_DESTINATION); return resultUuid; }).when(studyService).runSensitivityAnalysis(any(), any(), any()); studyService.runSensitivityAnalysis(studyEntity.getId(), modificationNode.getId(), "testUserId"); @@ -517,7 +517,7 @@ public void testResetUuidResultWhenSAFailed() { // Test reset uuid result in the database assertTrue(networkModificationTreeService.getComputationResultUuid(modificationNode.getId(), SENSITIVITY_ANALYSIS).isEmpty()); - Message message = output.receive(TIMEOUT, studyUpdateDestination); + Message message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyEntity.getId(), message.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); String updateType = (String) message.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SENSITIVITY_ANALYSIS_FAILED, updateType); @@ -538,13 +538,13 @@ public void testSensitivityAnalysisFailedForNotification() throws Exception { .andExpect(status().isOk()); // failed sensitivity analysis - Message message = output.receive(TIMEOUT, studyUpdateDestination); + Message message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, message.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); String updateType = (String) message.getHeaders().get(HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SENSITIVITY_ANALYSIS_FAILED, updateType); // message sent by run and save controller to notify frontend sensitivity analysis is running and should update status - message = output.receive(TIMEOUT, studyUpdateDestination); + message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, message.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) message.getHeaders().get(HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SENSITIVITY_ANALYSIS_STATUS, updateType); @@ -567,7 +567,7 @@ public void testSensitivityAnalysisFailedForNotification() throws Exception { // failed sensitivity analysis without receiver -> no failure message sent to frontend // message sent by run and save controller to notify frontend sensitivity analysis is running and should update status - message = output.receive(TIMEOUT, studyUpdateDestination); + message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid2, message.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); updateType = (String) message.getHeaders().get(HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SENSITIVITY_ANALYSIS_STATUS, updateType); @@ -606,7 +606,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header("userId", "userId")) .andExpect(status().isOk()); - var mess = output.receive(TIMEOUT, studyUpdateDestination); + var mess = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertNotNull(mess); modificationNode.setId(UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE)))); assertEquals(InsertMode.CHILD.name(), mess.getHeaders().get(NotificationService.HEADER_INSERT_MODE)); @@ -624,7 +624,7 @@ private void cleanDB() { @After public void tearDown() { - List destinations = List.of(studyUpdateDestination, sensitivityAnalysisFailedDestination, sensitivityAnalysisResultDestination, sensitivityAnalysisStoppedDestination); + List destinations = List.of(STUDY_UPDATE_DESTINATION, SENSITIVITY_ANALYSIS_FAILED_DESTINATION, SENSITIVITY_ANALYSIS_RESULT_DESTINATION, SENSITIVITY_ANALYSIS_STOPPED_DESTINATION); cleanDB(); @@ -720,11 +720,11 @@ private void setParametersAndDoChecks(UUID studyNameUserIdUuid, String parameter .content(parameters)).andExpect( status().isOk()); - Message sensiStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message sensiStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyNameUserIdUuid, sensiStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); assertEquals(NotificationService.UPDATE_TYPE_SENSITIVITY_ANALYSIS_STATUS, sensiStatusMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); - Message elementUpdateMessage = output.receive(TIMEOUT, elementUpdateDestination); + Message elementUpdateMessage = output.receive(TIMEOUT, ELEMENT_UPDATE_DESTINATION); assertEquals(studyNameUserIdUuid, elementUpdateMessage.getHeaders().get(NotificationService.HEADER_ELEMENT_UUID)); } } diff --git a/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java b/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java index 5fff2d40f..e4fccbe02 100644 --- a/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java +++ b/src/test/java/org/gridsuite/study/server/ShortCircuitTest.java @@ -123,6 +123,12 @@ public class ShortCircuitTest { private static final long TIMEOUT = 1000; + //output destinations + private static final String STUDY_UPDATE_DESTINATION = "study.update"; + private static final String SHORT_CIRCUIT_ANALYSIS_RESULT_DESTINATION = "shortcircuitanalysis.result"; + private static final String SHORT_CIRCUIT_ANALYSIS_STOPPED_DESTINATION = "shortcircuitanalysis.stopped"; + private static final String SHORT_CIRCUIT_ANALYSIS_FAILED_DESTINATION = "shortcircuitanalysis.failed"; + @Autowired private MockMvc mockMvc; @@ -154,12 +160,6 @@ public class ShortCircuitTest { @Autowired private ReportService reportService; - //output destinations - private final String studyUpdateDestination = "study.update"; - private final String shortCircuitAnalysisResultDestination = "shortcircuitanalysis.result"; - private final String shortCircuitAnalysisStoppedDestination = "shortcircuitanalysis.stopped"; - private final String shortCircuitAnalysisFailedDestination = "shortcircuitanalysis.failed"; - @Before public void setup() throws IOException { server = new MockWebServer(); @@ -195,7 +195,7 @@ public MockResponse dispatch(RecordedRequest request) { .setHeader("resultUuid", SHORT_CIRCUIT_ANALYSIS_RESULT_UUID) .setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D") .setHeader("busId", "BUS_TEST_ID") - .build(), shortCircuitAnalysisResultDestination); + .build(), SHORT_CIRCUIT_ANALYSIS_RESULT_DESTINATION); return new MockResponse().setResponseCode(200) .setBody(shortCircuitAnalysisResultUuidStr) .addHeader("Content-Type", "application/json; charset=utf-8"); @@ -203,7 +203,7 @@ public MockResponse dispatch(RecordedRequest request) { input.send(MessageBuilder.withPayload("") .setHeader("resultUuid", SHORT_CIRCUIT_ANALYSIS_RESULT_UUID) .setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D") - .build(), shortCircuitAnalysisResultDestination); + .build(), SHORT_CIRCUIT_ANALYSIS_RESULT_DESTINATION); return new MockResponse().setResponseCode(200) .setBody(shortCircuitAnalysisResultUuidStr) .addHeader("Content-Type", "application/json; charset=utf-8"); @@ -211,14 +211,14 @@ public MockResponse dispatch(RecordedRequest request) { input.send(MessageBuilder.withPayload("") .setHeader("resultUuid", SHORT_CIRCUIT_ANALYSIS_RESULT_UUID_NOT_FOUND) .setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D") - .build(), shortCircuitAnalysisResultDestination); + .build(), SHORT_CIRCUIT_ANALYSIS_RESULT_DESTINATION); return new MockResponse().setResponseCode(200) .setBody(shortCircuitAnalysisResultNotFoundUuidStr) .addHeader("Content-Type", "application/json; charset=utf-8"); } else if (path.matches("/v1/networks/" + NETWORK_UUID_STRING + "/run-and-save\\?receiver=.*&reportUuid=.*&reporterId=.*&variantId=" + VARIANT_ID)) { input.send(MessageBuilder.withPayload("") .setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D") - .build(), shortCircuitAnalysisFailedDestination); + .build(), SHORT_CIRCUIT_ANALYSIS_FAILED_DESTINATION); return new MockResponse().setResponseCode(200) .setBody(shortCircuitAnalysisErrorResultUuidStr) .addHeader("Content-Type", "application/json; charset=utf-8"); @@ -251,7 +251,7 @@ public MockResponse dispatch(RecordedRequest request) { input.send(MessageBuilder.withPayload("") .setHeader("resultUuid", resultUuid) .setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D") - .build(), shortCircuitAnalysisStoppedDestination); + .build(), SHORT_CIRCUIT_ANALYSIS_STOPPED_DESTINATION); return new MockResponse().setResponseCode(200) .addHeader("Content-Type", "application/json; charset=utf-8"); } else if (path.matches("/v1/results")) { @@ -645,7 +645,7 @@ public void testResetUuidResultWhenSCFailed() { StudyService studyService = Mockito.mock(StudyService.class); doAnswer(invocation -> { - input.send(MessageBuilder.withPayload("").setHeader(HEADER_RECEIVER, resultUuidJson).build(), shortCircuitAnalysisFailedDestination); + input.send(MessageBuilder.withPayload("").setHeader(HEADER_RECEIVER, resultUuidJson).build(), SHORT_CIRCUIT_ANALYSIS_FAILED_DESTINATION); return resultUuid; }).when(studyService).runShortCircuit(any(), any(), any()); studyService.runShortCircuit(studyEntity.getId(), modificationNode.getId(), ""); @@ -653,7 +653,7 @@ public void testResetUuidResultWhenSCFailed() { // Test reset uuid result in the database assertTrue(networkModificationTreeService.getComputationResultUuid(modificationNode.getId(), ComputationType.SHORT_CIRCUIT).isEmpty()); - Message message = output.receive(TIMEOUT, studyUpdateDestination); + Message message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyEntity.getId(), message.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); String updateType = (String) message.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_SHORT_CIRCUIT_FAILED, updateType); @@ -664,7 +664,7 @@ private void checkUpdateModelStatusMessagesReceived(UUID studyUuid, String updat } private void checkUpdateModelStatusMessagesReceived(UUID studyUuid, String updateTypeToCheck, String otherUpdateTypeToCheck) { - Message shortCircuitAnalysisStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message shortCircuitAnalysisStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, shortCircuitAnalysisStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); String updateType = (String) shortCircuitAnalysisStatusMessage.getHeaders().get(HEADER_UPDATE_TYPE); if (otherUpdateTypeToCheck == null) { @@ -802,7 +802,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header("userId", "userId")) .andExpect(status().isOk()); - var mess = output.receive(TIMEOUT, studyUpdateDestination); + var mess = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertNotNull(mess); modificationNode.setId(UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE)))); assertEquals(InsertMode.CHILD.name(), mess.getHeaders().get(NotificationService.HEADER_INSERT_MODE)); @@ -816,7 +816,7 @@ private void cleanDB() { @After public void tearDown() { - List destinations = List.of(studyUpdateDestination, shortCircuitAnalysisResultDestination, shortCircuitAnalysisStoppedDestination, shortCircuitAnalysisFailedDestination); + List destinations = List.of(STUDY_UPDATE_DESTINATION, SHORT_CIRCUIT_ANALYSIS_RESULT_DESTINATION, SHORT_CIRCUIT_ANALYSIS_STOPPED_DESTINATION, SHORT_CIRCUIT_ANALYSIS_FAILED_DESTINATION); cleanDB(); diff --git a/src/test/java/org/gridsuite/study/server/SingleLineDiagramTest.java b/src/test/java/org/gridsuite/study/server/SingleLineDiagramTest.java index 3ed1d4c41..e4eff2abd 100644 --- a/src/test/java/org/gridsuite/study/server/SingleLineDiagramTest.java +++ b/src/test/java/org/gridsuite/study/server/SingleLineDiagramTest.java @@ -95,6 +95,9 @@ public class SingleLineDiagramTest { private static final UUID CASE_UUID = UUID.fromString(CASE_UUID_STRING); private static final UUID LOADFLOW_PARAMETERS_UUID = UUID.fromString("0c0f1efd-bd22-4a75-83d3-9e530245c7f4"); + //output destinations + private static final String STUDY_UPDATE_DESTINATION = "study.update"; + @Autowired private MockMvc mockMvc; @@ -131,9 +134,6 @@ public class SingleLineDiagramTest { @Autowired private ObjectMapper objectMapper; - //output destinations - private String studyUpdateDestination = "study.update"; - @MockBean private NetworkStoreService networkStoreService; @@ -578,7 +578,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header("userId", "userId")) .andExpect(status().isOk()); - var mess = output.receive(TIMEOUT, studyUpdateDestination); + var mess = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertNotNull(mess); modificationNode.setId(UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE)))); assertEquals(InsertMode.CHILD.name(), mess.getHeaders().get(NotificationService.HEADER_INSERT_MODE)); @@ -625,7 +625,7 @@ private void cleanDB() { @After public void tearDown() { - List destinations = List.of(studyUpdateDestination); + List destinations = List.of(STUDY_UPDATE_DESTINATION); cleanDB(); diff --git a/src/test/java/org/gridsuite/study/server/StudyControllerDynamicSimulationTest.java b/src/test/java/org/gridsuite/study/server/StudyControllerDynamicSimulationTest.java index 63b7aa934..7ff03183c 100644 --- a/src/test/java/org/gridsuite/study/server/StudyControllerDynamicSimulationTest.java +++ b/src/test/java/org/gridsuite/study/server/StudyControllerDynamicSimulationTest.java @@ -40,7 +40,6 @@ import org.gridsuite.study.server.utils.elasticsearch.DisableElasticsearch; import org.json.JSONObject; import org.junit.After; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; @@ -64,7 +63,7 @@ import java.nio.charset.StandardCharsets; import java.util.*; -import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.*; import static org.mockito.BDDMockito.any; import static org.mockito.BDDMockito.eq; import static org.mockito.Mockito.when; @@ -80,6 +79,7 @@ @DisableElasticsearch @ContextConfigurationWithTestChannel public class StudyControllerDynamicSimulationTest { + private static final Logger LOGGER = LoggerFactory.getLogger(StudyControllerDynamicSimulationTest.class); private static final String API_VERSION = StudyApi.API_VERSION; private static final String DELIMITER = "/"; @@ -155,6 +155,13 @@ public class StudyControllerDynamicSimulationTest { private static final long TIMEOUT = 1000; + //output destinations + private static final String ELEMENT_UPDATE_DESTINATION = "element.update"; + private static final String STUDY_UPDATE_DESTINATION = "study.update"; + private static final String DS_RESULT_DESTINATION = "ds.result"; + private static final String DS_STOPPED_DESTINATION = "ds.stopped"; + private static final String DS_FAILED_DESTINATION = "ds.failed"; + @Autowired private MockMvc studyClient; @@ -182,25 +189,10 @@ public class StudyControllerDynamicSimulationTest { @Autowired private InputDestination input; - //output destinations - private final String elementUpdateDestination = "element.update"; - private final String studyUpdateDestination = "study.update"; - private final String dsResultDestination = "ds.result"; - private final String dsStoppedDestination = "ds.stopped"; - private final String dsFailedDestination = "ds.failed"; - - private Logger getLogger() { - return LoggerFactory.getLogger(this.getClass()); - } - - @Before - public void setup() { - } - @After public void tearDown() { cleanDB(); - List destinations = List.of(studyUpdateDestination, dsFailedDestination, dsResultDestination, dsStoppedDestination); + List destinations = List.of(STUDY_UPDATE_DESTINATION, DS_FAILED_DESTINATION, DS_RESULT_DESTINATION, DS_STOPPED_DESTINATION); TestUtils.assertQueuesEmptyThenClear(destinations, output); } @@ -246,7 +238,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU studyClient.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header("userId", "userId")) .andExpect(status().isOk()); - var mess = output.receive(TIMEOUT, studyUpdateDestination); + var mess = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertThat(mess).isNotNull(); modificationNode.setId(UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE)))); assertThat(mess.getHeaders()).containsEntry(NotificationService.HEADER_INSERT_MODE, InsertMode.CHILD.name()); @@ -277,13 +269,13 @@ public void testRunDynamicSimulationGivenRegularNodeAndFailed() throws Exception // --- check async messages emitted by runDynamicSimulation of StudyService --- // // must have message UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS from channel : studyUpdateDestination - Message dynamicSimulationStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message dynamicSimulationStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertThat(dynamicSimulationStatusMessage.getHeaders()) .containsEntry(NotificationService.HEADER_STUDY_UUID, studyUuid) .containsEntry(NotificationService.HEADER_UPDATE_TYPE, NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS); // resultUuid must be present in database at this moment UUID actualResultUuid = networkModificationTreeService.getComputationResultUuid(modificationNode1Uuid, ComputationType.DYNAMIC_SIMULATION).get(); - getLogger().info("Actual result uuid in the database = " + actualResultUuid); + LOGGER.info("Actual result uuid in the database = " + actualResultUuid); assertThat(actualResultUuid).isEqualTo(RESULT_UUID); // mock the notification from dynamic-simulation server in case of failed @@ -292,12 +284,12 @@ public void testRunDynamicSimulationGivenRegularNodeAndFailed() throws Exception input.send(MessageBuilder.withPayload("") .setHeader("resultUuid", RESULT_UUID.toString()) .setHeader("receiver", receiver) - .build(), dsFailedDestination + .build(), DS_FAILED_DESTINATION ); // --- check async messages emitted by consumeDsFailed of ConsumerService --- // // must have message UPDATE_TYPE_DYNAMIC_SIMULATION_FAILED from channel : studyUpdateDestination - dynamicSimulationStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + dynamicSimulationStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertThat(dynamicSimulationStatusMessage.getHeaders()) .containsEntry(NotificationService.HEADER_STUDY_UUID, studyUuid) .containsEntry(NotificationService.HEADER_UPDATE_TYPE, NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_FAILED); @@ -345,13 +337,13 @@ public void testRunDynamicSimulationGivenRegularNode() throws Exception { // --- check async messages emitted by runDynamicSimulation of StudyService --- // // must have message UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS from channel : studyUpdateDestination - Message dynamicSimulationStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message dynamicSimulationStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertThat(dynamicSimulationStatusMessage.getHeaders()) .containsEntry(NotificationService.HEADER_STUDY_UUID, studyUuid) .containsEntry(NotificationService.HEADER_UPDATE_TYPE, NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS); // resultUuid must be present in database at this moment UUID actualResultUuid = networkModificationTreeService.getComputationResultUuid(modificationNode1Uuid, ComputationType.DYNAMIC_SIMULATION).get(); - getLogger().info("Actual result uuid in the database = " + actualResultUuid); + LOGGER.info("Actual result uuid in the database = " + actualResultUuid); assertThat(actualResultUuid).isEqualTo(RESULT_UUID); // mock the notification from dynamic-simulation server in case of having the result @@ -360,18 +352,18 @@ public void testRunDynamicSimulationGivenRegularNode() throws Exception { input.send(MessageBuilder.withPayload("") .setHeader("resultUuid", RESULT_UUID.toString()) .setHeader("receiver", receiver) - .build(), dsResultDestination + .build(), DS_RESULT_DESTINATION ); // --- check async messages emitted by consumeDsResult of ConsumerService --- // // must have message UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS from channel : studyUpdateDestination - dynamicSimulationStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + dynamicSimulationStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertThat(dynamicSimulationStatusMessage.getHeaders()) .containsEntry(NotificationService.HEADER_STUDY_UUID, studyUuid) .containsEntry(NotificationService.HEADER_UPDATE_TYPE, NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS); // must have message UPDATE_TYPE_DYNAMIC_SIMULATION_RESULT from channel : studyUpdateDestination - Message dynamicSimulationResultMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message dynamicSimulationResultMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertThat(dynamicSimulationResultMessage.getHeaders()) .containsEntry(NotificationService.HEADER_STUDY_UUID, studyUuid) .containsEntry(NotificationService.HEADER_UPDATE_TYPE, NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_RESULT); @@ -420,13 +412,13 @@ public void testRunDynamicSimulationGivenRegularNodeAndStopped() throws Exceptio // --- check async messages emitted by runDynamicSimulation of StudyService --- // // must have message UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS from channel : studyUpdateDestination - Message dynamicSimulationStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message dynamicSimulationStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertThat(dynamicSimulationStatusMessage.getHeaders()) .containsEntry(NotificationService.HEADER_STUDY_UUID, studyUuid) .containsEntry(NotificationService.HEADER_UPDATE_TYPE, NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS); // resultUuid must be present in database at this moment UUID actualResultUuid = networkModificationTreeService.getComputationResultUuid(modificationNode1Uuid, ComputationType.DYNAMIC_SIMULATION).get(); - getLogger().info("Actual result uuid in the database = " + actualResultUuid); + LOGGER.info("Actual result uuid in the database = " + actualResultUuid); assertThat(actualResultUuid).isEqualTo(RESULT_UUID); // mock the notification from dynamic-simulation server in case of stop @@ -435,12 +427,12 @@ public void testRunDynamicSimulationGivenRegularNodeAndStopped() throws Exceptio input.send(MessageBuilder.withPayload("") .setHeader("resultUuid", RESULT_UUID.toString()) .setHeader("receiver", receiver) - .build(), dsStoppedDestination + .build(), DS_STOPPED_DESTINATION ); // --- check async messages emitted by consumeDsStopped of ConsumerService --- // // must have message UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS from channel : studyUpdateDestination - dynamicSimulationStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + dynamicSimulationStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertThat(dynamicSimulationStatusMessage.getHeaders()) .containsEntry(NotificationService.HEADER_STUDY_UUID, studyUuid) .containsEntry(NotificationService.HEADER_UPDATE_TYPE, NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS); @@ -482,8 +474,8 @@ public void testGetDynamicSimulationTimeSeriesResult() throws Exception { // --- check result --- // String timeSeriesExpectedJson = TimeSeries.toJson(timeSeries); - getLogger().info("Time series expected Json = " + timeSeriesExpectedJson); - getLogger().info("Time series result Json = " + timeSeriesResultJson); + LOGGER.info("Time series expected Json = " + timeSeriesExpectedJson); + LOGGER.info("Time series result Json = " + timeSeriesResultJson); assertThat(objectMapper.readTree(timeSeriesResultJson)).isEqualTo(objectMapper.readTree(timeSeriesExpectedJson)); } @@ -579,8 +571,8 @@ public void testGetDynamicSimulationStatus() throws Exception { // --- check result --- // DynamicSimulationStatus statusExpected = DynamicSimulationStatus.DIVERGED; - getLogger().info("Status expected = " + statusExpected); - getLogger().info("Status result = " + statusResult); + LOGGER.info("Status expected = " + statusExpected); + LOGGER.info("Status result = " + statusResult); assertThat(statusResult).isEqualTo(statusExpected); } @@ -601,8 +593,8 @@ public void testGetDynamicSimulationMappings() throws Exception { List mappingInfos = objectMapper.readValue(content, new TypeReference<>() { }); // --- check result --- // - getLogger().info("Mapping infos expected in Json = " + objectMapper.writeValueAsString(MAPPINGS)); - getLogger().info("Mapping infos result in Json = " + objectMapper.writeValueAsString(mappingInfos)); + LOGGER.info("Mapping infos expected in Json = " + objectMapper.writeValueAsString(MAPPINGS)); + LOGGER.info("Mapping infos result in Json = " + objectMapper.writeValueAsString(mappingInfos)); assertThat(mappingInfos).hasSameSizeAs(MAPPINGS); } @@ -641,8 +633,8 @@ public void testSetAndGetDynamicSimulationParameters() throws Exception { String expectedJson = objectMapper.writeValueAsString(defaultDynamicSimulationParameters); // result parameters must be identical to persisted parameters - getLogger().info("Parameters expected in Json = " + expectedJson); - getLogger().info("Parameters result in Json = " + resultJson); + LOGGER.info("Parameters expected in Json = " + expectedJson); + LOGGER.info("Parameters result in Json = " + resultJson); assertThat(objectMapper.readTree(resultJson)).isEqualTo(objectMapper.readTree(expectedJson)); } @@ -685,8 +677,8 @@ public void testGetDynamicSimulationModels() throws Exception { String expectedJson = objectMapper.writeValueAsString(MODELS); // result parameters must be identical to persisted parameters - getLogger().info("Models expect in Json = " + expectedJson); - getLogger().info("Models result in Json = " + resultJson); + LOGGER.info("Models expect in Json = " + expectedJson); + LOGGER.info("Models result in Json = " + resultJson); assertThat(objectMapper.readTree(resultJson)).isEqualTo(objectMapper.readTree(expectedJson)); } @@ -726,13 +718,13 @@ public void testGetDynamicSimulationModelsGivenEmptyMapping() throws Exception { private void checkNotificationsAfterInjectingDynamicSimulationParameters(UUID studyUuid) { // must have message UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS from channel : studyUpdateDestination - Message studyUpdateMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message studyUpdateMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertThat(studyUpdateMessage.getHeaders()) .containsEntry(NotificationService.HEADER_STUDY_UUID, studyUuid) .containsEntry(NotificationService.HEADER_UPDATE_TYPE, NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS); // must have message HEADER_USER_ID_VALUE from channel : elementUpdateDestination - Message elementUpdateMessage = output.receive(TIMEOUT, elementUpdateDestination); + Message elementUpdateMessage = output.receive(TIMEOUT, ELEMENT_UPDATE_DESTINATION); assertThat(elementUpdateMessage.getHeaders()) .containsEntry(NotificationService.HEADER_ELEMENT_UUID, studyUuid) .containsEntry(NotificationService.HEADER_MODIFIED_BY, HEADER_USER_ID_VALUE); @@ -742,19 +734,19 @@ private void checkNotificationsAfterInjectingDynamicSimulationParameters(UUID st private void checkNotificationsAfterInjectingDynamicSimulationEvent(UUID studyUuid, String crudType) { // must have message crudType from channel : studyUpdateDestination - Message studyUpdateMessageBegin = output.receive(TIMEOUT, studyUpdateDestination); + Message studyUpdateMessageBegin = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertThat(studyUpdateMessageBegin.getHeaders()) .containsEntry(NotificationService.HEADER_STUDY_UUID, studyUuid) .containsEntry(NotificationService.HEADER_UPDATE_TYPE, crudType); // must have message EVENTS_CRUD_FINISHED from channel : studyUpdateDestination - Message elementUpdateMessageFinished = output.receive(TIMEOUT, studyUpdateDestination); + Message elementUpdateMessageFinished = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertThat(elementUpdateMessageFinished.getHeaders()) .containsEntry(NotificationService.HEADER_STUDY_UUID, studyUuid) .containsEntry(NotificationService.HEADER_UPDATE_TYPE, NotificationService.EVENTS_CRUD_FINISHED); // must have message UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS from channel : studyUpdateDestination - Message studyUpdateMessageStatus = output.receive(TIMEOUT, studyUpdateDestination); + Message studyUpdateMessageStatus = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertThat(studyUpdateMessageStatus.getHeaders()) .containsEntry(NotificationService.HEADER_STUDY_UUID, studyUuid) .containsEntry(NotificationService.HEADER_UPDATE_TYPE, NotificationService.UPDATE_TYPE_DYNAMIC_SIMULATION_STATUS); diff --git a/src/test/java/org/gridsuite/study/server/StudyServiceTest.java b/src/test/java/org/gridsuite/study/server/StudyServiceTest.java index 48fac3ce1..a793fbecc 100644 --- a/src/test/java/org/gridsuite/study/server/StudyServiceTest.java +++ b/src/test/java/org/gridsuite/study/server/StudyServiceTest.java @@ -67,6 +67,18 @@ public class StudyServiceTest { private static final Logger LOGGER = LoggerFactory.getLogger(StudyServiceTest.class); + private static final long TIMEOUT = 1000; + private static final String CASE_UUID_STRING = "00000000-8cf0-11bd-b23e-10b96e4ef00d"; + private static final UUID CASE_UUID = UUID.fromString(CASE_UUID_STRING); + private static final String CASE_FORMAT_PARAM = "caseFormat"; + private static final String NETWORK_UUID_STRING = "38400000-8cf0-11bd-b23e-10b96e4ef00d"; + private static final UUID NETWORK_UUID = UUID.fromString(NETWORK_UUID_STRING); + private static final String USER_ID_HEADER = "userId"; + private static final String HEADER_UPDATE_TYPE = "updateType"; + private static final UUID LOADFLOW_PARAMETERS_UUID = UUID.fromString("0c0f1efd-bd22-4a75-83d3-9e530245c7f4"); + + private static final String STUDY_UPDATE_DESTINATION = "study.update"; + WireMockServer wireMockServer; WireMockUtils wireMockUtils; @@ -90,16 +102,6 @@ public class StudyServiceTest { ObjectMapper mapper; ObjectWriter objectWriter; - private static final long TIMEOUT = 1000; - private static final String CASE_UUID_STRING = "00000000-8cf0-11bd-b23e-10b96e4ef00d"; - private static final UUID CASE_UUID = UUID.fromString(CASE_UUID_STRING); - private static final String CASE_FORMAT_PARAM = "caseFormat"; - private static final String NETWORK_UUID_STRING = "38400000-8cf0-11bd-b23e-10b96e4ef00d"; - private static final UUID NETWORK_UUID = UUID.fromString(NETWORK_UUID_STRING); - private static final String USER_ID_HEADER = "userId"; - private static final String HEADER_UPDATE_TYPE = "updateType"; - private static final UUID LOADFLOW_PARAMETERS_UUID = UUID.fromString("0c0f1efd-bd22-4a75-83d3-9e530245c7f4"); - @Autowired private StudyRepository studyRepository; @@ -126,8 +128,6 @@ public void setup() throws IOException { networkConversionService.setNetworkConversionServerBaseUri(wireMockServer.baseUrl()); } - private final String studyUpdateDestination = "study.update"; - @Test public void testCheckNetworkExistenceReturnsOk() throws Exception { Map importParameters = new HashMap<>(); @@ -180,7 +180,7 @@ public void testRecreateStudyNetworkWithStudyCaseAndImportParameters() throws Ex countDownLatch.await(); // study network recreation done notification - Message message = output.receive(TIMEOUT, studyUpdateDestination); + Message message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); MessageHeaders headers = message.getHeaders(); assertEquals(NotificationService.UPDATE_TYPE_STUDY_NETWORK_RECREATION_DONE, headers.get(NotificationService.HEADER_UPDATE_TYPE)); assertEquals(userId, headers.get(HEADER_USER_ID)); @@ -231,7 +231,7 @@ public void testRecreateStudyNetworkFromExistingCase() throws Exception { countDownLatch.await(); // study network recreation done notification - Message message = output.receive(TIMEOUT, studyUpdateDestination); + Message message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); MessageHeaders headers = message.getHeaders(); assertEquals(NotificationService.UPDATE_TYPE_STUDY_NETWORK_RECREATION_DONE, headers.get(NotificationService.HEADER_UPDATE_TYPE)); assertEquals(userId, headers.get(HEADER_USER_ID)); @@ -300,7 +300,7 @@ private UUID createStudy(String userId, UUID caseUuid, Map impor private void assertStudyCreation(UUID studyUuid, String userId, String... errorMessage) { // assert that the broker message has been sent a study creation request message - Message message = output.receive(TIMEOUT, studyUpdateDestination); + Message message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals("", new String(message.getPayload())); MessageHeaders headers = message.getHeaders(); @@ -308,10 +308,10 @@ private void assertStudyCreation(UUID studyUuid, String userId, String... errorM assertEquals(studyUuid, headers.get(NotificationService.HEADER_STUDY_UUID)); assertEquals(NotificationService.UPDATE_TYPE_STUDIES, headers.get(HEADER_UPDATE_TYPE)); - output.receive(TIMEOUT, studyUpdateDestination); // message for first modification node creation + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); // message for first modification node creation // assert that the broker message has been sent a study creation message for creation - message = output.receive(TIMEOUT, studyUpdateDestination); + message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals("", new String(message.getPayload())); headers = message.getHeaders(); assertEquals(userId, headers.get(HEADER_USER_ID)); @@ -329,7 +329,7 @@ private void cleanDB() { @After public void tearDown() { - List destinations = List.of(studyUpdateDestination); + List destinations = List.of(STUDY_UPDATE_DESTINATION); cleanDB(); diff --git a/src/test/java/org/gridsuite/study/server/StudyTest.java b/src/test/java/org/gridsuite/study/server/StudyTest.java index 21a90cc04..7e67a5f5a 100644 --- a/src/test/java/org/gridsuite/study/server/StudyTest.java +++ b/src/test/java/org/gridsuite/study/server/StudyTest.java @@ -181,6 +181,10 @@ public class StudyTest { private static final String PROFILE_LOADFLOW_DUPLICATED_PARAMETERS_UUID_STRING = "a4ce25e1-59a7-401d-abb1-04425fe24587"; private static final String DUPLICATED_PARAMS_JSON = "\"" + PROFILE_LOADFLOW_DUPLICATED_PARAMETERS_UUID_STRING + "\""; + //output destinations + private static final String STUDY_UPDATE_DESTINATION = "study.update"; + private static final String ELEMENT_UPDATE_DESTINATION = "element.update"; + private static final String DEFAULT_PROVIDER = "defaultProvider"; @Value("${non-evacuated-energy.default-provider}") @@ -259,10 +263,6 @@ public class StudyTest { @MockBean private NetworkStoreService networkStoreService; - //output destinations - private final String studyUpdateDestination = "study.update"; - private final String elementUpdateDestination = "element.update"; - private boolean indexed = false; private static EquipmentInfos toEquipmentInfos(Line line) { @@ -841,7 +841,7 @@ public void test() throws Exception { modificationNode1.setNodeBuildStatus(NodeBuildStatus.from(BuildStatus.BUILT)); networkModificationTreeService.updateNode(studyNameUserIdUuid, modificationNode1, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); checkElementUpdatedMessageSent(studyNameUserIdUuid, userId); mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/export-network/{format}", studyNameUserIdUuid, modificationNode1Uuid, "XIIDM")) @@ -1027,7 +1027,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header(USER_ID_HEADER, userId)) .andExpect(status().isOk()); checkElementUpdatedMessageSent(studyUuid, userId); - var mess = output.receive(TIMEOUT, studyUpdateDestination); + var mess = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertNotNull(mess); modificationNode.setId(UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE)))); assertEquals(InsertMode.CHILD.name(), mess.getHeaders().get(NotificationService.HEADER_INSERT_MODE)); @@ -1124,7 +1124,7 @@ private void assertStudyCreation(UUID studyUuid, String userId, String... errorM assertTrue(studyRepository.findById(studyUuid).isPresent()); // assert that the broker message has been sent a study creation request message - Message message = output.receive(TIMEOUT, studyUpdateDestination); + Message message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals("", new String(message.getPayload())); MessageHeaders headers = message.getHeaders(); @@ -1132,10 +1132,10 @@ private void assertStudyCreation(UUID studyUuid, String userId, String... errorM assertEquals(studyUuid, headers.get(NotificationService.HEADER_STUDY_UUID)); assertEquals(NotificationService.UPDATE_TYPE_STUDIES, headers.get(HEADER_UPDATE_TYPE)); - output.receive(TIMEOUT, studyUpdateDestination); // message for first modification node creation + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); // message for first modification node creation // assert that the broker message has been sent a study creation message for creation - message = output.receive(TIMEOUT, studyUpdateDestination); + message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals("", new String(message.getPayload())); headers = message.getHeaders(); assertEquals(userId, headers.get(HEADER_USER_ID)); @@ -1247,13 +1247,13 @@ public void testGetStudyCreationRequests() throws Exception { countDownLatch.countDown(); // drop the broker message for study creation request (creation) - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); // drop the broker message for study creation - output.receive(TIMEOUT * 3, studyUpdateDestination); + output.receive(TIMEOUT * 3, STUDY_UPDATE_DESTINATION); // drop the broker message for node creation - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); // drop the broker message for study creation request (deletion) - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); mvcResult = mockMvc.perform(get("/v1/study_creation_requests").header(USER_ID_HEADER, "userId")).andExpectAll( status().isOk(), @@ -1299,13 +1299,13 @@ public void testGetStudyCreationRequests() throws Exception { countDownLatch.countDown(); // drop the broker message for study creation request (creation) - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); // drop the broker message for study creation output.receive(TIMEOUT * 3); // drop the broker message for node creation - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); // drop the broker message for study creation request (deletion) - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); mvcResult = mockMvc.perform(get("/v1/study_creation_requests") .header(USER_ID_HEADER, "userId")).andExpectAll( @@ -1337,7 +1337,7 @@ public void testGetStudyCreationRequests() throws Exception { private void checkUpdateModelStatusMessagesReceived(UUID studyUuid, UUID nodeUuid, String updateType) { // assert that the broker message has been sent for updating model status - Message messageStatus = output.receive(TIMEOUT, studyUpdateDestination); + Message messageStatus = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals("", new String(messageStatus.getPayload())); MessageHeaders headersStatus = messageStatus.getHeaders(); assertEquals(studyUuid, headersStatus.get(NotificationService.HEADER_STUDY_UUID)); @@ -1359,7 +1359,7 @@ private void checkUpdateModelsStatusMessagesReceived(UUID studyUuid, UUID nodeUu } private void checkNodeBuildStatusUpdatedMessageReceived(UUID studyUuid, List nodesUuids) { - Message messageStatus = output.receive(TIMEOUT, studyUpdateDestination); + Message messageStatus = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals("", new String(messageStatus.getPayload())); MessageHeaders headersStatus = messageStatus.getHeaders(); assertEquals(studyUuid, headersStatus.get(NotificationService.HEADER_STUDY_UUID)); @@ -1369,7 +1369,7 @@ private void checkNodeBuildStatusUpdatedMessageReceived(UUID studyUuid, List messageStudyUpdate = output.receive(TIMEOUT, studyUpdateDestination); + Message messageStudyUpdate = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); NetworkImpactsInfos actualPayload = mapper.readValue(new String(messageStudyUpdate.getPayload()), new TypeReference() { }); assertThat(expectedPayload, new MatcherJson<>(mapper, actualPayload)); @@ -1384,7 +1384,7 @@ private void checkEquipmentMessagesReceived(UUID studyNameUserIdUuid, UUID nodeU private void checkEquipmentCreatingMessagesReceived(UUID studyNameUserIdUuid, UUID nodeUuid) { // assert that the broker message has been sent for updating study type - Message messageStudyUpdate = output.receive(TIMEOUT, studyUpdateDestination); + Message messageStudyUpdate = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals("", new String(messageStudyUpdate.getPayload())); MessageHeaders headersStudyUpdate = messageStudyUpdate.getHeaders(); assertEquals(studyNameUserIdUuid, headersStudyUpdate.get(NotificationService.HEADER_STUDY_UUID)); @@ -1394,7 +1394,7 @@ private void checkEquipmentCreatingMessagesReceived(UUID studyNameUserIdUuid, UU private void checkEquipmentUpdatingFinishedMessagesReceived(UUID studyNameUserIdUuid, UUID nodeUuid) { // assert that the broker message has been sent for updating study type - Message messageStudyUpdate = output.receive(TIMEOUT, studyUpdateDestination); + Message messageStudyUpdate = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals("", new String(messageStudyUpdate.getPayload())); MessageHeaders headersStudyUpdate = messageStudyUpdate.getHeaders(); assertEquals(studyNameUserIdUuid, headersStudyUpdate.get(NotificationService.HEADER_STUDY_UUID)); @@ -1404,7 +1404,7 @@ private void checkEquipmentUpdatingFinishedMessagesReceived(UUID studyNameUserId private void checkStudyMetadataUpdatedMessagesReceived() { // assert that the broker message has been sent for updating study type - Message messageStudyUpdate = output.receive(TIMEOUT, studyUpdateDestination); + Message messageStudyUpdate = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals("", new String(messageStudyUpdate.getPayload())); MessageHeaders headersStudyUpdate = messageStudyUpdate.getHeaders(); assertEquals(NotificationService.UPDATE_TYPE_STUDY_METADATA_UPDATED, headersStudyUpdate.get(NotificationService.HEADER_UPDATE_TYPE)); @@ -1483,7 +1483,7 @@ private void testDuplicateStudy(UUID study1Uuid) throws Exception { node2.setVoltageInitResultUuid(UUID.randomUUID()); node2.setSecurityAnalysisResultUuid(UUID.randomUUID()); networkModificationTreeService.updateNode(study1Uuid, node2, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); checkElementUpdatedMessageSent(study1Uuid, userId); // duplicate the study @@ -1536,7 +1536,7 @@ public void testDuplicateStudyWithErrorDuringCaseDuplication() throws Exception ObjectMapper mapper = new ObjectMapper(); String duplicatedStudyUuid = mapper.readValue(response, String.class); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); assertNull(studyRepository.findById(UUID.fromString(duplicatedStudyUuid)).orElse(null)); } @@ -1549,20 +1549,20 @@ private StudyEntity duplicateStudy(UUID studyUuid, String userId, String caseFor ObjectMapper mapper = new ObjectMapper(); String newUuid = mapper.readValue(response, String.class); StudyEntity sourceStudy = studyRepository.findById(studyUuid).orElseThrow(); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); - Message indexationStatusMessageOnGoing = output.receive(TIMEOUT, studyUpdateDestination); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); + Message indexationStatusMessageOnGoing = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(newUuid, indexationStatusMessageOnGoing.getHeaders().get(NotificationService.HEADER_STUDY_UUID).toString()); assertEquals(NotificationService.UPDATE_TYPE_INDEXATION_STATUS, indexationStatusMessageOnGoing.getHeaders().get(HEADER_UPDATE_TYPE)); assertEquals(StudyIndexationStatus.INDEXING_ONGOING.name(), indexationStatusMessageOnGoing.getHeaders().get(NotificationService.HEADER_INDEXATION_STATUS)); - Message indexationStatusMessageDone = output.receive(TIMEOUT, studyUpdateDestination); + Message indexationStatusMessageDone = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(newUuid, indexationStatusMessageDone.getHeaders().get(NotificationService.HEADER_STUDY_UUID).toString()); assertEquals(NotificationService.UPDATE_TYPE_INDEXATION_STATUS, indexationStatusMessageDone.getHeaders().get(HEADER_UPDATE_TYPE)); assertEquals(StudyIndexationStatus.INDEXED.name(), indexationStatusMessageDone.getHeaders().get(NotificationService.HEADER_INDEXATION_STATUS)); - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); StudyEntity duplicatedStudy = studyRepository.findById(UUID.fromString(newUuid)).orElse(null); assertNotNull(duplicatedStudy); @@ -1682,7 +1682,7 @@ public void testCutAndPasteNode() throws Exception { node2.setLoadFlowResultUuid(UUID.randomUUID()); node2.setSecurityAnalysisResultUuid(UUID.randomUUID()); networkModificationTreeService.updateNode(study1Uuid, node2, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); checkElementUpdatedMessageSent(study1Uuid, userId); // node2 should not have any child @@ -1920,21 +1920,21 @@ public void testCutAndPasteSubtree() throws Exception { checkNodeBuildStatusUpdatedMessageReceived(study1Uuid, List.of(emptyNode.getId(), emptyNodeChild.getId())); //loadflow_status - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); //securityAnalysis_status - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); //sensitivityAnalysis_status - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); //nonEvacuatedEnergy_status - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); //shortCircuitAnalysis_status - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); //oneBusShortCircuitAnalysis_status - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); //dynamicSimulation_status - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); //voltageInit_status - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); checkSubtreeMovedMessageSent(study1Uuid, emptyNode.getId(), node1.getId()); checkElementUpdatedMessageSent(study1Uuid, userId); @@ -2001,7 +2001,7 @@ public void testDuplicateNode() throws Exception { node2.setLoadFlowResultUuid(UUID.randomUUID()); node2.setSecurityAnalysisResultUuid(UUID.randomUUID()); networkModificationTreeService.updateNode(study1Uuid, node2, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); checkElementUpdatedMessageSent(study1Uuid, userId); //node2 should not have any child @@ -2127,7 +2127,7 @@ public void testDuplicateSubtree() throws Exception { node2.setLoadFlowResultUuid(UUID.randomUUID()); node2.setSecurityAnalysisResultUuid(UUID.randomUUID()); networkModificationTreeService.updateNode(study1Uuid, node2, userId); - output.receive(TIMEOUT, studyUpdateDestination); + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); checkElementUpdatedMessageSent(study1Uuid, userId); //node 4 should not have any children @@ -2288,7 +2288,7 @@ private void cutAndPasteNode(UUID studyUuid, NetworkModificationNode nodeToCopy, * moving node */ //nodeMoved - Message message = output.receive(TIMEOUT, studyUpdateDestination); + Message message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, message.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); assertEquals(NotificationService.NODE_MOVED, message.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); assertEquals(nodeToCopy.getId(), message.getHeaders().get(NotificationService.HEADER_MOVED_NODE)); @@ -2300,52 +2300,52 @@ private void cutAndPasteNode(UUID studyUuid, NetworkModificationNode nodeToCopy, */ IntStream.rangeClosed(1, childCount).forEach(i -> { //nodeUpdated - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); //loadflow_status - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); //securityAnalysis_status - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); //sensitivityAnalysis_status - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); //nonEvacuatedEnergy_status - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); //shortCircuitAnalysis_status - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); //oneBusShortCircuitAnalysis_status - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); //dynamicSimulation_status - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); //voltageInit_status - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); }); /* * invalidating new children */ //nodeUpdated - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); //loadflow_status - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); //securityAnalysis_status - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); //sensitivityAnalysis_status - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); //sensitivityAnalysisonEvacuated_status - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); //shortCircuitAnalysis_status - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); //oneBusShortCircuitAnalysis_status - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); //dynamicSimulation_status - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); //voltageInit_status - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); } else { /* * Invalidating moved node */ //nodeUpdated - assertNotNull(output.receive(TIMEOUT, studyUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION)); } } @@ -2373,9 +2373,9 @@ private UUID duplicateNode(UUID sourceStudyUuid, UUID targetStudyUuid, NetworkMo nodesAfterDuplication.removeAll(allNodesBeforeDuplication); assertEquals(1, nodesAfterDuplication.size()); - output.receive(TIMEOUT, studyUpdateDestination); // nodeCreated + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); // nodeCreated if (!EMPTY_MODIFICATION_GROUP_UUID.equals(nodeToCopy.getModificationGroupUuid())) { - output.receive(TIMEOUT, studyUpdateDestination); // nodeUpdated + output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); // nodeUpdated } checkUpdateModelsStatusMessagesReceived(targetStudyUuid, nodesAfterDuplication.get(0)); checkElementUpdatedMessageSent(targetStudyUuid, userId); @@ -2407,7 +2407,7 @@ public void testGetDefaultProviders() throws Exception { } private void checkSubtreeMovedMessageSent(UUID studyUuid, UUID movedNodeUuid, UUID referenceNodeUuid) { - Message message = output.receive(TIMEOUT, studyUpdateDestination); + Message message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(NotificationService.SUBTREE_MOVED, message.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); assertEquals(studyUuid, message.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); assertEquals(movedNodeUuid, message.getHeaders().get(NotificationService.HEADER_MOVED_NODE)); @@ -2416,7 +2416,7 @@ private void checkSubtreeMovedMessageSent(UUID studyUuid, UUID movedNodeUuid, UU } private void checkSubtreeCreatedMessageSent(UUID studyUuid, UUID newNodeUuid, UUID referenceNodeUuid) { - Message message = output.receive(TIMEOUT, studyUpdateDestination); + Message message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(NotificationService.SUBTREE_CREATED, message.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); assertEquals(studyUuid, message.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); assertEquals(newNodeUuid, message.getHeaders().get(NotificationService.HEADER_NEW_NODE)); @@ -2425,7 +2425,7 @@ private void checkSubtreeCreatedMessageSent(UUID studyUuid, UUID newNodeUuid, UU } private void checkElementUpdatedMessageSent(UUID elementUuid, String userId) { - Message message = output.receive(TIMEOUT, elementUpdateDestination); + Message message = output.receive(TIMEOUT, ELEMENT_UPDATE_DESTINATION); assertEquals(elementUuid, message.getHeaders().get(NotificationService.HEADER_ELEMENT_UUID)); assertEquals(userId, message.getHeaders().get(NotificationService.HEADER_MODIFIED_BY)); } @@ -2442,8 +2442,8 @@ public void reindexStudyTest() throws Exception { mockMvc.perform(post("/v1/studies/{studyUuid}/reindex-all", notExistingNetworkStudyUuid)) .andExpect(status().isInternalServerError()); - Message indexationStatusMessageOnGoing = output.receive(TIMEOUT, studyUpdateDestination); - Message indexationStatusMessageNotIndexed = output.receive(TIMEOUT, studyUpdateDestination); + Message indexationStatusMessageOnGoing = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); + Message indexationStatusMessageNotIndexed = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); var requests = TestUtils.getRequestsWithBodyDone(1, server); assertTrue(requests.stream().anyMatch(r -> r.getPath().contains("/v1/networks/" + NOT_EXISTING_NETWORK_UUID + "/reindex-all"))); @@ -2459,13 +2459,13 @@ public void reindexStudyTest() throws Exception { mockMvc.perform(get("/v1/studies/{studyUuid}/indexation/status", study1Uuid)) .andExpectAll(status().isOk(), content().string("NOT_INDEXED")); - indexationStatusMessageNotIndexed = output.receive(TIMEOUT, studyUpdateDestination); + indexationStatusMessageNotIndexed = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); mockMvc.perform(post("/v1/studies/{studyUuid}/reindex-all", study1Uuid)) .andExpect(status().isOk()); - indexationStatusMessageOnGoing = output.receive(TIMEOUT, studyUpdateDestination); - Message indexationStatusMessageDone = output.receive(TIMEOUT, studyUpdateDestination); + indexationStatusMessageOnGoing = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); + Message indexationStatusMessageDone = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(study1Uuid, indexationStatusMessageDone.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); assertEquals(NotificationService.UPDATE_TYPE_INDEXATION_STATUS, indexationStatusMessageDone.getHeaders().get(HEADER_UPDATE_TYPE)); @@ -2478,14 +2478,14 @@ public void reindexStudyTest() throws Exception { assertEquals(2, requests.stream().filter(r -> r.getPath().contains("/v1/networks/" + NETWORK_UUID_STRING + "/indexed-equipments")).count()); assertEquals(1, requests.stream().filter(r -> r.getPath().matches("/v1/reports/.*")).count()); - Message buildStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message buildStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(study1Uuid, buildStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); assertEquals(NotificationService.NODE_BUILD_STATUS_UPDATED, buildStatusMessage.getHeaders().get(HEADER_UPDATE_TYPE)); mockMvc.perform(post("/v1/studies/{studyUuid}/reindex-all", study1Uuid)) .andExpect(status().is5xxServerError()); - indexationStatusMessageOnGoing = output.receive(TIMEOUT, studyUpdateDestination); - indexationStatusMessageNotIndexed = output.receive(TIMEOUT, studyUpdateDestination); + indexationStatusMessageOnGoing = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); + indexationStatusMessageNotIndexed = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); requests = TestUtils.getRequestsWithBodyDone(1, server); assertTrue(requests.stream().anyMatch(r -> r.getPath().contains("/v1/networks/" + NETWORK_UUID_STRING + "/reindex-all"))); @@ -2504,30 +2504,30 @@ public void providerTest() throws Exception { .contentType(MediaType.TEXT_PLAIN) .header(USER_ID_HEADER, USER_ID_HEADER)) .andExpect(status().isOk()); - Message message = output.receive(TIMEOUT, studyUpdateDestination); + Message message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertNotNull(message); assertEquals(NotificationService.UPDATE_TYPE_LOADFLOW_STATUS, message.getHeaders().get(HEADER_UPDATE_TYPE)); - assertNotNull(output.receive(TIMEOUT, elementUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, ELEMENT_UPDATE_DESTINATION)); mockMvc.perform(post("/v1/studies/{studyUuid}/security-analysis/provider", studyUuid) .content("SuperSA") .contentType(MediaType.TEXT_PLAIN) .header(USER_ID_HEADER, USER_ID_HEADER)) .andExpect(status().isOk()); - message = output.receive(TIMEOUT, studyUpdateDestination); + message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertNotNull(message); assertEquals(NotificationService.UPDATE_TYPE_SECURITY_ANALYSIS_STATUS, message.getHeaders().get(HEADER_UPDATE_TYPE)); - assertNotNull(output.receive(TIMEOUT, elementUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, ELEMENT_UPDATE_DESTINATION)); mockMvc.perform(post("/v1/studies/{studyUuid}/non-evacuated-energy/provider", studyUuid) .content("SuperNEE") .contentType(MediaType.TEXT_PLAIN) .header(USER_ID_HEADER, USER_ID_HEADER)) .andExpect(status().isOk()); - message = output.receive(TIMEOUT, studyUpdateDestination); + message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertNotNull(message); assertEquals(NotificationService.UPDATE_TYPE_NON_EVACUATED_ENERGY_STATUS, message.getHeaders().get(HEADER_UPDATE_TYPE)); - assertNotNull(output.receive(TIMEOUT, elementUpdateDestination)); + assertNotNull(output.receive(TIMEOUT, ELEMENT_UPDATE_DESTINATION)); mockMvc.perform(get("/v1/studies/{studyUuid}/non-evacuated-energy/provider", studyUuid)) .andExpectAll(status().isOk(), @@ -2539,7 +2539,7 @@ public void providerTest() throws Exception { @After public void tearDown() { - List destinations = List.of(studyUpdateDestination, elementUpdateDestination); + List destinations = List.of(STUDY_UPDATE_DESTINATION, ELEMENT_UPDATE_DESTINATION); cleanDB(); diff --git a/src/test/java/org/gridsuite/study/server/VoltageInitTest.java b/src/test/java/org/gridsuite/study/server/VoltageInitTest.java index 0fa7b83f6..940d44a19 100644 --- a/src/test/java/org/gridsuite/study/server/VoltageInitTest.java +++ b/src/test/java/org/gridsuite/study/server/VoltageInitTest.java @@ -151,6 +151,13 @@ public class VoltageInitTest { private static final String MODIFICATIONS_GROUP_UUID = "aaaaaaaa-bbbb-cccc-8c82-1c90300da329"; + //output destinations + private static final String STUDY_UPDATE_DESTINATION = "study.update"; + private static final String VOLTAGE_INIT_RESULT_DESTINATION = "voltageinit.result"; + private static final String VOLTAGE_INIT_STOPPED_DESTINATION = "voltageinit.stopped"; + private static final String VOLTAGE_INIT_FAILED_DESTINATION = "voltageinit.failed"; + private static final String ELEMENT_UPDATE_DESTINATION = "element.update"; + @Autowired private MockMvc mockMvc; @@ -197,13 +204,6 @@ public class VoltageInitTest { @Autowired private NetworkModificationNodeInfoRepository networkModificationNodeInfoRepository; - //output destinations - private final String studyUpdateDestination = "study.update"; - private final String voltageInitResultDestination = "voltageinit.result"; - private final String voltageInitStoppedDestination = "voltageinit.stopped"; - private final String voltageInitFailedDestination = "voltageinit.failed"; - private final String elementUpdateDestination = "element.update"; - @Before public void setup() throws IOException { server = new MockWebServer(); @@ -245,7 +245,7 @@ public MockResponse dispatch(RecordedRequest request) { .setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D") .setHeader(HEADER_REACTIVE_SLACKS_OVER_THRESHOLD, Boolean.TRUE) .setHeader(HEADER_REACTIVE_SLACKS_THRESHOLD_VALUE, 10.) - .build(), voltageInitResultDestination); + .build(), VOLTAGE_INIT_RESULT_DESTINATION); return new MockResponse().setResponseCode(200) .setBody(voltageInitResultUuidStr) .addHeader("Content-Type", "application/json; charset=utf-8"); @@ -253,7 +253,7 @@ public MockResponse dispatch(RecordedRequest request) { input.send(MessageBuilder.withPayload("") .setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D") .setHeader("resultUuid", VOLTAGE_INIT_ERROR_RESULT_UUID) - .build(), voltageInitFailedDestination); + .build(), VOLTAGE_INIT_FAILED_DESTINATION); return new MockResponse().setResponseCode(200) .setBody(voltageInitErrorResultUuidStr) .addHeader("Content-Type", "application/json; charset=utf-8"); @@ -281,7 +281,7 @@ public MockResponse dispatch(RecordedRequest request) { input.send(MessageBuilder.withPayload("") .setHeader("resultUuid", resultUuid) .setHeader("receiver", "%7B%22nodeUuid%22%3A%22" + request.getPath().split("%")[5].substring(4) + "%22%2C%22userId%22%3A%22userId%22%7D") - .build(), voltageInitStoppedDestination); + .build(), VOLTAGE_INIT_STOPPED_DESTINATION); return new MockResponse().setResponseCode(200) .addHeader("Content-Type", "application/json; charset=utf-8"); } else if (path.matches("/v1/results/invalidate-status.*")) { @@ -331,11 +331,11 @@ private void createOrUpdateParametersAndDoChecks(UUID studyNameUserIdUuid, Study .content(objectMapper.writeValueAsString(parameters))).andExpect( status().isOk()); - Message voltageInitStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message voltageInitStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyNameUserIdUuid, voltageInitStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); assertEquals(NotificationService.UPDATE_TYPE_VOLTAGE_INIT_STATUS, voltageInitStatusMessage.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE)); - Message elementUpdateMessage = output.receive(TIMEOUT, elementUpdateDestination); + Message elementUpdateMessage = output.receive(TIMEOUT, ELEMENT_UPDATE_DESTINATION); assertEquals(studyNameUserIdUuid, elementUpdateMessage.getHeaders().get(NotificationService.HEADER_ELEMENT_UUID)); } @@ -398,7 +398,7 @@ public void testUpdatingParametersWithSameComputationParametersDoesNotInvalidate TestUtils.assertRequestMatches("GET", "/v1/parameters/.*", server); // STUDY_CHANGED event - output.receive(1000, studyUpdateDestination); + output.receive(1000, STUDY_UPDATE_DESTINATION); } @Test @@ -428,9 +428,9 @@ public void testApplyModificationsWhenParameterIsActivated() throws Exception { TestUtils.assertRequestMatches("PUT", "/v1/results/.*/modifications-group-uuid", server); // Applying modifications also invalidate all results of the node, so it creates a lot of study update notifications - IntStream.range(0, 18).forEach(i -> output.receive(1000, studyUpdateDestination)); + IntStream.range(0, 18).forEach(i -> output.receive(1000, STUDY_UPDATE_DESTINATION)); // It deletes the voltage-init modification and creates a new one on the node - IntStream.range(0, 2).forEach(i -> output.receive(1000, elementUpdateDestination)); + IntStream.range(0, 2).forEach(i -> output.receive(1000, ELEMENT_UPDATE_DESTINATION)); } @Test @@ -585,14 +585,14 @@ private void checkUpdateModelsStatusMessagesReceived(UUID studyUuid) { } private void checkElementUpdatedMessageSent(UUID elementUuid, String userId) { - Message message = output.receive(TIMEOUT, elementUpdateDestination); + Message message = output.receive(TIMEOUT, ELEMENT_UPDATE_DESTINATION); assertEquals(elementUuid, message.getHeaders().get(NotificationService.HEADER_ELEMENT_UUID)); assertEquals(userId, message.getHeaders().get(NotificationService.HEADER_MODIFIED_BY)); } private void checkEquipmentUpdatingFinishedMessagesReceived(UUID studyNameUserIdUuid, UUID nodeUuid) { // assert that the broker message has been sent for updating study type - Message messageStudyUpdate = output.receive(TIMEOUT, studyUpdateDestination); + Message messageStudyUpdate = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals("", new String(messageStudyUpdate.getPayload())); MessageHeaders headersStudyUpdate = messageStudyUpdate.getHeaders(); assertEquals(studyNameUserIdUuid, headersStudyUpdate.get(NotificationService.HEADER_STUDY_UUID)); @@ -601,7 +601,7 @@ private void checkEquipmentUpdatingFinishedMessagesReceived(UUID studyNameUserId } private void checkNodesBuildStatusUpdatedMessageReceived(UUID studyUuid, List nodesUuids) { - Message messageStatus = output.receive(TIMEOUT, studyUpdateDestination); + Message messageStatus = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals("", new String(messageStatus.getPayload())); MessageHeaders headersStatus = messageStatus.getHeaders(); assertEquals(studyUuid, headersStatus.get(NotificationService.HEADER_STUDY_UUID)); @@ -611,7 +611,7 @@ private void checkNodesBuildStatusUpdatedMessageReceived(UUID studyUuid, List messageStudyUpdate = output.receive(TIMEOUT, studyUpdateDestination); + Message messageStudyUpdate = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals("", new String(messageStudyUpdate.getPayload())); MessageHeaders headersStudyUpdate = messageStudyUpdate.getHeaders(); assertEquals(studyNameUserIdUuid, headersStudyUpdate.get(NotificationService.HEADER_STUDY_UUID)); @@ -639,7 +639,7 @@ public void testNotResetedUuidResultWhenVoltageInitFailed() { MessageBuilder.withPayload("") .setHeader(HEADER_RECEIVER, resultUuidJson) .setHeader("resultUuid", VOLTAGE_INIT_ERROR_RESULT_UUID) - .build(), voltageInitFailedDestination); + .build(), VOLTAGE_INIT_FAILED_DESTINATION); return resultUuid; }).when(studyService).runVoltageInit(any(), any(), any()); studyService.runVoltageInit(studyEntity.getId(), modificationNode.getId(), ""); @@ -647,7 +647,7 @@ public void testNotResetedUuidResultWhenVoltageInitFailed() { // Test doesn't reset uuid result in the database assertEquals(VOLTAGE_INIT_ERROR_RESULT_UUID, networkModificationTreeService.getComputationResultUuid(modificationNode.getId(), VOLTAGE_INITIALIZATION).get().toString()); - Message message = output.receive(TIMEOUT, studyUpdateDestination); + Message message = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyEntity.getId(), message.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); String updateType = (String) message.getHeaders().get(NotificationService.HEADER_UPDATE_TYPE); assertEquals(NotificationService.UPDATE_TYPE_VOLTAGE_INIT_FAILED, updateType); @@ -658,7 +658,7 @@ private void checkUpdateModelStatusMessagesReceived(UUID studyUuid, String updat } private void checkUpdateModelStatusMessagesReceived(UUID studyUuid, String updateTypeToCheck, String otherUpdateTypeToCheck) { - Message voltageInitStatusMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message voltageInitStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, voltageInitStatusMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); String updateType = (String) voltageInitStatusMessage.getHeaders().get(HEADER_UPDATE_TYPE); if (otherUpdateTypeToCheck == null) { @@ -752,7 +752,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header("userId", "userId")) .andExpect(status().isOk()); - var mess = output.receive(TIMEOUT, studyUpdateDestination); + var mess = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertNotNull(mess); modificationNode.setId(UUID.fromString(String.valueOf(mess.getHeaders().get(NotificationService.HEADER_NEW_NODE)))); assertEquals(InsertMode.CHILD.name(), mess.getHeaders().get(NotificationService.HEADER_INSERT_MODE)); @@ -766,7 +766,7 @@ private void cleanDB() { @After public void tearDown() { - List destinations = List.of(studyUpdateDestination, voltageInitResultDestination, voltageInitStoppedDestination, voltageInitFailedDestination); + List destinations = List.of(STUDY_UPDATE_DESTINATION, VOLTAGE_INIT_RESULT_DESTINATION, VOLTAGE_INIT_STOPPED_DESTINATION, VOLTAGE_INIT_FAILED_DESTINATION); cleanDB(); @@ -795,7 +795,7 @@ private static StudyVoltageInitParameters createStudyVoltageInitParameters(boole } private void checkReactiveSlacksAlertMessagesReceived(UUID studyUuid, Double thresholdValue) throws Exception { - Message voltageInitMessage = output.receive(TIMEOUT, studyUpdateDestination); + Message voltageInitMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION); assertEquals(studyUuid, voltageInitMessage.getHeaders().get(NotificationService.HEADER_STUDY_UUID)); assertEquals(STUDY_ALERT, voltageInitMessage.getHeaders().get(HEADER_UPDATE_TYPE)); assertNotNull(voltageInitMessage.getPayload());