blob: 55e00dd7cd6479fcb47c72b5c9712e63fe9fcd1b [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
18import org.junit.Test;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070019import org.onlab.onos.core.ApplicationId;
Thomas Vachuskab97cf282014-10-20 23:31:12 -070020import org.onlab.onos.TestApplicationId;
Ray Milkeye6684082014-10-16 16:59:47 -070021import org.onlab.onos.net.HostId;
22import org.onlab.onos.net.flow.TrafficSelector;
23import org.onlab.onos.net.flow.TrafficTreatment;
24
25import static org.hamcrest.MatcherAssert.assertThat;
26import static org.hamcrest.Matchers.equalTo;
27import static org.hamcrest.Matchers.is;
28import static org.hamcrest.Matchers.not;
Pavlin Radoslavovd26f57a2014-10-23 17:19:45 -070029import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
Ray Milkeye6684082014-10-16 16:59:47 -070030import static org.onlab.onos.net.NetTestTools.hid;
31
32/**
33 * Unit tests for the HostToHostIntent class.
34 */
35public class TestHostToHostIntent {
36
Thomas Vachuskab97cf282014-10-20 23:31:12 -070037 private static final ApplicationId APPID = new TestApplicationId("foo");
38
Ray Milkeye6684082014-10-16 16:59:47 -070039 private TrafficSelector selector = new IntentTestsMocks.MockSelector();
40 private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
41
Thomas Vachuskab97cf282014-10-20 23:31:12 -070042 private HostToHostIntent makeHostToHost(HostId one, HostId two) {
43 return new HostToHostIntent(APPID, one, two, selector, treatment);
Ray Milkeye6684082014-10-16 16:59:47 -070044 }
45
46 /**
47 * Tests the equals() method where two HostToHostIntents have references
48 * to the same hosts. These should compare equal.
49 */
50 @Test
51 public void testSameEquals() {
52
53 HostId one = hid("00:00:00:00:00:01/-1");
54 HostId two = hid("00:00:00:00:00:02/-1");
Thomas Vachuskab97cf282014-10-20 23:31:12 -070055 HostToHostIntent i1 = makeHostToHost(one, two);
56 HostToHostIntent i2 = makeHostToHost(one, two);
Ray Milkeye6684082014-10-16 16:59:47 -070057
58 assertThat(i1, is(equalTo(i2)));
59 }
60
61 /**
62 * Tests the equals() method where two HostToHostIntents have references
63 * to different Hosts. These should compare not equal.
64 */
65 @Test
Thomas Vachuskaa12fdf22014-10-21 01:33:48 -070066 public void testSameEquals2() {
Ray Milkeye6684082014-10-16 16:59:47 -070067 HostId one = hid("00:00:00:00:00:01/-1");
68 HostId two = hid("00:00:00:00:00:02/-1");
Thomas Vachuskab97cf282014-10-20 23:31:12 -070069 HostToHostIntent i1 = makeHostToHost(one, two);
70 HostToHostIntent i2 = makeHostToHost(two, one);
Ray Milkeye6684082014-10-16 16:59:47 -070071
Thomas Vachuskaa12fdf22014-10-21 01:33:48 -070072 assertThat(i1, is(equalTo(i2)));
Ray Milkeye6684082014-10-16 16:59:47 -070073 }
74
75 /**
76 * Tests that the hashCode() values for two equivalent HostToHostIntent
77 * objects are the same.
78 */
Ray Milkeye6684082014-10-16 16:59:47 -070079 @Test
80 public void testHashCodeEquals() {
81 HostId one = hid("00:00:00:00:00:01/-1");
82 HostId two = hid("00:00:00:00:00:02/-1");
Thomas Vachuskab97cf282014-10-20 23:31:12 -070083 HostToHostIntent i1 = makeHostToHost(one, two);
84 HostToHostIntent i2 = makeHostToHost(one, two);
Ray Milkeye6684082014-10-16 16:59:47 -070085
86 assertThat(i1.hashCode(), is(equalTo(i2.hashCode())));
87 }
88
89 /**
90 * Tests that the hashCode() values for two distinct LinkCollectionIntent
91 * objects are different.
92 */
Ray Milkeye6684082014-10-16 16:59:47 -070093 @Test
Thomas Vachuskaa12fdf22014-10-21 01:33:48 -070094 public void testHashCodeEquals2() {
Ray Milkeye6684082014-10-16 16:59:47 -070095 HostId one = hid("00:00:00:00:00:01/-1");
96 HostId two = hid("00:00:00:00:00:02/-1");
Thomas Vachuskab97cf282014-10-20 23:31:12 -070097 HostToHostIntent i1 = makeHostToHost(one, two);
98 HostToHostIntent i2 = makeHostToHost(two, one);
Ray Milkeye6684082014-10-16 16:59:47 -070099
Thomas Vachuskaa12fdf22014-10-21 01:33:48 -0700100 assertThat(i1.hashCode(), is(equalTo(i2.hashCode())));
101 }
102
103 /**
104 * Tests that the hashCode() values for two distinct LinkCollectionIntent
105 * objects are different.
106 */
107 @Test
108 public void testHashCodeDifferent() {
109 HostId one = hid("00:00:00:00:00:01/-1");
110 HostId two = hid("00:00:00:00:00:02/-1");
111 HostId three = hid("00:00:00:00:00:32/-1");
112 HostToHostIntent i1 = makeHostToHost(one, two);
113 HostToHostIntent i2 = makeHostToHost(one, three);
114
Ray Milkeye6684082014-10-16 16:59:47 -0700115 assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode()))));
116 }
117
118 /**
119 * Checks that the HostToHostIntent class is immutable.
120 */
121 @Test
122 public void checkImmutability() {
Pavlin Radoslavovd26f57a2014-10-23 17:19:45 -0700123 assertThatClassIsImmutable(HostToHostIntent.class);
Ray Milkeye6684082014-10-16 16:59:47 -0700124 }
125}