samueljcc | fd3b990 | 2015-10-28 15:59:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | |
Ray Milkey | 6c1bac3 | 2015-11-13 14:40:40 -0800 | [diff] [blame] | 17 | package org.onosproject.vtnrsc; |
| 18 | |
| 19 | import org.junit.Test; |
| 20 | import org.onlab.packet.IpAddress; |
| 21 | |
| 22 | import com.google.common.testing.EqualsTester; |
samueljcc | fd3b990 | 2015-10-28 15:59:22 -0700 | [diff] [blame] | 23 | |
| 24 | import static org.hamcrest.MatcherAssert.assertThat; |
| 25 | import static org.hamcrest.Matchers.is; |
| 26 | import static org.hamcrest.Matchers.notNullValue; |
| 27 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 28 | |
samueljcc | fd3b990 | 2015-10-28 15:59:22 -0700 | [diff] [blame] | 29 | /** |
| 30 | * Unit tests for FixedIp class. |
| 31 | */ |
| 32 | public class FixedIpTest { |
| 33 | |
| 34 | final SubnetId subnetId1 = SubnetId.subnetId("lef11-95w-4er-9c9c"); |
| 35 | final SubnetId subnetId2 = SubnetId.subnetId("lefaa-95w-4er-9c9c"); |
| 36 | final IpAddress ip1 = IpAddress.valueOf("192.168.0.1"); |
| 37 | final IpAddress ip2 = IpAddress.valueOf("192.168.1.1"); |
| 38 | |
| 39 | /** |
| 40 | * Checks that the FixedIp class is immutable. |
| 41 | */ |
| 42 | @Test |
| 43 | public void testImmutability() { |
| 44 | assertThatClassIsImmutable(FixedIp.class); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Checks the operation of equals(). |
| 49 | */ |
| 50 | @Test |
| 51 | public void testEquals() { |
| 52 | FixedIp fixedIp1 = FixedIp.fixedIp(subnetId1, ip1); |
| 53 | FixedIp fixedIp2 = FixedIp.fixedIp(subnetId1, ip1); |
| 54 | FixedIp fixedIp3 = FixedIp.fixedIp(subnetId2, ip2); |
| 55 | new EqualsTester().addEqualityGroup(fixedIp1, fixedIp2) |
| 56 | .addEqualityGroup(fixedIp3).testEquals(); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Checks the construction of a FixedIp object. |
| 61 | */ |
| 62 | @Test |
| 63 | public void testConstruction() { |
| 64 | FixedIp fixedIp = FixedIp.fixedIp(subnetId1, ip1); |
| 65 | assertThat(ip1, is(notNullValue())); |
| 66 | assertThat(ip1, is(fixedIp.ip())); |
| 67 | assertThat(subnetId1, is(notNullValue())); |
| 68 | assertThat(subnetId1, is(fixedIp.subnetId())); |
| 69 | } |
| 70 | } |