Committed by
Gerrit Code Review
Unit tests to improve API test coverage
Change-Id: I2193b1b29968f2d2b7ba3ddb5947a38343c193c8
Showing
4 changed files
with
226 additions
and
1 deletions
| ... | @@ -69,7 +69,7 @@ public class DefaultPortDescription extends AbstractDescription | ... | @@ -69,7 +69,7 @@ public class DefaultPortDescription extends AbstractDescription |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | // Default constructor for serialization | 71 | // Default constructor for serialization |
| 72 | - private DefaultPortDescription() { | 72 | + protected DefaultPortDescription() { |
| 73 | this.number = null; | 73 | this.number = null; |
| 74 | this.isEnabled = false; | 74 | this.isEnabled = false; |
| 75 | this.portSpeed = DEFAULT_SPEED; | 75 | this.portSpeed = DEFAULT_SPEED; | ... | ... |
| 1 | +package org.onosproject.net; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | + | ||
| 5 | +import org.junit.Test; | ||
| 6 | + | ||
| 7 | +import com.google.common.collect.ImmutableList; | ||
| 8 | +import com.google.common.testing.EqualsTester; | ||
| 9 | + | ||
| 10 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
| 11 | +import static org.hamcrest.Matchers.is; | ||
| 12 | +import static org.onosproject.net.NetTestTools.PID; | ||
| 13 | + | ||
| 14 | +/** | ||
| 15 | + * Unit tests for the DefaultDisjointPathTest. | ||
| 16 | + */ | ||
| 17 | +public class DefaultDisjointPathTest { | ||
| 18 | + private static DefaultLink link1 = | ||
| 19 | + DefaultLink.builder() | ||
| 20 | + .type(Link.Type.DIRECT) | ||
| 21 | + .providerId(PID) | ||
| 22 | + .src(NetTestTools.connectPoint("dev1", 1)) | ||
| 23 | + .dst(NetTestTools.connectPoint("dev2", 1)).build(); | ||
| 24 | + | ||
| 25 | + private static DefaultLink link2 = | ||
| 26 | + DefaultLink.builder() | ||
| 27 | + .type(Link.Type.DIRECT) | ||
| 28 | + .providerId(PID) | ||
| 29 | + .src(NetTestTools.connectPoint("dev1", 1)) | ||
| 30 | + .dst(NetTestTools.connectPoint("dev2", 1)).build(); | ||
| 31 | + | ||
| 32 | + private static DefaultLink link3 = | ||
| 33 | + DefaultLink.builder() | ||
| 34 | + .type(Link.Type.DIRECT) | ||
| 35 | + .providerId(PID) | ||
| 36 | + .src(NetTestTools.connectPoint("dev2", 1)) | ||
| 37 | + .dst(NetTestTools.connectPoint("dev3", 1)).build(); | ||
| 38 | + | ||
| 39 | + private static List<Link> links1 = ImmutableList.of(link1, link2); | ||
| 40 | + private static DefaultPath path1 = | ||
| 41 | + new DefaultPath(PID, links1, 1.0); | ||
| 42 | + | ||
| 43 | + private static List<Link> links2 = ImmutableList.of(link2, link1); | ||
| 44 | + private static DefaultPath path2 = | ||
| 45 | + new DefaultPath(PID, links2, 2.0); | ||
| 46 | + | ||
| 47 | + private static List<Link> links3 = ImmutableList.of(link1, link2, link3); | ||
| 48 | + private static DefaultPath path3 = | ||
| 49 | + new DefaultPath(PID, links3, 3.0); | ||
| 50 | + | ||
| 51 | + private static DefaultDisjointPath disjointPath1 = | ||
| 52 | + new DefaultDisjointPath(PID, path1, path2); | ||
| 53 | + private static DefaultDisjointPath sameAsDisjointPath1 = | ||
| 54 | + new DefaultDisjointPath(PID, path1, path2); | ||
| 55 | + private static DefaultDisjointPath disjointPath2 = | ||
| 56 | + new DefaultDisjointPath(PID, path2, path1); | ||
| 57 | + private static DefaultDisjointPath disjointPath3 = | ||
| 58 | + new DefaultDisjointPath(PID, path1, path3); | ||
| 59 | + private static DefaultDisjointPath disjointPath4 = | ||
| 60 | + new DefaultDisjointPath(PID, path1, null); | ||
| 61 | + | ||
| 62 | + | ||
| 63 | + /** | ||
| 64 | + * Tests construction and fetching of member data. | ||
| 65 | + */ | ||
| 66 | + @Test | ||
| 67 | + public void testConstruction() { | ||
| 68 | + assertThat(disjointPath1.primary(), is(path1)); | ||
| 69 | + assertThat(disjointPath1.backup(), is(path2)); | ||
| 70 | + assertThat(disjointPath1.links(), is(links1)); | ||
| 71 | + assertThat(disjointPath1.cost(), is(1.0)); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + /** | ||
| 75 | + * Tests switching to the backup path. | ||
| 76 | + */ | ||
| 77 | + @Test | ||
| 78 | + public void testUseBackup() { | ||
| 79 | + disjointPath1.useBackup(); | ||
| 80 | + assertThat(disjointPath1.primary(), is(path1)); | ||
| 81 | + assertThat(disjointPath1.backup(), is(path2)); | ||
| 82 | + assertThat(disjointPath1.links(), is(links2)); | ||
| 83 | + assertThat(disjointPath1.cost(), is(2.0)); | ||
| 84 | + | ||
| 85 | + disjointPath1.useBackup(); | ||
| 86 | + assertThat(disjointPath1.links(), is(links1)); | ||
| 87 | + assertThat(disjointPath1.cost(), is(1.0)); | ||
| 88 | + | ||
| 89 | + assertThat(disjointPath4.primary(), is(path1)); | ||
| 90 | + assertThat(disjointPath4.backup(), is((DefaultDisjointPath) null)); | ||
| 91 | + disjointPath4.useBackup(); | ||
| 92 | + assertThat(disjointPath4.primary(), is(path1)); | ||
| 93 | + assertThat(disjointPath4.backup(), is((DefaultDisjointPath) null)); | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + /** | ||
| 97 | + * Tests equals(), hashCode(), and toString() methods. | ||
| 98 | + */ | ||
| 99 | + @Test | ||
| 100 | + public void testEquals() { | ||
| 101 | + new EqualsTester() | ||
| 102 | + .addEqualityGroup(disjointPath1, sameAsDisjointPath1, disjointPath2) | ||
| 103 | + .addEqualityGroup(disjointPath3) | ||
| 104 | + .addEqualityGroup(disjointPath4) | ||
| 105 | + .testEquals(); | ||
| 106 | + } | ||
| 107 | +} |
| 1 | +package org.onosproject.net.config.basics; | ||
| 2 | + | ||
| 3 | +import java.time.Duration; | ||
| 4 | + | ||
| 5 | +import org.junit.Test; | ||
| 6 | +import org.onosproject.net.Link; | ||
| 7 | +import org.onosproject.net.LinkKey; | ||
| 8 | +import org.onosproject.net.NetTestTools; | ||
| 9 | +import org.onosproject.net.config.ConfigApplyDelegate; | ||
| 10 | + | ||
| 11 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
| 12 | +import com.fasterxml.jackson.databind.node.JsonNodeFactory; | ||
| 13 | + | ||
| 14 | +import static java.lang.Boolean.FALSE; | ||
| 15 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
| 16 | +import static org.hamcrest.Matchers.is; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * Unit tests for the BasicLinkConfig class. | ||
| 20 | + */ | ||
| 21 | + | ||
| 22 | +public class BasicLinkConfigTest { | ||
| 23 | + private static final long BANDWIDTH = 11; | ||
| 24 | + private static final double METRIC = 3.0; | ||
| 25 | + private static final Duration LATENCY = Duration.ofNanos(5555); | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * Tests construction, setters and getters of a BasicLinkConfig object. | ||
| 29 | + */ | ||
| 30 | + @Test | ||
| 31 | + public void testConstruction() { | ||
| 32 | + BasicLinkConfig config = new BasicLinkConfig(); | ||
| 33 | + ConfigApplyDelegate delegate = configApply -> { }; | ||
| 34 | + ObjectMapper mapper = new ObjectMapper(); | ||
| 35 | + LinkKey linkKey = LinkKey.linkKey( | ||
| 36 | + NetTestTools.connectPoint("device1", 1), | ||
| 37 | + NetTestTools.connectPoint("device2", 2)); | ||
| 38 | + | ||
| 39 | + config.init(linkKey, "KEY", JsonNodeFactory.instance.objectNode(), mapper, delegate); | ||
| 40 | + | ||
| 41 | + | ||
| 42 | + config.bandwidth(BANDWIDTH) | ||
| 43 | + .isDurable(FALSE) | ||
| 44 | + .metric(METRIC) | ||
| 45 | + .type(Link.Type.DIRECT) | ||
| 46 | + .latency(LATENCY); | ||
| 47 | + | ||
| 48 | + assertThat(config.bandwidth(), is(BANDWIDTH)); | ||
| 49 | + assertThat(config.isDurable(), is(FALSE)); | ||
| 50 | + assertThat(config.metric(), is(METRIC)); | ||
| 51 | + assertThat(config.type(), is(Link.Type.DIRECT)); | ||
| 52 | + assertThat(config.latency(), is(LATENCY)); | ||
| 53 | + assertThat(config.isValid(), is(true)); | ||
| 54 | + } | ||
| 55 | +} |
| 1 | +package org.onosproject.net.device; | ||
| 2 | + | ||
| 3 | +import org.junit.Test; | ||
| 4 | +import org.onosproject.net.PortNumber; | ||
| 5 | + | ||
| 6 | +import com.google.common.testing.EqualsTester; | ||
| 7 | + | ||
| 8 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
| 9 | +import static org.hamcrest.Matchers.is; | ||
| 10 | +import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass; | ||
| 11 | +import static org.onosproject.net.Port.Type.COPPER; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * Unit tests for the DefaultPortDescription test. | ||
| 15 | + */ | ||
| 16 | +public class DefaultPortDescriptionTest { | ||
| 17 | + | ||
| 18 | + private static PortNumber port1 = PortNumber.portNumber(1); | ||
| 19 | + private static long portSpeed1 = 111L; | ||
| 20 | + private static DefaultPortDescription portDescription1 = | ||
| 21 | + new DefaultPortDescription(port1, true, COPPER, portSpeed1); | ||
| 22 | + | ||
| 23 | + private static DefaultPortDescription sameAsPortDescription1 = | ||
| 24 | + new DefaultPortDescription(portDescription1, | ||
| 25 | + portDescription1.annotations()); | ||
| 26 | + | ||
| 27 | + private static PortNumber port2 = PortNumber.portNumber(2); | ||
| 28 | + private static DefaultPortDescription portDescription2 = | ||
| 29 | + new DefaultPortDescription(port2, true); | ||
| 30 | + | ||
| 31 | + private static DefaultPortDescription portDescription3 = | ||
| 32 | + new DefaultPortDescription(); | ||
| 33 | + /** | ||
| 34 | + * Tests the immutability of {@link DefaultPortDescription}. | ||
| 35 | + */ | ||
| 36 | + @Test | ||
| 37 | + public void testImmutable() { | ||
| 38 | + assertThatClassIsImmutableBaseClass(DefaultPortDescription.class); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * Tests object construction and fetching of member data. | ||
| 43 | + */ | ||
| 44 | + @Test | ||
| 45 | + public void testConstruction() { | ||
| 46 | + assertThat(portDescription1.portNumber(), is(port1)); | ||
| 47 | + assertThat(portDescription1.isEnabled(), is(true)); | ||
| 48 | + assertThat(portDescription1.portSpeed(), is(portSpeed1)); | ||
| 49 | + assertThat(portDescription1.type(), is(COPPER)); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * Tests equals(), hashCode(), and toString() methods. | ||
| 54 | + */ | ||
| 55 | + @Test | ||
| 56 | + public void testEquals() { | ||
| 57 | + new EqualsTester() | ||
| 58 | + .addEqualityGroup(portDescription1, sameAsPortDescription1) | ||
| 59 | + .addEqualityGroup(portDescription2) | ||
| 60 | + .addEqualityGroup(portDescription3) | ||
| 61 | + .testEquals(); | ||
| 62 | + } | ||
| 63 | +} |
-
Please register or login to post a comment