blob: 904e013c5ec570908e1b30c298971476a17143c7 [file] [log] [blame]
Ray Milkeyc0fa4db2014-10-17 08:49:54 -07001package org.onlab.onos.net.intent;
2
3import org.junit.Test;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -07004import org.onlab.onos.core.ApplicationId;
Thomas Vachuskab97cf282014-10-20 23:31:12 -07005import org.onlab.onos.TestApplicationId;
Ray Milkeyc0fa4db2014-10-17 08:49:54 -07006import org.onlab.onos.net.ConnectPoint;
7import org.onlab.onos.net.flow.TrafficSelector;
8import org.onlab.onos.net.flow.TrafficTreatment;
9
10import static org.hamcrest.MatcherAssert.assertThat;
Thomas Vachuskab97cf282014-10-20 23:31:12 -070011import static org.hamcrest.Matchers.*;
Ray Milkeyc0fa4db2014-10-17 08:49:54 -070012import static org.onlab.onos.net.NetTestTools.connectPoint;
13
14/**
15 * Unit tests for the HostToHostIntent class.
16 */
17public class TestPointToPointIntent {
18
Thomas Vachuskab97cf282014-10-20 23:31:12 -070019 private static final ApplicationId APPID = new TestApplicationId("foo");
20
Ray Milkeyc0fa4db2014-10-17 08:49:54 -070021 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 Vachuskab97cf282014-10-20 23:31:12 -070027 private PointToPointIntent makePointToPoint(ConnectPoint ingress,
Ray Milkeyc0fa4db2014-10-17 08:49:54 -070028 ConnectPoint egress) {
Thomas Vachuskab97cf282014-10-20 23:31:12 -070029 return new PointToPointIntent(APPID, selector, treatment, ingress, egress);
Ray Milkeyc0fa4db2014-10-17 08:49:54 -070030 }
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 Vachuskab97cf282014-10-20 23:31:12 -070038 PointToPointIntent i1 = makePointToPoint(point1, point2);
39 PointToPointIntent i2 = makePointToPoint(point1, point2);
Ray Milkeyc0fa4db2014-10-17 08:49:54 -070040
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 Vachuskab97cf282014-10-20 23:31:12 -070050 PointToPointIntent i1 = makePointToPoint(point1, point2);
51 PointToPointIntent i2 = makePointToPoint(point2, point1);
Ray Milkeyc0fa4db2014-10-17 08:49:54 -070052
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 Vachuskab97cf282014-10-20 23:31:12 -070062 PointToPointIntent i1 = makePointToPoint(point1, point2);
63 PointToPointIntent i2 = makePointToPoint(point1, point2);
Ray Milkeyc0fa4db2014-10-17 08:49:54 -070064
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 Vachuskab97cf282014-10-20 23:31:12 -070074 PointToPointIntent i1 = makePointToPoint(point1, point2);
75 PointToPointIntent i2 = makePointToPoint(point2, point1);
Ray Milkeyc0fa4db2014-10-17 08:49:54 -070076
77 assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode()))));
78 }
79}