blob: 09dfcb267fd216171be2b6c68da4af1318a158c6 [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;
18import static org.onlab.onos.net.NetTestTools.connectPoint;
19
20/**
21 * Unit tests for the MultiPointToSinglePointIntent class.
22 */
23public class TestMultiPointToSinglePointIntent {
24
Thomas Vachuskab97cf282014-10-20 23:31:12 -070025 private static final ApplicationId APPID = new TestApplicationId("foo");
26
Ray Milkeye6684082014-10-16 16:59:47 -070027 private ConnectPoint point1 = connectPoint("dev1", 1);
28 private ConnectPoint point2 = connectPoint("dev2", 1);
29 private ConnectPoint point3 = connectPoint("dev3", 1);
30
31 private TrafficSelector selector = new IntentTestsMocks.MockSelector();
32 private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
33
34 Set<ConnectPoint> ingress1;
35 Set<ConnectPoint> ingress2;
36
37 /**
38 * Creates a MultiPointToSinglePointIntent object.
39 *
Ray Milkeye6684082014-10-16 16:59:47 -070040 * @param ingress set of ingress points
Thomas Vachuskab97cf282014-10-20 23:31:12 -070041 * @param egress egress point
Ray Milkeye6684082014-10-16 16:59:47 -070042 * @return MultiPointToSinglePoint intent
43 */
Thomas Vachuskab97cf282014-10-20 23:31:12 -070044 private MultiPointToSinglePointIntent makeIntent(Set<ConnectPoint> ingress,
45 ConnectPoint egress) {
46 return new MultiPointToSinglePointIntent(APPID, selector, treatment,
47 ingress, egress);
Ray Milkeye6684082014-10-16 16:59:47 -070048 }
49
50 /**
51 * Initializes the ingress sets.
52 */
53 @Before
54 public void setup() {
55 ingress1 = new HashSet<>();
56 ingress2 = new HashSet<>();
57 }
58
59 /**
60 * Tests the equals() method where two MultiPointToSinglePoint have references
61 * to the same Links in different orders. These should compare equal.
62 */
63 @Test
64 public void testSameEquals() {
65
66 Set<ConnectPoint> ingress1 = new HashSet<>();
67 ingress1.add(point2);
68 ingress1.add(point3);
69
70 Set<ConnectPoint> ingress2 = new HashSet<>();
71 ingress2.add(point3);
72 ingress2.add(point2);
73
Thomas Vachuskab97cf282014-10-20 23:31:12 -070074 Intent i1 = makeIntent(ingress1, point1);
75 Intent i2 = makeIntent(ingress2, point1);
Ray Milkeye6684082014-10-16 16:59:47 -070076
77 assertThat(i1, is(equalTo(i2)));
78 }
79
80 /**
81 * Tests the equals() method where two MultiPointToSinglePoint have references
82 * to different Links. These should compare not equal.
83 */
84 @Test
85 public void testLinksDifferentEquals() {
86 ingress1.add(point3);
87
88 ingress2.add(point3);
89 ingress2.add(point2);
90
Thomas Vachuskab97cf282014-10-20 23:31:12 -070091 Intent i1 = makeIntent(ingress1, point1);
92 Intent i2 = makeIntent(ingress2, point1);
Ray Milkeye6684082014-10-16 16:59:47 -070093
94 assertThat(i1, is(not(equalTo(i2))));
95 }
96
97 /**
98 * Tests that the hashCode() values for two equivalent MultiPointToSinglePoint
99 * objects are the same.
100 */
101 @Test
102 public void testHashCodeEquals() {
103 ingress1.add(point2);
104 ingress1.add(point3);
105
106 ingress2.add(point3);
107 ingress2.add(point2);
108
Thomas Vachuskab97cf282014-10-20 23:31:12 -0700109 Intent i1 = makeIntent(ingress1, point1);
110 Intent i2 = makeIntent(ingress2, point1);
Ray Milkeye6684082014-10-16 16:59:47 -0700111
112 assertThat(i1.hashCode(), is(equalTo(i2.hashCode())));
113 }
114
115 /**
116 * Tests that the hashCode() values for two distinct MultiPointToSinglePoint
117 * objects are different.
118 */
119 @Test
120 public void testHashCodeDifferent() {
121 ingress1.add(point2);
122
123 ingress2.add(point3);
124 ingress2.add(point2);
125
Thomas Vachuskab97cf282014-10-20 23:31:12 -0700126 Intent i1 = makeIntent(ingress1, point1);
127 Intent i2 = makeIntent(ingress2, point1);
Ray Milkeye6684082014-10-16 16:59:47 -0700128
129
130 assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode()))));
131 }
132
133 /**
134 * Checks that the MultiPointToSinglePointIntent class is immutable.
135 */
136 @Test
137 public void checkImmutability() {
138 ImmutableClassChecker.
139 assertThatClassIsImmutable(MultiPointToSinglePointIntent.class);
140 }
141}