blob: f5e25513faebb39ef6f2c628250092402e31a912 [file] [log] [blame]
Ray Milkeye6684082014-10-16 16:59:47 -07001package org.onlab.onos.net.intent;
2
3import org.junit.Test;
4import org.onlab.onos.net.HostId;
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.hid;
13
14/**
15 * Unit tests for the HostToHostIntent class.
16 */
17public class TestHostToHostIntent {
18
19 private TrafficSelector selector = new IntentTestsMocks.MockSelector();
20 private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
21
22 private HostToHostIntent makeHostToHost(long id, HostId one, HostId two) {
23 return new HostToHostIntent(new IntentId(id),
24 one,
25 two,
26 selector,
27 treatment);
28 }
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");
39 HostToHostIntent i1 = makeHostToHost(12, one, two);
40 HostToHostIntent i2 = makeHostToHost(12, one, two);
41
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
50 public void testLinksDifferentEquals() {
51
52 HostId one = hid("00:00:00:00:00:01/-1");
53 HostId two = hid("00:00:00:00:00:02/-1");
54 HostToHostIntent i1 = makeHostToHost(12, one, two);
55 HostToHostIntent i2 = makeHostToHost(12, two, one);
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
65 @Test
66 public void testBaseDifferentEquals() {
67 HostId one = hid("00:00:00:00:00:01/-1");
68 HostId two = hid("00:00:00:00:00:02/-1");
69 HostToHostIntent i1 = makeHostToHost(12, one, two);
70 HostToHostIntent i2 = makeHostToHost(11, one, two);
71
72 assertThat(i1, is(not(equalTo(i2))));
73 }
74
75 /**
76 * Tests that the hashCode() values for two equivalent HostToHostIntent
77 * objects are the same.
78 */
79
80 @Test
81 public void testHashCodeEquals() {
82 HostId one = hid("00:00:00:00:00:01/-1");
83 HostId two = hid("00:00:00:00:00:02/-1");
84 HostToHostIntent i1 = makeHostToHost(12, one, two);
85 HostToHostIntent i2 = makeHostToHost(12, one, two);
86
87 assertThat(i1.hashCode(), is(equalTo(i2.hashCode())));
88 }
89
90 /**
91 * Tests that the hashCode() values for two distinct LinkCollectionIntent
92 * objects are different.
93 */
94
95 @Test
96 public void testHashCodeDifferent() {
97 HostId one = hid("00:00:00:00:00:01/-1");
98 HostId two = hid("00:00:00:00:00:02/-1");
99 HostToHostIntent i1 = makeHostToHost(12, one, two);
100 HostToHostIntent i2 = makeHostToHost(112, one, two);
101
102 assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode()))));
103 }
104
105 /**
106 * Checks that the HostToHostIntent class is immutable.
107 */
108 @Test
109 public void checkImmutability() {
110 ImmutableClassChecker.assertThatClassIsImmutable(HostToHostIntent.class);
111 }
112}