Skip to content

Commit

Permalink
Move virtual-hubs to farao-core (#851)
Browse files Browse the repository at this point in the history
* moved virtual-hubs to farao-core

* cleaned up a pom

Signed-off-by: Philippe Edwards <[email protected]>

* added security around xml import of virtual hubs

* fixes after review

---------

Signed-off-by: Philippe Edwards <[email protected]>
Co-authored-by: OpenSuze <[email protected]>
  • Loading branch information
phiedw and OpenSuze authored Dec 18, 2023
1 parent dc780f3 commit c16c77d
Show file tree
Hide file tree
Showing 47 changed files with 2,373 additions and 21 deletions.
2 changes: 1 addition & 1 deletion data/crac-io/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
<module>crac-io-api</module>
<module>crac-io-json</module>
</modules>
</project>
</project>
5 changes: 1 addition & 4 deletions data/glsk/glsk-virtual-hubs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@
<artifactId>farao-reference-program</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>farao-virtual-hubs-network-extension</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>farao-virtual-hubs-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
Expand Down
3 changes: 2 additions & 1 deletion data/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
<module>rao-result</module>
<module>result-exporter</module>
<module>refprog</module>
<module>virtual-hubs</module>
</modules>
</project>
</project>
25 changes: 25 additions & 0 deletions data/virtual-hubs/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.farao-community.farao</groupId>
<artifactId>farao-data</artifactId>
<version>4.7.0-SNAPSHOT</version>
</parent>

<artifactId>farao-virtual-hubs</artifactId>
<packaging>pom</packaging>
<name>FARAO virtual hubs</name>
<description>Virtual hubs management for FARAO framework</description>

<modules>
<module>virtual-hubs-api</module>
<module>virtual-hubs-json</module>
<module>virtual-hubs-network-assigner</module>
<module>virtual-hubs-network-extension</module>
<module>virtual-hubs-xml</module>
</modules>

</project>
20 changes: 20 additions & 0 deletions data/virtual-hubs/virtual-hubs-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.farao-community.farao</groupId>
<artifactId>farao-virtual-hubs</artifactId>
<version>4.7.0-SNAPSHOT</version>
</parent>
<artifactId>farao-virtual-hubs-api</artifactId>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2020, 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 https://mozilla.org/MPL/2.0/.
*/
package com.farao_community.farao.virtual_hubs;

import java.util.Objects;

/**
* Market area description POJO
*
* @author Sebastien Murgey {@literal <[email protected]>}
*/
public class MarketArea {
private final String code;
private final String eic;
private final boolean isMcParticipant;

public MarketArea(String code, String eic, boolean isMcParticipant) {
this.code = Objects.requireNonNull(code, "MarketArea creation does not allow null code");
this.eic = Objects.requireNonNull(eic, "MarketArea creation does not allow null eic");
this.isMcParticipant = isMcParticipant;
}

public String getCode() {
return code;
}

public String getEic() {
return eic;
}

public boolean isMcParticipant() {
return isMcParticipant;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2020, 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 https://mozilla.org/MPL/2.0/.
*/
package com.farao_community.farao.virtual_hubs;

import java.util.Objects;

/**
* Virtual hub description POJO
*
* @author Sebastien Murgey {@literal <[email protected]>}
*/
public class VirtualHub {
private final String code;
private final String eic;
private final boolean isMcParticipant;
private final String nodeName;
private final MarketArea relatedMa;

public VirtualHub(String code, String eic, boolean isMcParticipant, String nodeName, MarketArea relatedMa) {
this.code = Objects.requireNonNull(code, "VirtualHub creation does not allow null code");
this.eic = Objects.requireNonNull(eic, "VirtualHub creation does not allow null eic");
this.isMcParticipant = isMcParticipant;
this.nodeName = Objects.requireNonNull(nodeName, "VirtualHub creation does not allow null nodeName");
this.relatedMa = Objects.requireNonNull(relatedMa, "VirtualHub creation does not allow null relatedMa");
}

public String getCode() {
return code;
}

public String getEic() {
return eic;
}

public boolean isMcParticipant() {
return isMcParticipant;
}

public String getNodeName() {
return nodeName;
}

public MarketArea getRelatedMa() {
return relatedMa;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2020, 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 https://mozilla.org/MPL/2.0/.
*/
package com.farao_community.farao.virtual_hubs;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
* Virtual hubs configuration POJO
*
* @author Sebastien Murgey {@literal <[email protected]>}
*/
public class VirtualHubsConfiguration {
private final List<MarketArea> marketAreas = new ArrayList<>();
private final List<VirtualHub> virtualHubs = new ArrayList<>();

public void addMarketArea(MarketArea marketArea) {
marketAreas.add(Objects.requireNonNull(marketArea, "Virtual hubs configuration does not allow adding null market area"));
}

public void addVirtualHub(VirtualHub virtualHub) {
virtualHubs.add(Objects.requireNonNull(virtualHub, "Virtual hubs configuration does not allow adding null virtual hub"));
}

public List<MarketArea> getMarketAreas() {
return marketAreas;
}

public List<VirtualHub> getVirtualHubs() {
return virtualHubs;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2020, 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 https://mozilla.org/MPL/2.0/.
*/
package com.farao_community.farao.virtual_hubs;

import org.junit.jupiter.api.Test;

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

/**
* @author Sebastien Murgey {@literal <[email protected]>}
*/
class MarketAreaTest {
@Test
public void checkThatMarketAreaIsCorrectlyCreated() {
MarketArea myMarketArea = new MarketArea("AreaCode", "AreaEic", true);
assertEquals("AreaCode", myMarketArea.getCode());
assertEquals("AreaEic", myMarketArea.getEic());
assertTrue(myMarketArea.isMcParticipant());

MarketArea myOtherMarketArea = new MarketArea("OtherAreaCode", "OtherAreaEic", false);
assertEquals("OtherAreaCode", myOtherMarketArea.getCode());
assertEquals("OtherAreaEic", myOtherMarketArea.getEic());
assertFalse(myOtherMarketArea.isMcParticipant());
}

@Test
public void checkThatMarketAreaCreationThrowsWhenCodeIsNull() {
NullPointerException thrown = assertThrows(
NullPointerException.class,
() -> new MarketArea(null, "AreaEic", true),
"Null code in MarketArea creation should throw but does not"
);
assertEquals("MarketArea creation does not allow null code", thrown.getMessage());
}

@Test
public void checkThatMarketAreaCreationThrowsWhenEicIsNull() {
NullPointerException thrown = assertThrows(
NullPointerException.class,
() -> new MarketArea("AreaCode", null, true),
"Null eic in MarketArea creation should throw but does not"
);
assertEquals("MarketArea creation does not allow null eic", thrown.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright (c) 2020, 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 https://mozilla.org/MPL/2.0/.
*/
package com.farao_community.farao.virtual_hubs;

import org.junit.jupiter.api.Test;

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

/**
* @author Sebastien Murgey {@literal <[email protected]>}
*/
class VirtualHubTest {
@Test
public void checkThatVirtualHubIsCorrectlyCreated() {
MarketArea marketArea = new MarketArea("AreaCode", "AreaEic", true);
VirtualHub myVirtualHub = new VirtualHub("HubCode", "HubEic", true, "HubNodeName", marketArea);
assertEquals("HubCode", myVirtualHub.getCode());
assertEquals("HubEic", myVirtualHub.getEic());
assertTrue(myVirtualHub.isMcParticipant());
assertEquals("HubNodeName", myVirtualHub.getNodeName());
assertEquals(marketArea, myVirtualHub.getRelatedMa());

MarketArea otherMarketArea = new MarketArea("OtherAreaCode", "OtherAreaEic", false);
VirtualHub myOtherVirtualHub = new VirtualHub("OtherHubCode", "OtherHubEic", false, "OtherHubNodeName", otherMarketArea);
assertEquals("OtherHubCode", myOtherVirtualHub.getCode());
assertEquals("OtherHubEic", myOtherVirtualHub.getEic());
assertFalse(myOtherVirtualHub.isMcParticipant());
assertEquals("OtherHubNodeName", myOtherVirtualHub.getNodeName());
assertEquals(otherMarketArea, myOtherVirtualHub.getRelatedMa());
}

@Test
public void checkThatVirtualHubCreationThrowsWhenCodeIsNull() {
MarketArea marketArea = new MarketArea("AreaCode", "AreaEic", true);
NullPointerException thrown = assertThrows(
NullPointerException.class,
() -> new VirtualHub(null, "HubEic", true, "HubNodeName", marketArea),
"Null code in VirtualHub creation should throw but does not"
);
assertEquals("VirtualHub creation does not allow null code", thrown.getMessage());
}

@Test
public void checkThatVirtualHubCreationThrowsWhenEicIsNull() {
MarketArea marketArea = new MarketArea("AreaCode", "AreaEic", true);
NullPointerException thrown = assertThrows(
NullPointerException.class,
() -> new VirtualHub("HubCode", null, true, "HubNodeName", marketArea),
"Null code in VirtualHub creation should throw but does not"
);
assertEquals("VirtualHub creation does not allow null eic", thrown.getMessage());
}

@Test
public void checkThatVirtualHubCreationThrowsWhenNodeNameIsNull() {
MarketArea marketArea = new MarketArea("AreaCode", "AreaEic", true);
NullPointerException thrown = assertThrows(
NullPointerException.class,
() -> new VirtualHub("HubCode", "HubEic", true, null, marketArea),
"Null nodeName in VirtualHub creation should throw but does not"
);
assertEquals("VirtualHub creation does not allow null nodeName", thrown.getMessage());
}

@Test
public void checkThatVirtualHubCreationThrowsWhenMarketAreaIsNull() {
NullPointerException thrown = assertThrows(
NullPointerException.class,
() -> new VirtualHub("HubCode", "HubEic", true, "HubNodeName", null),
"Null relatedMa in VirtualHub creation should throw but does not"
);
assertEquals("VirtualHub creation does not allow null relatedMa", thrown.getMessage());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2020, 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 https://mozilla.org/MPL/2.0/.
*/
package com.farao_community.farao.virtual_hubs;

import org.junit.jupiter.api.Test;

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

/**
* @author Sebastien Murgey {@literal <[email protected]>}
*/
class VirtualHubsConfigurationTest {
@Test
public void checkThatConfigurationManipulationWorksAsExpected() {
VirtualHubsConfiguration configuration = new VirtualHubsConfiguration();
MarketArea marketArea = new MarketArea("AreaCode", "AreaEic", true);
configuration.addMarketArea(marketArea);
configuration.addMarketArea(new MarketArea("OtherAreaCode", "OtherAreaEic", false));
configuration.addVirtualHub(new VirtualHub("HubCode", "HubEic", true, "HibNodeName", marketArea));

assertEquals(2, configuration.getMarketAreas().size());
assertEquals(1, configuration.getVirtualHubs().size());
assertTrue(configuration.getMarketAreas().contains(marketArea));
}

@Test
public void checkThatAddingNullMarketAreaInConfigurationThrows() {
VirtualHubsConfiguration configuration = new VirtualHubsConfiguration();
NullPointerException thrown = assertThrows(
NullPointerException.class,
() -> configuration.addMarketArea(null),
"Null market area addition in configuration should throw but does not"
);
assertEquals("Virtual hubs configuration does not allow adding null market area", thrown.getMessage());
}

@Test
public void checkThatAddingNullVirtualHubInConfigurationThrows() {
VirtualHubsConfiguration configuration = new VirtualHubsConfiguration();
NullPointerException thrown = assertThrows(
NullPointerException.class,
() -> configuration.addVirtualHub(null),
"Null virtual hub addition in configuration should throw but does not"
);
assertEquals("Virtual hubs configuration does not allow adding null virtual hub", thrown.getMessage());
}
}
Loading

0 comments on commit c16c77d

Please sign in to comment.