blob: ea528a03f1dbbc2aec39e48d7c3fafbf53407ea9 [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;
19import org.junit.Before;
20import org.junit.Test;
21import org.onlab.packet.IpAddress;
22
23import static org.hamcrest.MatcherAssert.assertThat;
24import static org.hamcrest.Matchers.is;
25
26/**
27 * Unit tests for LispAppDataLcafAddress class.
28 */
29public class LispAppDataLcafAddressTest {
30
31 private LispAppDataLcafAddress address1;
32 private LispAppDataLcafAddress sameAsAddress1;
33 private LispAppDataLcafAddress address2;
34
35 @Before
36 public void setup() {
37
Jian Li115d8602016-08-15 20:21:53 +090038 LispAppDataLcafAddress.AppDataAddressBuilder builder1 =
39 new LispAppDataLcafAddress.AppDataAddressBuilder();
Jian Lie9af3b42016-08-08 15:50:01 +090040
Jian Li115d8602016-08-15 20:21:53 +090041 LispAfiAddress ipv4Address1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1"));
42
43 address1 = builder1
44 .withProtocol((byte) 0x01)
45 .withIpTos((short) 10)
46 .withLocalPortLow((short) 1)
47 .withLocalPortHigh((short) 255)
48 .withRemotePortLow((short) 2)
49 .withRemotePortHigh((short) 254)
50 .withAddress(ipv4Address1)
51 .build();
52
53 LispAppDataLcafAddress.AppDataAddressBuilder builder2 =
54 new LispAppDataLcafAddress.AppDataAddressBuilder();
55
56 sameAsAddress1 = builder2
57 .withProtocol((byte) 0x01)
58 .withIpTos((short) 10)
59 .withLocalPortLow((short) 1)
60 .withLocalPortHigh((short) 255)
61 .withRemotePortLow((short) 2)
62 .withRemotePortHigh((short) 254)
63 .withAddress(ipv4Address1)
64 .build();
65
66 LispAppDataLcafAddress.AppDataAddressBuilder builder3 =
67 new LispAppDataLcafAddress.AppDataAddressBuilder();
Jian Lie9af3b42016-08-08 15:50:01 +090068
69 LispAfiAddress ipv4Address2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.1"));
Jian Li115d8602016-08-15 20:21:53 +090070
71 address2 = builder3
72 .withProtocol((byte) 0x02)
73 .withIpTos((short) 20)
74 .withLocalPortLow((short) 1)
75 .withLocalPortHigh((short) 255)
76 .withRemotePortLow((short) 2)
77 .withRemotePortHigh((short) 254)
78 .withAddress(ipv4Address2)
79 .build();
Jian Lie9af3b42016-08-08 15:50:01 +090080 }
81
82 @Test
83 public void testEquality() {
84 new EqualsTester()
85 .addEqualityGroup(address1, sameAsAddress1)
86 .addEqualityGroup(address2).testEquals();
87 }
88
89 @Test
90 public void testConstruction() {
91 LispAppDataLcafAddress appDataLcafAddress = address1;
92
93 LispAfiAddress ipv4Address = new LispIpv4Address(IpAddress.valueOf("192.168.1.1"));
94
95 assertThat(appDataLcafAddress.getProtocol(), is((byte) 0x01));
Jian Li115d8602016-08-15 20:21:53 +090096 assertThat(appDataLcafAddress.getIpTos(), is(10));
97 assertThat(appDataLcafAddress.getLocalPortLow(), is((short) 1));
98 assertThat(appDataLcafAddress.getLocalPortHigh(), is((short) 255));
99 assertThat(appDataLcafAddress.getRemotePortLow(), is((short) 2));
100 assertThat(appDataLcafAddress.getRemotePortHigh(), is((short) 254));
Jian Lie9af3b42016-08-08 15:50:01 +0900101 assertThat(appDataLcafAddress.getAddress(), is(ipv4Address));
102 }
103}