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
17 changes: 17 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
<sonar.organization>gridsuite</sonar.organization>
<sonar.projectKey>org.gridsuite:network-modification-server</sonar.projectKey>
<network-modification.version>1.8.0</network-modification.version>
<!-- FIXME remove this in the next powsybl release update -->

Check warning on line 61 in pom.xml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Take the required action to fix the issue indicated by this "FIXME" comment.

See more on https://sonarcloud.io/project/issues?id=org.gridsuite%3Anetwork-modification-server&issues=AaCB7mPLB4nJheLJ8GPe&open=AaCB7mPLB4nJheLJ8GPe&pullRequest=886
<network-store.version>1.51.0</network-store.version>
<network-modification.version>1.8.0</network-modification.version>
</properties>

<build>
Expand Down Expand Up @@ -129,6 +132,20 @@
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-network-store-client</artifactId>
<!-- FIXME remove this in the next powsybl release update -->

Check warning on line 135 in pom.xml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Take the required action to fix the issue indicated by this "FIXME" comment.

See more on https://sonarcloud.io/project/issues?id=org.gridsuite%3Anetwork-modification-server&issues=AaCB7mPLB4nJheLJ8GPf&open=AaCB7mPLB4nJheLJ8GPf&pullRequest=886
<version>${network-store.version}</version>
</dependency>
<!-- FIXME: to be removed at next release of gridsuite-dependencies or powsybl-ws-dependencies -->

Check warning on line 138 in pom.xml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Take the required action to fix the issue indicated by this "FIXME" comment.

See more on https://sonarcloud.io/project/issues?id=org.gridsuite%3Anetwork-modification-server&issues=AaCB7mPLB4nJheLJ8GPg&open=AaCB7mPLB4nJheLJ8GPg&pullRequest=886
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-network-store-iidm-impl</artifactId>
<version>${network-store.version}</version>
</dependency>
<!-- FIXME: to be removed at next release of gridsuite-dependencies or powsybl-ws-dependencies -->

Check warning on line 144 in pom.xml

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Take the required action to fix the issue indicated by this "FIXME" comment.

See more on https://sonarcloud.io/project/issues?id=org.gridsuite%3Anetwork-modification-server&issues=AaCB7mPLB4nJheLJ8GPh&open=AaCB7mPLB4nJheLJ8GPh&pullRequest=886
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-network-store-model</artifactId>
<version>${network-store.version}</version>
</dependency>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to override the iidm-impl version.
We usually override the version of the 3 network-store artefacts

Suggested change
</dependency>
</dependency>
<!-- FIXME: to be removed at next release of gridsuite-dependencies or powsybl-ws-dependencies -->
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-network-store-iidm-impl</artifactId>
<version>${network-store.version}</version>
</dependency>
<!-- FIXME: to be removed at next release of gridsuite-dependencies or powsybl-ws-dependencies -->
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-network-store-model</artifactId>
<version>${network-store.version}</version>
</dependency>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

<dependency>
<groupId>org.gridsuite</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,11 @@ public void duplicateGroup(@NonNull UUID sourceGroupUuid, @NonNull UUID targetGr
}

