-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ibdp/Node: use Optional#flatMap correctly (#7043)
We accidentally made an `Optional<Optional<Rib>>` that could be absent, or present with a Rib, or present with an absent Rib. We meant to chain the optionality, which is done with `flatMap`.
- Loading branch information
Showing
2 changed files
with
40 additions
and
1 deletion.
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
39 changes: 39 additions & 0 deletions
39
projects/batfish/src/test/java/org/batfish/dataplane/ibdp/NodeTest.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,39 @@ | ||
package org.batfish.dataplane.ibdp; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import org.batfish.datamodel.Configuration; | ||
import org.batfish.datamodel.ConfigurationFormat; | ||
import org.batfish.datamodel.Vrf; | ||
import org.batfish.datamodel.dataplane.rib.RibId; | ||
import org.junit.Test; | ||
|
||
public class NodeTest { | ||
@Test | ||
public void testGetRib() { | ||
Configuration c = | ||
Configuration.builder() | ||
.setHostname("c") | ||
.setConfigurationFormat(ConfigurationFormat.FLAT_JUNIPER) | ||
.build(); | ||
Vrf v = Vrf.builder().setOwner(c).setName("v").build(); | ||
Node n = new Node(c); | ||
// Right Vrf, right RIB -> present | ||
assertThat( | ||
n.getRib(new RibId(c.getHostname(), v.getName(), RibId.DEFAULT_RIB_NAME)).isPresent(), | ||
equalTo(true)); | ||
// Right Vrf, wrong RIB -> absent | ||
assertThat( | ||
n.getRib(new RibId(c.getHostname(), v.getName(), "no-such-rib")).isPresent(), | ||
equalTo(false)); | ||
// Wrong Vrf -> absent | ||
assertThat( | ||
n.getRib(new RibId(c.getHostname(), "no-such-vrf", RibId.DEFAULT_RIB_NAME)).isPresent(), | ||
equalTo(false)); | ||
// Wrong Config -> absent | ||
assertThat( | ||
n.getRib(new RibId("no-such-host", v.getName(), RibId.DEFAULT_RIB_NAME)).isPresent(), | ||
equalTo(false)); | ||
} | ||
} |