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