Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
massimo-ferraro committed Jan 23, 2017
1 parent 9add7c7 commit 8b47fc6
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 13 deletions.
5 changes: 5 additions & 0 deletions wca-integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>com.google.jimfs</groupId>
<artifactId>jimfs</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>eu.itesla_project</groupId>
<artifactId>iidm-network-impl</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* 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.wca;

import static org.junit.Assert.assertEquals;
Expand All @@ -8,37 +14,53 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URISyntaxException;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.zip.GZIPInputStream;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.junit.Rule;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import com.google.common.io.CharStreams;
import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;

import eu.itesla_project.iidm.network.Network;
import eu.itesla_project.iidm.network.test.NetworkTest1Factory;

/**
*
* @author Massimo Ferraro <massimo.ferraro@techrain.it>
*/
public class WCAUtilsTest {

@Rule
public TemporaryFolder testFolder = new TemporaryFolder();


private FileSystem fileSystem;

@Before
public void setUp() throws Exception {
fileSystem = Jimfs.newFileSystem(Configuration.unix());
}

@After
public void tearDown() throws Exception {
fileSystem.close();
}

@Test
public void testExportState() throws IOException, URISyntaxException {
Path folder = testFolder.newFolder().toPath();
Path folder = Files.createDirectory(fileSystem.getPath("/export-folder"));
Network network = NetworkTest1Factory.create();
network.setCaseDate(new DateTime(1483228800000l).withZone(DateTimeZone.UTC));
WCAUtils.exportState(network, folder, 0, 0);
File exportedState = Paths.get(folder.toString(), network.getId() + "_0_0.xiidm.gz").toFile();
assertTrue(exportedState.exists());
File expectedState = new File(getClass().getResource("/network1_0_0.xiidm.gz").toURI());
assertEquals(CharStreams.toString(new InputStreamReader(new GZIPInputStream(new FileInputStream(expectedState)))),
CharStreams.toString(new InputStreamReader(new GZIPInputStream(new FileInputStream(exportedState)))));
Path exportedState = folder.resolve(network.getId() + "_0_0.xiidm.gz");
assertTrue(Files.exists(exportedState));
File expectedState = new File(getClass().getResource("/network1.xiidm").toURI());
assertEquals(CharStreams.toString(new InputStreamReader(new FileInputStream(expectedState))),
CharStreams.toString(new InputStreamReader(new GZIPInputStream(Files.newInputStream(exportedState)))));
}

}
23 changes: 23 additions & 0 deletions wca-integration/src/test/resources/network1.xiidm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<iidm:network xmlns:iidm="http://www.itesla_project.eu/schema/iidm/1_0" id="network1" caseDate="2017-01-01T00:00:00.000Z" forecastDistance="0" sourceFormat="test">
<iidm:substation id="substation1" country="FR" tso="TSO1" geographicalTags="region1">
<iidm:voltageLevel id="voltageLevel1" nominalV="400.0" topologyKind="NODE_BREAKER">
<iidm:nodeBreakerTopology nodeCount="10">
<iidm:busbarSection id="voltageLevel1BusbarSection1" node="0"/>
<iidm:busbarSection id="voltageLevel1BusbarSection2" node="1"/>
<iidm:switch id="voltageLevel1Breaker1" kind="BREAKER" retained="true" open="false" node1="0" node2="1"/>
<iidm:switch id="load1Disconnector1" kind="DISCONNECTOR" retained="false" open="false" node1="2" node2="3"/>
<iidm:switch id="load1Breaker1" kind="DISCONNECTOR" retained="false" open="false" node1="3" node2="0"/>
<iidm:switch id="generator1Disconnector1" kind="DISCONNECTOR" retained="false" open="false" node1="5" node2="6"/>
<iidm:switch id="generator1Breaker1" kind="DISCONNECTOR" retained="false" open="false" node1="6" node2="1"/>
</iidm:nodeBreakerTopology>
<iidm:generator id="generator1" energySource="NUCLEAR" minP="200.0" maxP="900.0" voltageRegulatorOn="true" targetP="900.0" targetV="380.0" node="5">
<iidm:reactiveCapabilityCurve>
<iidm:point p="200.0" minQ="300.0" maxQ="500.0"/>
<iidm:point p="900.0" minQ="300.0" maxQ="500.0"/>
</iidm:reactiveCapabilityCurve>
</iidm:generator>
<iidm:load id="load1" loadType="UNDEFINED" p0="10.0" q0="3.0" node="2"/>
</iidm:voltageLevel>
</iidm:substation>
</iidm:network>
Binary file not shown.

0 comments on commit 8b47fc6

Please sign in to comment.