Skip to content

Commit

Permalink
Add unit test to validate the ucte import ()
Browse files Browse the repository at this point in the history
  • Loading branch information
SlimaneAmar committed Dec 1, 2020
1 parent 22e91b7 commit 0ff76df
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
*/
package com.powsybl.network.conversion.server;

import com.powsybl.commons.datasource.MemDataSource;
import com.powsybl.commons.datasource.ReadOnlyDataSource;
import com.powsybl.commons.datasource.ResourceDataSource;
import com.powsybl.commons.datasource.ResourceSet;
import com.powsybl.iidm.export.Exporters;
import com.powsybl.iidm.import_.Importers;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.xml.XMLExporter;
import com.powsybl.network.store.client.NetworkStoreService;
import com.powsybl.network.store.client.PreloadingStrategy;
import com.powsybl.network.store.iidm.impl.NetworkFactoryImpl;
import com.powsybl.ucte.converter.UcteImporter;
import org.apache.commons.compress.utils.IOUtils;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -30,6 +35,7 @@
import org.springframework.web.client.RestTemplate;

import java.io.InputStream;
import java.util.Properties;
import java.util.UUID;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -111,6 +117,26 @@ public void test() throws Exception {
}
}

@Test
public void testImportUcte() throws Exception {
String baseName = "uctNetwork";
ReadOnlyDataSource dataSource = new ResourceDataSource(baseName, new ResourceSet("", baseName + ".uct"));
Properties properties = new Properties();
properties.put(XMLExporter.SORTED, true);
properties.put(XMLExporter.WITH_BRANCH_STATE_VARIABLES, true);
Network networkCoreImpl = new UcteImporter().importData(dataSource, new com.powsybl.iidm.network.impl.NetworkFactoryImpl(), properties);
Network networkStoreImpl = new UcteImporter().importData(dataSource, new NetworkFactoryImpl(), properties);

MemDataSource memCoreDataSource = new MemDataSource();
Exporters.export("XIIDM", networkCoreImpl, properties, memCoreDataSource);
String resultCore = new String(memCoreDataSource.getData("", "xiidm"), "UTF-8").replaceAll("caseDate=\".*\"", "");
MemDataSource memStoreDataSource = new MemDataSource();
Exporters.export("XIIDM", networkStoreImpl, properties, memStoreDataSource);
String resultStore = new String(memStoreDataSource.getData("", "xiidm"), "UTF-8").replaceAll("caseDate=\".*\"", "");

assertEquals(resultCore, resultStore);
}

