blob: 1b0a5a4bd1fc16ad1b52089edf42a20ed2198390 [file] [log] [blame]
Jian Li18f3bce2016-08-04 17:36:41 +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.protocols;
17
18import com.google.common.testing.EqualsTester;
19import org.junit.Before;
20import org.junit.Test;
21
22import static org.hamcrest.MatcherAssert.assertThat;
23import static org.hamcrest.Matchers.is;
24
25/**
26 * Unit tests for DefaultLispMapRegister class.
27 */
Jian Li47671902016-08-11 01:18:18 +090028public final class DefaultLispMapRegisterTest {
Jian Li18f3bce2016-08-04 17:36:41 +090029
30 private LispMapRegister register1;
31 private LispMapRegister sameAsRegister1;
32 private LispMapRegister register2;
33
34 @Before
35 public void setup() {
36
37 LispMapRegister.RegisterBuilder builder1 =
38 new DefaultLispMapRegister.DefaultRegisterBuilder();
39
40 register1 = builder1
41 .withIsProxyMapReply(true)
42 .withIsWantMapNotify(false)
43 .withKeyId((short) 1)
44 .withNonce(1L)
45 .withRecordCount((byte) 0x01)
46 .build();
47
48 LispMapRegister.RegisterBuilder builder2 =
49 new DefaultLispMapRegister.DefaultRegisterBuilder();
50
51 sameAsRegister1 = builder2
52 .withIsProxyMapReply(true)
53 .withIsWantMapNotify(false)
54 .withKeyId((short) 1)
55 .withNonce(1L)
56 .withRecordCount((byte) 0x01)
57 .build();
58
59 LispMapRegister.RegisterBuilder builder3 =
60 new DefaultLispMapRegister.DefaultRegisterBuilder();
61
62 register2 = builder3
63 .withIsProxyMapReply(true)
64 .withIsWantMapNotify(false)
65 .withKeyId((short) 2)
66 .withNonce(2L)
67 .withRecordCount((byte) 0x02)
68 .build();
69 }
70
71 @Test
72 public void testEquality() {
73 new EqualsTester()
74 .addEqualityGroup(register1, sameAsRegister1)
75 .addEqualityGroup(register2).testEquals();
76 }
77
78 @Test
79 public void testConstruction() {
80 DefaultLispMapRegister register = (DefaultLispMapRegister) register1;
81
82 assertThat(register.isProxyMapReply(), is(true));
83 assertThat(register.isWantMapNotify(), is(false));
84 assertThat(register.getKeyId(), is((short) 1));
85 assertThat(register.getNonce(), is(1L));
86 assertThat(register.getRecordCount(), is((byte) 0x01));
87 }
88}