Ray Milkey | c8f481f | 2014-11-18 15:37:12 -0800 | [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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent; |
Ray Milkey | c8f481f | 2014-11-18 15:37:12 -0800 | [diff] [blame] | 17 | |
| 18 | import org.junit.Test; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import org.onosproject.TestApplicationId; |
| 20 | import org.onosproject.core.ApplicationId; |
| 21 | import org.onosproject.net.HostId; |
| 22 | import org.onosproject.net.flow.TrafficSelector; |
Ray Milkey | c8f481f | 2014-11-18 15:37:12 -0800 | [diff] [blame] | 23 | |
| 24 | import com.google.common.testing.EqualsTester; |
| 25 | |
Ray Milkey | 37f6a38 | 2014-11-25 14:54:42 -0800 | [diff] [blame] | 26 | import static org.hamcrest.MatcherAssert.assertThat; |
| 27 | import static org.hamcrest.Matchers.equalTo; |
| 28 | import static org.hamcrest.Matchers.is; |
Ray Milkey | c8f481f | 2014-11-18 15:37:12 -0800 | [diff] [blame] | 29 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 30 | import static org.onosproject.net.NetTestTools.APP_ID; |
| 31 | import static org.onosproject.net.NetTestTools.hid; |
Ray Milkey | c8f481f | 2014-11-18 15:37:12 -0800 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Unit tests for the HostToHostIntent class. |
| 35 | */ |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 36 | public class HostToHostIntentTest extends IntentTest { |
| 37 | private final TrafficSelector selector = new IntentTestsMocks.MockSelector(); |
| 38 | private final IntentTestsMocks.MockTreatment treatment = new IntentTestsMocks.MockTreatment(); |
| 39 | private final HostId id1 = hid("12:34:56:78:91:ab/1"); |
| 40 | private final HostId id2 = hid("12:34:56:78:92:ab/1"); |
| 41 | private final HostId id3 = hid("12:34:56:78:93:ab/1"); |
Ray Milkey | c8f481f | 2014-11-18 15:37:12 -0800 | [diff] [blame] | 42 | |
Ray Milkey | 37f6a38 | 2014-11-25 14:54:42 -0800 | [diff] [blame] | 43 | private static final ApplicationId APPID = new TestApplicationId("foo"); |
| 44 | |
| 45 | private HostToHostIntent makeHostToHost(HostId one, HostId two) { |
| 46 | return new HostToHostIntent(APPID, one, two, selector, treatment); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Tests the equals() method where two HostToHostIntents have references |
| 51 | * to the same hosts. These should compare equal. |
| 52 | */ |
| 53 | @Test |
| 54 | public void testSameEquals() { |
| 55 | |
| 56 | HostId one = hid("00:00:00:00:00:01/-1"); |
| 57 | HostId two = hid("00:00:00:00:00:02/-1"); |
| 58 | HostToHostIntent i1 = makeHostToHost(one, two); |
| 59 | HostToHostIntent i2 = makeHostToHost(one, two); |
| 60 | |
| 61 | assertThat(i1.one(), is(equalTo(i2.one()))); |
| 62 | assertThat(i1.two(), is(equalTo(i2.two()))); |
| 63 | } |
| 64 | |
Ray Milkey | c8f481f | 2014-11-18 15:37:12 -0800 | [diff] [blame] | 65 | /** |
| 66 | * Checks that the HostToHostIntent class is immutable. |
| 67 | */ |
| 68 | @Test |
| 69 | public void testImmutability() { |
| 70 | assertThatClassIsImmutable(HostToHostIntent.class); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Tests equals(), hashCode() and toString() methods. |
| 75 | */ |
Ray Milkey | 37f6a38 | 2014-11-25 14:54:42 -0800 | [diff] [blame] | 76 | @Test |
Ray Milkey | c8f481f | 2014-11-18 15:37:12 -0800 | [diff] [blame] | 77 | public void testEquals() { |
Ray Milkey | c8f481f | 2014-11-18 15:37:12 -0800 | [diff] [blame] | 78 | final HostToHostIntent intent1 = new HostToHostIntent(APP_ID, |
| 79 | id1, |
| 80 | id2, |
| 81 | selector, |
| 82 | treatment); |
Ray Milkey | 37f6a38 | 2014-11-25 14:54:42 -0800 | [diff] [blame] | 83 | |
Ray Milkey | c8f481f | 2014-11-18 15:37:12 -0800 | [diff] [blame] | 84 | final HostToHostIntent intent2 = new HostToHostIntent(APP_ID, |
| 85 | id2, |
| 86 | id3, |
| 87 | selector, |
| 88 | treatment); |
| 89 | |
| 90 | new EqualsTester() |
Ray Milkey | 37f6a38 | 2014-11-25 14:54:42 -0800 | [diff] [blame] | 91 | .addEqualityGroup(intent1) |
Ray Milkey | c8f481f | 2014-11-18 15:37:12 -0800 | [diff] [blame] | 92 | .addEqualityGroup(intent2) |
| 93 | .testEquals(); |
| 94 | } |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 95 | |
| 96 | @Override |
| 97 | protected Intent createOne() { |
| 98 | return new HostToHostIntent(APP_ID, id1, id2, selector, treatment); |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | protected Intent createAnother() { |
| 103 | return new HostToHostIntent(APP_ID, id1, id3, selector, treatment); |
| 104 | } |
Ray Milkey | c8f481f | 2014-11-18 15:37:12 -0800 | [diff] [blame] | 105 | } |