private CompletableFuture<Optional<NetworkModificationResult>> applyModifications(UUID networkUuid, String variantId, ModificationApplicationGroup modificationGroupInfos) {
if (!networkStoreService.networkExists(networkUuid)) {
// The network is not loaded
return CompletableFuture.completedFuture(Optional.empty());
}

if (!modificationGroupInfos.modifications().isEmpty()) {
PreloadingStrategy preloadingStrategy = modificationGroupInfos.modifications().stream()
.filter(m -> m.isActivatedOn(modificationGroupInfos.rootNetworkTag()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@
import static org.gridsuite.modification.server.utils.TestUtils.runRequestAsync;
import static org.gridsuite.modification.server.utils.assertions.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
Expand Down Expand Up @@ -105,6 +104,7 @@ void setUp() {
objectWriter = mapper.writer().withDefaultPrettyPrinter();
network = NetworkCreation.create(TEST_NETWORK_ID, true);
when(networkStoreService.getNetwork(eq(TEST_NETWORK_ID), nullable(PreloadingStrategy.class))).then((Answer<Network>) invocation -> network);
when(networkStoreService.networkExists(any(UUID.class))).thenReturn(true);
networkModificationRepository.deleteAll();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ void setUp() {

when(networkStoreService.getNetwork(eq(TEST_NETWORK_MIXED_TOPOLOGY_ID),
nullable(PreloadingStrategy.class))).then((Answer<Network>) invocation -> NetworkCreation.createMixedTopology(TEST_NETWORK_MIXED_TOPOLOGY_ID));
when(networkStoreService.networkExists(any(UUID.class))).thenReturn(true);

doThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR, "Internal server error"))
.when(networkStoreService).flush(argThat(n -> TEST_NETWORK_WITH_FLUSH_ERROR_ID.toString().equals(n.getId())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public void setUp() {

when(networkStoreService.getNetwork(eq(NOT_FOUND_NETWORK_ID), any(PreloadingStrategy.class))).thenThrow(new PowsyblException());
when(networkStoreService.getNetwork(eq(TEST_NETWORK_ID), any(PreloadingStrategy.class))).then((Answer<Network>) invocation -> network);
when(networkStoreService.networkExists(TEST_NETWORK_ID)).thenReturn(true);

wireMockServer = new WireMockServer(wireMockConfig().dynamicPort());
wireMockUtils = new WireMockUtils(wireMockServer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public void setUp(final MockWebServer mockWebServer) {
network = NetworkCreation.create(TEST_NETWORK_ID, true);
return network;
});
when(networkStoreService.networkExists(any(UUID.class))).thenReturn(true);

waitStartBuild = new CountDownLatch(1);
blockBuild = new CountDownLatch(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
import static com.powsybl.iidm.network.VariantManagerConstants.INITIAL_VARIANT_ID;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
Expand Down Expand Up @@ -87,6 +86,7 @@ class EquipmentIndexationTest {
void setUp() {
network = NetworkCreation.create(NETWORK_UUID, true);
when(networkStoreService.getNetwork(eq(NETWORK_UUID), nullable(PreloadingStrategy.class))).then((Answer<Network>) invocation -> network);
when(networkStoreService.networkExists(any(UUID.class))).thenReturn(true);

// clean DB
modificationApplicationRepository.deleteAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ void setUp() {
when(networkInfos.getNetwork()).thenReturn(network);
when(networkInfos.getNetworkUuuid()).thenReturn(networkUuid);
when(networkStoreService.getNetwork(eq(networkInfos.getNetworkUuuid()), any(PreloadingStrategy.class))).thenReturn(network);
when(networkStoreService.networkExists(any(UUID.class))).thenReturn(true);
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,27 @@
*/
package org.gridsuite.modification.server.service;

import com.powsybl.network.store.client.NetworkStoreService;
import org.gridsuite.modification.dto.CompositeModificationInfos;
import org.gridsuite.modification.dto.LoadModificationInfos;
import org.gridsuite.modification.dto.ModificationInfos;
import org.gridsuite.modification.server.dto.ModificationApplicationContext;
import org.gridsuite.modification.server.dto.NetworkModificationsResult;
import org.gridsuite.modification.server.entities.ModificationEntity;
import org.gridsuite.modification.server.repositories.ModificationRepository;
import org.gridsuite.modification.server.repositories.NetworkModificationRepository;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.bean.override.mockito.MockitoBean;

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

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

/**
* @author Mathieu Deharbe <mathieu.deharbe at rte-france.com>
Expand All @@ -37,6 +43,9 @@ class NetworkModificationServiceTest {
@Autowired
private ModificationRepository modificationRepository;

@MockitoBean
private NetworkStoreService networkStoreService;

@Test
void shouldMoveModificationOutOfCompositeContainerWhenStashed() {
UUID groupUuid = UUID.randomUUID();
Expand Down Expand Up @@ -91,6 +100,27 @@ void shouldFindParentCompositeOnlyForModificationsNestedInAComposite() {
assertFalse(parentComposites.containsKey(directGroupChildUuid));
}

@Test
void shouldNotApplyModificationsWhenNetworkDoesNotExist() {
UUID networkUuid = UUID.randomUUID();
UUID targetGroupUuid = UUID.randomUUID();
List<ModificationInfos> saved = networkModificationRepository.saveModifications(
UUID.randomUUID(), List.of(ModificationEntity.fromDTO(dummyModification(UUID.randomUUID()))));

when(networkStoreService.networkExists(any(UUID.class))).thenReturn(false);

NetworkModificationsResult result = networkModificationService.duplicateModifications(
targetGroupUuid,
null,
saved.stream().map(ModificationInfos::getUuid).toList(),
List.of(new ModificationApplicationContext(networkUuid, "variant", UUID.randomUUID(), UUID.randomUUID(), "tag1"))
).join();

assertEquals(1, result.modificationUuids().size());
assertEquals(1, result.modificationResults().size());
assertTrue(result.modificationResults().get(0).isEmpty());
}

private static LoadModificationInfos dummyModification(UUID uuid) {
return LoadModificationInfos.builder()
.equipmentId("dummyEquipmentId")
Expand Down
Loading