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