Ray Milkey
Committed by Gerrit Code Review

Unit tests to improve API test coverage

Change-Id: I2193b1b29968f2d2b7ba3ddb5947a38343c193c8
......@@ -69,7 +69,7 @@ public class DefaultPortDescription extends AbstractDescription
}
// Default constructor for serialization
private DefaultPortDescription() {
protected DefaultPortDescription() {
this.number = null;
this.isEnabled = false;
this.portSpeed = DEFAULT_SPEED;
......
package org.onosproject.net;
import java.util.List;
import org.junit.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.testing.EqualsTester;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.onosproject.net.NetTestTools.PID;
/**
* Unit tests for the DefaultDisjointPathTest.
*/
public class DefaultDisjointPathTest {
private static DefaultLink link1 =
DefaultLink.builder()
.type(Link.Type.DIRECT)
.providerId(PID)
.src(NetTestTools.connectPoint("dev1", 1))
.dst(NetTestTools.connectPoint("dev2", 1)).build();
private static DefaultLink link2 =
DefaultLink.builder()
.type(Link.Type.DIRECT)
.providerId(PID)
.src(NetTestTools.connectPoint("dev1", 1))
.dst(NetTestTools.connectPoint("dev2", 1)).build();
private static DefaultLink link3 =
DefaultLink.builder()
.type(Link.Type.DIRECT)
.providerId(PID)
.src(NetTestTools.connectPoint("dev2", 1))
.dst(NetTestTools.connectPoint("dev3", 1)).build();
private static List<Link> links1 = ImmutableList.of(link1, link2);
private static DefaultPath path1 =
new DefaultPath(PID, links1, 1.0);
private static List<Link> links2 = ImmutableList.of(link2, link1);
private static DefaultPath path2 =
new DefaultPath(PID, links2, 2.0);
private static List<Link> links3 = ImmutableList.of(link1, link2, link3);
private static DefaultPath path3 =
new DefaultPath(PID, links3, 3.0);
private static DefaultDisjointPath disjointPath1 =
new DefaultDisjointPath(PID, path1, path2);
private static DefaultDisjointPath sameAsDisjointPath1 =
new DefaultDisjointPath(PID, path1, path2);
private static DefaultDisjointPath disjointPath2 =
new DefaultDisjointPath(PID, path2, path1);
private static DefaultDisjointPath disjointPath3 =
new DefaultDisjointPath(PID, path1, path3);
private static DefaultDisjointPath disjointPath4 =
new DefaultDisjointPath(PID, path1, null);
/**
* Tests construction and fetching of member data.
*/
@Test
public void testConstruction() {
assertThat(disjointPath1.primary(), is(path1));
assertThat(disjointPath1.backup(), is(path2));
assertThat(disjointPath1.links(), is(links1));
assertThat(disjointPath1.cost(), is(1.0));
}
/**
* Tests switching to the backup path.
*/
@Test
public void testUseBackup() {
disjointPath1.useBackup();
assertThat(disjointPath1.primary(), is(path1));
assertThat(disjointPath1.backup(), is(path2));
assertThat(disjointPath1.links(), is(links2));
assertThat(disjointPath1.cost(), is(2.0));
disjointPath1.useBackup();
assertThat(disjointPath1.links(), is(links1));
assertThat(disjointPath1.cost(), is(1.0));
assertThat(disjointPath4.primary(), is(path1));
assertThat(disjointPath4.backup(), is((DefaultDisjointPath) null));
disjointPath4.useBackup();
assertThat(disjointPath4.primary(), is(path1));
assertThat(disjointPath4.backup(), is((DefaultDisjointPath) null));
}
/**
* Tests equals(), hashCode(), and toString() methods.
*/
@Test
public void testEquals() {
new EqualsTester()
.addEqualityGroup(disjointPath1, sameAsDisjointPath1, disjointPath2)
.addEqualityGroup(disjointPath3)
.addEqualityGroup(disjointPath4)
.testEquals();
}
}
package org.onosproject.net.config.basics;
import java.time.Duration;
import org.junit.Test;
import org.onosproject.net.Link;
import org.onosproject.net.LinkKey;
import org.onosproject.net.NetTestTools;
import org.onosproject.net.config.ConfigApplyDelegate;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import static java.lang.Boolean.FALSE;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
/**
* Unit tests for the BasicLinkConfig class.
*/
public class BasicLinkConfigTest {
private static final long BANDWIDTH = 11;
private static final double METRIC = 3.0;
private static final Duration LATENCY = Duration.ofNanos(5555);
/**
* Tests construction, setters and getters of a BasicLinkConfig object.
*/
@Test
public void testConstruction() {
BasicLinkConfig config = new BasicLinkConfig();
ConfigApplyDelegate delegate = configApply -> { };
ObjectMapper mapper = new ObjectMapper();
LinkKey linkKey = LinkKey.linkKey(
NetTestTools.connectPoint("device1", 1),
NetTestTools.connectPoint("device2", 2));
config.init(linkKey, "KEY", JsonNodeFactory.instance.objectNode(), mapper, delegate);
config.bandwidth(BANDWIDTH)
.isDurable(FALSE)
.metric(METRIC)
.type(Link.Type.DIRECT)
.latency(LATENCY);
assertThat(config.bandwidth(), is(BANDWIDTH));
assertThat(config.isDurable(), is(FALSE));
assertThat(config.metric(), is(METRIC));
assertThat(config.type(), is(Link.Type.DIRECT));
assertThat(config.latency(), is(LATENCY));
assertThat(config.isValid(), is(true));
}
}
package org.onosproject.net.device;
import org.junit.Test;
import org.onosproject.net.PortNumber;
import com.google.common.testing.EqualsTester;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass;
import static org.onosproject.net.Port.Type.COPPER;
/**
* Unit tests for the DefaultPortDescription test.
*/
public class DefaultPortDescriptionTest {
private static PortNumber port1 = PortNumber.portNumber(1);
private static long portSpeed1 = 111L;
private static DefaultPortDescription portDescription1 =
new DefaultPortDescription(port1, true, COPPER, portSpeed1);
private static DefaultPortDescription sameAsPortDescription1 =
new DefaultPortDescription(portDescription1,
portDescription1.annotations());
private static PortNumber port2 = PortNumber.portNumber(2);
private static DefaultPortDescription portDescription2 =
new DefaultPortDescription(port2, true);
private static DefaultPortDescription portDescription3 =
new DefaultPortDescription();
/**
* Tests the immutability of {@link DefaultPortDescription}.
*/
@Test
public void testImmutable() {
assertThatClassIsImmutableBaseClass(DefaultPortDescription.class);
}
/**
* Tests object construction and fetching of member data.
*/
@Test
public void testConstruction() {
assertThat(portDescription1.portNumber(), is(port1));
assertThat(portDescription1.isEnabled(), is(true));
assertThat(portDescription1.portSpeed(), is(portSpeed1));
assertThat(portDescription1.type(), is(COPPER));
}
/**
* Tests equals(), hashCode(), and toString() methods.
*/
@Test
public void testEquals() {
new EqualsTester()
.addEqualityGroup(portDescription1, sameAsPortDescription1)
.addEqualityGroup(portDescription2)
.addEqualityGroup(portDescription3)
.testEquals();
}
}