blob: 270ffd6527d4e8d6074b299688b9bc2be14cb3a6 [file] [log] [blame]
Ray Milkeye6684082014-10-16 16:59:47 -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 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;
Pavlin Radoslavovd26f57a2014-10-23 17:19:45 -070014import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
Ray Milkeye6684082014-10-16 16:59:47 -070015import static org.onlab.onos.net.NetTestTools.hid;
16
17/**
18 * Unit tests for the HostToHostIntent class.
19 */
20public class TestHostToHostIntent {
21
Thomas Vachuskab97cf282014-10-20 23:31:12 -070022 private static final ApplicationId APPID = new TestApplicationId("foo");
23
Ray Milkeye6684082014-10-16 16:59:47 -070024 private TrafficSelector selector = new IntentTestsMocks.MockSelector();
25 private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
26
Thomas Vachuskab97cf282014-10-20 23:31:12 -070027 private HostToHostIntent makeHostToHost(HostId one, HostId two) {
28 return new HostToHostIntent(APPID, one, two, selector, treatment);
Ray Milkeye6684082014-10-16 16:59:47 -070029 }
30
31 /**
32 * Tests the equals() method where two HostToHostIntents have references
33 * to the same hosts. These should compare equal.
34 */
35 @Test
36 public void testSameEquals() {
37
38 HostId one = hid("00:00:00:00:00:01/-1");
39 HostId two = hid("00:00:00:00:00:02/-1");
Thomas Vachuskab97cf282014-10-20 23:31:12 -070040 HostToHostIntent i1 = makeHostToHost(one, two);
41 HostToHostIntent i2 = makeHostToHost(one, two);
Ray Milkeye6684082014-10-16 16:59:47 -070042
43 assertThat(i1, is(equalTo(i2)));
44 }
45
46 /**
47 * Tests the equals() method where two HostToHostIntents have references
48 * to different Hosts. These should compare not equal.
49 */
50 @Test
Thomas Vachuskaa12fdf22014-10-21 01:33:48 -070051 public void testSameEquals2() {
Ray Milkeye6684082014-10-16 16:59:47 -070052 HostId one = hid("00:00:00:00:00:01/-1");
53 HostId two = hid("00:00:00:00:00:02/-1");
Thomas Vachuskab97cf282014-10-20 23:31:12 -070054 HostToHostIntent i1 = makeHostToHost(one, two);
55 HostToHostIntent i2 = makeHostToHost(two, one);
Ray Milkeye6684082014-10-16 16:59:47 -070056
Thomas Vachuskaa12fdf22014-10-21 01:33:48 -070057 assertThat(i1, is(equalTo(i2)));
Ray Milkeye6684082014-10-16 16:59:47 -070058 }
59
60 /**
61 * Tests that the hashCode() values for two equivalent HostToHostIntent
62 * objects are the same.
63 */
Ray Milkeye6684082014-10-16 16:59:47 -070064 @Test
65 public void testHashCodeEquals() {
66 HostId one = hid("00:00:00:00:00:01/-1");
67 HostId two = hid("00:00:00:00:00:02/-1");
Thomas Vachuskab97cf282014-10-20 23:31:12 -070068 HostToHostIntent i1 = makeHostToHost(one, two);
69 HostToHostIntent i2 = makeHostToHost(one, two);
Ray Milkeye6684082014-10-16 16:59:47 -070070
71 assertThat(i1.hashCode(), is(equalTo(i2.hashCode())));
72 }
73
74 /**
75 * Tests that the hashCode() values for two distinct LinkCollectionIntent
76 * objects are different.
77 */
Ray Milkeye6684082014-10-16 16:59:47 -070078 @Test
Thomas Vachuskaa12fdf22014-10-21 01:33:48 -070079 public void testHashCodeEquals2() {
Ray Milkeye6684082014-10-16 16:59:47 -070080 HostId one = hid("00:00:00:00:00:01/-1");
81 HostId two = hid("00:00:00:00:00:02/-1");
Thomas Vachuskab97cf282014-10-20 23:31:12 -070082 HostToHostIntent i1 = makeHostToHost(one, two);
83 HostToHostIntent i2 = makeHostToHost(two, one);
Ray Milkeye6684082014-10-16 16:59:47 -070084
Thomas Vachuskaa12fdf22014-10-21 01:33:48 -070085 assertThat(i1.hashCode(), is(equalTo(i2.hashCode())));
86 }
87
88 /**
89 * Tests that the hashCode() values for two distinct LinkCollectionIntent
90 * objects are different.
91 */
92 @Test
93 public void testHashCodeDifferent() {
94 HostId one = hid("00:00:00:00:00:01/-1");
95 HostId two = hid("00:00:00:00:00:02/-1");
96 HostId three = hid("00:00:00:00:00:32/-1");
97 HostToHostIntent i1 = makeHostToHost(one, two);
98 HostToHostIntent i2 = makeHostToHost(one, three);
99
Ray Milkeye6684082014-10-16 16:59:47 -0700100 assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode()))));
101 }
102
103 /**
104 * Checks that the HostToHostIntent class is immutable.
105 */
106 @Test
107 public void checkImmutability() {
Pavlin Radoslavovd26f57a2014-10-23 17:19:45 -0700108 assertThatClassIsImmutable(HostToHostIntent.class);
Ray Milkeye6684082014-10-16 16:59:47 -0700109 }
110}