-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move virtual-hubs to farao-core (#851)
* 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
Showing
47 changed files
with
2,373 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,4 @@ | |
<module>crac-io-api</module> | ||
<module>crac-io-json</module> | ||
</modules> | ||
</project> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
38 changes: 38 additions & 0 deletions
38
...ubs/virtual-hubs-api/src/main/java/com/farao_community/farao/virtual_hubs/MarketArea.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...ubs/virtual-hubs-api/src/main/java/com/farao_community/farao/virtual_hubs/VirtualHub.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...bs-api/src/main/java/com/farao_community/farao/virtual_hubs/VirtualHubsConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...virtual-hubs-api/src/test/java/com/farao_community/farao/virtual_hubs/MarketAreaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
...virtual-hubs-api/src/test/java/com/farao_community/farao/virtual_hubs/VirtualHubTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
...pi/src/test/java/com/farao_community/farao/virtual_hubs/VirtualHubsConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
Oops, something went wrong.