Skip to content
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

Remove property #528

Merged
merged 3 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,11 @@ public void setProperty(String name, Object value) {
}
properties.put(name, value);
}

public void removeProperty(String name) {
Objects.requireNonNull(name);
if (properties != null) {
properties.remove(name);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public interface PropertyBag {
Object getProperty(String name);

void setProperty(String name, Object value);

void removeProperty(String name);
}
23 changes: 21 additions & 2 deletions src/test/java/com/powsybl/openloadflow/network/PropertyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.openloadflow.network.impl.Networks;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -20,16 +21,34 @@
*/
class PropertyTest {

private LfNetwork lfNetwork;

@BeforeEach
void setUp() {
Network network = EurostagTutorialExample1Factory.create();
lfNetwork = Networks.load(network, new FirstSlackBusSelector()).get(0);
}

@Test
void test() {
Network network = EurostagTutorialExample1Factory.create();
LfNetwork lfNetwork = Networks.load(network, new FirstSlackBusSelector()).get(0);
assertNull(lfNetwork.getProperty("a"));
lfNetwork.setProperty("a", "test");
assertEquals("test", lfNetwork.getProperty("a"));
LfBus lfBus = lfNetwork.getBus(0);
assertNull(lfBus.getProperty("b"));
lfBus.setProperty("b", "hello");
assertEquals("hello", lfBus.getProperty("b"));
lfBus.removeProperty("b");
assertNull(lfBus.getProperty("b"));
lfBus.setProperty("c", "hi");
assertEquals("hi", lfBus.getProperty("c"));
}

@Test
void testRemoveWithEmptyMap() {
// also try to remove a not defined property
assertNull(lfNetwork.getProperty("x"));
lfNetwork.removeProperty("x");
assertNull(lfNetwork.getProperty("x"));
}
}