blob: c22f22b944cad2369ecab592fbe1e5aa5b06617f [file] [log] [blame]
Jian Lie9af3b42016-08-08 15:50:01 +09001/*
2 * Copyright 2016-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.lisp.msg.types;
17
18import com.google.common.testing.EqualsTester;
Jian Li76ea0572016-08-29 12:41:16 +090019import io.netty.buffer.ByteBuf;
20import io.netty.buffer.Unpooled;
Jian Lie9af3b42016-08-08 15:50:01 +090021import org.junit.Before;
22import org.junit.Test;
23import org.onlab.packet.IpAddress;
Jian Li76ea0572016-08-29 12:41:16 +090024import org.onosproject.lisp.msg.exceptions.LispParseError;
25import org.onosproject.lisp.msg.exceptions.LispWriterException;
Jian Li5e505c62016-12-05 02:44:24 +090026import org.onosproject.lisp.msg.types.LispIpv6Address.Ipv6AddressReader;
27import org.onosproject.lisp.msg.types.LispIpv6Address.Ipv6AddressWriter;
Jian Lie9af3b42016-08-08 15:50:01 +090028
29import static org.hamcrest.MatcherAssert.assertThat;
30import static org.hamcrest.Matchers.is;
Jian Li76ea0572016-08-29 12:41:16 +090031
Jian Lie9af3b42016-08-08 15:50:01 +090032
33/**
34 * Unit tests for LispIpv6Address class.
35 */
36public class LispIpv6AddressTest {
37
38 private LispIpv6Address address1;
39 private LispIpv6Address sameAsAddress1;
40 private LispIpv6Address address2;
41
42 @Before
43 public void setup() {
44
45 address1 = new LispIpv6Address(IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8885"));
46 sameAsAddress1 = new LispIpv6Address(IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8885"));
47 address2 = new LispIpv6Address(IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8886"));
48 }
49
50 @Test
51 public void testEquality() {
52 new EqualsTester()
53 .addEqualityGroup(address1, sameAsAddress1)
54 .addEqualityGroup(address2).testEquals();
55 }
56
57 @Test
58 public void testConstruction() {
59 LispIpv6Address ipv6Address = address1;
60 assertThat(ipv6Address.getAddress(), is(IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8885")));
61 }
Jian Li76ea0572016-08-29 12:41:16 +090062
63 @Test
64 public void testSerialization() throws LispWriterException, LispParseError {
65 ByteBuf byteBuf = Unpooled.buffer();
66
67 Ipv6AddressWriter writer = new Ipv6AddressWriter();
68 writer.writeTo(byteBuf, address1);
69
70 Ipv6AddressReader reader = new Ipv6AddressReader();
71 LispIpv6Address deserialized = reader.readFrom(byteBuf);
72
Jian Li5e505c62016-12-05 02:44:24 +090073 new EqualsTester().addEqualityGroup(address1, deserialized).testEquals();
Jian Li76ea0572016-08-29 12:41:16 +090074 }
Jian Lie9af3b42016-08-08 15:50:01 +090075}