Jian Li | 44155b0 | 2017-02-15 17:03:38 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Jian Li | 44155b0 | 2017-02-15 17:03:38 +0900 | [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 | */ |
| 16 | package org.onosproject.mapping; |
| 17 | |
| 18 | import com.google.common.testing.EqualsTester; |
| 19 | import org.junit.Test; |
| 20 | import org.onlab.packet.IpPrefix; |
| 21 | import org.onosproject.mapping.addresses.MappingAddress; |
| 22 | import org.onosproject.mapping.addresses.MappingAddresses; |
| 23 | |
| 24 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
| 25 | |
| 26 | /** |
| 27 | * Unit tests for the default mapping key class. |
| 28 | */ |
| 29 | public class DefaultMappingKeyTest { |
| 30 | |
| 31 | private static final String IP_ADDRESS_1 = "1.2.3.4/24"; |
| 32 | private static final String IP_ADDRESS_2 = "5.6.7.8/24"; |
| 33 | |
| 34 | /** |
| 35 | * Checks that the DefaultMappingKey class is immutable. |
| 36 | */ |
| 37 | @Test |
| 38 | public void testImmutability() { |
| 39 | assertThatClassIsImmutable(DefaultMappingKey.class); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Tests equals() method. |
| 44 | */ |
| 45 | @Test |
| 46 | public void testEquals() { |
| 47 | IpPrefix ip1 = IpPrefix.valueOf(IP_ADDRESS_1); |
| 48 | MappingAddress address1 = MappingAddresses.ipv4MappingAddress(ip1); |
| 49 | |
| 50 | MappingKey key1 = DefaultMappingKey.builder() |
| 51 | .withAddress(address1) |
| 52 | .build(); |
| 53 | MappingKey sameAsKey1 = DefaultMappingKey.builder() |
| 54 | .withAddress(address1) |
| 55 | .build(); |
| 56 | |
| 57 | IpPrefix ip2 = IpPrefix.valueOf(IP_ADDRESS_2); |
| 58 | MappingAddress address2 = MappingAddresses.ipv4MappingAddress(ip2); |
| 59 | |
| 60 | MappingKey key2 = DefaultMappingKey.builder() |
| 61 | .withAddress(address2) |
| 62 | .build(); |
| 63 | |
| 64 | new EqualsTester() |
| 65 | .addEqualityGroup(key1, sameAsKey1) |
| 66 | .addEqualityGroup(key2) |
| 67 | .testEquals(); |
| 68 | } |
| 69 | } |