blob: 41769c61775e32aaefc2db2f70654392b2499dff [file] [log] [blame]
Ray Milkeyc0fa4db2014-10-17 08:49:54 -07001package org.onlab.onos.net.intent;
2
3import org.junit.Test;
4import org.onlab.onos.net.ConnectPoint;
5import org.onlab.onos.net.flow.TrafficSelector;
6import org.onlab.onos.net.flow.TrafficTreatment;
7
8import static org.hamcrest.MatcherAssert.assertThat;
9import static org.hamcrest.Matchers.equalTo;
10import static org.hamcrest.Matchers.is;
11import static org.hamcrest.Matchers.not;
12import static org.onlab.onos.net.NetTestTools.connectPoint;
13
14/**
15 * Unit tests for the HostToHostIntent class.
16 */
17public 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}