Skip to content
Open
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
Expand Up @@ -6,10 +6,12 @@
*/
package org.gridsuite.study.server.dto;

import java.util.Map;
import java.util.UUID;

/**
* @author Radouane KHOUADRI {@literal <redouane.khouadri at rte-france.com>}
*/
public record ContingencyCount(
int contingencies,
int notFoundElements
Map<UUID, ContingencyCountByContingencyList> countByContingencyList
) { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* 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.study.server.dto;

import java.util.Map;
import java.util.Set;

/**
* @author Franck Lecuyer {@literal <franck.lecuyer at rte-france.com>}
*/
public record ContingencyCountByContingencyList(
int nbContingencies,
Map<String, Set<String>> notFoundElements,
String invalidContingencyErrorMessage
) { }
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.springframework.web.util.UriComponentsBuilder;

import java.util.List;
import java.util.Map;
import java.util.UUID;

import static org.gridsuite.study.server.StudyConstants.*;
Expand All @@ -32,7 +33,7 @@ public class ActionsService {
private static final String NETWORK_UUID = "networkUuid";
private static final String CONTINGENCY_LIST_IDS = "ids";

public static final ContingencyCount EMPTY_CONTINGENCY_COUNT = new ContingencyCount(0, 0);
public static final ContingencyCount EMPTY_CONTINGENCY_COUNT = new ContingencyCount(Map.of());

private String actionsServerBaseUri;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import com.github.tomakehurst.wiremock.stubbing.ServeEvent;
import com.powsybl.contingency.violations.LimitViolationType;
import com.powsybl.security.SecurityAnalysisParameters;
import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration;
import org.gridsuite.study.server.ContextConfigurationWithTestChannel;
import org.gridsuite.study.server.dto.ContingencyCount;
import org.gridsuite.study.server.dto.ContingencyCountByContingencyList;
import org.gridsuite.study.server.dto.NodeReceiver;
import org.gridsuite.study.server.dto.RootNetworkNodeInfo;
import org.gridsuite.study.server.networkmodificationtree.dto.*;
Expand Down Expand Up @@ -54,11 +56,13 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static org.assertj.core.api.Assertions.assertThat;
import static org.gridsuite.study.server.StudyConstants.HEADER_RECEIVER;
import static org.gridsuite.study.server.StudyConstants.HEADER_USER_ID;
import static org.gridsuite.study.server.dto.ComputationType.LOAD_FLOW;
Expand Down Expand Up @@ -158,7 +162,8 @@
private static final byte[] SECURITY_ANALYSIS_NMK_CONSTRAINTS_RESULT_CSV_ZIPPED = {0x04, 0x03};
private static final byte[] SECURITY_ANALYSIS_NMK_CUT_OFF_POWER_RESULT_CSV_ZIPPED = {0x05, 0x03};
private static final String SECURITY_ANALYSIS_STATUS_JSON = "\"CONVERGED\"";
private static final ContingencyCount CONTINGENCIES_COUNT = new ContingencyCount(2, 0);
private static final ContingencyCount CONTINGENCIES_COUNT =
new ContingencyCount(Map.of(UUID.randomUUID(), new ContingencyCountByContingencyList(2, Map.of("contingencyName", Set.of("equipmentName")), "titi is not a valid contingency")));

public static final String SECURITY_ANALYSIS_DEFAULT_PARAMETERS_JSON =
"{\"lowVoltageAbsoluteThreshold\":0.0,\"lowVoltageProportionalThreshold\":0.0,\"highVoltageAbsoluteThreshold\":0.0,\"highVoltageProportionalThreshold\":0.0,"
Expand Down Expand Up @@ -514,7 +519,7 @@
assertNotNull(rootNetworkNodeInfoService.getComputationResultUuid(modificationNode.getId(), rootNetworkUuid, SECURITY_ANALYSIS));
assertEquals(resultUuid, rootNetworkNodeInfoService.getComputationResultUuid(modificationNode.getId(), rootNetworkUuid, SECURITY_ANALYSIS));

StudyService studyService = Mockito.mock(StudyService.class);

Check warning on line 522 in src/test/java/org/gridsuite/study/server/rootnetworks/SecurityAnalysisTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a static import for "mock".

See more on https://sonarcloud.io/project/issues?id=org.gridsuite%3Astudy-server&issues=AZ83_O-trSujSI0HZy0c&open=AZ83_O-trSujSI0HZy0c&pullRequest=1012
doAnswer(invocation -> {
input.send(MessageBuilder.withPayload("").setHeader(HEADER_RECEIVER, resultUuidJson).build(), saFailedDestination);
return resultUuid;
Expand Down Expand Up @@ -749,8 +754,10 @@
.andReturn();
resultAsString = mvcResult.getResponse().getContentAsString();
ContingencyCount count = objectMapper.readValue(resultAsString, ContingencyCount.class);
Integer expectedResponse = CONTINGENCIES_COUNT.contingencies();
assertEquals(expectedResponse, count.contingencies());

assertThat(CONTINGENCIES_COUNT)
.usingRecursiveComparison(RecursiveComparisonConfiguration.builder().build())
.isEqualTo(count);

securityAnalysisServerStubs.verifyContingencyListCount(Map.of("ids", WireMock.matching(".*")));

Expand All @@ -760,8 +767,7 @@
.andReturn();
resultAsString = mvcResult.getResponse().getContentAsString();
ContingencyCount count2 = objectMapper.readValue(resultAsString, ContingencyCount.class);
assertEquals(0, count2.contingencies());

assertEquals(0, count2.countByContingencyList().size());
}

private void checkMessagesReceived(UUID studyUuid, String updateTypeToCheck) {
Expand Down
Loading