-
Notifications
You must be signed in to change notification settings - Fork 1
Implement state estimation result provider and service #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
achour94
merged 2 commits into
main
from
results/implement-state-estimation-result-provider
Feb 25, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,4 +11,5 @@ | |
| */ | ||
| public enum ResultType { | ||
| SECURITY_ANALYSIS, | ||
| STATE_ESTIMATION | ||
| } | ||
39 changes: 39 additions & 0 deletions
39
...er/src/main/java/org/gridsuite/monitor/server/services/StateEstimationResultProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /** | ||
| * Copyright (c) 2026, RTE (http://www.rte-france.com) | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
| package org.gridsuite.monitor.server.services; | ||
|
|
||
| import org.gridsuite.monitor.commons.ResultType; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| /** | ||
| * @author Achour BERRAHMA <achour.berrahma at rte-france.com> | ||
| */ | ||
| @Service | ||
| public class StateEstimationResultProvider implements ResultProvider { | ||
| private final StateEstimationService stateEstimationService; | ||
|
|
||
| public StateEstimationResultProvider(StateEstimationService stateEstimationService) { | ||
| this.stateEstimationService = stateEstimationService; | ||
| } | ||
|
|
||
| @Override | ||
| public ResultType getType() { | ||
| return ResultType.STATE_ESTIMATION; | ||
| } | ||
|
|
||
| @Override | ||
| public String getResult(UUID resultId) { | ||
| return stateEstimationService.getResult(resultId); | ||
| } | ||
|
|
||
| @Override | ||
| public void deleteResult(UUID resultId) { | ||
| stateEstimationService.deleteResult(resultId); | ||
| } | ||
| } |
67 changes: 67 additions & 0 deletions
67
...or-server/src/main/java/org/gridsuite/monitor/server/services/StateEstimationService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /** | ||
| * Copyright (c) 2026, RTE (http://www.rte-france.com) | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
| package org.gridsuite.monitor.server.services; | ||
|
|
||
| import lombok.Setter; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.boot.web.client.RestTemplateBuilder; | ||
| import org.springframework.http.HttpMethod; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.web.client.RestTemplate; | ||
| import org.springframework.web.util.UriComponentsBuilder; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| /** | ||
| * @author Achour BERRAHMA <achour.berrahma at rte-france.com> | ||
| */ | ||
| @Service | ||
| public class StateEstimationService { | ||
| private static final Logger LOGGER = LoggerFactory.getLogger(StateEstimationService.class); | ||
| static final String SE_API_VERSION = "v1"; | ||
| private static final String DELIMITER = "/"; | ||
|
|
||
| private final RestTemplate restTemplate; | ||
|
|
||
| @Setter | ||
| private String stateEstimationServerBaseUri; | ||
|
|
||
| private String getStateEstimationServerBaseUri() { | ||
| return this.stateEstimationServerBaseUri + DELIMITER + SE_API_VERSION + DELIMITER; | ||
| } | ||
|
|
||
| public StateEstimationService( | ||
| RestTemplateBuilder restTemplateBuilder, | ||
| @Value("${gridsuite.services.state-estimation-server.base-uri:http://state-estimation-server/}") String stateEstimationServerBaseUri) { | ||
| this.stateEstimationServerBaseUri = stateEstimationServerBaseUri; | ||
| this.restTemplate = restTemplateBuilder.build(); | ||
| } | ||
|
|
||
| public String getResult(UUID resultUuid) { | ||
| LOGGER.info("Fetching state estimation result {}", resultUuid); | ||
|
|
||
| var path = UriComponentsBuilder.fromPath("/results/{resultUuid}") | ||
| .buildAndExpand(resultUuid) | ||
| .toUriString(); | ||
|
|
||
| return restTemplate.exchange(getStateEstimationServerBaseUri() + path, HttpMethod.GET, null, String.class).getBody(); | ||
| } | ||
|
|
||
| public void deleteResult(UUID resultUuid) { | ||
| LOGGER.info("Deleting state estimation result {}", resultUuid); | ||
|
|
||
| var path = UriComponentsBuilder.fromPath("/results") | ||
| .queryParam("resultsUuids", List.of(resultUuid)) | ||
| .build() | ||
| .toUriString(); | ||
|
|
||
| restTemplate.delete(getStateEstimationServerBaseUri() + path); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...rc/test/java/org/gridsuite/monitor/server/services/StateEstimationResultProviderTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /** | ||
| * Copyright (c) 2026, RTE (http://www.rte-france.com) | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
| package org.gridsuite.monitor.server.services; | ||
|
|
||
| import org.gridsuite.monitor.commons.ResultType; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.Mockito; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.mockito.Mockito.*; | ||
|
|
||
| /** | ||
| * @author Achour BERRAHMA <achour.berrahma at rte-france.com> | ||
| */ | ||
| class StateEstimationResultProviderTest { | ||
| private final StateEstimationService stateEstimationService = | ||
| Mockito.mock(StateEstimationService.class); | ||
|
|
||
| private final StateEstimationResultProvider provider = | ||
| new StateEstimationResultProvider(stateEstimationService); | ||
|
|
||
| @Test | ||
| void getTypeShouldReturnStateEstimation() { | ||
| assertThat(provider.getType()) | ||
| .isEqualTo(ResultType.STATE_ESTIMATION); | ||
| } | ||
|
|
||
| @Test | ||
| void getResultShouldDelegateToStateEstimationService() { | ||
| UUID id = UUID.randomUUID(); | ||
| String expected = "result"; | ||
|
|
||
| when(stateEstimationService.getResult(id)).thenReturn(expected); | ||
|
|
||
| String result = provider.getResult(id); | ||
|
|
||
| assertThat(result).isEqualTo(expected); | ||
| verify(stateEstimationService).getResult(id); | ||
| verifyNoMoreInteractions(stateEstimationService); | ||
| } | ||
|
|
||
| @Test | ||
| void deleteResultShouldDelegateToStateEstimationService() { | ||
| UUID id = UUID.randomUUID(); | ||
|
|
||
| doNothing().when(stateEstimationService).deleteResult(id); | ||
|
|
||
| provider.deleteResult(id); | ||
|
|
||
| verify(stateEstimationService).deleteResult(id); | ||
| verifyNoMoreInteractions(stateEstimationService); | ||
| } | ||
| } |
98 changes: 98 additions & 0 deletions
98
...erver/src/test/java/org/gridsuite/monitor/server/services/StateEstimationServiceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /** | ||
| * Copyright (c) 2026, RTE (http://www.rte-france.com) | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
| package org.gridsuite.monitor.server.services; | ||
|
|
||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.autoconfigure.web.client.RestClientTest; | ||
| import org.springframework.http.HttpMethod; | ||
| import org.springframework.http.MediaType; | ||
| import org.springframework.test.context.ContextConfiguration; | ||
| import org.springframework.test.web.client.MockRestServiceServer; | ||
| import org.springframework.test.web.client.match.MockRestRequestMatchers; | ||
| import org.springframework.test.web.client.response.MockRestResponseCreators; | ||
| import org.springframework.web.client.RestClientException; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThatNoException; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
| import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
|
||
| /** | ||
| * @author Achour BERRAHMA <achour.berrahma at rte-france.com> | ||
| */ | ||
| @RestClientTest(StateEstimationService.class) | ||
| @ContextConfiguration(classes = { StateEstimationService.class }) | ||
| class StateEstimationServiceTest { | ||
|
|
||
| private static final UUID RESULT_UUID = UUID.randomUUID(); | ||
| private static final String RESULT_BODY = "{\"status\":\"OK\"}"; | ||
|
|
||
| @Autowired | ||
| private StateEstimationService stateEstimationService; | ||
|
|
||
| @Autowired | ||
| private MockRestServiceServer server; | ||
|
|
||
| @AfterEach | ||
| void tearDown() { | ||
| server.verify(); | ||
| } | ||
|
|
||
| @Test | ||
| void getResult() { | ||
| server.expect(MockRestRequestMatchers.method(HttpMethod.GET)) | ||
| .andExpect(MockRestRequestMatchers.requestTo( | ||
| "http://state-estimation-server/v1/results/" + RESULT_UUID | ||
| )) | ||
| .andRespond(MockRestResponseCreators.withSuccess( | ||
| RESULT_BODY, | ||
| MediaType.APPLICATION_JSON | ||
| )); | ||
|
|
||
| String result = stateEstimationService.getResult(RESULT_UUID); | ||
|
|
||
| assertThat(result).isEqualTo(RESULT_BODY); | ||
| } | ||
|
|
||
| @Test | ||
| void getResultFailed() { | ||
| server.expect(MockRestRequestMatchers.method(HttpMethod.GET)) | ||
| .andExpect(MockRestRequestMatchers.requestTo( | ||
| "http://state-estimation-server/v1/results/" + RESULT_UUID | ||
| )) | ||
| .andRespond(MockRestResponseCreators.withServerError()); | ||
|
|
||
| assertThatThrownBy(() -> stateEstimationService.getResult(RESULT_UUID)) | ||
| .isInstanceOf(RestClientException.class); | ||
| } | ||
|
|
||
| @Test | ||
| void deleteResult() { | ||
| server.expect(MockRestRequestMatchers.method(HttpMethod.DELETE)) | ||
| .andExpect(MockRestRequestMatchers.requestTo( | ||
| "http://state-estimation-server/v1/results?resultsUuids=" + RESULT_UUID | ||
| )) | ||
| .andRespond(MockRestResponseCreators.withSuccess()); | ||
|
|
||
| assertThatNoException().isThrownBy(() -> stateEstimationService.deleteResult(RESULT_UUID)); | ||
| } | ||
|
|
||
| @Test | ||
| void deleteResultFailed() { | ||
| server.expect(MockRestRequestMatchers.method(HttpMethod.DELETE)) | ||
| .andExpect(MockRestRequestMatchers.requestTo( | ||
| "http://state-estimation-server/v1/results?resultsUuids=" + RESULT_UUID | ||
| )) | ||
| .andRespond(MockRestResponseCreators.withServerError()); | ||
|
|
||
| assertThatThrownBy(() -> stateEstimationService.deleteResult(RESULT_UUID)) | ||
| .isInstanceOf(RestClientException.class); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normalize the base URI to avoid
//v1//resultsrequests.With a trailing slash in the default base URI and leading slashes in paths, the constructed URLs contain double slashes, which can break strict path matching and won’t match the test expectations.
🔧 Proposed fix
🤖 Prompt for AI Agents