blob: ec6281418ca48b6f4600ccbc81e93825f2a56dd4 [file] [log] [blame]
Ray Milkey85267002016-11-16 11:06:35 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Ray Milkey85267002016-11-16 11:06:35 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Ray Milkeydbf59f02016-08-19 12:54:16 -070016package org.onosproject.net;
17
18import java.util.List;
19
20import org.junit.Test;
21
22import com.google.common.collect.ImmutableList;
23import com.google.common.testing.EqualsTester;
24
25import static org.hamcrest.MatcherAssert.assertThat;
26import static org.hamcrest.Matchers.is;
27import static org.onosproject.net.NetTestTools.PID;
28
29/**
30 * Unit tests for the DefaultDisjointPathTest.
31 */
32public class DefaultDisjointPathTest {
33 private static DefaultLink link1 =
34 DefaultLink.builder()
35 .type(Link.Type.DIRECT)
36 .providerId(PID)
37 .src(NetTestTools.connectPoint("dev1", 1))
38 .dst(NetTestTools.connectPoint("dev2", 1)).build();
39
40 private static DefaultLink link2 =
41 DefaultLink.builder()
42 .type(Link.Type.DIRECT)
43 .providerId(PID)
44 .src(NetTestTools.connectPoint("dev1", 1))
45 .dst(NetTestTools.connectPoint("dev2", 1)).build();
46
47 private static DefaultLink link3 =
48 DefaultLink.builder()
49 .type(Link.Type.DIRECT)
50 .providerId(PID)
51 .src(NetTestTools.connectPoint("dev2", 1))
52 .dst(NetTestTools.connectPoint("dev3", 1)).build();
53
54 private static List<Link> links1 = ImmutableList.of(link1, link2);
55 private static DefaultPath path1 =
56 new DefaultPath(PID, links1, 1.0);
57
58 private static List<Link> links2 = ImmutableList.of(link2, link1);
59 private static DefaultPath path2 =
60 new DefaultPath(PID, links2, 2.0);
61
62 private static List<Link> links3 = ImmutableList.of(link1, link2, link3);
63 private static DefaultPath path3 =
64 new DefaultPath(PID, links3, 3.0);
65
66 private static DefaultDisjointPath disjointPath1 =
67 new DefaultDisjointPath(PID, path1, path2);
68 private static DefaultDisjointPath sameAsDisjointPath1 =
69 new DefaultDisjointPath(PID, path1, path2);
70 private static DefaultDisjointPath disjointPath2 =
71 new DefaultDisjointPath(PID, path2, path1);
72 private static DefaultDisjointPath disjointPath3 =
73 new DefaultDisjointPath(PID, path1, path3);
74 private static DefaultDisjointPath disjointPath4 =
75 new DefaultDisjointPath(PID, path1, null);
76
77
78 /**
79 * Tests construction and fetching of member data.
80 */
81 @Test
82 public void testConstruction() {
83 assertThat(disjointPath1.primary(), is(path1));
84 assertThat(disjointPath1.backup(), is(path2));
85 assertThat(disjointPath1.links(), is(links1));
86 assertThat(disjointPath1.cost(), is(1.0));
87 }
88
89 /**
Ray Milkeydbf59f02016-08-19 12:54:16 -070090 * Tests equals(), hashCode(), and toString() methods.
91 */
92 @Test
93 public void testEquals() {
94 new EqualsTester()
95 .addEqualityGroup(disjointPath1, sameAsDisjointPath1, disjointPath2)
96 .addEqualityGroup(disjointPath3)
97 .addEqualityGroup(disjointPath4)
98 .testEquals();
99 }
100}