blob: 214ffee2f6453b1ca141dd1958f1c095ed8ff9d9 [file] [log] [blame]
Jian Li44155b02017-02-15 17:03:38 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Jian Li44155b02017-02-15 17:03:38 +09003 *
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 */
16package org.onosproject.mapping;
17
18import com.google.common.testing.EqualsTester;
19import org.junit.Test;
20import org.onlab.packet.IpPrefix;
21import org.onosproject.mapping.addresses.MappingAddress;
22import org.onosproject.mapping.addresses.MappingAddresses;
23
24import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
25
26/**
27 * Unit tests for the default mapping key class.
28 */
29public 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}