blob: abe4627cf8372799240688b5e4f13fecc3ecda6a [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;
Ray Milkeya7cf8c82018-02-08 15:07:06 -080024import org.onlab.graph.ScalarWeight;
Ray Milkeydbf59f02016-08-19 12:54:16 -070025
26import static org.hamcrest.MatcherAssert.assertThat;
27import static org.hamcrest.Matchers.is;
28import static org.onosproject.net.NetTestTools.PID;
29
30/**
31 * Unit tests for the DefaultDisjointPathTest.
32 */
33public class DefaultDisjointPathTest {
34 private static DefaultLink link1 =
35 DefaultLink.builder()
36 .type(Link.Type.DIRECT)
37 .providerId(PID)
38 .src(NetTestTools.connectPoint("dev1", 1))
39 .dst(NetTestTools.connectPoint("dev2", 1)).build();
40
41 private static DefaultLink link2 =
42 DefaultLink.builder()
43 .type(Link.Type.DIRECT)
44 .providerId(PID)
45 .src(NetTestTools.connectPoint("dev1", 1))
46 .dst(NetTestTools.connectPoint("dev2", 1)).build();
47
48 private static DefaultLink link3 =
49 DefaultLink.builder()
50 .type(Link.Type.DIRECT)
51 .providerId(PID)
52 .src(NetTestTools.connectPoint("dev2", 1))
53 .dst(NetTestTools.connectPoint("dev3", 1)).build();
54
55 private static List<Link> links1 = ImmutableList.of(link1, link2);
56 private static DefaultPath path1 =
Ray Milkeya7cf8c82018-02-08 15:07:06 -080057 new DefaultPath(PID, links1, ScalarWeight.toWeight(1.0));
Ray Milkeydbf59f02016-08-19 12:54:16 -070058
59 private static List<Link> links2 = ImmutableList.of(link2, link1);
60 private static DefaultPath path2 =
Ray Milkeya7cf8c82018-02-08 15:07:06 -080061 new DefaultPath(PID, links2, ScalarWeight.toWeight(2.0));
Ray Milkeydbf59f02016-08-19 12:54:16 -070062
63 private static List<Link> links3 = ImmutableList.of(link1, link2, link3);
64 private static DefaultPath path3 =
Ray Milkeya7cf8c82018-02-08 15:07:06 -080065 new DefaultPath(PID, links3, ScalarWeight.toWeight(3.0));
Ray Milkeydbf59f02016-08-19 12:54:16 -070066
67 private static DefaultDisjointPath disjointPath1 =
68 new DefaultDisjointPath(PID, path1, path2);
69 private static DefaultDisjointPath sameAsDisjointPath1 =
70 new DefaultDisjointPath(PID, path1, path2);
71 private static DefaultDisjointPath disjointPath2 =
72 new DefaultDisjointPath(PID, path2, path1);
73 private static DefaultDisjointPath disjointPath3 =
74 new DefaultDisjointPath(PID, path1, path3);
75 private static DefaultDisjointPath disjointPath4 =
76 new DefaultDisjointPath(PID, path1, null);
77
78
79 /**
80 * Tests construction and fetching of member data.
81 */
82 @Test
83 public void testConstruction() {
84 assertThat(disjointPath1.primary(), is(path1));
85 assertThat(disjointPath1.backup(), is(path2));
86 assertThat(disjointPath1.links(), is(links1));
Ray Milkeycc001242018-09-18 14:55:59 -070087 assertThat(disjointPath1.weight(), is(ScalarWeight.toWeight(1.0)));
Ray Milkeydbf59f02016-08-19 12:54:16 -070088 }
89
90 /**
Ray Milkeydbf59f02016-08-19 12:54:16 -070091 * Tests equals(), hashCode(), and toString() methods.
92 */
93 @Test
94 public void testEquals() {
95 new EqualsTester()
96 .addEqualityGroup(disjointPath1, sameAsDisjointPath1, disjointPath2)
97 .addEqualityGroup(disjointPath3)
98 .addEqualityGroup(disjointPath4)
99 .testEquals();
100 }
101}