-
Notifications
You must be signed in to change notification settings - Fork 5
Extend Validation to EnergyManagement Systems #1359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4bbe628
Extend Validation to EnergyManagement Systems
danielfeismann 9088286
remove validation for emInput.controllStrategy
danielfeismann 9f9034d
fmt
danielfeismann 6afd362
adapted test
danielfeismann f533287
Merge branch 'dev' into df/#1356-validation-em
danielfeismann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
58 changes: 58 additions & 0 deletions
58
src/main/java/edu/ie3/datamodel/utils/validation/EnergyManagementValidationUtils.java
This file contains hidden or 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,58 @@ | ||
/* | ||
* © 2021. TU Dortmund University, | ||
* Institute of Energy Systems, Energy Efficiency and Energy Economics, | ||
* Research group Distribution grid planning and operation | ||
*/ | ||
package edu.ie3.datamodel.utils.validation; | ||
|
||
import edu.ie3.datamodel.exceptions.InvalidEntityException; | ||
import edu.ie3.datamodel.exceptions.ValidationException; | ||
import edu.ie3.datamodel.models.input.EmInput; | ||
import edu.ie3.datamodel.utils.Try; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class EnergyManagementValidationUtils extends ValidationUtils { | ||
|
||
/** Private Constructor as this class is not meant to be instantiated */ | ||
private EnergyManagementValidationUtils() { | ||
throw new IllegalStateException("Don't try and instantiate a Utility class."); | ||
} | ||
|
||
/** | ||
* Validates a energy management unit if: | ||
* | ||
* <ul> | ||
* <li>its control strategy is not null | ||
* <li>its control strategy matches the supported strategies | ||
* </ul> | ||
* | ||
* A "distribution" method, that forwards the check request to specific implementations to fulfill | ||
* the checking task, based on the class of the given object. | ||
* | ||
* @param energyManagement EmInput to validate | ||
* @return a list of try objects either containing an {@link ValidationException} or an empty | ||
* Success | ||
*/ | ||
protected static List<Try<Void, ? extends ValidationException>> check(EmInput energyManagement) { | ||
List<Try<Void, ? extends ValidationException>> exceptions = new ArrayList<>(); | ||
|
||
exceptions.add( | ||
Try.ofVoid( | ||
energyManagement.getControlStrategy() == null, | ||
() -> | ||
new InvalidEntityException( | ||
"No control strategy of energy management defined for", energyManagement))); | ||
|
||
exceptions.add( | ||
Try.ofVoid( | ||
!(energyManagement.getControlStrategy().equals("PRIORITIZED") | ||
|| energyManagement.getControlStrategy().equals("PROPORTIONAL")), | ||
() -> | ||
new InvalidEntityException( | ||
"Control strategy of energy management system must be one of the following: PRIORITIZED, PROPORTIONAL.", | ||
energyManagement))); | ||
|
||
return exceptions; | ||
} | ||
} |
This file contains hidden or 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
41 changes: 41 additions & 0 deletions
41
src/test/groovy/edu/ie3/datamodel/utils/validation/EmValidationUtilsTest.groovy
This file contains hidden or 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,41 @@ | ||
/* | ||
* © 2025. TU Dortmund University, | ||
* Institute of Energy Systems, Energy Efficiency and Energy Economics, | ||
* Research group Distribution grid planning and operation | ||
*/ | ||
package edu.ie3.datamodel.utils.validation | ||
|
||
import edu.ie3.datamodel.exceptions.InvalidEntityException | ||
import edu.ie3.datamodel.exceptions.ValidationException | ||
import edu.ie3.datamodel.utils.Try | ||
import edu.ie3.test.common.GridTestData | ||
import spock.lang.Specification | ||
|
||
class EmValidationUtilsTest extends Specification { | ||
|
||
def "Smoke Test: Correct energy management system throws no exception"() { | ||
given: | ||
def em = GridTestData.energyManagementInput | ||
|
||
when: | ||
List<Try<Void, ? extends ValidationException>> tries = EnergyManagementValidationUtils.check(em) | ||
|
||
then: | ||
tries.every { it.success } | ||
} | ||
|
||
def "The check method recognizes all potential errors for an energy management input"() { | ||
when: | ||
List<Try<Void, ? extends ValidationException>> exceptions = EnergyManagementValidationUtils.check(invalidEm).stream().filter { it -> it.failure }.toList() | ||
|
||
then: | ||
exceptions.size() == expectedSize | ||
Exception ex = exceptions.get(0).exception.get() | ||
ex.class == expectedException.class | ||
ex.message == expectedException.message | ||
|
||
where: | ||
invalidEm || expectedSize || expectedException | ||
GridTestData.energyManagementInput.copy().controlStrategy("invalid").build() || 1 || new InvalidEntityException("Control strategy of energy management system must be one of the following: PRIORITIZED, PROPORTIONAL.", invalidEm) | ||
} | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.