Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 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 Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 16 | package org.onlab.onos.net.intent; |
| 17 | |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame^] | 18 | import org.junit.Ignore; |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 19 | import org.junit.Test; |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 20 | import org.onlab.onos.core.ApplicationId; |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 21 | import org.onlab.onos.TestApplicationId; |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 22 | import org.onlab.onos.net.HostId; |
| 23 | import org.onlab.onos.net.flow.TrafficSelector; |
| 24 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 25 | |
| 26 | import static org.hamcrest.MatcherAssert.assertThat; |
| 27 | import static org.hamcrest.Matchers.equalTo; |
| 28 | import static org.hamcrest.Matchers.is; |
| 29 | import static org.hamcrest.Matchers.not; |
Pavlin Radoslavov | d26f57a | 2014-10-23 17:19:45 -0700 | [diff] [blame] | 30 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 31 | import static org.onlab.onos.net.NetTestTools.hid; |
| 32 | |
| 33 | /** |
| 34 | * Unit tests for the HostToHostIntent class. |
| 35 | */ |
| 36 | public class TestHostToHostIntent { |
| 37 | |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 38 | private static final ApplicationId APPID = new TestApplicationId("foo"); |
| 39 | |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 40 | private TrafficSelector selector = new IntentTestsMocks.MockSelector(); |
| 41 | private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); |
| 42 | |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 43 | private HostToHostIntent makeHostToHost(HostId one, HostId two) { |
| 44 | return new HostToHostIntent(APPID, one, two, selector, treatment); |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Tests the equals() method where two HostToHostIntents have references |
| 49 | * to the same hosts. These should compare equal. |
| 50 | */ |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame^] | 51 | @Test @Ignore("Needs to be merged with other API test") |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 52 | 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 Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 56 | HostToHostIntent i1 = makeHostToHost(one, two); |
| 57 | HostToHostIntent i2 = makeHostToHost(one, two); |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 58 | |
| 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'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame^] | 66 | @Test @Ignore("Needs to be merged with other API test") |
Thomas Vachuska | a12fdf2 | 2014-10-21 01:33:48 -0700 | [diff] [blame] | 67 | public void testSameEquals2() { |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 68 | HostId one = hid("00:00:00:00:00:01/-1"); |
| 69 | HostId two = hid("00:00:00:00:00:02/-1"); |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 70 | HostToHostIntent i1 = makeHostToHost(one, two); |
| 71 | HostToHostIntent i2 = makeHostToHost(two, one); |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 72 | |
Thomas Vachuska | a12fdf2 | 2014-10-21 01:33:48 -0700 | [diff] [blame] | 73 | assertThat(i1, is(equalTo(i2))); |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Tests that the hashCode() values for two equivalent HostToHostIntent |
| 78 | * objects are the same. |
| 79 | */ |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame^] | 80 | @Test @Ignore("Needs to be merged with other API test") |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 81 | 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 Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 84 | HostToHostIntent i1 = makeHostToHost(one, two); |
| 85 | HostToHostIntent i2 = makeHostToHost(one, two); |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 86 | |
| 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'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame^] | 94 | @Test @Ignore("Needs to be merged with other API test") |
Thomas Vachuska | a12fdf2 | 2014-10-21 01:33:48 -0700 | [diff] [blame] | 95 | public void testHashCodeEquals2() { |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 96 | HostId one = hid("00:00:00:00:00:01/-1"); |
| 97 | HostId two = hid("00:00:00:00:00:02/-1"); |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 98 | HostToHostIntent i1 = makeHostToHost(one, two); |
| 99 | HostToHostIntent i2 = makeHostToHost(two, one); |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 100 | |
Thomas Vachuska | a12fdf2 | 2014-10-21 01:33:48 -0700 | [diff] [blame] | 101 | 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'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame^] | 108 | @Test @Ignore("Needs to be merged with other API test") |
Thomas Vachuska | a12fdf2 | 2014-10-21 01:33:48 -0700 | [diff] [blame] | 109 | 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 Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 116 | 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 Radoslavov | d26f57a | 2014-10-23 17:19:45 -0700 | [diff] [blame] | 124 | assertThatClassIsImmutable(HostToHostIntent.class); |
Ray Milkey | e668408 | 2014-10-16 16:59:47 -0700 | [diff] [blame] | 125 | } |
| 126 | } |