Ray Milkey | 8526700 | 2016-11-16 11:06:35 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Ray Milkey | 8526700 | 2016-11-16 11:06:35 -0800 | [diff] [blame] | 3 | * |
| 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 Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 16 | package org.onosproject.net; |
| 17 | |
| 18 | import java.util.List; |
| 19 | |
| 20 | import org.junit.Test; |
| 21 | |
| 22 | import com.google.common.collect.ImmutableList; |
| 23 | import com.google.common.testing.EqualsTester; |
Ray Milkey | a7cf8c8 | 2018-02-08 15:07:06 -0800 | [diff] [blame] | 24 | import org.onlab.graph.ScalarWeight; |
Ray Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 25 | |
| 26 | import static org.hamcrest.MatcherAssert.assertThat; |
| 27 | import static org.hamcrest.Matchers.is; |
| 28 | import static org.onosproject.net.NetTestTools.PID; |
| 29 | |
| 30 | /** |
| 31 | * Unit tests for the DefaultDisjointPathTest. |
| 32 | */ |
| 33 | public 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 Milkey | a7cf8c8 | 2018-02-08 15:07:06 -0800 | [diff] [blame] | 57 | new DefaultPath(PID, links1, ScalarWeight.toWeight(1.0)); |
Ray Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 58 | |
| 59 | private static List<Link> links2 = ImmutableList.of(link2, link1); |
| 60 | private static DefaultPath path2 = |
Ray Milkey | a7cf8c8 | 2018-02-08 15:07:06 -0800 | [diff] [blame] | 61 | new DefaultPath(PID, links2, ScalarWeight.toWeight(2.0)); |
Ray Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 62 | |
| 63 | private static List<Link> links3 = ImmutableList.of(link1, link2, link3); |
| 64 | private static DefaultPath path3 = |
Ray Milkey | a7cf8c8 | 2018-02-08 15:07:06 -0800 | [diff] [blame] | 65 | new DefaultPath(PID, links3, ScalarWeight.toWeight(3.0)); |
Ray Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 66 | |
| 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 Milkey | cc00124 | 2018-09-18 14:55:59 -0700 | [diff] [blame] | 87 | assertThat(disjointPath1.weight(), is(ScalarWeight.toWeight(1.0))); |
Ray Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | /** |
Ray Milkey | dbf59f0 | 2016-08-19 12:54:16 -0700 | [diff] [blame] | 91 | * 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 | } |