Skip to content

Commit

Permalink
Remove unecesarry @SneakyThrows in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan-WorkGH committed Jun 11, 2024
1 parent 1b55f69 commit 814c68e
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,9 @@
*/
package org.gridsuite.study.server.Impacts;

import static org.gridsuite.study.server.utils.ImpactUtils.createCollectionElementImpact;
import static org.gridsuite.study.server.utils.ImpactUtils.createElementImpact;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.powsybl.iidm.network.IdentifiableType;
import org.gridsuite.study.server.dto.impacts.AbstractBaseImpact;
import org.gridsuite.study.server.dto.impacts.CollectionElementImpact;
import org.gridsuite.study.server.dto.impacts.SimpleElementImpact;
Expand All @@ -27,10 +20,16 @@
import org.gridsuite.study.server.utils.TestUtils;
import org.junit.Test;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.powsybl.iidm.network.IdentifiableType;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import lombok.SneakyThrows;
import static org.gridsuite.study.server.utils.ImpactUtils.createCollectionElementImpact;
import static org.gridsuite.study.server.utils.ImpactUtils.createElementImpact;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* @author Slimane Amar <slimane.amar at rte-france.com>
Expand All @@ -40,8 +39,7 @@ public class NetworkImpactTest {
private final ObjectMapper mapper = new ObjectMapper();

@Test
@SneakyThrows
public void testNetworkModificationResult() {
public void testNetworkModificationResult() throws IOException {
SimpleElementImpact creationImpact = createElementImpact(SimpleImpactType.CREATION, IdentifiableType.LINE, "lineId", new TreeSet<>(List.of("s2", "s1")));
SimpleElementImpact modificationImpact = createElementImpact(SimpleImpactType.MODIFICATION, IdentifiableType.LOAD, "loadId", new TreeSet<>(List.of("s3")));
SimpleElementImpact injectionDeletionImpact = createElementImpact(SimpleImpactType.DELETION, IdentifiableType.GENERATOR, "generatorId", new TreeSet<>(List.of("s4")));
Expand Down Expand Up @@ -84,8 +82,7 @@ public void testNetworkModificationResult() {
}

@Test
@SneakyThrows
public void testCollectionElementImpact() {
public void testCollectionElementImpact() throws JsonProcessingException {

CollectionElementImpact linesCollectionImpact = createCollectionElementImpact(IdentifiableType.LINE);
CollectionElementImpact loadsCollectionImpact = createCollectionElementImpact(IdentifiableType.LOAD);
Expand Down Expand Up @@ -114,8 +111,7 @@ public void testCollectionElementImpact() {
}

@Test
@SneakyThrows
public void testNetworkImpact() {
public void testNetworkImpact() throws JsonProcessingException {
NetworkImpactsInfos networkImpactsInfos = NetworkImpactsInfos.builder()
.impactedSubstationsIds(new HashSet<>(List.of("s1", "s2")))
.deletedEquipments(
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/org/gridsuite/study/server/LoadFlowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,7 @@ public void testDeleteLoadFlowResults() throws Exception {
}

@Test
@SneakyThrows
public void testResetUuidResultWhenLFFailed() {
public void testResetUuidResultWhenLFFailed() throws Exception {
UUID resultUuid = UUID.randomUUID();
StudyEntity studyEntity = insertDummyStudy(UUID.randomUUID(), UUID.randomUUID(), LOADFLOW_PARAMETERS_UUID);
RootNode rootNode = networkModificationTreeService.getStudyTree(studyEntity.getId());
Expand Down
25 changes: 9 additions & 16 deletions src/test/java/org/gridsuite/study/server/NetworkMapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
import org.gridsuite.study.server.service.NetworkMapService;
import org.gridsuite.study.server.service.NetworkModificationTreeService;
import org.gridsuite.study.server.service.shortcircuit.ShortCircuitService;
import org.gridsuite.study.server.utils.WireMockUtils;
import org.gridsuite.study.server.utils.elasticsearch.DisableElasticsearch;
import org.gridsuite.study.server.utils.MatcherJson;
import org.gridsuite.study.server.utils.TestUtils;
import org.gridsuite.study.server.utils.WireMockUtils;
import org.gridsuite.study.server.utils.elasticsearch.DisableElasticsearch;
import org.jetbrains.annotations.NotNull;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -185,9 +185,8 @@ public MockResponse dispatch(RecordedRequest request) {
server.setDispatcher(dispatcher);
}

@SneakyThrows
@Test
public void testGetLoadMapServer() {
public void testGetLoadMapServer() throws Exception {
networkMapService.setNetworkMapServerBaseUri(wireMockServer.baseUrl());

//create study
Expand Down Expand Up @@ -517,8 +516,7 @@ private RootNode getRootNode(UUID study) throws Exception {
.getContentAsString(), new TypeReference<>() { });
}

@SneakyThrows
private MvcResult getNetworkElementsIds(UUID studyUuid, UUID rootNodeUuid, String responseBody, String requestBody) {
private MvcResult getNetworkElementsIds(UUID studyUuid, UUID rootNodeUuid, String responseBody, String requestBody) throws Exception {
UUID stubUuid = wireMockUtils.stubNetworkElementsIdsPost(NETWORK_UUID_STRING, responseBody);

MockHttpServletRequestBuilder mockHttpServletRequestBuilder = post("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-map/equipments-ids", studyUuid, rootNodeUuid)
Expand All @@ -531,8 +529,7 @@ private MvcResult getNetworkElementsIds(UUID studyUuid, UUID rootNodeUuid, Strin
return mvcResult;
}

@SneakyThrows
private MvcResult getNetworkElementsInfos(UUID studyUuid, UUID rootNodeUuid, String elementType, String infoType, List<String> substationsIds, String responseBody) {
private MvcResult getNetworkElementsInfos(UUID studyUuid, UUID rootNodeUuid, String elementType, String infoType, List<String> substationsIds, String responseBody) throws Exception {
UUID stubUuid = wireMockUtils.stubNetworkElementsInfosGet(NETWORK_UUID_STRING, elementType, infoType, responseBody);
MockHttpServletRequestBuilder mockHttpServletRequestBuilder = get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network/elements", studyUuid, rootNodeUuid)
.queryParam(QUERY_PARAM_ELEMENT_TYPE, elementType)
Expand All @@ -549,8 +546,7 @@ private MvcResult getNetworkElementsInfos(UUID studyUuid, UUID rootNodeUuid, Str
return mvcResult;
}

@SneakyThrows
private MvcResult getNetworkElementInfos(UUID studyUuid, UUID rootNodeUuid, String elementType, String infoType, String elementId, String responseBody) {
private MvcResult getNetworkElementInfos(UUID studyUuid, UUID rootNodeUuid, String elementType, String infoType, String elementId, String responseBody) throws Exception {
UUID stubUuid = wireMockUtils.stubNetworkElementInfosGet(NETWORK_UUID_STRING, elementType, infoType, elementId, responseBody);
MvcResult mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network/elements/{elementId}", studyUuid, rootNodeUuid, elementId)
.queryParam(QUERY_PARAM_ELEMENT_TYPE, elementType)
Expand All @@ -563,8 +559,7 @@ private MvcResult getNetworkElementInfos(UUID studyUuid, UUID rootNodeUuid, Stri
return mvcResult;
}

@SneakyThrows
private MvcResult getNetworkElementInfosNotFound(UUID studyUuid, UUID rootNodeUuid, String elementType, String infoType, String elementId) {
private MvcResult getNetworkElementInfosNotFound(UUID studyUuid, UUID rootNodeUuid, String elementType, String infoType, String elementId) throws Exception {
UUID stubUuid = wireMockUtils.stubNetworkElementInfosGetNotFound(NETWORK_UUID_STRING, elementType, infoType, elementId);
MvcResult mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network/elements/{elementId}", studyUuid, rootNodeUuid, elementId)
.queryParam(QUERY_PARAM_ELEMENT_TYPE, elementType)
Expand All @@ -578,8 +573,7 @@ private MvcResult getNetworkElementInfosNotFound(UUID studyUuid, UUID rootNodeUu
return mvcResult;
}

@SneakyThrows
private void getNetworkElementInfosWithError(UUID studyUuid, UUID rootNodeUuid, String elementType, String infoType, String elementId) {
private void getNetworkElementInfosWithError(UUID studyUuid, UUID rootNodeUuid, String elementType, String infoType, String elementId) throws Exception {
UUID stubUuid = wireMockUtils.stubNetworkElementInfosGetWithError(NETWORK_UUID_STRING, elementType, infoType, elementId);
mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network/elements/{elementId}", studyUuid, rootNodeUuid, elementId)
.queryParam(QUERY_PARAM_ELEMENT_TYPE, elementType)
Expand All @@ -590,8 +584,7 @@ private void getNetworkElementInfosWithError(UUID studyUuid, UUID rootNodeUuid,
wireMockUtils.verifyNetworkElementInfosGet(stubUuid, NETWORK_UUID_STRING, elementType, infoType, elementId);
}

@SneakyThrows
private MvcResult getNetworkEquipmentInfos(UUID studyUuid, UUID rootNodeUuid, String infoTypePath, String equipmentId, String responseBody) {
private MvcResult getNetworkEquipmentInfos(UUID studyUuid, UUID rootNodeUuid, String infoTypePath, String equipmentId, String responseBody) throws Exception {
UUID stubUuid = wireMockUtils.stubNetworkEquipmentInfosGet(NETWORK_UUID_STRING, infoTypePath, equipmentId, responseBody);
MvcResult mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-map/{infoTypePath}/{equipmentId}", studyUuid, rootNodeUuid, infoTypePath, equipmentId))
.andExpect(status().isOk())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import okhttp3.mockwebserver.RecordedRequest;
import org.gridsuite.study.server.dto.BuildInfos;
import org.gridsuite.study.server.dto.CreatedStudyBasicInfos;
import org.gridsuite.study.server.dto.impacts.SimpleElementImpact.SimpleImpactType;
import org.gridsuite.study.server.dto.ShortCircuitPredefinedConfiguration;
import org.gridsuite.study.server.dto.impacts.SimpleElementImpact.SimpleImpactType;
import org.gridsuite.study.server.dto.modification.*;
import org.gridsuite.study.server.networkmodificationtree.dto.*;
import org.gridsuite.study.server.notification.NotificationService;
Expand Down Expand Up @@ -1595,9 +1595,8 @@ public void testCreateVoltageLevel() throws Exception {
.andExpect(status().isForbidden());
}

@SneakyThrows
@Test
public void testLineSplitWithVoltageLevel() {
public void testLineSplitWithVoltageLevel() throws Exception {
String userId = "userId";
StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE");
UUID studyNameUserIdUuid = studyEntity.getId();
Expand Down Expand Up @@ -1664,7 +1663,6 @@ public void testLineSplitWithVoltageLevel() {
wireMockUtils.verifyNetworkModificationPut(stubPutId, MODIFICATION_UUID, badBody);
}

@SneakyThrows
@Test
public void testLineAttachToVoltageLevel() {
String userId = "userId";
Expand Down Expand Up @@ -1704,7 +1702,6 @@ public void testLineAttachToVoltageLevel() {
wireMockUtils.verifyNetworkModificationPut(stubPutId, MODIFICATION_UUID, createLineAttachToVoltageLevelAttributes);
}

@SneakyThrows
@Test
public void testLinesAttachToSplitLines() {
String userId = "userId";
Expand Down Expand Up @@ -1757,7 +1754,6 @@ public void testLinesAttachToSplitLines() {
wireMockUtils.verifyNetworkModificationPut(stubPutId, MODIFICATION_UUID, badBody);
}

@SneakyThrows
@Test
public void testScaling() {
checkScaling(ModificationType.GENERATOR_SCALING);
Expand Down Expand Up @@ -1818,7 +1814,6 @@ private void checkScaling(ModificationType scalingType) throws Exception {
wireMockUtils.verifyNetworkModificationPut(stubPutId, MODIFICATION_UUID, requestBody);
}

@SneakyThrows
@Test
public void testDeleteVoltageLevelOnline() {
String userId = "userId";
Expand Down Expand Up @@ -1870,7 +1865,6 @@ public void testDeleteVoltageLevelOnline() {
wireMockUtils.verifyNetworkModificationPut(stubIdPutErr, MODIFICATION_UUID, badBody);
}

@SneakyThrows
@Test
public void testDeleteAttachingline() {
String userId = "userId";
Expand Down Expand Up @@ -2448,7 +2442,6 @@ public void testRemoveLoadFlowComputationReport() throws Exception {
});
}

@SneakyThrows
@Test
public void testUpdateOfBuildStatus() {
StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE");
Expand Down Expand Up @@ -2827,9 +2820,8 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU
return modificationNode;
}

@SneakyThrows
@Test
public void testCreateModificationWithErrors() {
public void testCreateModificationWithErrors() throws Exception {
StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID, "UCTE");
UUID studyNameUserIdUuid = studyEntity.getId();
UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -905,9 +905,8 @@ public void testNodeDescriptionUpdate() throws Exception {
checkElementUpdatedMessageSent(root.getStudyId(), userId);
}

@SneakyThrows
@Test
public void testLightNode() {
public void testLightNode() throws Exception {
String userId = "userId";
RootNode root = createRoot();
final NetworkModificationNode hypo = buildNetworkModificationNode("hypo", "potamus", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.NOT_BUILT);
Expand Down Expand Up @@ -1295,8 +1294,7 @@ public void testUpdateApplicationStatus() {
* Create a network modification tree to test the build status.
* @return a pair with the ID of the study and the ID of the leaf node of the tree
*/
@SneakyThrows
private Pair<UUID, NetworkModificationNode> createTreeForBuildStatus() {
private Pair<UUID, NetworkModificationNode> createTreeForBuildStatus() throws Exception {
String userId = "userId";
RootNode root = createRoot();
final NetworkModificationNode node1 = buildNetworkModificationNode("built_with_error", "not built node", UUID.randomUUID(), VARIANT_ID, UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), BuildStatus.BUILT_WITH_ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
import org.springframework.test.web.servlet.MvcResult;

import java.io.IOException;
import java.util.*;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static org.gridsuite.study.server.StudyConstants.HEADER_RECEIVER;
Expand Down Expand Up @@ -393,8 +396,7 @@ public void testNonEvacuatedEnergy() throws Exception {
}

@Test
@SneakyThrows
public void testGetSensitivityNonEvacuatedEnergyResultWithWrongId() {
public void testGetSensitivityNonEvacuatedEnergyResultWithWrongId() throws Exception {
StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID);
UUID notFoundSensitivityUuid = UUID.randomUUID();
UUID studyUuid = studyEntity.getId();
Expand All @@ -421,8 +423,7 @@ public void testGetSensitivityNonEvacuatedEnergyResultWithWrongId() {
}

@Test
@SneakyThrows
public void testResetUuidResultWhenNonEvacuatedEnergyFailed() {
public void testResetUuidResultWhenNonEvacuatedEnergyFailed() throws Exception {
UUID resultUuid = UUID.randomUUID();
StudyEntity studyEntity = insertDummyStudy(UUID.randomUUID(), UUID.randomUUID());
RootNode rootNode = networkModificationTreeService.getStudyTree(studyEntity.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@

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.SECURITY_ANALYSIS;
import static org.gridsuite.study.server.dto.ComputationType.LOAD_FLOW;
import static org.gridsuite.study.server.dto.ComputationType.SECURITY_ANALYSIS;
import static org.gridsuite.study.server.utils.TestUtils.getBinaryAsBuffer;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -388,8 +388,7 @@ public void testSecurityAnalysis() throws Exception {
}

@Test
@SneakyThrows
public void testResetUuidResultWhenSAFailed() {
public void testResetUuidResultWhenSAFailed() throws Exception {
UUID resultUuid = UUID.randomUUID();
StudyEntity studyEntity = insertDummyStudy(UUID.randomUUID(), UUID.randomUUID());
RootNode rootNode = networkModificationTreeService.getStudyTree(studyEntity.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,7 @@ public void testSensitivityAnalysis() throws Exception {
}

@Test
@SneakyThrows
public void testGetSensitivityResultWithWrongId() {
public void testGetSensitivityResultWithWrongId() throws Exception {
StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID);
UUID notFoundSensitivityUuid = UUID.randomUUID();
UUID studyUuid = studyEntity.getId();
Expand Down Expand Up @@ -494,8 +493,7 @@ public void testGetSensitivityResultWithWrongId() {
}

@Test
@SneakyThrows
public void testResetUuidResultWhenSAFailed() {
public void testResetUuidResultWhenSAFailed() throws Exception {
UUID resultUuid = UUID.randomUUID();
StudyEntity studyEntity = insertDummyStudy(UUID.randomUUID(), UUID.randomUUID());
RootNode rootNode = networkModificationTreeService.getStudyTree(studyEntity.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import org.springframework.test.web.servlet.MockMvc;

import java.io.IOException;

import java.util.Collections;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -630,8 +629,7 @@ public void testOneBusShortCircuit() throws Exception {
}

@Test
@SneakyThrows
public void testResetUuidResultWhenSCFailed() {
public void testResetUuidResultWhenSCFailed() throws Exception {
UUID resultUuid = UUID.randomUUID();
StudyEntity studyEntity = insertDummyStudy(UUID.randomUUID(), UUID.randomUUID());
RootNode rootNode = networkModificationTreeService.getStudyTree(studyEntity.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU
return modificationNode;
}

@SneakyThrows
private MvcResult getNetworkElementsInfos(UUID studyUuid, UUID rootNodeUuid, String elementType, String infoType, List<String> substationsIds, String responseBody) {
private MvcResult getNetworkElementsInfos(UUID studyUuid, UUID rootNodeUuid, String elementType, String infoType, List<String> substationsIds, String responseBody) throws Exception {
UUID stubUuid = wireMockUtils.stubNetworkElementsInfosGet(NETWORK_UUID_STRING, elementType, infoType, responseBody);
MockHttpServletRequestBuilder mockHttpServletRequestBuilder = get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network/elements", studyUuid, rootNodeUuid)
.queryParam(QUERY_PARAM_ELEMENT_TYPE, elementType)
Expand All @@ -603,8 +602,7 @@ private MvcResult getNetworkElementsInfos(UUID studyUuid, UUID rootNodeUuid, Str
return mvcResult;
}

@SneakyThrows
private MvcResult getNetworkEquipmentsInfos(UUID studyUuid, UUID rootNodeUuid, String equipmentPath, List<String> substationsIds, String responseBody) {
private MvcResult getNetworkEquipmentsInfos(UUID studyUuid, UUID rootNodeUuid, String equipmentPath, List<String> substationsIds, String responseBody) throws Exception {
UUID stubUuid = wireMockUtils.stubNetworkEquipmentsInfosGet(NETWORK_UUID_STRING, equipmentPath, responseBody);
MockHttpServletRequestBuilder mockHttpServletRequestBuilder = get("/v1/studies/{studyUuid}/nodes/{nodeUuid}/network-map/{elementPath}", studyUuid, rootNodeUuid, equipmentPath);
if (!substationsIds.isEmpty()) {
Expand Down
Loading

0 comments on commit 814c68e

Please sign in to comment.