blob: b0c244b7035518dc6e7ae978941ec37b18a2be8c [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Ray Milkeye6684082014-10-16 16:59:47 -070016package org.onlab.onos.net.intent;
17
Ray Milkeye6684082014-10-16 16:59:47 -070018import org.junit.Before;
Brian O'Connor520c0522014-11-23 23:50:47 -080019import org.junit.Ignore;
Ray Milkeye6684082014-10-16 16:59:47 -070020import org.junit.Test;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070021import org.onlab.onos.core.ApplicationId;
Thomas Vachuskab97cf282014-10-20 23:31:12 -070022import org.onlab.onos.TestApplicationId;
Ray Milkeye6684082014-10-16 16:59:47 -070023import org.onlab.onos.net.ConnectPoint;
24import org.onlab.onos.net.flow.TrafficSelector;
25import org.onlab.onos.net.flow.TrafficTreatment;
26
Thomas Vachuskab97cf282014-10-20 23:31:12 -070027import java.util.HashSet;
28import java.util.Set;
29
Ray Milkeye6684082014-10-16 16:59:47 -070030import static org.hamcrest.CoreMatchers.not;
31import static org.hamcrest.MatcherAssert.assertThat;
32import static org.hamcrest.Matchers.equalTo;
33import static org.hamcrest.Matchers.is;
Pavlin Radoslavovd26f57a2014-10-23 17:19:45 -070034import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
Ray Milkeye6684082014-10-16 16:59:47 -070035import static org.onlab.onos.net.NetTestTools.connectPoint;
36
37/**
38 * Unit tests for the MultiPointToSinglePointIntent class.
39 */
40public class TestMultiPointToSinglePointIntent {
41
Thomas Vachuskab97cf282014-10-20 23:31:12 -070042 private static final ApplicationId APPID = new TestApplicationId("foo");
43
Ray Milkeye6684082014-10-16 16:59:47 -070044 private ConnectPoint point1 = connectPoint("dev1", 1);
45 private ConnectPoint point2 = connectPoint("dev2", 1);
46 private ConnectPoint point3 = connectPoint("dev3", 1);
47
48 private TrafficSelector selector = new IntentTestsMocks.MockSelector();
49 private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
50
51 Set<ConnectPoint> ingress1;
52 Set<ConnectPoint> ingress2;
53
54 /**
55 * Creates a MultiPointToSinglePointIntent object.
56 *
Ray Milkeye6684082014-10-16 16:59:47 -070057 * @param ingress set of ingress points
Thomas Vachuskab97cf282014-10-20 23:31:12 -070058 * @param egress egress point
Ray Milkeye6684082014-10-16 16:59:47 -070059 * @return MultiPointToSinglePoint intent
60 */
Thomas Vachuskab97cf282014-10-20 23:31:12 -070061 private MultiPointToSinglePointIntent makeIntent(Set<ConnectPoint> ingress,
62 ConnectPoint egress) {
63 return new MultiPointToSinglePointIntent(APPID, selector, treatment,
64 ingress, egress);
Ray Milkeye6684082014-10-16 16:59:47 -070065 }
66
67 /**
68 * Initializes the ingress sets.
69 */
70 @Before
71 public void setup() {
72 ingress1 = new HashSet<>();
73 ingress2 = new HashSet<>();
74 }
75
76 /**
77 * Tests the equals() method where two MultiPointToSinglePoint have references
78 * to the same Links in different orders. These should compare equal.
79 */
Brian O'Connor520c0522014-11-23 23:50:47 -080080 @Test @Ignore("Needs to be merged with other API test")
Ray Milkeye6684082014-10-16 16:59:47 -070081 public void testSameEquals() {
82
83 Set<ConnectPoint> ingress1 = new HashSet<>();
84 ingress1.add(point2);
85 ingress1.add(point3);
86
87 Set<ConnectPoint> ingress2 = new HashSet<>();
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(equalTo(i2)));
95 }
96
97 /**
98 * Tests the equals() method where two MultiPointToSinglePoint have references
99 * to different Links. These should compare not equal.
100 */
Brian O'Connor520c0522014-11-23 23:50:47 -0800101 @Test @Ignore("Needs to be merged with other API test")
Ray Milkeye6684082014-10-16 16:59:47 -0700102 public void testLinksDifferentEquals() {
103 ingress1.add(point3);
104
105 ingress2.add(point3);
106 ingress2.add(point2);
107
Thomas Vachuskab97cf282014-10-20 23:31:12 -0700108 Intent i1 = makeIntent(ingress1, point1);
109 Intent i2 = makeIntent(ingress2, point1);
Ray Milkeye6684082014-10-16 16:59:47 -0700110
111 assertThat(i1, is(not(equalTo(i2))));
112 }
113
114 /**
115 * Tests that the hashCode() values for two equivalent MultiPointToSinglePoint
116 * objects are the same.
117 */
Brian O'Connor520c0522014-11-23 23:50:47 -0800118 @Test @Ignore("Needs to be merged with other API test")
Ray Milkeye6684082014-10-16 16:59:47 -0700119 public void testHashCodeEquals() {
120 ingress1.add(point2);
121 ingress1.add(point3);
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 assertThat(i1.hashCode(), is(equalTo(i2.hashCode())));
130 }
131
132 /**
133 * Tests that the hashCode() values for two distinct MultiPointToSinglePoint
134 * objects are different.
135 */
Brian O'Connor520c0522014-11-23 23:50:47 -0800136 @Test @Ignore("Needs to be merged with other API test")
Ray Milkeye6684082014-10-16 16:59:47 -0700137 public void testHashCodeDifferent() {
138 ingress1.add(point2);
139
140 ingress2.add(point3);
141 ingress2.add(point2);
142
Thomas Vachuskab97cf282014-10-20 23:31:12 -0700143 Intent i1 = makeIntent(ingress1, point1);
144 Intent i2 = makeIntent(ingress2, point1);
Ray Milkeye6684082014-10-16 16:59:47 -0700145
146
147 assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode()))));
148 }
149
150 /**
151 * Checks that the MultiPointToSinglePointIntent class is immutable.
152 */
153 @Test
154 public void checkImmutability() {
Pavlin Radoslavovd26f57a2014-10-23 17:19:45 -0700155 assertThatClassIsImmutable(MultiPointToSinglePointIntent.class);
Ray Milkeye6684082014-10-16 16:59:47 -0700156 }
157}