Skip to content

Commit

Permalink
Fix some tests and style.
Browse files Browse the repository at this point in the history
Signed-off-by: Bertrand Rix <[email protected]>
  • Loading branch information
obrix committed Nov 8, 2023
1 parent 3f92d99 commit cee760b
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.powsybl.network.store.iidm.impl;

import com.google.common.collect.ImmutableList;
import com.powsybl.iidm.network.*;
import com.powsybl.network.store.model.IdentifiableAttributes;
import com.powsybl.network.store.model.Resource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.primitives.Ints;
import com.powsybl.cgmes.extensions.*;
import com.powsybl.commons.PowsyblException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,7 @@ void merge(NetworkObjectIndex other) {
for (var generatorResource : other.generatorCache.allResourcesGetter.get()) {
this.createGenerator(generatorResource);
}
for (var batteryResource: other.batteryCache.allResourcesGetter.get()) {
for (var batteryResource : other.batteryCache.allResourcesGetter.get()) {
this.createBattery(batteryResource);
}
for (var shuntResource : other.shuntCompensatorCache.allResourcesGetter.get()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package com.powsybl.network.store.iidm.impl;

import com.powsybl.network.store.model.*;
import org.openxmlformats.schemas.drawingml.x2006.chart.STHoleSizeUByte;

import java.util.List;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Stream<VoltageLevel> getVoltageLevelStream() {

@Override
public int getVoltageLevelCount() {
return (int)getVoltageLevelStream().count();
return (int) getVoltageLevelStream().count();
}

@Override
Expand Down Expand Up @@ -531,13 +531,13 @@ public Network detach() {

// Move the substations and voltageLevels to the new network
//ref.setRef(new RefObj<>(null));
for(Substation substation : getSubstations()) {
for (Substation substation : getSubstations()) {
SubstationImpl impl = (SubstationImpl) substation;
Resource< SubstationAttributes> attributes = impl.getResource();
detachedNetwork.index.createSubstation(attributes);
index.removeSubstation(attributes.getId());
}
for(VoltageLevel vl : getVoltageLevels()) {
for (VoltageLevel vl : getVoltageLevels()) {
VoltageLevelImpl impl = (VoltageLevelImpl) vl;
Resource<VoltageLevelAttributes> attributes = impl.getResource();
detachedNetwork.index.createVoltageLevel(attributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class VoltageLevelAdderImpl extends AbstractIdentifiableAdder<VoltageLevelAdderI
this.substationResource = substationResource;
}


@Override
public VoltageLevelAdder setNominalV(double nominalV) {
this.nominalV = nominalV;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ static Network createBusBreakerNetworkWithOneBus(String networkSuffix) {
static Network createBusBreakerNetworkWithTwoBuses() {
return createBusBreakerNetworkWithTwoBuses("");
}

static Network createBusBreakerNetworkWithTwoBuses(String networkSuffix) {
Network network = createBusBreakerNetworkWithOneBus(networkSuffix);
VoltageLevel vl1 = network.getVoltageLevel("VL1" + networkSuffix);
Expand All @@ -645,7 +646,7 @@ static Network createBusBreakerNetworkWithTwoBuses(String networkSuffix) {
.add();
vl1.getBusBreakerView().newSwitch()
.setId("BR1" + networkSuffix)
.setBus1("B2" + networkSuffix)
.setBus1("B2" + networkSuffix)
.setBus2("B1" + networkSuffix)
.setOpen(false)
.add();
Expand Down Expand Up @@ -739,7 +740,7 @@ static Network createBusBreakerNetworkWithLine(String networkSuffix) {
.setId("B21" + networkSuffix)
.add();
vl2.newGenerator()
.setId("G2" + networkSuffix)
.setId("G2" + networkSuffix)
.setBus("B21" + networkSuffix)
.setMaxP(100.0)
.setMinP(50.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void networkTest() throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JodaModule());
String json = objectMapper.writeValueAsString(resource);
assertEquals("{\"type\":\"NETWORK\",\"id\":\"foo\",\"variantNum\":0,\"attributes\":{\"uuid\":\"7928181c-7977-4592-ba19-88027e4254e4\",\"fictitious\":false,\"caseDate\":1420070400000,\"forecastDistance\":0,\"connectedComponentsValid\":false,\"synchronousComponentsValid\":false}}", json);
assertEquals("{\"type\":\"NETWORK\",\"id\":\"foo\",\"parentNetwork\":null,\"variantNum\":0,\"attributes\":{\"uuid\":\"7928181c-7977-4592-ba19-88027e4254e4\",\"fictitious\":false,\"caseDate\":1420070400000,\"forecastDistance\":0,\"connectedComponentsValid\":false,\"synchronousComponentsValid\":false}}", json);
Resource<NetworkAttributes> resource2 = objectMapper.readValue(json, new TypeReference<Resource<NetworkAttributes>>() { });
assertNotNull(resource2);
assertEquals("foo", resource2.getId());
Expand All @@ -61,7 +61,7 @@ public void substationTest() throws IOException {
ObjectMapper objectMapper = JsonUtil.createObjectMapper();
String json = objectMapper.writeValueAsString(resource);

String jsonRef = "{\"type\":\"SUBSTATION\",\"id\":\"S\",\"variantNum\":0,\"attributes\":{\"name\":\"SS\",\"fictitious\":false,\"country\":\"FR\",\"tso\":\"RTE\"}}";
String jsonRef = "{\"type\":\"SUBSTATION\",\"id\":\"S\",\"parentNetwork\":null,\"variantNum\":0,\"attributes\":{\"name\":\"SS\",\"fictitious\":false,\"country\":\"FR\",\"tso\":\"RTE\"}}";
assertEquals(jsonRef, json);

Resource<SubstationAttributes> resource2 = objectMapper.readValue(json, new TypeReference<Resource<SubstationAttributes>>() { });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void test() throws IOException {
TopLevelDocument document = TopLevelDocument.of(resource);
ObjectMapper objectMapper = JsonUtil.createObjectMapper();
String json = objectMapper.writeValueAsString(document);
String jsonRef = "{\"data\":[{\"type\":\"SUBSTATION\",\"id\":\"S\",\"variantNum\":0,\"attributes\":{\"fictitious\":false,\"country\":\"FR\"}}],\"meta\":{}}";
String jsonRef = "{\"data\":[{\"type\":\"SUBSTATION\",\"id\":\"S\",\"parentNetwork\":null,\"variantNum\":0,\"attributes\":{\"fictitious\":false,\"country\":\"FR\"}}],\"meta\":{}}";
assertEquals(jsonRef, json);
TopLevelDocument document2 = objectMapper.readValue(json, TopLevelDocument.class);
assertEquals(resource, document2.getData().get(0));
Expand All @@ -51,7 +51,7 @@ public void testMultiResources() throws IOException {
TopLevelDocument document = TopLevelDocument.of(ImmutableList.of(resource, resource));
ObjectMapper objectMapper = JsonUtil.createObjectMapper();
String json = objectMapper.writeValueAsString(document);
String jsonRef = "{\"data\":[{\"type\":\"SUBSTATION\",\"id\":\"S\",\"variantNum\":0,\"attributes\":{\"fictitious\":false,\"country\":\"FR\"}},{\"type\":\"SUBSTATION\",\"id\":\"S\",\"variantNum\":0,\"attributes\":{\"fictitious\":false,\"country\":\"FR\"}}],\"meta\":{}}";
String jsonRef = "{\"data\":[{\"type\":\"SUBSTATION\",\"id\":\"S\",\"parentNetwork\":null,\"variantNum\":0,\"attributes\":{\"fictitious\":false,\"country\":\"FR\"}},{\"type\":\"SUBSTATION\",\"id\":\"S\",\"parentNetwork\":null,\"variantNum\":0,\"attributes\":{\"fictitious\":false,\"country\":\"FR\"}}],\"meta\":{}}";
assertEquals(jsonRef, json);
TopLevelDocument document2 = objectMapper.readValue(json, TopLevelDocument.class);
assertEquals(2, document2.getData().size());
Expand Down Expand Up @@ -85,7 +85,7 @@ public void testGenerator() throws IOException {
TopLevelDocument document = TopLevelDocument.of(resourceGenerator);
ObjectMapper objectMapper = JsonUtil.createObjectMapper();
String json = objectMapper.writeValueAsString(document);
String jsonRef = "{\"data\":[{\"type\":\"GENERATOR\",\"id\":\"gen1\",\"variantNum\":0,\"attributes\":{\"voltageLevelId\":\"vl1\",\"name\":\"name\",\"fictitious\":false,\"node\":1,\"bus\":\"bus1\",\"energySource\":\"HYDRO\",\"minP\":2.0,\"maxP\":1.0,\"voltageRegulatorOn\":false,\"targetP\":3.0,\"targetQ\":0.0,\"targetV\":4.0,\"ratedS\":0.0,\"p\":NaN,\"q\":NaN,\"regulatingTerminal\":{\"connectableId\":\"idEq\",\"side\":\"ONE\"}}}],\"meta\":{}}";
String jsonRef = "{\"data\":[{\"type\":\"GENERATOR\",\"id\":\"gen1\",\"parentNetwork\":null,\"variantNum\":0,\"attributes\":{\"voltageLevelId\":\"vl1\",\"name\":\"name\",\"fictitious\":false,\"node\":1,\"bus\":\"bus1\",\"energySource\":\"HYDRO\",\"minP\":2.0,\"maxP\":1.0,\"voltageRegulatorOn\":false,\"targetP\":3.0,\"targetQ\":0.0,\"targetV\":4.0,\"ratedS\":0.0,\"p\":NaN,\"q\":NaN,\"regulatingTerminal\":{\"connectableId\":\"idEq\",\"side\":\"ONE\"}}}],\"meta\":{}}";
assertEquals(jsonRef, json);
TopLevelDocument document2 = objectMapper.readValue(json, TopLevelDocument.class);
assertEquals(resourceGenerator, document2.getData().get(0));
Expand Down

0 comments on commit cee760b

Please sign in to comment.