diff --git a/iidm-actions-contingencies-xml-client/pom.xml b/iidm-actions-contingencies-xml-client/pom.xml index d7f11332..afef7578 100644 --- a/iidm-actions-contingencies-xml-client/pom.xml +++ b/iidm-actions-contingencies-xml-client/pom.xml @@ -3,66 +3,76 @@ 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/. --> - 4.0.0 - - eu.itesla_project - itesla-parent - 0.1-SNAPSHOT - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + eu.itesla_project + itesla-parent + 0.1-SNAPSHOT + - iidm-actions-contingencies-xml-client - 0.1-SNAPSHOT - actions contingencies xml client - - - org.slf4j - slf4j-api - - - eu.itesla_project - modules - ${project.version} - - + iidm-actions-contingencies-xml-client + 0.1-SNAPSHOT + actions contingencies xml client + + + org.slf4j + slf4j-api + + + eu.itesla_project + modules + ${project.version} + + junit junit test - - org.slf4j - slf4j-simple - test - + + org.slf4j + slf4j-simple + test + + + eu.itesla_project + iidm-network-impl + test + + + eu.itesla_project + iidm-network-test + test + + + + + + + org.codehaus.mojo + jaxb2-maven-plugin + 2.3 + + + xjc + + xjc + + + + + + eu.itesla_project.iidm.actions_contingencies.xml.mapping + en_US + + src/main/resources/xsd/actions.xsd + + + + + + - - - - - org.codehaus.mojo - jaxb2-maven-plugin - 2.3 - - - xjc - - xjc - - - - - - eu.itesla_project.iidm.actions_contingencies.xml.mapping - en_US - - src/main/resources/xsd/actions.xsd - - - - - - - - + \ No newline at end of file diff --git a/iidm-actions-contingencies-xml-client/src/main/java/eu/itesla_project/iidm/actions_contingencies/xml/XmlFileContingenciesAndActionsDatabaseClient.java b/iidm-actions-contingencies-xml-client/src/main/java/eu/itesla_project/iidm/actions_contingencies/xml/XmlFileContingenciesAndActionsDatabaseClient.java index db51b771..17f283d4 100644 --- a/iidm-actions-contingencies-xml-client/src/main/java/eu/itesla_project/iidm/actions_contingencies/xml/XmlFileContingenciesAndActionsDatabaseClient.java +++ b/iidm-actions-contingencies-xml-client/src/main/java/eu/itesla_project/iidm/actions_contingencies/xml/XmlFileContingenciesAndActionsDatabaseClient.java @@ -7,8 +7,11 @@ */ package eu.itesla_project.iidm.actions_contingencies.xml; +import java.io.IOException; +import java.io.InputStream; import java.math.BigInteger; import java.net.URL; +import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; @@ -30,6 +33,7 @@ import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; +import eu.itesla_project.iidm.actions_contingencies.xml.mapping.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xml.sax.SAXException; @@ -38,28 +42,6 @@ import eu.itesla_project.contingency.ContingencyImpl; import eu.itesla_project.contingency.GeneratorContingency; import eu.itesla_project.contingency.LineContingency; -import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Action; -import eu.itesla_project.iidm.actions_contingencies.xml.mapping.ActionCtgAssociations; -import eu.itesla_project.iidm.actions_contingencies.xml.mapping.ActionPlan; -import eu.itesla_project.iidm.actions_contingencies.xml.mapping.ActionsContingencies; -import eu.itesla_project.iidm.actions_contingencies.xml.mapping.And; -import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Association; -import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Constraint; -import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Contingency; -import eu.itesla_project.iidm.actions_contingencies.xml.mapping.ElementaryAction; -import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Equipment; -import eu.itesla_project.iidm.actions_contingencies.xml.mapping.GenerationOperation; -import eu.itesla_project.iidm.actions_contingencies.xml.mapping.LineOperation; -import eu.itesla_project.iidm.actions_contingencies.xml.mapping.LogicalExpression; -import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Operand; -import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Or; -import eu.itesla_project.iidm.actions_contingencies.xml.mapping.PstOperation; -import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Redispatching; -import eu.itesla_project.iidm.actions_contingencies.xml.mapping.SwitchOperation; -import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Then; -import eu.itesla_project.iidm.actions_contingencies.xml.mapping.VoltageLevel; -import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Zone; -import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Zones; import eu.itesla_project.iidm.network.Line; import eu.itesla_project.iidm.network.Network; import eu.itesla_project.iidm.network.TieLine; @@ -101,22 +83,31 @@ public class XmlFileContingenciesAndActionsDatabaseClient implements Contingenci private ActionsContingencies actionContingencies; private Map zonesMapping = new HashMap(); - public XmlFileContingenciesAndActionsDatabaseClient(Path file) - throws JAXBException, SAXException { + public XmlFileContingenciesAndActionsDatabaseClient(Path file) throws JAXBException, SAXException, IOException { + try (InputStream stream = Files.newInputStream(file)) { + load(stream); + } + } + + public XmlFileContingenciesAndActionsDatabaseClient(URL url) throws JAXBException, SAXException, IOException { + try (InputStream stream = url.openStream()) { + load(stream); + } + } - JAXBContext jaxbContext = JAXBContext - .newInstance(ActionsContingencies.class); + private void load(InputStream stream) throws JAXBException, SAXException, IOException { + JAXBContext jaxbContext = JAXBContext.newInstance(ActionsContingencies.class); Unmarshaller jaxbMarshaller = jaxbContext.createUnmarshaller(); - SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); - URL res=XmlFileContingenciesAndActionsDatabaseClient.class.getClassLoader().getResource("xsd/actions.xsd"); - Schema schema = sf.newSchema(res); + SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + URL res = XmlFileContingenciesAndActionsDatabaseClient.class.getClassLoader().getResource("xsd/actions.xsd"); + if (res == null) { + throw new IOException("Unable to find schema"); + } + Schema schema = sf.newSchema(res); jaxbMarshaller.setSchema(schema); - actionContingencies = (ActionsContingencies) jaxbMarshaller - .unmarshal(file.toFile()); - - + actionContingencies = (ActionsContingencies) jaxbMarshaller.unmarshal(stream); } @Override @@ -921,10 +912,17 @@ else if (sw.getAction().equals("closing")) if ( network.getTwoWindingsTransformer(transformerId) != null ) { if (pst.getAction().equals("shunt")) elements.add(new ShuntAction(pst.getId(), pst.getImplementationTime(), pst.getAchievmentIndex())); - else if (pst.getAction().equals("tapChange")) - elements.add(new TapChangeAction(pst.getId(), pst.getImplementationTime(), pst.getAchievmentIndex())); + else if (pst.getAction().equals("tapChange")) { + Parameter tapPositionParameter = getParameter(pst.getParameter(), "tapPosition"); + if (tapPositionParameter != null) { + int tapPosition = Integer.parseInt(tapPositionParameter.getValue()); + elements.add(new TapChangeAction(pst.getId(), tapPosition, pst.getImplementationTime(), pst.getAchievmentIndex())); + } + } else if (pst.getAction().equals("opening")) { - elements.add(new TransformerOpeningAction(pst.getId(), pst.getImplementationTime(), pst.getAchievmentIndex())); + Parameter substationParameter = getParameter(pst.getParameter(), "substation"); + String substation = (substationParameter == null) ? null : substationParameter.getValue(); + elements.add(new TransformerOpeningAction(pst.getId(), substation, pst.getImplementationTime(), pst.getAchievmentIndex())); } else LOGGER.warn("pst operation not supported : " + pst.getAction()); @@ -1001,4 +999,10 @@ private boolean constraintOnEquipment(List constraints, String equip return false; } + private static Parameter getParameter(List parameters, String name) { + Objects.requireNonNull(parameters); + Objects.requireNonNull(name); + + return parameters.stream().filter(p -> p.getName().equals(name)).findFirst().get(); + } } \ No newline at end of file diff --git a/iidm-actions-contingencies-xml-client/src/main/java/eu/itesla_project/iidm/actions_contingencies/xml/XmlFileContingenciesAndActionsDatabaseClientFactory.java b/iidm-actions-contingencies-xml-client/src/main/java/eu/itesla_project/iidm/actions_contingencies/xml/XmlFileContingenciesAndActionsDatabaseClientFactory.java index 9977d916..c3c6f512 100644 --- a/iidm-actions-contingencies-xml-client/src/main/java/eu/itesla_project/iidm/actions_contingencies/xml/XmlFileContingenciesAndActionsDatabaseClientFactory.java +++ b/iidm-actions-contingencies-xml-client/src/main/java/eu/itesla_project/iidm/actions_contingencies/xml/XmlFileContingenciesAndActionsDatabaseClientFactory.java @@ -6,6 +6,7 @@ */ package eu.itesla_project.iidm.actions_contingencies.xml; +import java.io.IOException; import java.nio.file.Path; import javax.xml.bind.JAXBException; @@ -21,30 +22,25 @@ /** - * * @author Quinary */ public class XmlFileContingenciesAndActionsDatabaseClientFactory implements - ContingenciesAndActionsDatabaseClientFactory { - - private static final Logger LOGGER = LoggerFactory.getLogger(XmlFileContingenciesAndActionsDatabaseClientFactory.class); - - @Override - public ContingenciesAndActionsDatabaseClient create() { - XmlFileContingenciesAndActionsDatabaseClient client=null; - ModuleConfig config = PlatformConfig.defaultConfig().getModuleConfig("xmlcontingencydb"); - Path xmlFile = config.getPathProperty("xmlFile"); - - try { - client= new XmlFileContingenciesAndActionsDatabaseClient(xmlFile); - } catch (JAXBException e) { - LOGGER.error("Error loading input file "+xmlFile,e); - } catch (SAXException e) { - LOGGER.error("Error loading input file "+xmlFile,e); - } - return client; - - - } + ContingenciesAndActionsDatabaseClientFactory { + private static final Logger LOGGER = LoggerFactory.getLogger(XmlFileContingenciesAndActionsDatabaseClientFactory.class); + + @Override + public ContingenciesAndActionsDatabaseClient create() { + XmlFileContingenciesAndActionsDatabaseClient client = null; + ModuleConfig config = PlatformConfig.defaultConfig().getModuleConfig("xmlcontingencydb"); + Path xmlFile = config.getPathProperty("xmlFile"); + + try { + client = new XmlFileContingenciesAndActionsDatabaseClient(xmlFile); + } catch (JAXBException | SAXException | IOException e) { + LOGGER.error("Error loading input file " + xmlFile, e); + } + + return client; + } } diff --git a/iidm-actions-contingencies-xml-client/src/main/resources/xsd/actions.xsd b/iidm-actions-contingencies-xml-client/src/main/resources/xsd/actions.xsd index 91c4d549..2fa4aaf2 100644 --- a/iidm-actions-contingencies-xml-client/src/main/resources/xsd/actions.xsd +++ b/iidm-actions-contingencies-xml-client/src/main/resources/xsd/actions.xsd @@ -8,251 +8,260 @@ --> - - - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iidm-actions-contingencies-xml-client/src/test/java/eu/itesla_project/iidm/actions_contingencies/xml/test/ACXmlClientTest.java b/iidm-actions-contingencies-xml-client/src/test/java/eu/itesla_project/iidm/actions_contingencies/xml/test/ACXmlClientTest.java index 4cd0d003..bf9de9c3 100644 --- a/iidm-actions-contingencies-xml-client/src/test/java/eu/itesla_project/iidm/actions_contingencies/xml/test/ACXmlClientTest.java +++ b/iidm-actions-contingencies-xml-client/src/test/java/eu/itesla_project/iidm/actions_contingencies/xml/test/ACXmlClientTest.java @@ -8,35 +8,35 @@ import static org.junit.Assert.*; -import java.nio.file.Path; -import java.nio.file.Paths; - +import java.io.IOException; +import java.net.URL; import org.junit.Test; import eu.itesla_project.iidm.actions_contingencies.xml.XmlFileContingenciesAndActionsDatabaseClient; import eu.itesla_project.modules.contingencies.ContingenciesAndActionsDatabaseClient; +import org.xml.sax.SAXException; + +import javax.xml.bind.JAXBException; /** -* -* @author Quinary -*/ + * @author Quinary + */ public class ACXmlClientTest { - @Test - public void test() { - - Path p1 = Paths.get("src/test/resources/test-ac.xml"); - try { - ContingenciesAndActionsDatabaseClient client = new XmlFileContingenciesAndActionsDatabaseClient(p1); - client.getActionPlans(); - client.getZones(); - - } catch (Exception e) { - e.printStackTrace(); - fail("Error "+e.getMessage()); - } - - } + @Test + public void test() { + try { + URL config = getClass().getResource("/test-ac.xml"); + ContingenciesAndActionsDatabaseClient client = new XmlFileContingenciesAndActionsDatabaseClient(config); + client.getActionPlans(); + client.getZones(); + + } catch (JAXBException | SAXException | IOException e) { + e.printStackTrace(); + fail("Error " + e.getMessage()); + } + + } } diff --git a/iidm-actions-contingencies-xml-client/src/test/java/eu/itesla_project/iidm/actions_contingencies/xml/test/PstOperationTest.java b/iidm-actions-contingencies-xml-client/src/test/java/eu/itesla_project/iidm/actions_contingencies/xml/test/PstOperationTest.java new file mode 100644 index 00000000..992fa6c7 --- /dev/null +++ b/iidm-actions-contingencies-xml-client/src/test/java/eu/itesla_project/iidm/actions_contingencies/xml/test/PstOperationTest.java @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2017, 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 eu.itesla_project.iidm.actions_contingencies.xml.test; + +import eu.itesla_project.iidm.actions_contingencies.xml.XmlFileContingenciesAndActionsDatabaseClient; +import eu.itesla_project.iidm.network.Network; +import eu.itesla_project.iidm.network.test.PhaseShifterTestCaseFactory; +import eu.itesla_project.modules.contingencies.Action; +import eu.itesla_project.modules.contingencies.ActionElement; +import eu.itesla_project.modules.contingencies.ActionElementType; +import eu.itesla_project.modules.contingencies.TapChangeAction; + +import org.junit.Test; +import org.xml.sax.SAXException; + +import javax.xml.bind.JAXBException; +import java.io.IOException; +import java.net.URL; +import java.util.List; + +import static org.junit.Assert.*; + +/** + * @author Mathieu Bague + */ +public class PstOperationTest { + + @Test + public void test() throws JAXBException, SAXException, IOException { + Network network = PhaseShifterTestCaseFactory.create(); + + URL config = getClass().getResource("/pstOperations.xml"); + XmlFileContingenciesAndActionsDatabaseClient client = new XmlFileContingenciesAndActionsDatabaseClient(config); + + List actions = client.getActions(network); + assertEquals(1, actions.size()); + + Action action = actions.get(0); + assertEquals("tapChange", action.getId()); + assertTrue(action.isCurative()); + assertFalse(action.isPreventive()); + assertEquals(123, action.getStartTime().intValue()); + assertEquals(1, action.getElements().size()); + + ActionElement actionElement = action.getElements().iterator().next(); + assertEquals(ActionElementType.TAP_CHANGE, actionElement.getType()); + TapChangeAction tapChangeAction = (TapChangeAction) actionElement; + assertEquals("PS1", tapChangeAction.getEquipmentId()); + assertEquals(0, tapChangeAction.getAchievmentIndex().intValue()); + assertEquals(150, tapChangeAction.getImplementationTime().intValue()); + assertEquals(2, tapChangeAction.getTapPosition()); + } +} diff --git a/iidm-actions-contingencies-xml-client/src/test/resources/pstOperations.xml b/iidm-actions-contingencies-xml-client/src/test/resources/pstOperations.xml new file mode 100644 index 00000000..90a14868 --- /dev/null +++ b/iidm-actions-contingencies-xml-client/src/test/resources/pstOperations.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + 2 + + + + + + + + + + diff --git a/modules/pom.xml b/modules/pom.xml index 6eafcbf0..79a98a57 100644 --- a/modules/pom.xml +++ b/modules/pom.xml @@ -144,6 +144,11 @@ iidm-network-impl test + + ${project.groupId} + iidm-network-test + test + org.slf4j log4j-over-slf4j diff --git a/modules/src/main/java/eu/itesla_project/modules/contingencies/TapChangeAction.java b/modules/src/main/java/eu/itesla_project/modules/contingencies/TapChangeAction.java index 6c7091cc..4c3c731d 100644 --- a/modules/src/main/java/eu/itesla_project/modules/contingencies/TapChangeAction.java +++ b/modules/src/main/java/eu/itesla_project/modules/contingencies/TapChangeAction.java @@ -7,61 +7,67 @@ package eu.itesla_project.modules.contingencies; import eu.itesla_project.contingency.tasks.ModificationTask; +import eu.itesla_project.modules.contingencies.tasks.PstTapChanging; + +import java.util.Objects; /** - * * @author Quinary + * @author Mathieu Bague */ public class TapChangeAction implements ActionElement { - private String equipmentId; - - private Number implementationTime; - - private Number achievmentIndex; - - public TapChangeAction(String elementId) { - this.equipmentId=elementId; - } - - public TapChangeAction(String elementId ,Number implementationTime, Number achievmentIndex ) { - this.equipmentId=elementId; - this.implementationTime=implementationTime; - this.achievmentIndex=achievmentIndex; - - } - - - @Override - public ActionElementType getType() { - - return ActionElementType.TAP_CHANGE; - } - - @Override - public String getEquipmentId() { - return equipmentId; - } - - @Override - public ModificationTask toTask() { - // TODO Auto-generated method stub - return null; - } - - @Override - public Number getImplementationTime() { - return implementationTime; - } - - @Override - public Number getAchievmentIndex() { - return achievmentIndex; - } - - @Override - public ModificationTask toTask(ActionParameters parameters) { - throw new UnsupportedOperationException(); - } + private final String equipmentId; + + private final int tapPosition; + + private final Number implementationTime; + + private final Number achievmentIndex; + + public TapChangeAction(String elementId, int tapPosition) { + this(elementId, tapPosition, null, null); + } + + public TapChangeAction(String elementId, int tapPosition, Number implementationTime, Number achievmentIndex) { + this.equipmentId = Objects.requireNonNull(elementId); + this.tapPosition = tapPosition; + this.implementationTime = implementationTime; + this.achievmentIndex = achievmentIndex; + } + + @Override + public ActionElementType getType() { + return ActionElementType.TAP_CHANGE; + } + + @Override + public String getEquipmentId() { + return equipmentId; + } + + public int getTapPosition() { + return tapPosition; + } + + @Override + public ModificationTask toTask() { + return new PstTapChanging(equipmentId, tapPosition); + } + + @Override + public Number getImplementationTime() { + return implementationTime; + } + + @Override + public Number getAchievmentIndex() { + return achievmentIndex; + } + + @Override + public ModificationTask toTask(ActionParameters parameters) { + throw new UnsupportedOperationException(); + } } diff --git a/modules/src/main/java/eu/itesla_project/modules/contingencies/tasks/PstTapChanging.java b/modules/src/main/java/eu/itesla_project/modules/contingencies/tasks/PstTapChanging.java new file mode 100644 index 00000000..f86309ca --- /dev/null +++ b/modules/src/main/java/eu/itesla_project/modules/contingencies/tasks/PstTapChanging.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2017, 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 eu.itesla_project.modules.contingencies.tasks; + +import eu.itesla_project.commons.ITeslaException; +import eu.itesla_project.contingency.tasks.ModificationTask; +import eu.itesla_project.iidm.network.Network; +import eu.itesla_project.iidm.network.PhaseTapChanger; +import eu.itesla_project.iidm.network.TwoWindingsTransformer; + +import java.util.Objects; + +/** + * @author Mathieu Bague + */ +public class PstTapChanging implements ModificationTask { + + private final String transformerId; + + private final int tapPosition; + + public PstTapChanging(String transformerId, int tapPosition) { + this.transformerId = Objects.requireNonNull(transformerId); + this.tapPosition = tapPosition; + } + + @Override + public void modify(Network network) { + TwoWindingsTransformer transformer = network.getTwoWindingsTransformer(transformerId); + if (transformer == null) { + throw new ITeslaException("Two windings transformer '" + transformerId + "' not found"); + } + PhaseTapChanger tapChanger = transformer.getPhaseTapChanger(); + if (tapChanger == null) { + throw new ITeslaException("Transformer " + transformerId + " is not a PST"); + } + tapChanger.setRegulationMode(PhaseTapChanger.RegulationMode.FIXED_TAP); + tapChanger.setTapPosition(tapPosition); + } +} diff --git a/modules/src/test/java/eu/itesla_project/modules/contigencies/TapChangeActionTest.java b/modules/src/test/java/eu/itesla_project/modules/contigencies/TapChangeActionTest.java new file mode 100644 index 00000000..688f1177 --- /dev/null +++ b/modules/src/test/java/eu/itesla_project/modules/contigencies/TapChangeActionTest.java @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2017, 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 eu.itesla_project.modules.contigencies; + +import eu.itesla_project.contingency.tasks.ModificationTask; +import eu.itesla_project.iidm.network.Network; +import eu.itesla_project.iidm.network.PhaseTapChanger; +import eu.itesla_project.iidm.network.test.PhaseShifterTestCaseFactory; +import eu.itesla_project.modules.contingencies.ActionElementType; +import eu.itesla_project.modules.contingencies.TapChangeAction; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +/** + * @author Mathieu Bague + */ +public class TapChangeActionTest { + + @Test + public void testContructors() { + TapChangeAction action = new TapChangeAction("equipmentId", 1); + assertEquals("equipmentId", action.getEquipmentId()); + assertEquals(1, action.getTapPosition()); + assertNull(action.getAchievmentIndex()); + assertNull(action.getImplementationTime()); + assertEquals(ActionElementType.TAP_CHANGE, action.getType()); + + action = new TapChangeAction("equipmentId2", 2, 150, 0); + assertEquals("equipmentId2", action.getEquipmentId()); + assertEquals(2, action.getTapPosition()); + assertEquals(0, action.getAchievmentIndex()); + assertEquals(150, action.getImplementationTime()); + } + + @Test + public void testToTask() { + Network network = PhaseShifterTestCaseFactory.create(); + PhaseTapChanger tapChanger = network.getTwoWindingsTransformer("PS1").getPhaseTapChanger(); + assertEquals(1, tapChanger.getTapPosition()); + + TapChangeAction action = new TapChangeAction("PS1", 2); + ModificationTask task = action.toTask(); + task.modify(network); + assertEquals(2, tapChanger.getTapPosition()); + + try { + action.toTask(null); + fail(); + } catch (UnsupportedOperationException exc) { + } + } +}