-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adapt the RaoRequest to the new builder pattern (#166)
* adapt the RaoRequest to the new builder pattern * rao-runner : 1.18.0 -> 1.18.1 * add tests for the RaoRunnerService * add tests for the RaoRunnerService * add tests for the RaoRunnerService * Fix test --------- Co-authored-by: Theo Pascoli <theo.pascoli@rte-france.com> Co-authored-by: vbochetRTE <vincent.bochet@rte-france.com>
- Loading branch information
1 parent
8ce32d1
commit ddd0577
Showing
5 changed files
with
161 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
81 changes: 81 additions & 0 deletions
81
...t/java/com/farao_community/farao/cse/export_runner/app/services/RaoRunnerServiceTest.java
This file contains 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,81 @@ | ||
/* | ||
* Copyright (c) 2022, 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 com.farao_community.farao.cse.export_runner.app.services; | ||
|
||
import com.farao_community.farao.cse.runner.api.exception.CseInternalException; | ||
import com.farao_community.farao.rao_runner.api.resource.RaoRequest; | ||
import com.farao_community.farao.rao_runner.api.resource.RaoResponse; | ||
import com.farao_community.farao.rao_runner.starter.RaoRunnerClient; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* @author Theo Pascoli {@literal <theo.pascoli at rte-france.com>} | ||
*/ | ||
@SpringBootTest | ||
class RaoRunnerServiceTest { | ||
|
||
@Mock | ||
private RaoRunnerClient raoRunnerClient; | ||
|
||
@InjectMocks | ||
private RaoRunnerService raoRunnerService; | ||
|
||
private final String id = "testId"; | ||
private final String networkPresignedUrl = "http://network.url"; | ||
private final String cracInJsonFormatUrl = "http://crac.url"; | ||
private final String raoParametersUrl = "http://parameters.url"; | ||
private final String artifactDestinationPath = "/path/to/artifact"; | ||
|
||
@Test | ||
void testRunSuccessful() throws CseInternalException { | ||
RaoResponse expectedResponse = new RaoResponse.RaoResponseBuilder().withId("id").build(); // Assuming RaoResponse is a valid response type | ||
|
||
when(raoRunnerClient.runRao(any(RaoRequest.class))).thenReturn(expectedResponse); | ||
|
||
RaoResponse actualResponse = raoRunnerService.run(id, networkPresignedUrl, cracInJsonFormatUrl, raoParametersUrl, artifactDestinationPath); | ||
|
||
assertEquals(expectedResponse, actualResponse); | ||
} | ||
|
||
@Test | ||
void testRunThrowsCseInternalException() { | ||
when(raoRunnerClient.runRao(any())).thenThrow(new RuntimeException("Test exception")); | ||
|
||
Exception exception = assertThrows(CseInternalException.class, () -> { | ||
raoRunnerService.run(id, networkPresignedUrl, cracInJsonFormatUrl, raoParametersUrl, artifactDestinationPath); | ||
}); | ||
|
||
String expectedMessage = "RAO run failed"; | ||
String actualMessage = exception.getMessage(); | ||
|
||
assertTrue(actualMessage.contains(expectedMessage)); | ||
} | ||
|
||
@Test | ||
void testRaoRequestValues() { | ||
RaoRequest raoRequest = new RaoRequest.RaoRequestBuilder() | ||
.withId(id) | ||
.withNetworkFileUrl(networkPresignedUrl) | ||
.withCracFileUrl(cracInJsonFormatUrl) | ||
.withRaoParametersFileUrl(raoParametersUrl) | ||
.withResultsDestination(artifactDestinationPath) | ||
.build(); | ||
|
||
assertEquals("testId", raoRequest.getId()); | ||
assertEquals("http://network.url", raoRequest.getNetworkFileUrl()); | ||
assertEquals("http://crac.url", raoRequest.getCracFileUrl()); | ||
assertEquals("http://parameters.url", raoRequest.getRaoParametersFileUrl()); | ||
assertEquals("/path/to/artifact", raoRequest.getResultsDestination().get()); | ||
} | ||
} |
This file contains 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
51 changes: 51 additions & 0 deletions
51
...ava/com/farao_community/farao/cse/import_runner/app/dichotomy/RaoRunnerValidatorTest.java
This file contains 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,51 @@ | ||
/* | ||
* Copyright (c) 2023, 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 com.farao_community.farao.cse.import_runner.app.dichotomy; | ||
|
||
import com.farao_community.farao.cse.import_runner.app.services.FileExporter; | ||
import com.farao_community.farao.cse.runner.api.resource.ProcessType; | ||
import com.farao_community.farao.rao_runner.api.resource.RaoRequest; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.mockito.ArgumentMatchers.*; | ||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.verify; | ||
|
||
/** | ||
* @author Theo Pascoli {@literal <theo.pascoli at rte-france.com>} | ||
*/ | ||
@SpringBootTest | ||
class RaoRunnerValidatorTest { | ||
|
||
private static final String NETWORK_PRE_SIGNED_URL = "http://network.url"; | ||
private static final String BASE_DIR_PATH = "/base/dir/path"; | ||
private static final String RAO_PARAMETERS_URL = "http://parameters.url"; | ||
private static final String REQUEST_ID = "requestId"; | ||
private static final String CRAC_URL = "http://crac.url"; | ||
|
||
@MockBean | ||
private FileExporter fileExporter; | ||
|
||
@Test | ||
void buildRaoRequestWithEmptyPreviousActionsShouldNotSaveParameters() { | ||
List<String> previousActions = Collections.singletonList("Action1"); | ||
|
||
RaoRunnerValidator raoRunnerValidator = new RaoRunnerValidator(ProcessType.D2CC, REQUEST_ID, null, CRAC_URL, RAO_PARAMETERS_URL, null, null, null, null, null, false); | ||
RaoRequest result = raoRunnerValidator.buildRaoRequest(NETWORK_PRE_SIGNED_URL, BASE_DIR_PATH, previousActions); | ||
|
||
verify(fileExporter, never()).saveRaoParameters(anyString(), anyList(), any(), any(), anyBoolean()); | ||
assertNotNull(result); | ||
assertEquals(RAO_PARAMETERS_URL, result.getRaoParametersFileUrl()); | ||
} | ||
} |
This file contains 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