Ray Milkey | c8f481f | 2014-11-18 15:37:12 -0800 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Ray Milkey | c8f481f | 2014-11-18 15:37:12 -0800 | [diff] [blame] | 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.hid; |
Ray Milkey | c8f481f | 2014-11-18 15:37:12 -0800 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Unit tests for the HostToHostIntent class. |
| 34 | */ |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 35 | public class HostToHostIntentTest extends IntentTest { |
| 36 | private final TrafficSelector selector = new IntentTestsMocks.MockSelector(); |
| 37 | private final IntentTestsMocks.MockTreatment treatment = new IntentTestsMocks.MockTreatment(); |
| 38 | private final HostId id1 = hid("12:34:56:78:91:ab/1"); |
| 39 | private final HostId id2 = hid("12:34:56:78:92:ab/1"); |
| 40 | private final HostId id3 = hid("12:34:56:78:93:ab/1"); |
Ray Milkey | c8f481f | 2014-11-18 15:37:12 -0800 | [diff] [blame] | 41 | |
Ray Milkey | 37f6a38 | 2014-11-25 14:54:42 -0800 | [diff] [blame] | 42 | private static final ApplicationId APPID = new TestApplicationId("foo"); |
| 43 | |
| 44 | private HostToHostIntent makeHostToHost(HostId one, HostId two) { |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 45 | return HostToHostIntent.builder() |
| 46 | .appId(APPID) |
| 47 | .one(one) |
| 48 | .two(two) |
| 49 | .selector(selector) |
| 50 | .treatment(treatment) |
| 51 | .build(); |
Ray Milkey | 37f6a38 | 2014-11-25 14:54:42 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Tests the equals() method where two HostToHostIntents have references |
| 56 | * to the same hosts. These should compare equal. |
| 57 | */ |
| 58 | @Test |
| 59 | public void testSameEquals() { |
| 60 | |
| 61 | HostId one = hid("00:00:00:00:00:01/-1"); |
| 62 | HostId two = hid("00:00:00:00:00:02/-1"); |
| 63 | HostToHostIntent i1 = makeHostToHost(one, two); |
| 64 | HostToHostIntent i2 = makeHostToHost(one, two); |
| 65 | |
| 66 | assertThat(i1.one(), is(equalTo(i2.one()))); |
| 67 | assertThat(i1.two(), is(equalTo(i2.two()))); |
| 68 | } |
| 69 | |
Ray Milkey | c8f481f | 2014-11-18 15:37:12 -0800 | [diff] [blame] | 70 | /** |
| 71 | * Checks that the HostToHostIntent class is immutable. |
| 72 | */ |
| 73 | @Test |
| 74 | public void testImmutability() { |
| 75 | assertThatClassIsImmutable(HostToHostIntent.class); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Tests equals(), hashCode() and toString() methods. |
| 80 | */ |
Ray Milkey | 37f6a38 | 2014-11-25 14:54:42 -0800 | [diff] [blame] | 81 | @Test |
Ray Milkey | c8f481f | 2014-11-18 15:37:12 -0800 | [diff] [blame] | 82 | public void testEquals() { |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 83 | final HostToHostIntent intent1 = HostToHostIntent.builder() |
| 84 | .appId(APPID) |
| 85 | .one(id1) |
| 86 | .two(id2) |
| 87 | .selector(selector) |
| 88 | .treatment(treatment) |
| 89 | .build(); |
Ray Milkey | 37f6a38 | 2014-11-25 14:54:42 -0800 | [diff] [blame] | 90 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 91 | final HostToHostIntent intent2 = HostToHostIntent.builder() |
| 92 | .appId(APPID) |
| 93 | .one(id2) |
| 94 | .two(id3) |
| 95 | .selector(selector) |
| 96 | .treatment(treatment) |
| 97 | .build(); |
Ray Milkey | c8f481f | 2014-11-18 15:37:12 -0800 | [diff] [blame] | 98 | |
| 99 | new EqualsTester() |
Ray Milkey | 37f6a38 | 2014-11-25 14:54:42 -0800 | [diff] [blame] | 100 | .addEqualityGroup(intent1) |
Ray Milkey | c8f481f | 2014-11-18 15:37:12 -0800 | [diff] [blame] | 101 | .addEqualityGroup(intent2) |
| 102 | .testEquals(); |
| 103 | } |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 104 | |
| 105 | @Override |
| 106 | protected Intent createOne() { |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 107 | return HostToHostIntent.builder() |
| 108 | .appId(APPID) |
| 109 | .one(id1) |
| 110 | .two(id2) |
| 111 | .selector(selector) |
| 112 | .treatment(treatment) |
| 113 | .build(); |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | @Override |
| 117 | protected Intent createAnother() { |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 118 | return HostToHostIntent.builder() |
| 119 | .appId(APPID) |
| 120 | .one(id1) |
| 121 | .two(id3) |
| 122 | .selector(selector) |
| 123 | .treatment(treatment) |
| 124 | .build(); |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 125 | } |
Ray Milkey | c8f481f | 2014-11-18 15:37:12 -0800 | [diff] [blame] | 126 | } |