@Test
public void testWithMergingView() throws Exception {
UUID testNetworkId1 = UUID.fromString("7928181c-7977-4592-ba19-88027e4254e4");
Expand All @@ -122,8 +148,8 @@ public void testWithMergingView() throws Exception {
given(networkStoreClient.getNetwork(testNetworkId3, PreloadingStrategy.COLLECTION)).willReturn(createNetwork("3_"));

MvcResult mvcResult = mvc.perform(get("/v1/networks/{networkUuid}/export/{format}", testNetworkId1.toString(), "XIIDM")
.param("networkUuid", testNetworkId2.toString())
.param("networkUuid", testNetworkId3.toString()))
.param("networkUuid", testNetworkId2.toString())
.param("networkUuid", testNetworkId3.toString()))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_OCTET_STREAM))
.andReturn();
Expand All @@ -132,7 +158,7 @@ public void testWithMergingView() throws Exception {
assertTrue(mvcResult.getResponse().getContentAsString().startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
}

public Network createNetwork(String prefix) {
private Network createNetwork(String prefix) {
Network network = NetworkFactory.findDefault().createNetwork(prefix + "network", "test");
Substation p1 = network.newSubstation()
.setId(prefix + "P1")
Expand Down
47 changes: 47 additions & 0 deletions src/test/resources/uctNetwork.uct
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
##C 2007.05.01
##N
##ZBE
B_SU1_11 Belgium Nod1 0 0 50.0000 0.00000 0.00000 0.00000
B_SU1_21 Belgium Nod2 0 2 225.00 0.00000 0.00000 100.000 0.00000 F
##ZFR
F_SU1_11 France Node1 0 0 50.0000 0.00000 0.00000 0.00000
F_SU1_12 France Node3 0 0 0.00000 0.00000 0.00000 0.00000
F_SU1_21 France Node2 0 0 0.00000 0.00000 0.00000 0.00000
F_SU1_31 France Node4 0 0 225.00 25.0000 10.0000 5.00000 2.00000 F
F_SU2_11 France ONode 0 2 400.00 0.00000 0.00000 50.0000 0.00000 F
##ZHR
HCCCCC1 namename11 0 0 123.000 18.4000 0.00000 0.00000
HDDDDD2 namename11 0 0 0.00000 0.00000 0.00000 0.00000
##ZPL
ZABCD221 0 0 0.00000 0.00000 0.00000 0.00000
ZEFGH221 0 0 0.00000 0.00000 0.00000 0.00000
ZIJK1412 0 0 0.00000 0.00000 0.00000 0.00000
ZLMNO221 0 0 0.00000 0.00000 0.00000 0.00000
##ZME
0AAAAA2 NAME12121212 0 0 0.00000 0.00000 0.00000 0.00000
0BBBBB5 NAME12121212 0 2 115.00 0.00000 0.00000 -33.200 10.0000 0.00000 -300.00 10.0000 -40.000 F
##ZXX
XB__F_11 FR-BE Xnode1 1 0 0.00000 0.00000 0.00000 0.00000
XB__F_21 FR-BE Xnode2 1 0 0.00000 0.00000 0.00000 0.00000
XG__F_21 France Xnode 1 0 50.0000 0.00000 0.00000 0.00000
##L
F_SU1_12 F_SU1_11 1 2 0.0000 0.0000 0.000000 5000 Test Coupler
F_SU1_12 F_SU2_11 1 0 0.5500 1.6800 13.25000 5000 Test Line
F_SU1_12 F_SU2_11 2 0 0.6666 1.8888 13.25000 5000 Test Line 2
XB__F_11 B_SU1_11 1 1 0.5500 1.6800 13.25000 5000 Test TL 1/2
XB__F_11 F_SU1_11 1 1 0.5500 1.6800 13.25000 5000 Test TL 1/1
XB__F_21 B_SU1_21 1 1 0.5500 1.6800 13.25000 5000 Test TL 2/2
XB__F_21 F_SU1_21 1 1 0.5500 1.6800 13.25000 5000 Test TL 2/1
XG__F_21 F_SU1_21 1 1 0.5500 1.6800 13.25000 5000 Test DL
##T
0BBBBB5 0AAAAA2 1 0 110.0 220.0 125.0 0.2500 10.686 0.000000 0.0000 656
B_SU1_11 B_SU1_21 1 0 400.0 225.0 5000. 0.5500 1.6800 13.25000 0.0000 5000 Test 2WT 2
F_SU1_11 F_SU1_21 1 0 400.0 225.0 5000. 0.5500 1.6800 13.25000 0.0000 5000 Test 2WT 1
HDDDDD2 HCCCCC1 1 0 231.0 400.0 400.0 0.1880 15.100 -9.76000 0.0000 1000
ZABCD221 ZEFGH221 1 0 220.0 220.0 330.0 0.0484 0.4840 0.000000 0.0000 866
ZIJK1412 ZLMNO221 1 0 400.0 231.0 400.0 1.1360 53.504 -27.2125 0.0000 693
##R
0BBBBB5 0AAAAA2 1 2.000 7 -3
HDDDDD2 HCCCCC1 1 1.000 60.00 13 3 ASYM
ZABCD221 ZEFGH221 1 1.573 90.00 8 -1 SYMM
ZIJK1412 ZLMNO221 1 1.250 11 1 220.0

0 comments on commit 0ff76df

Please sign in to comment.