blob: 0ba90703146369e0ecfbd8156daab407184f2483 [file] [log] [blame]
Jian Li299bc1d2017-03-17 19:17:40 +09001/*
2 * Copyright 2017-present 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 */
16package org.onosproject.drivers.lisp.extensions;
17
18import com.google.common.testing.EqualsTester;
19import org.junit.Before;
20import org.junit.Test;
21import org.onlab.packet.IpPrefix;
22import org.onosproject.mapping.addresses.MappingAddress;
23import org.onosproject.mapping.addresses.MappingAddresses;
24
25import static org.hamcrest.MatcherAssert.assertThat;
26import static org.hamcrest.Matchers.is;
27
28/**
29 * Unit tests for LispAsAddress extension class.
30 */
31public class LispAsAddressTest {
32
33 private static final IpPrefix IP_ADDRESS_1 = IpPrefix.valueOf("1.2.3.4/24");
34 private static final IpPrefix IP_ADDRESS_2 = IpPrefix.valueOf("5.6.7.8/24");
35
36 private static final int AS_NUMBER_1 = 1;
37 private static final int AS_NUMBER_2 = 2;
38
39 private LispAsAddress address1;
40 private LispAsAddress sameAsAddress1;
41 private LispAsAddress address2;
42
43 @Before
44 public void setUp() {
45
46 MappingAddress ma1 = MappingAddresses.ipv4MappingAddress(IP_ADDRESS_1);
47
48 address1 = new LispAsAddress.Builder()
49 .withAsNumber(AS_NUMBER_1)
50 .withAddress(ma1)
51 .build();
52
53 sameAsAddress1 = new LispAsAddress.Builder()
54 .withAsNumber(AS_NUMBER_1)
55 .withAddress(ma1)
56 .build();
57
58 MappingAddress ma2 = MappingAddresses.ipv4MappingAddress(IP_ADDRESS_2);
59
60 address2 = new LispAsAddress.Builder()
61 .withAsNumber(AS_NUMBER_2)
62 .withAddress(ma2)
63 .build();
64
65 }
66
67 @Test
68 public void testEquality() {
69 new EqualsTester()
70 .addEqualityGroup(address1, sameAsAddress1)
71 .addEqualityGroup(address2).testEquals();
72 }
73
74 @Test
75 public void testConstruction() {
76 LispAsAddress address = address1;
77
78 MappingAddress ma = MappingAddresses.ipv4MappingAddress(IP_ADDRESS_1);
79
80 assertThat(address.getAsNumber(), is(AS_NUMBER_1));
81 assertThat(address.getAddress(), is(ma));
82 }
83
84 @Test
85 public void testSerialization() {
86 LispAsAddress other = new LispAsAddress();
87 other.deserialize(address1.serialize());
88
89 new EqualsTester()
90 .addEqualityGroup(address1, other)
91 .testEquals();
92 }
93}