Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Open Networking Laboratory |
| 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 | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 16 | package org.onlab.onos.net.intent; |
| 17 | |
| 18 | import org.junit.Test; |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 19 | import org.onlab.onos.core.ApplicationId; |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 20 | import org.onlab.onos.TestApplicationId; |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 21 | import org.onlab.onos.net.ConnectPoint; |
| 22 | import org.onlab.onos.net.flow.TrafficSelector; |
| 23 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 24 | |
| 25 | import static org.hamcrest.MatcherAssert.assertThat; |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 26 | import static org.hamcrest.Matchers.*; |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 27 | import static org.onlab.onos.net.NetTestTools.connectPoint; |
| 28 | |
| 29 | /** |
| 30 | * Unit tests for the HostToHostIntent class. |
| 31 | */ |
| 32 | public class TestPointToPointIntent { |
| 33 | |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 34 | private static final ApplicationId APPID = new TestApplicationId("foo"); |
| 35 | |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 36 | private TrafficSelector selector = new IntentTestsMocks.MockSelector(); |
| 37 | private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); |
| 38 | |
| 39 | private ConnectPoint point1 = connectPoint("dev1", 1); |
| 40 | private ConnectPoint point2 = connectPoint("dev2", 1); |
| 41 | |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 42 | private PointToPointIntent makePointToPoint(ConnectPoint ingress, |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 43 | ConnectPoint egress) { |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 44 | return new PointToPointIntent(APPID, selector, treatment, ingress, egress); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Tests the equals() method where two PointToPointIntents have references |
| 49 | * to the same ingress and egress points. These should compare equal. |
| 50 | */ |
| 51 | @Test |
| 52 | public void testSameEquals() { |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 53 | PointToPointIntent i1 = makePointToPoint(point1, point2); |
| 54 | PointToPointIntent i2 = makePointToPoint(point1, point2); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 55 | |
| 56 | assertThat(i1, is(equalTo(i2))); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Tests the equals() method where two HostToHostIntents have references |
| 61 | * to different Hosts. These should compare not equal. |
| 62 | */ |
| 63 | @Test |
| 64 | public void testLinksDifferentEquals() { |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 65 | PointToPointIntent i1 = makePointToPoint(point1, point2); |
| 66 | PointToPointIntent i2 = makePointToPoint(point2, point1); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 67 | |
| 68 | assertThat(i1, is(not(equalTo(i2)))); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Tests that the hashCode() values for two equivalent HostToHostIntent |
| 73 | * objects are the same. |
| 74 | */ |
| 75 | @Test |
| 76 | public void testHashCodeEquals() { |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 77 | PointToPointIntent i1 = makePointToPoint(point1, point2); |
| 78 | PointToPointIntent i2 = makePointToPoint(point1, point2); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 79 | |
| 80 | assertThat(i1.hashCode(), is(equalTo(i2.hashCode()))); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Tests that the hashCode() values for two distinct LinkCollectionIntent |
| 85 | * objects are different. |
| 86 | */ |
| 87 | @Test |
| 88 | public void testHashCodeDifferent() { |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 89 | PointToPointIntent i1 = makePointToPoint(point1, point2); |
| 90 | PointToPointIntent i2 = makePointToPoint(point2, point1); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 91 | |
| 92 | assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode())))); |
| 93 | } |
| 94 | } |