blob: 4ebee73137d660412d1999fa7c956e9d055dd389 [file] [log] [blame]
Ray Milkeye6684082014-10-16 16:59:47 -07001package org.onlab.onos.net.intent;
2
3import org.junit.Test;
Thomas Vachuskab97cf282014-10-20 23:31:12 -07004import org.onlab.onos.ApplicationId;
5import org.onlab.onos.TestApplicationId;
Ray Milkeye6684082014-10-16 16:59:47 -07006import org.onlab.onos.net.HostId;
7import org.onlab.onos.net.flow.TrafficSelector;
8import org.onlab.onos.net.flow.TrafficTreatment;
9
10import static org.hamcrest.MatcherAssert.assertThat;
11import static org.hamcrest.Matchers.equalTo;
12import static org.hamcrest.Matchers.is;
13import static org.hamcrest.Matchers.not;
14import static org.onlab.onos.net.NetTestTools.hid;
15
16/**
17 * Unit tests for the HostToHostIntent class.
18 */
19public class TestHostToHostIntent {
20
Thomas Vachuskab97cf282014-10-20 23:31:12 -070021 private static final ApplicationId APPID = new TestApplicationId("foo");
22
Ray Milkeye6684082014-10-16 16:59:47 -070023 private TrafficSelector selector = new IntentTestsMocks.MockSelector();
24 private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
25
Thomas Vachuskab97cf282014-10-20 23:31:12 -070026 private HostToHostIntent makeHostToHost(HostId one, HostId two) {
27 return new HostToHostIntent(APPID, one, two, selector, treatment);
Ray Milkeye6684082014-10-16 16:59:47 -070028 }
29
30 /**
31 * Tests the equals() method where two HostToHostIntents have references
32 * to the same hosts. These should compare equal.
33 */
34 @Test
35 public void testSameEquals() {
36
37 HostId one = hid("00:00:00:00:00:01/-1");
38 HostId two = hid("00:00:00:00:00:02/-1");
Thomas Vachuskab97cf282014-10-20 23:31:12 -070039 HostToHostIntent i1 = makeHostToHost(one, two);
40 HostToHostIntent i2 = makeHostToHost(one, two);
Ray Milkeye6684082014-10-16 16:59:47 -070041
42 assertThat(i1, is(equalTo(i2)));
43 }
44
45 /**
46 * Tests the equals() method where two HostToHostIntents have references
47 * to different Hosts. These should compare not equal.
48 */
49 @Test
Thomas Vachuskaa12fdf22014-10-21 01:33:48 -070050 public void testSameEquals2() {
Ray Milkeye6684082014-10-16 16:59:47 -070051 HostId one = hid("00:00:00:00:00:01/-1");
52 HostId two = hid("00:00:00:00:00:02/-1");
Thomas Vachuskab97cf282014-10-20 23:31:12 -070053 HostToHostIntent i1 = makeHostToHost(one, two);
54 HostToHostIntent i2 = makeHostToHost(two, one);
Ray Milkeye6684082014-10-16 16:59:47 -070055
Thomas Vachuskaa12fdf22014-10-21 01:33:48 -070056 assertThat(i1, is(equalTo(i2)));
Ray Milkeye6684082014-10-16 16:59:47 -070057 }
58
59 /**
60 * Tests that the hashCode() values for two equivalent HostToHostIntent
61 * objects are the same.
62 */
Ray Milkeye6684082014-10-16 16:59:47 -070063 @Test
64 public void testHashCodeEquals() {
65 HostId one = hid("00:00:00:00:00:01/-1");
66 HostId two = hid("00:00:00:00:00:02/-1");
Thomas Vachuskab97cf282014-10-20 23:31:12 -070067 HostToHostIntent i1 = makeHostToHost(one, two);
68 HostToHostIntent i2 = makeHostToHost(one, two);
Ray Milkeye6684082014-10-16 16:59:47 -070069
70 assertThat(i1.hashCode(), is(equalTo(i2.hashCode())));
71 }
72
73 /**
74 * Tests that the hashCode() values for two distinct LinkCollectionIntent
75 * objects are different.
76 */
Ray Milkeye6684082014-10-16 16:59:47 -070077 @Test
Thomas Vachuskaa12fdf22014-10-21 01:33:48 -070078 public void testHashCodeEquals2() {
Ray Milkeye6684082014-10-16 16:59:47 -070079 HostId one = hid("00:00:00:00:00:01/-1");
80 HostId two = hid("00:00:00:00:00:02/-1");
Thomas Vachuskab97cf282014-10-20 23:31:12 -070081 HostToHostIntent i1 = makeHostToHost(one, two);
82 HostToHostIntent i2 = makeHostToHost(two, one);
Ray Milkeye6684082014-10-16 16:59:47 -070083
Thomas Vachuskaa12fdf22014-10-21 01:33:48 -070084 assertThat(i1.hashCode(), is(equalTo(i2.hashCode())));
85 }
86
87 /**
88 * Tests that the hashCode() values for two distinct LinkCollectionIntent
89 * objects are different.
90 */
91 @Test
92 public void testHashCodeDifferent() {
93 HostId one = hid("00:00:00:00:00:01/-1");
94 HostId two = hid("00:00:00:00:00:02/-1");
95 HostId three = hid("00:00:00:00:00:32/-1");
96 HostToHostIntent i1 = makeHostToHost(one, two);
97 HostToHostIntent i2 = makeHostToHost(one, three);
98
Ray Milkeye6684082014-10-16 16:59:47 -070099 assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode()))));
100 }
101
102 /**
103 * Checks that the HostToHostIntent class is immutable.
104 */
105 @Test
106 public void checkImmutability() {
107 ImmutableClassChecker.assertThatClassIsImmutable(HostToHostIntent.class);
108 }
109}