blob: 0e4f706cbb7729c2e2539d5124ce6585f85e7f37 [file] [log] [blame]
Ray Milkeye6684082014-10-16 16:59:47 -07001package org.onlab.onos.net.intent;
2
Ray Milkeye6684082014-10-16 16:59:47 -07003import org.junit.Before;
4import org.junit.Test;
Thomas Vachuskab97cf282014-10-20 23:31:12 -07005import org.onlab.onos.ApplicationId;
6import org.onlab.onos.TestApplicationId;
Ray Milkeye6684082014-10-16 16:59:47 -07007import org.onlab.onos.net.ConnectPoint;
8import org.onlab.onos.net.flow.TrafficSelector;
9import org.onlab.onos.net.flow.TrafficTreatment;
10
Thomas Vachuskab97cf282014-10-20 23:31:12 -070011import java.util.HashSet;
12import java.util.Set;
13
Ray Milkeye6684082014-10-16 16:59:47 -070014import static org.hamcrest.CoreMatchers.not;
15import static org.hamcrest.MatcherAssert.assertThat;
16import static org.hamcrest.Matchers.equalTo;
17import static org.hamcrest.Matchers.is;
Pavlin Radoslavovd26f57a2014-10-23 17:19:45 -070018import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
Ray Milkeye6684082014-10-16 16:59:47 -070019import static org.onlab.onos.net.NetTestTools.connectPoint;
20
21/**
22 * Unit tests for the MultiPointToSinglePointIntent class.
23 */
24public class TestMultiPointToSinglePointIntent {
25
Thomas Vachuskab97cf282014-10-20 23:31:12 -070026 private static final ApplicationId APPID = new TestApplicationId("foo");
27
Ray Milkeye6684082014-10-16 16:59:47 -070028 private ConnectPoint point1 = connectPoint("dev1", 1);
29 private ConnectPoint point2 = connectPoint("dev2", 1);
30 private ConnectPoint point3 = connectPoint("dev3", 1);
31
32 private TrafficSelector selector = new IntentTestsMocks.MockSelector();
33 private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
34
35 Set<ConnectPoint> ingress1;
36 Set<ConnectPoint> ingress2;
37
38 /**
39 * Creates a MultiPointToSinglePointIntent object.
40 *
Ray Milkeye6684082014-10-16 16:59:47 -070041 * @param ingress set of ingress points
Thomas Vachuskab97cf282014-10-20 23:31:12 -070042 * @param egress egress point
Ray Milkeye6684082014-10-16 16:59:47 -070043 * @return MultiPointToSinglePoint intent
44 */
Thomas Vachuskab97cf282014-10-20 23:31:12 -070045 private MultiPointToSinglePointIntent makeIntent(Set<ConnectPoint> ingress,
46 ConnectPoint egress) {
47 return new MultiPointToSinglePointIntent(APPID, selector, treatment,
48 ingress, egress);
Ray Milkeye6684082014-10-16 16:59:47 -070049 }
50
51 /**
52 * Initializes the ingress sets.
53 */
54 @Before
55 public void setup() {
56 ingress1 = new HashSet<>();
57 ingress2 = new HashSet<>();
58 }
59
60 /**
61 * Tests the equals() method where two MultiPointToSinglePoint have references
62 * to the same Links in different orders. These should compare equal.
63 */
64 @Test
65 public void testSameEquals() {
66
67 Set<ConnectPoint> ingress1 = new HashSet<>();
68 ingress1.add(point2);
69 ingress1.add(point3);
70
71 Set<ConnectPoint> ingress2 = new HashSet<>();
72 ingress2.add(point3);
73 ingress2.add(point2);
74
Thomas Vachuskab97cf282014-10-20 23:31:12 -070075 Intent i1 = makeIntent(ingress1, point1);
76 Intent i2 = makeIntent(ingress2, point1);
Ray Milkeye6684082014-10-16 16:59:47 -070077
78 assertThat(i1, is(equalTo(i2)));
79 }
80
81 /**
82 * Tests the equals() method where two MultiPointToSinglePoint have references
83 * to different Links. These should compare not equal.
84 */
85 @Test
86 public void testLinksDifferentEquals() {
87 ingress1.add(point3);
88
89 ingress2.add(point3);
90 ingress2.add(point2);
91
Thomas Vachuskab97cf282014-10-20 23:31:12 -070092 Intent i1 = makeIntent(ingress1, point1);
93 Intent i2 = makeIntent(ingress2, point1);
Ray Milkeye6684082014-10-16 16:59:47 -070094
95 assertThat(i1, is(not(equalTo(i2))));
96 }
97
98 /**
99 * Tests that the hashCode() values for two equivalent MultiPointToSinglePoint
100 * objects are the same.
101 */
102 @Test
103 public void testHashCodeEquals() {
104 ingress1.add(point2);
105 ingress1.add(point3);
106
107 ingress2.add(point3);
108 ingress2.add(point2);
109
Thomas Vachuskab97cf282014-10-20 23:31:12 -0700110 Intent i1 = makeIntent(ingress1, point1);
111 Intent i2 = makeIntent(ingress2, point1);
Ray Milkeye6684082014-10-16 16:59:47 -0700112
113 assertThat(i1.hashCode(), is(equalTo(i2.hashCode())));
114 }
115
116 /**
117 * Tests that the hashCode() values for two distinct MultiPointToSinglePoint
118 * objects are different.
119 */
120 @Test
121 public void testHashCodeDifferent() {
122 ingress1.add(point2);
123
124 ingress2.add(point3);
125 ingress2.add(point2);
126
Thomas Vachuskab97cf282014-10-20 23:31:12 -0700127 Intent i1 = makeIntent(ingress1, point1);
128 Intent i2 = makeIntent(ingress2, point1);
Ray Milkeye6684082014-10-16 16:59:47 -0700129
130
131 assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode()))));
132 }
133
134 /**
135 * Checks that the MultiPointToSinglePointIntent class is immutable.
136 */
137 @Test
138 public void checkImmutability() {
Pavlin Radoslavovd26f57a2014-10-23 17:19:45 -0700139 assertThatClassIsImmutable(MultiPointToSinglePointIntent.class);
Ray Milkeye6684082014-10-16 16:59:47 -0700140 }
141}