Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* 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.securityanalysis.server.error;

/**
* @author Etienne Lesot <etienne.lesot at rte-france.com>
*/
public class AllContingencyListMissingException extends IllegalArgumentException {
public AllContingencyListMissingException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.gridsuite.securityanalysis.server.service;

import org.gridsuite.securityanalysis.server.dto.ContingencyInfos;
import org.gridsuite.securityanalysis.server.error.AllContingencyListMissingException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
Expand Down Expand Up @@ -46,10 +47,9 @@ public ActionsService(
}

public List<ContingencyInfos> getContingencyList(List<UUID> ids, UUID networkUuid, String variantId) {
Objects.requireNonNull(ids);
Objects.requireNonNull(networkUuid);
if (ids.isEmpty()) {
throw new IllegalArgumentException("List 'ids' must not be null or empty");
if (ids == null || ids.isEmpty()) {
throw new AllContingencyListMissingException("There is no contingency list selected");
}

URI path = UriComponentsBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.gridsuite.securityanalysis.server.dto.SecurityAnalysisParametersDTO;
import org.gridsuite.securityanalysis.server.dto.SecurityAnalysisStatus;
import org.gridsuite.securityanalysis.server.dto.parameters.LimitReductionsByVoltageLevel;
import org.gridsuite.securityanalysis.server.error.AllContingencyListMissingException;
import org.gridsuite.securityanalysis.server.error.SecurityAnalysisBusinessErrorCode;
import org.gridsuite.securityanalysis.server.error.SecurityAnalysisException;
import org.gridsuite.securityanalysis.server.util.SecurityAnalysisRunnerSupplier;
Expand Down Expand Up @@ -177,7 +178,7 @@ protected void preRun(SecurityAnalysisRunContext runContext) {
actionsService.getContingencyList(runContext.getParameters().contingencyListUuids(), runContext.getNetworkUuid(), runContext.getVariantId())
);
runContext.setContingencies(contingencies);
} catch (IllegalArgumentException e) {
} catch (AllContingencyListMissingException e) {
throw new SecurityAnalysisException(SecurityAnalysisBusinessErrorCode.CONTINGENCY_LIST_CONFIG_EMPTY, "The configuration does not contain any contingency.");
} catch (HttpClientErrorException.NotFound e) {
throw new SecurityAnalysisException(SecurityAnalysisBusinessErrorCode.MISSING_CONTINGENCY_LIST, "The configuration contains one or more contingency lists that have been deleted.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import okhttp3.Headers;
import okhttp3.HttpUrl;
import org.gridsuite.securityanalysis.server.dto.ContingencyInfos;
import org.gridsuite.securityanalysis.server.error.AllContingencyListMissingException;
import org.gridsuite.securityanalysis.server.util.ContextConfigurationWithTestChannel;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -29,16 +30,12 @@
import org.springframework.http.MediaType;

import java.io.IOException;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.*;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
Expand Down Expand Up @@ -93,7 +90,7 @@ public MockResponse dispatch(RecordedRequest request) {
} else if (requestPath.equals(String.format("/v1/contingency-lists/contingency-infos/export?networkUuid=%s&ids=%s", NETWORK_UUID, LIST_UUID))) {
return new MockResponse(HttpStatus.OK.value(), Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), jsonExpected);
} else if (requestPath.equals(String.format("/v1/contingency-lists/contingency-infos/export?networkUuid=%s&variantId=%s&ids=%s", NETWORK_UUID, VARIANT_ID, VERY_LARGE_LIST_UUID))
|| requestPath.equals(String.format("/v1/contingency-lists/contingency-infos/export?networkUuid=%s&ids=%s", NETWORK_UUID, VERY_LARGE_LIST_UUID))) {
|| requestPath.equals(String.format("/v1/contingency-lists/contingency-infos/export?networkUuid=%s&ids=%s", NETWORK_UUID, VERY_LARGE_LIST_UUID))) {
return new MockResponse(HttpStatus.OK.value(), Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), veryLargeJsonExpected);
} else if (requestPath.equals(String.format("/v1/contingency-lists/contingency-infos/export?networkUuid=%s&ids=%s&ids=%s", NETWORK_UUID, LIST_UUID, LIST_UUID_VARIANT))) {
return new MockResponse(HttpStatus.OK.value(), Headers.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE), jsonExpectedForList);
Expand Down Expand Up @@ -139,4 +136,15 @@ void testGetContingenciesByListOfIds() {
List<ContingencyInfos> list = actionsService.getContingencyList(List.of(LIST_UUID, LIST_UUID_VARIANT), UUID.fromString(NETWORK_UUID), null);
assertEquals(Stream.of(CONTINGENCY, CONTINGENCY_VARIANT).map(ContingencyInfos::getContingency).toList(), list.stream().map(ContingencyInfos::getContingency).collect(Collectors.toList()));
}

@Test
void testErrors() {
String expectedMessage = "There is no contingency list selected";
UUID networkUuid = UUID.fromString(NETWORK_UUID);
String message = assertThrows(AllContingencyListMissingException.class, () -> actionsService.getContingencyList(null, networkUuid, null)).getMessage();
assertEquals(expectedMessage, message);
List<UUID> emptyList = Collections.emptyList();
message = assertThrows(AllContingencyListMissingException.class, () -> actionsService.getContingencyList(emptyList, networkUuid, null)).getMessage();
assertEquals(expectedMessage, message);
}
}
Loading