-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load default loadflow parameters from json file in classpath (#3040)
* Add default loadflow parameters loader from json in resources * Add abstract class * Fix dummy extension class Signed-off-by: Hugo KULESZA <hugo.kulesza@rte-france.com>
- Loading branch information
1 parent
cae1343
commit 15a6deb
Showing
6 changed files
with
142 additions
and
1 deletion.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...dflow-api/src/main/java/com/powsybl/loadflow/AbstractLoadFlowDefaultParametersLoader.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,34 @@ | ||
/** | ||
* Copyright (c) 2024, 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/. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
package com.powsybl.loadflow; | ||
|
||
import java.io.InputStream; | ||
import java.util.Objects; | ||
|
||
/** | ||
* @author Hugo Kulesza {@literal <hugo.kulesza at rte-france.com>} | ||
*/ | ||
public abstract class AbstractLoadFlowDefaultParametersLoader implements LoadFlowDefaultParametersLoader { | ||
|
||
private final String name; | ||
private final String jsonParametersFile; | ||
|
||
AbstractLoadFlowDefaultParametersLoader(String name, String jsonParametersFile) { | ||
this.name = Objects.requireNonNull(name); | ||
this.jsonParametersFile = Objects.requireNonNull(jsonParametersFile); | ||
} | ||
|
||
@Override | ||
public String getSourceName() { | ||
return name; | ||
} | ||
|
||
public InputStream loadDefaultParametersFromFile() { | ||
return getClass().getResourceAsStream(jsonParametersFile); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...flow/loadflow-api/src/main/java/com/powsybl/loadflow/LoadFlowDefaultParametersLoader.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,20 @@ | ||
/** | ||
* Copyright (c) 2024, 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/. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
package com.powsybl.loadflow; | ||
|
||
import java.io.InputStream; | ||
|
||
/** | ||
* @author Hugo Kulesza {@literal <hugo.kulesza at rte-france.com>} | ||
*/ | ||
public interface LoadFlowDefaultParametersLoader { | ||
|
||
String getSourceName(); | ||
|
||
InputStream loadDefaultParametersFromFile(); | ||
} |
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
20 changes: 20 additions & 0 deletions
20
.../loadflow-api/src/test/java/com/powsybl/loadflow/LoadFlowDefaultParametersLoaderMock.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,20 @@ | ||
/** | ||
* Copyright (c) 2024, 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/. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
package com.powsybl.loadflow; | ||
|
||
/** | ||
* @author Hugo Kulesza {@literal <hugo.kulesza at rte-france.com>} | ||
*/ | ||
public class LoadFlowDefaultParametersLoaderMock extends AbstractLoadFlowDefaultParametersLoader { | ||
|
||
private static final String RESOURCE_FILE = "/LoadFlowParametersUpdate.json"; | ||
|
||
LoadFlowDefaultParametersLoaderMock(String name) { | ||
super(name, RESOURCE_FILE); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
.../loadflow-api/src/test/java/com/powsybl/loadflow/LoadFlowDefaultParametersLoaderTest.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,44 @@ | ||
/** | ||
* Copyright (c) 2024, 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/. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
package com.powsybl.loadflow; | ||
|
||
import com.powsybl.commons.extensions.Extension; | ||
import com.powsybl.loadflow.json.JsonLoadFlowParametersTest; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* @author Hugo Kulesza {@literal <hugo.kulesza at rte-france.com>} | ||
*/ | ||
class LoadFlowDefaultParametersLoaderTest { | ||
|
||
@Test | ||
void testLoadParametersFromClassPath() { | ||
LoadFlowDefaultParametersLoaderMock loader = new LoadFlowDefaultParametersLoaderMock("test"); | ||
|
||
LoadFlowParameters parameters = new LoadFlowParameters(List.of(loader)); | ||
|
||
List<Extension<LoadFlowParameters>> extensions = parameters.getExtensions().stream().toList(); | ||
assertEquals(1, extensions.size()); | ||
JsonLoadFlowParametersTest.DummyExtension dummyExtension = (JsonLoadFlowParametersTest.DummyExtension) extensions.get(0); | ||
assertEquals(5, dummyExtension.getParameterDouble()); | ||
} | ||
|
||
@Test | ||
void testConflictBetweenDefaultParametersLoader() { | ||
LoadFlowDefaultParametersLoaderMock loader1 = new LoadFlowDefaultParametersLoaderMock("test1"); | ||
LoadFlowDefaultParametersLoaderMock loader2 = new LoadFlowDefaultParametersLoaderMock("test2"); | ||
|
||
LoadFlowParameters parameters = new LoadFlowParameters(List.of(loader1, loader2)); | ||
List<Extension<LoadFlowParameters>> extensions = parameters.getExtensions().stream().toList(); | ||
assertEquals(0, extensions.size()); | ||
} | ||
} |
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