blob: fc2a16003fa224b5f5d5816a538abb00311fdb18 [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;
Jian Li76ea0572016-08-29 12:41:16 +090023import org.onosproject.lisp.msg.exceptions.LispParseError;
24import org.onosproject.lisp.msg.exceptions.LispWriterException;
Jian Lie9af3b42016-08-08 15:50:01 +090025
26import static org.hamcrest.MatcherAssert.assertThat;
27import static org.hamcrest.Matchers.is;
28
Jian Li76ea0572016-08-29 12:41:16 +090029import static org.onosproject.lisp.msg.types.LispDistinguishedNameAddress.*;
30
Jian Lie9af3b42016-08-08 15:50:01 +090031/**
32 * Unit tests for LispDistinguishedNameAddress class.
33 */
34public class LispDistinguishedNameAddressTest {
35
36 private LispDistinguishedNameAddress address1;
37 private LispDistinguishedNameAddress sameAsAddress1;
38 private LispDistinguishedNameAddress address2;
39
40 @Before
41 public void setup() {
42
43 address1 = new LispDistinguishedNameAddress("distAddress1");
44 sameAsAddress1 = new LispDistinguishedNameAddress("distAddress1");
45 address2 = new LispDistinguishedNameAddress("distAddress2");
46 }
47
48 @Test
49 public void testEquality() {
50 new EqualsTester()
51 .addEqualityGroup(address1, sameAsAddress1)
52 .addEqualityGroup(address2).testEquals();
53 }
54
55 @Test
56 public void testConstruction() {
57 LispDistinguishedNameAddress distinguishedNameAddress = address1;
58
59 assertThat(distinguishedNameAddress.getDistinguishedName(), is("distAddress1"));
60 }
Jian Li76ea0572016-08-29 12:41:16 +090061
62 @Test
63 public void testSerialization() throws LispWriterException, LispParseError {
64 ByteBuf byteBuf = Unpooled.buffer();
65
66 DistinguishedNameAddressWriter writer = new DistinguishedNameAddressWriter();
67 writer.writeTo(byteBuf, address1);
68
69 DistinguishedNameAddressReader reader = new DistinguishedNameAddressReader();
70 LispDistinguishedNameAddress deserialized = reader.readFrom(byteBuf);
71
72 new EqualsTester()
73 .addEqualityGroup(address1, deserialized).testEquals();
74 }
Jian Lie9af3b42016-08-08 15:50:01 +090075}