blob: 7b99612cdfb8c83505a30e8adbb4e72ba529cb62 [file] [log] [blame]
Jian Li47671902016-08-11 01:18:18 +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 DefaultLispLocatorRecord class.
27 */
28public final class DefaultLispLocatorRecordTest {
29
30 private LispLocatorRecord record1;
31 private LispLocatorRecord sameAsRecord1;
32 private LispLocatorRecord record2;
33
34 @Before
35 public void setup() {
36
37 LispLocatorRecord.LocatorRecordBuilder builder1 =
38 new DefaultLispLocatorRecord.DefaultLocatorRecordBuilder();
39
40 record1 = builder1
41 .withPriority((byte) 0x01)
42 .withWeight((byte) 0x01)
43 .withMulticastPriority((byte) 0x01)
44 .withMulticastWeight((byte) 0x01)
45 .withLocalLocator(true)
46 .withRlocProbed(false)
47 .withRouted(true)
48 .build();
49
50 LispLocatorRecord.LocatorRecordBuilder builder2 =
51 new DefaultLispLocatorRecord.DefaultLocatorRecordBuilder();
52
53 sameAsRecord1 = builder2
54 .withPriority((byte) 0x01)
55 .withWeight((byte) 0x01)
56 .withMulticastPriority((byte) 0x01)
57 .withMulticastWeight((byte) 0x01)
58 .withLocalLocator(true)
59 .withRlocProbed(false)
60 .withRouted(true)
61 .build();
62
63 LispLocatorRecord.LocatorRecordBuilder builder3 =
64 new DefaultLispLocatorRecord.DefaultLocatorRecordBuilder();
65
66 record2 = builder3
67 .withPriority((byte) 0x02)
68 .withWeight((byte) 0x02)
69 .withMulticastPriority((byte) 0x02)
70 .withMulticastWeight((byte) 0x02)
71 .withLocalLocator(false)
72 .withRlocProbed(true)
73 .withRouted(false)
74 .build();
75 }
76
77 @Test
78 public void testEquality() {
79 new EqualsTester()
80 .addEqualityGroup(record1, sameAsRecord1)
81 .addEqualityGroup(record2).testEquals();
82 }
83
84 @Test
85 public void testConstruction() {
86 DefaultLispLocatorRecord record = (DefaultLispLocatorRecord) record1;
87
88 assertThat(record.getPriority(), is((byte) 0x01));
89 assertThat(record.getWeight(), is((byte) 0x01));
90 assertThat(record.getMulticastPriority(), is((byte) 0x01));
91 assertThat(record.getMulticastWeight(), is((byte) 0x01));
92 assertThat(record.isLocalLocator(), is(true));
93 assertThat(record.isRlocProbed(), is(false));
94 assertThat(record.isRouted(), is(true));
95 }
96}