Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
16 changes: 16 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
<sonar.organization>gridsuite</sonar.organization>
<sonar.projectKey>org.gridsuite:network-modification-server</sonar.projectKey>
<network-modification.version>1.7.0</network-modification.version>
<!-- FIXME remove this in the next powsybl release update -->
<network-store-client.version>1.51.0-SNAPSHOT</network-store-client.version>
</properties>

<build>
Expand Down Expand Up @@ -129,6 +131,20 @@
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-network-store-client</artifactId>
<!-- FIXME remove this in the next powsybl release update -->
<version>${network-store-client.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

<!-- 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>
<dependency>
<groupId>org.gridsuite</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,11 @@ void mapUuidsFromTwoModificationsLists(
}

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.getActivated() && !m.getStashed())
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,23 +6,30 @@
*/
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.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import static org.gridsuite.modification.server.service.NetworkModificationService.MODIFICATION_LIST_SIZE_MISMATCH_ERROR;
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 @@ -39,6 +46,9 @@ class NetworkModificationServiceTest {
@Autowired
private ModificationRepository modificationRepository;

@MockitoBean
private NetworkStoreService networkStoreService;

@Test
void shouldMapUuidsFromTwoModificationsLists() {
UUID sourceModificationUuid1 = UUID.randomUUID();
Expand Down Expand Up @@ -210,6 +220,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(), Set.of()))
).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