-
Notifications
You must be signed in to change notification settings - Fork 0
Add applicability per root network tag on network modifications #219
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
Changes from all commits
3a0ef83
b8a1fb5
f3cb797
d29b0e4
767099f
9f6fc09
ceeca5e
405cca9
7eddbf3
a4a871b
67d6f36
f4ea3c1
f337356
fdab3f3
71d439b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,9 @@ | |
| import com.powsybl.commons.report.ReportNode; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.Map; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| /** | ||
|
|
@@ -17,11 +20,21 @@ | |
| */ | ||
| class ModificationInfosTest { | ||
|
|
||
| private static final String TAG = "PH1"; | ||
| private static final String OTHER_TAG = "PH2"; | ||
|
|
||
| private static final class TestModificationInfos extends ModificationInfos { | ||
| // Intentionally does not override createSubReportNode() or toModification() | ||
| // to test the UnsupportedOperationException throwing behavior | ||
| } | ||
|
|
||
| private static ModificationInfos modificationInfos(Boolean activated, Map<String, Boolean> applicabilityByRootNetworkTag) { | ||
| ModificationInfos modificationInfos = new TestModificationInfos(); | ||
| modificationInfos.setActivated(activated); | ||
| modificationInfos.setApplicabilityByRootNetworkTag(applicabilityByRootNetworkTag); | ||
| return modificationInfos; | ||
| } | ||
|
|
||
| @Test | ||
| void testCreateSubReportNodeThrowsUnsupportedOperationException() { | ||
| ModificationInfos modificationInfos = new TestModificationInfos(); | ||
|
|
@@ -52,4 +65,71 @@ void testToModificationThrowsUnsupportedOperationException() { | |
| assertEquals(expectedMessage, exception.getMessage(), | ||
| "Exception message should indicate which method and class need implementation"); | ||
| } | ||
|
|
||
| @Test | ||
| void testNotActivatedWhenModificationIsStashed() { | ||
| ModificationInfos modificationInfos = modificationInfos(true, Map.of(TAG, true)); | ||
| modificationInfos.setStashed(true); | ||
| assertFalse(modificationInfos.isActivatedOn(TAG), | ||
| "A stashed modification is activated on no root network, whatever its applicabilities"); | ||
|
Mathieu-Deharbe marked this conversation as resolved.
|
||
| assertFalse(modificationInfos.isActivatedOn(null), | ||
| "A stashed modification is not activated without a root network context"); | ||
| } | ||
|
|
||
| @Test | ||
| void testActivatedWhenStashedIsUndefined() { | ||
| ModificationInfos modificationInfos = modificationInfos(true, Map.of(TAG, true)); | ||
| modificationInfos.setStashed(null); | ||
| assertTrue(modificationInfos.isActivatedOn(TAG), | ||
| "An undefined stash flag keeps the default of the field: the modification is not stashed"); | ||
| } | ||
|
|
||
| @Test | ||
| void testNotActivatedWhenModificationIsDeactivated() { | ||
| assertFalse(modificationInfos(false, Map.of(TAG, true)).isActivatedOn(TAG), | ||
| "A deactivated modification is activated on no root network, whatever its applicabilities"); | ||
| assertFalse(modificationInfos(null, Map.of(TAG, true)).isActivatedOn(TAG), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a side note this should'nt happen if we take the word of "activated" field description "Modification activated (defaults to true at creation when not provided)"
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's defaulted to true but it doesn't mean null value means activated. |
||
| "An undefined activation flag is not an activation"); | ||
| } | ||
|
|
||
| @Test | ||
| void testActivatedWhenNoRootNetworkTagGiven() { | ||
| assertTrue(modificationInfos(true, Map.of(TAG, false)).isActivatedOn(null), | ||
| "A null tag means no root network context: the per root network applicabilities are then ignored"); | ||
| } | ||
|
|
||
| @Test | ||
| void testActivatedWhenNoApplicabilityDefined() { | ||
| assertTrue(modificationInfos(true, null).isActivatedOn(TAG), | ||
| "A modification without any applicability is activated on every root network"); | ||
| } | ||
|
|
||
| @Test | ||
| void testActivatedWhenTagHasNoEntry() { | ||
| assertTrue(modificationInfos(true, Map.of()).isActivatedOn(TAG), | ||
| "A modification without any applicability entry for a tag is activated on it"); | ||
| assertTrue(modificationInfos(true, Map.of(OTHER_TAG, false)).isActivatedOn(TAG), | ||
| "An entry deactivating another tag leaves this one applicable"); | ||
| } | ||
|
|
||
| @Test | ||
| void testActivatedWhenTagEntryIsNull() { | ||
| // singletonMap, not Map.of, which rejects a null value | ||
| assertTrue(modificationInfos(true, Collections.singletonMap(TAG, null)).isActivatedOn(TAG), | ||
| "A tag mapped to no value is applicable: only an explicit false deactivates it"); | ||
| } | ||
|
|
||
| @Test | ||
| void testActivationFollowsTagEntry() { | ||
| assertTrue(modificationInfos(true, Map.of(TAG, true)).isActivatedOn(TAG)); | ||
| assertFalse(modificationInfos(true, Map.of(TAG, false)).isActivatedOn(TAG)); | ||
| } | ||
|
|
||
| @Test | ||
| void testTagsAreIndependent() { | ||
| ModificationInfos modificationInfos = modificationInfos(true, Map.of(TAG, false, OTHER_TAG, true)); | ||
| assertFalse(modificationInfos.isActivatedOn(TAG)); | ||
| assertTrue(modificationInfos.isActivatedOn(OTHER_TAG), | ||
| "Deactivating a tag must not affect the other ones"); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.