blob: 1c85b115428ce2dd3136eadc8e1997ce13f8b419 [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 DefaultLispMapRecord class.
27 */
Jian Li47671902016-08-11 01:18:18 +090028public final class DefaultLispMapRecordTest {
Jian Li18f3bce2016-08-04 17:36:41 +090029
30 private LispMapRecord record1;
31 private LispMapRecord sameAsRecord1;
32 private LispMapRecord record2;
33
34 @Before
35 public void setup() {
36
37 LispMapRecord.MapRecordBuilder builder1 =
38 new DefaultLispMapRecord.DefaultMapRecordBuilder();
39
40 record1 = builder1
41 .withRecordTtl(100)
42 .withAuthoritative(true)
43 .withLocatorCount(100)
44 .withMapVersionNumber((short) 1)
45 .withMaskLength((byte) 0x01)
46 .build();
47
48 LispMapRecord.MapRecordBuilder builder2 =
49 new DefaultLispMapRecord.DefaultMapRecordBuilder();
50
51 sameAsRecord1 = builder2
52 .withRecordTtl(100)
53 .withAuthoritative(true)
54 .withLocatorCount(100)
55 .withMapVersionNumber((short) 1)
56 .withMaskLength((byte) 0x01)
57 .build();
58
59 LispMapRecord.MapRecordBuilder builder3 =
60 new DefaultLispMapRecord.DefaultMapRecordBuilder();
61
62 record2 = builder3
63 .withRecordTtl(200)
64 .withAuthoritative(false)
65 .withLocatorCount(200)
66 .withMapVersionNumber((short) 2)
67 .withMaskLength((byte) 0x02)
68 .build();
69 }
70
71 @Test
72 public void testEquality() {
73 new EqualsTester()
74 .addEqualityGroup(record1, sameAsRecord1)
75 .addEqualityGroup(record2).testEquals();
76 }
77
78 @Test
79 public void testConstruction() {
80 DefaultLispMapRecord record = (DefaultLispMapRecord) record1;
81
82 assertThat(record.getRecordTtl(), is(100));
83 assertThat(record.isAuthoritative(), is(true));
84 assertThat(record.getLocatorCount(), is(100));
85 assertThat(record.getMapVersionNumber(), is((short) 1));
86 assertThat(record.getMaskLength(), is((byte) 0x01));
87 }
88}