blob: 4dd7f11a192f6d19d00d4ec3770a7a5a779371a7 [file] [log] [blame]
Ray Milkeydbf59f02016-08-19 12:54:16 -07001package org.onosproject.net;
2
3import java.util.List;
4
5import org.junit.Test;
6
7import com.google.common.collect.ImmutableList;
8import com.google.common.testing.EqualsTester;
9
10import static org.hamcrest.MatcherAssert.assertThat;
11import static org.hamcrest.Matchers.is;
12import static org.onosproject.net.NetTestTools.PID;
13
14/**
15 * Unit tests for the DefaultDisjointPathTest.
16 */
17public 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}