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 | */ |
| 16 | package org.onlab.onos.net.intent; |
| 17 | |
| 18 | import org.junit.Test; |
| 19 | import org.onlab.onos.net.HostId; |
| 20 | import org.onlab.onos.net.flow.TrafficSelector; |
| 21 | |
| 22 | import com.google.common.testing.EqualsTester; |
| 23 | |
| 24 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 25 | import static org.onlab.onos.net.NetTestTools.APP_ID; |
| 26 | import static org.onlab.onos.net.NetTestTools.hid; |
| 27 | |
| 28 | /** |
| 29 | * Unit tests for the HostToHostIntent class. |
| 30 | */ |
| 31 | public class HostToHostIntentTest { |
| 32 | final TrafficSelector selector = new IntentTestsMocks.MockSelector(); |
| 33 | final IntentTestsMocks.MockTreatment treatment = new IntentTestsMocks.MockTreatment(); |
| 34 | |
| 35 | /** |
| 36 | * Checks that the HostToHostIntent class is immutable. |
| 37 | */ |
| 38 | @Test |
| 39 | public void testImmutability() { |
| 40 | assertThatClassIsImmutable(HostToHostIntent.class); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Tests equals(), hashCode() and toString() methods. |
| 45 | */ |
| 46 | @Test |
| 47 | public void testEquals() { |
| 48 | final HostId id1 = hid("12:34:56:78:91:ab/1"); |
| 49 | final HostId id2 = hid("12:34:56:78:92:ab/1"); |
| 50 | final HostId id3 = hid("12:34:56:78:93:ab/1"); |
| 51 | |
| 52 | final HostToHostIntent intent1 = new HostToHostIntent(APP_ID, |
| 53 | id1, |
| 54 | id2, |
| 55 | selector, |
| 56 | treatment); |
| 57 | final HostToHostIntent sameAsIntent1 = new HostToHostIntent(APP_ID, |
| 58 | id1, |
| 59 | id2, |
| 60 | selector, |
| 61 | treatment); |
| 62 | final HostToHostIntent intent2 = new HostToHostIntent(APP_ID, |
| 63 | id2, |
| 64 | id3, |
| 65 | selector, |
| 66 | treatment); |
| 67 | |
| 68 | new EqualsTester() |
| 69 | .addEqualityGroup(intent1, sameAsIntent1) |
| 70 | .addEqualityGroup(intent2) |
| 71 | .testEquals(); |
| 72 | } |
| 73 | } |