Skip to content

Commit

Permalink
Set as immutable utility class
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan-WorkGH committed Jun 14, 2023
1 parent eb95400 commit 570dc1d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@
import com.powsybl.iidm.network.EnergySource;
import com.powsybl.iidm.network.SwitchKind;
import com.powsybl.iidm.network.extensions.ConnectablePosition;
import org.gridsuite.modification.server.dto.*;
import lombok.experimental.UtilityClass;
import org.gridsuite.modification.server.dto.CouplingDeviceInfos;
import org.gridsuite.modification.server.dto.GeneratorCreationInfos;
import org.gridsuite.modification.server.dto.ReactiveCapabilityCurveCreationInfos;
import org.gridsuite.modification.server.dto.VoltageLevelCreationInfos;

import java.util.Arrays;
import java.util.List;

/**
* @author Slimane Amar <slimane.amar at rte-france.com>
*/
public final class ModificationCreation {

private ModificationCreation() {
}

public static VoltageLevelCreationInfos getCreationVoltageLevel(String substationId, String voltageLevelId, String voltageLevelName) {
@UtilityClass
public class ModificationCreation {
public VoltageLevelCreationInfos getCreationVoltageLevel(String substationId, String voltageLevelId, String voltageLevelName) {
return VoltageLevelCreationInfos.builder()
.equipmentId(voltageLevelId)
.equipmentName(voltageLevelName)
Expand All @@ -37,8 +40,8 @@ public static VoltageLevelCreationInfos getCreationVoltageLevel(String substatio
.couplingDevices(Arrays.asList(CouplingDeviceInfos.builder().busbarSectionId1("1A").busbarSectionId2("1B").build())).build();
}

public static GeneratorCreationInfos getCreationGenerator(String vlId, String generatorId, String generatorName, String busOrBusbarSectionId,
String regulatingTerminalId, String regulatingTerminalType, String regulatingTerminalVlId) {
public GeneratorCreationInfos getCreationGenerator(String vlId, String generatorId, String generatorName, String busOrBusbarSectionId,
String regulatingTerminalId, String regulatingTerminalType, String regulatingTerminalVlId) {
return GeneratorCreationInfos.builder()
.equipmentId(generatorId)
.equipmentName(generatorName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,21 @@
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.extensions.ConnectablePosition;
import com.powsybl.network.store.iidm.impl.NetworkFactoryImpl;
import lombok.experimental.UtilityClass;

import java.util.UUID;

import static org.gridsuite.modification.server.utils.NetworkUtil.*;

public final class NetworkCreation {
public static final String VARIANT_ID = "variant_1";
@UtilityClass
public class NetworkCreation {
public final String VARIANT_ID = "variant_1";

private NetworkCreation() {
}

public static Network create(UUID uuid, boolean createHvdcLine) {
public Network create(UUID uuid, boolean createHvdcLine) {
return create(uuid, createHvdcLine, new NetworkFactoryImpl());
}

public static Network create(UUID uuid, boolean createHvdcLine, NetworkFactory networkFactory) {
public Network create(UUID uuid, boolean createHvdcLine, NetworkFactory networkFactory) {
Network network = networkFactory.createNetwork(uuid.toString(), "test");

Substation s1 = createSubstation(network, "s1", "s1", Country.FR);
Expand Down Expand Up @@ -235,7 +234,7 @@ public static Network create(UUID uuid, boolean createHvdcLine, NetworkFactory n
return network;
}

public static Network createBusBreaker(UUID uuid) {
public Network createBusBreaker(UUID uuid) {
Network network = new NetworkFactoryImpl().createNetwork(uuid.toString(), "test");

Substation s1 = createSubstation(network, "s1", "s1", Country.FR);
Expand All @@ -250,7 +249,7 @@ public static Network createBusBreaker(UUID uuid) {
return network;
}

public static Network createMixedTopology(UUID uuid) {
public Network createMixedTopology(UUID uuid) {
Network network = new NetworkFactoryImpl().createNetwork(uuid.toString(), "test");

Substation s1 = createSubstation(network, "s1", "s1", Country.FR);
Expand All @@ -270,6 +269,7 @@ public static Network createMixedTopology(UUID uuid) {
}

/**
* <pre>
* VL1 VL2 VL3
*
* ld1 g2 ld3
Expand All @@ -280,8 +280,9 @@ public static Network createMixedTopology(UUID uuid) {
* | | |
* bbs1 ----------bbs2------------bbs3
* l1 l2
* </pre>
*/
public static Network createForDeleteVoltageLevelOnLine(UUID uuid) {
public Network createForDeleteVoltageLevelOnLine(UUID uuid) {
Network network = new NetworkFactoryImpl().createNetwork(uuid.toString(), "NetworkForDeleteVoltageLevelOnLine");

// VL1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@

package org.gridsuite.modification.server.utils;

import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.Country;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.NetworkFactory;
import com.powsybl.iidm.network.Substation;
import com.powsybl.iidm.network.SwitchKind;
import com.powsybl.iidm.network.TopologyKind;
import com.powsybl.iidm.network.VoltageLevel;
import com.powsybl.iidm.network.extensions.ConnectablePosition;
import com.powsybl.network.store.iidm.impl.NetworkFactoryImpl;
import lombok.experimental.UtilityClass;

import java.util.UUID;

Expand All @@ -19,16 +26,14 @@
*
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public final class NetworkWithTeePoint {

private NetworkWithTeePoint() {
}

public static Network create(UUID uuid) {
@UtilityClass
public class NetworkWithTeePoint {
public Network create(UUID uuid) {
return create(uuid, new NetworkFactoryImpl());
}

/**
* <pre>
* VL1 VL2 VL3
*
* ld1 g2 ld3
Expand All @@ -48,9 +53,10 @@ public static Network create(UUID uuid) {
* br4
* |
* ld4
* </pre>
*/

public static Network create(UUID uuid, NetworkFactory networkFactory) {
public Network create(UUID uuid, NetworkFactory networkFactory) {
Network network = networkFactory.createNetwork(uuid.toString(), "NetworkWithTeePoint");

// VL1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,18 @@
import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder;
import com.github.tomakehurst.wiremock.matching.StringValuePattern;
import com.github.tomakehurst.wiremock.stubbing.ServeEvent;
import lombok.Data;

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

import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;

@Data
public class WireMockUtils {

private final WireMockServer wireMockServer;

public WireMockUtils(WireMockServer wireMockServer) {
this.wireMockServer = wireMockServer;
}

public void verifyGetRequest(UUID stubId, String urlPath, Map<String, StringValuePattern> queryParams, boolean regexMatching) {
RequestPatternBuilder requestBuilder = regexMatching ? WireMock.getRequestedFor(WireMock.urlPathMatching(urlPath)) : WireMock.getRequestedFor(WireMock.urlPathEqualTo(urlPath));
queryParams.forEach(requestBuilder::withQueryParam);
Expand All @@ -36,7 +33,7 @@ public void verifyGetRequest(UUID stubId, String urlPath, Map<String, StringValu

private void removeRequestForStub(UUID stubId, int nbRequests) {
List<ServeEvent> serveEvents = wireMockServer.getServeEvents(ServeEventQuery.forStubMapping(stubId)).getServeEvents();
assertEquals(nbRequests, serveEvents.size());
assertThat(serveEvents).hasSize(nbRequests);
for (ServeEvent serveEvent : serveEvents) {
wireMockServer.removeServeEvent(serveEvent.getId());
}
Expand Down

0 comments on commit 570dc1d

Please sign in to comment.