Skip to content

Commit

Permalink
Add tests for block and node wrappers & for merged GLSK files import
Browse files Browse the repository at this point in the history
  • Loading branch information
vbochetRTE committed Mar 21, 2023
1 parent 5d4900a commit 7cf275b
Show file tree
Hide file tree
Showing 5 changed files with 410 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public GlskDocument importGlsk(InputStream inputStream) {

@Override
public boolean canImport(InputStream inputStream) {
// TODO Change this methods behaviour according to the new import mechanism
if (!setDocument(inputStream)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2023, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.glsk.cse;

import org.junit.jupiter.api.Test;
import xsd.etso_core_cmpts.QuantityType;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* @author Vincent Bochet {@literal <vincent.bochet at rte-france.com>}
*/
class BlockWrapperTest {
@Test
void checkGetOrderReturnsValue() {
PropGSKBlockType block = new PropGSKBlockType();
block.setOrder(BigInteger.TEN);
assertEquals(Optional.of(BigInteger.TEN), new BlockWrapper(block).getOrder());
}

@Test
void checkGetOrderReturnsEmptyWhenBlockHasNoOrderAttribute() {
assertEquals(Optional.empty(), new BlockWrapper(new Object()).getOrder());
}

@Test
void checkGetMaximumShiftReturnsValue() {
PropGSKBlockType block = new PropGSKBlockType();
QuantityType quantity = new QuantityType();
quantity.setV(BigDecimal.TEN);
block.setMaximumShift(quantity);
assertEquals(Optional.of(BigDecimal.TEN), new BlockWrapper(block).getMaximumShift());
}

@Test
void checkGetMaximumShiftReturnsEmptyWhenBlockHasNoMaximumShiftAttribute() {
assertEquals(Optional.empty(), new BlockWrapper(new Object()).getMaximumShift());
}

@Test
void checkGetFactorReturnsValue() {
PropGSKBlockType block = new PropGSKBlockType();
QuantityType quantity = new QuantityType();
quantity.setV(BigDecimal.TEN);
block.setFactor(quantity);
assertEquals(Optional.of(BigDecimal.TEN), new BlockWrapper(block).getFactor());
}

@Test
void checkGetFactorReturnsEmptyWhenBlockHasNoFactorAttribute() {
assertEquals(Optional.empty(), new BlockWrapper(new Object()).getFactor());
}

@Test
void checkGetNodeListReturnsList() {
PropGSKBlockType block = new PropGSKBlockType();
block.getNode().add(new PropGSKNodeType());
assertEquals(1, new BlockWrapper(block).getNodeList().get().size());
}

@Test
void checkGetNodeListReturnsEmptyWhenBlockHasNoNodeListAttribute() {
assertEquals(Optional.empty(), new BlockWrapper(new Object()).getNodeList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import com.powsybl.glsk.api.GlskDocument;
import com.powsybl.glsk.api.GlskPoint;
import com.powsybl.glsk.api.GlskRegisteredResource;
import com.powsybl.glsk.api.GlskShiftKey;
import com.powsybl.glsk.api.io.GlskDocumentImporters;
import com.powsybl.glsk.commons.GlskException;
import com.powsybl.glsk.commons.ZonalData;
Expand Down Expand Up @@ -368,4 +370,76 @@ void checkGlskExceptionWhenMissingTag() {
InputStream is = getClass().getResourceAsStream("/testGlskMissingTag.xml");
assertThrows(GlskException.class, () -> CseGlskDocument.importGlsk(is));
}

@Test
void checkCseGlskDocumentImporterCorrectlyImportMergedGlsk() {
CseGlskDocument cseGlskDocument = CseGlskDocument.importGlsk(getClass().getResourceAsStream("/testGlskMerged.xml"));
assertNotNull(cseGlskDocument);
assertEquals(5, cseGlskDocument.getZones().size());

List<GlskPoint> atPoints = cseGlskDocument.getGlskPoints("10YAT-APG------L");
assertEquals(1, atPoints.size());
List<GlskShiftKey> atGlskShiftKeys = atPoints.get(0).getGlskShiftKeys();
assertEquals(1, atGlskShiftKeys.size());
assertEquals(0.95, atGlskShiftKeys.get(0).getQuantity());
List<GlskRegisteredResource> atRegisteredResources = atGlskShiftKeys.get(0).getRegisteredResourceArrayList();
assertEquals(2, atRegisteredResources.size());
assertEquals("AT01AA01", atRegisteredResources.get(0).getName());
assertEquals(0.7, atRegisteredResources.get(0).getParticipationFactor());
assertEquals("AT02AA01", atRegisteredResources.get(1).getName());
assertEquals(0.3, atRegisteredResources.get(1).getParticipationFactor());

List<GlskPoint> chPoints = cseGlskDocument.getGlskPoints("10YCH-SWISSGRIDZ");
assertEquals(1, chPoints.size());
List<GlskShiftKey> chGlskShiftKeys = chPoints.get(0).getGlskShiftKeys();
assertEquals(1, chGlskShiftKeys.size());
assertEquals(1.2, chGlskShiftKeys.get(0).getQuantity());
List<GlskRegisteredResource> chRegisteredResources = chGlskShiftKeys.get(0).getRegisteredResourceArrayList();
assertEquals(1, chRegisteredResources.size());
assertEquals("CH01AA01", chRegisteredResources.get(0).getName());
assertEquals(200.0, chRegisteredResources.get(0).getMaximumCapacity().get());
assertEquals(-10.0, chRegisteredResources.get(0).getMinimumCapacity().get());

List<GlskPoint> frPoints = cseGlskDocument.getGlskPoints("10YFR-RTE------C");
assertEquals(1, frPoints.size());
List<GlskShiftKey> frGlskShiftKeys = frPoints.get(0).getGlskShiftKeys();
assertEquals(1, frGlskShiftKeys.size());
assertEquals(1.05, frGlskShiftKeys.get(0).getQuantity());
List<GlskRegisteredResource> frRegisteredResources = frGlskShiftKeys.get(0).getRegisteredResourceArrayList();
assertEquals(3, frRegisteredResources.size());
assertEquals("FR01AA01", frRegisteredResources.get(0).getName());
assertEquals("FR02AA01", frRegisteredResources.get(1).getName());
assertEquals("FR03AA01", frRegisteredResources.get(2).getName());

List<GlskPoint> itPoints = cseGlskDocument.getGlskPoints("10YIT-GRTN-----B");
assertEquals(1, itPoints.size());
List<GlskShiftKey> itGlskShiftKeys = itPoints.get(0).getGlskShiftKeys();
assertEquals(2, itGlskShiftKeys.size());
assertEquals(1.15, itGlskShiftKeys.get(0).getQuantity());
assertEquals(1, itGlskShiftKeys.get(0).getMeritOrderPosition());
List<GlskRegisteredResource> itFirstRegisteredResources = itGlskShiftKeys.get(0).getRegisteredResourceArrayList();
assertEquals(1, itFirstRegisteredResources.size());
assertEquals("IT01AA01", itFirstRegisteredResources.get(0).getName());
assertEquals(1000, itFirstRegisteredResources.get(0).getMaximumCapacity().get());
assertEquals(1.15, itGlskShiftKeys.get(1).getQuantity());
assertEquals(-1, itGlskShiftKeys.get(1).getMeritOrderPosition());
List<GlskRegisteredResource> itSecondRegisteredResources = itGlskShiftKeys.get(1).getRegisteredResourceArrayList();
assertEquals(1, itSecondRegisteredResources.size());
assertEquals("IT01AA02", itSecondRegisteredResources.get(0).getName());
assertEquals(0, itSecondRegisteredResources.get(0).getMinimumCapacity().get());

List<GlskPoint> siPoints = cseGlskDocument.getGlskPoints("10YSI-ELES-----O");
assertEquals(1, siPoints.size());
List<GlskShiftKey> siGlskShiftKeys = siPoints.get(0).getGlskShiftKeys();
assertEquals(2, siGlskShiftKeys.size());
assertEquals(0.3, siGlskShiftKeys.get(0).getQuantity());
List<GlskRegisteredResource> siFirstRegisteredResources = siGlskShiftKeys.get(0).getRegisteredResourceArrayList();
assertEquals(2, siFirstRegisteredResources.size());
assertEquals("SI02AA01", siFirstRegisteredResources.get(0).getName());
assertEquals("SI02AA02", siFirstRegisteredResources.get(1).getName());
assertEquals(0.7, siGlskShiftKeys.get(1).getQuantity());
List<GlskRegisteredResource> siSecondRegisteredResources = siGlskShiftKeys.get(1).getRegisteredResourceArrayList();
assertEquals(1, siSecondRegisteredResources.size());
assertEquals("SI01AA01", siSecondRegisteredResources.get(0).getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2023, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.glsk.cse;

import org.junit.jupiter.api.Test;
import xsd.etso_core_cmpts.QuantityType;

import java.math.BigDecimal;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* @author Vincent Bochet {@literal <vincent.bochet at rte-france.com>}
*/
class NodeWrapperTest {
@Test
void checkGetNodeReturnsValue() {
MeritOrderUpNodeType node = new MeritOrderUpNodeType();
assertEquals(node, new NodeWrapper(node).getNode());
}

@Test
void checkGetOrderReturnsValue() {
MeritOrderUpNodeType node = new MeritOrderUpNodeType();
NodeNameType nodeName = new NodeNameType();
nodeName.setV("name");
node.setName(nodeName);
assertEquals(Optional.of("name"), new NodeWrapper(node).getName());
}

@Test
void checkGetOrderReturnsEmptyWhenNodeHasNoOrderAttribute() {
assertEquals(Optional.empty(), new NodeWrapper(new Object()).getName());
}

@Test
void checkGetFactorReturnsValue() {
ManualGSKNodeType node = new ManualGSKNodeType();
QuantityType quantity = new QuantityType();
quantity.setV(BigDecimal.TEN);
node.setFactor(quantity);
assertEquals(Optional.of(BigDecimal.TEN), new NodeWrapper(node).getFactor());
}

@Test
void checkGetFactorReturnsEmptyWhenNodeHasNoFactorAttribute() {
assertEquals(Optional.empty(), new NodeWrapper(new Object()).getFactor());
}

@Test
void checkGetPmaxReturnsValue() {
MeritOrderUpNodeType node = new MeritOrderUpNodeType();
QuantityType quantity = new QuantityType();
quantity.setV(BigDecimal.TEN);
node.setPmax(quantity);
assertEquals(Optional.of(BigDecimal.TEN), new NodeWrapper(node).getPmax());
}

@Test
void checkGetPmaxReturnsEmptyWhenNodeHasNoPmaxAttribute() {
assertEquals(Optional.empty(), new NodeWrapper(new Object()).getPmax());
}

@Test
void checkGetPminReturnsValue() {
MeritOrderUpNodeType node = new MeritOrderUpNodeType();
QuantityType quantity = new QuantityType();
quantity.setV(BigDecimal.TEN);
node.setPmin(quantity);
assertEquals(Optional.of(BigDecimal.TEN), new NodeWrapper(node).getPmin());
}

@Test
void checkGetPminReturnsEmptyWhenNodeHasNoPminAttribute() {
assertEquals(Optional.empty(), new NodeWrapper(new Object()).getPmin());
}
}
Loading

0 comments on commit 7cf275b

Please sign in to comment.