blob: 11311a7f9b559cb8a5cdfd8e3c65e59ae393281c [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
Brian O'Connor520c0522014-11-23 23:50:47 -080018import org.junit.Ignore;
Ray Milkeye6684082014-10-16 16:59:47 -070019import org.junit.Test;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070020import org.onlab.onos.core.ApplicationId;
Thomas Vachuskab97cf282014-10-20 23:31:12 -070021import org.onlab.onos.TestApplicationId;
Ray Milkeye6684082014-10-16 16:59:47 -070022import org.onlab.onos.net.HostId;
23import org.onlab.onos.net.flow.TrafficSelector;
24import org.onlab.onos.net.flow.TrafficTreatment;
25
26import static org.hamcrest.MatcherAssert.assertThat;
27import static org.hamcrest.Matchers.equalTo;
28import static org.hamcrest.Matchers.is;
29import static org.hamcrest.Matchers.not;
Pavlin Radoslavovd26f57a2014-10-23 17:19:45 -070030import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
Ray Milkeye6684082014-10-16 16:59:47 -070031import static org.onlab.onos.net.NetTestTools.hid;
32
33/**
34 * Unit tests for the HostToHostIntent class.
35 */
36public class TestHostToHostIntent {
37
Thomas Vachuskab97cf282014-10-20 23:31:12 -070038 private static final ApplicationId APPID = new TestApplicationId("foo");
39
Ray Milkeye6684082014-10-16 16:59:47 -070040 private TrafficSelector selector = new IntentTestsMocks.MockSelector();
41 private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment();
42
Thomas Vachuskab97cf282014-10-20 23:31:12 -070043 private HostToHostIntent makeHostToHost(HostId one, HostId two) {
44 return new HostToHostIntent(APPID, one, two, selector, treatment);
Ray Milkeye6684082014-10-16 16:59:47 -070045 }
46
47 /**
48 * Tests the equals() method where two HostToHostIntents have references
49 * to the same hosts. These should compare equal.
50 */
Brian O'Connor520c0522014-11-23 23:50:47 -080051 @Test @Ignore("Needs to be merged with other API test")
Ray Milkeye6684082014-10-16 16:59:47 -070052 public void testSameEquals() {
53
54 HostId one = hid("00:00:00:00:00:01/-1");
55 HostId two = hid("00:00:00:00:00:02/-1");
Thomas Vachuskab97cf282014-10-20 23:31:12 -070056 HostToHostIntent i1 = makeHostToHost(one, two);
57 HostToHostIntent i2 = makeHostToHost(one, two);
Ray Milkeye6684082014-10-16 16:59:47 -070058
59 assertThat(i1, is(equalTo(i2)));
60 }
61
62 /**
63 * Tests the equals() method where two HostToHostIntents have references
64 * to different Hosts. These should compare not equal.
65 */
Brian O'Connor520c0522014-11-23 23:50:47 -080066 @Test @Ignore("Needs to be merged with other API test")
Thomas Vachuskaa12fdf22014-10-21 01:33:48 -070067 public void testSameEquals2() {
Ray Milkeye6684082014-10-16 16:59:47 -070068 HostId one = hid("00:00:00:00:00:01/-1");
69 HostId two = hid("00:00:00:00:00:02/-1");
Thomas Vachuskab97cf282014-10-20 23:31:12 -070070 HostToHostIntent i1 = makeHostToHost(one, two);
71 HostToHostIntent i2 = makeHostToHost(two, one);
Ray Milkeye6684082014-10-16 16:59:47 -070072
Thomas Vachuskaa12fdf22014-10-21 01:33:48 -070073 assertThat(i1, is(equalTo(i2)));
Ray Milkeye6684082014-10-16 16:59:47 -070074 }
75
76 /**
77 * Tests that the hashCode() values for two equivalent HostToHostIntent
78 * objects are the same.
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 testHashCodeEquals() {
82 HostId one = hid("00:00:00:00:00:01/-1");
83 HostId two = hid("00:00:00:00:00:02/-1");
Thomas Vachuskab97cf282014-10-20 23:31:12 -070084 HostToHostIntent i1 = makeHostToHost(one, two);
85 HostToHostIntent i2 = makeHostToHost(one, two);
Ray Milkeye6684082014-10-16 16:59:47 -070086
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 */
Brian O'Connor520c0522014-11-23 23:50:47 -080094 @Test @Ignore("Needs to be merged with other API test")
Thomas Vachuskaa12fdf22014-10-21 01:33:48 -070095 public void testHashCodeEquals2() {
Ray Milkeye6684082014-10-16 16:59:47 -070096 HostId one = hid("00:00:00:00:00:01/-1");
97 HostId two = hid("00:00:00:00:00:02/-1");
Thomas Vachuskab97cf282014-10-20 23:31:12 -070098 HostToHostIntent i1 = makeHostToHost(one, two);
99 HostToHostIntent i2 = makeHostToHost(two, one);
Ray Milkeye6684082014-10-16 16:59:47 -0700100
Thomas Vachuskaa12fdf22014-10-21 01:33:48 -0700101 assertThat(i1.hashCode(), is(equalTo(i2.hashCode())));
102 }
103
104 /**
105 * Tests that the hashCode() values for two distinct LinkCollectionIntent
106 * objects are different.
107 */
Brian O'Connor520c0522014-11-23 23:50:47 -0800108 @Test @Ignore("Needs to be merged with other API test")
Thomas Vachuskaa12fdf22014-10-21 01:33:48 -0700109 public void testHashCodeDifferent() {
110 HostId one = hid("00:00:00:00:00:01/-1");
111 HostId two = hid("00:00:00:00:00:02/-1");
112 HostId three = hid("00:00:00:00:00:32/-1");
113 HostToHostIntent i1 = makeHostToHost(one, two);
114 HostToHostIntent i2 = makeHostToHost(one, three);
115
Ray Milkeye6684082014-10-16 16:59:47 -0700116 assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode()))));
117 }
118
119 /**
120 * Checks that the HostToHostIntent class is immutable.
121 */
122 @Test
123 public void checkImmutability() {
Pavlin Radoslavovd26f57a2014-10-23 17:19:45 -0700124 assertThatClassIsImmutable(HostToHostIntent.class);
Ray Milkeye6684082014-10-16 16:59:47 -0700125 }
126}