blob: 819da3d2af895c391a5019447ff62af7e73cf9a4 [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;
Jian Lie4ba2a42016-08-29 20:24:15 +090019import io.netty.buffer.ByteBuf;
20import io.netty.buffer.Unpooled;
Jian Li18f3bce2016-08-04 17:36:41 +090021import org.junit.Before;
22import org.junit.Test;
Jian Lie4ba2a42016-08-29 20:24:15 +090023import org.onosproject.lisp.msg.exceptions.LispParseError;
24import org.onosproject.lisp.msg.exceptions.LispReaderException;
25import org.onosproject.lisp.msg.exceptions.LispWriterException;
Jian Li18f3bce2016-08-04 17:36:41 +090026
27import static org.hamcrest.MatcherAssert.assertThat;
28import static org.hamcrest.Matchers.is;
Jian Lie4ba2a42016-08-29 20:24:15 +090029import static org.onosproject.lisp.msg.protocols.DefaultLispMapNotify.*;
Jian Li18f3bce2016-08-04 17:36:41 +090030
31/**
32 * Unit tests for DefaultLispMapNotify class.
33 */
Jian Li47671902016-08-11 01:18:18 +090034public final class DefaultLispMapNotifyTest {
Jian Li18f3bce2016-08-04 17:36:41 +090035
36 private LispMapNotify notify1;
37 private LispMapNotify sameAsNotify1;
38 private LispMapNotify notify2;
39
40 @Before
41 public void setup() {
42
43 LispMapNotify.NotifyBuilder builder1 =
Jian Lie4ba2a42016-08-29 20:24:15 +090044 new DefaultNotifyBuilder();
Jian Li18f3bce2016-08-04 17:36:41 +090045
46 notify1 = builder1
47 .withKeyId((short) 1)
48 .withNonce(1L)
Jian Lie4ba2a42016-08-29 20:24:15 +090049 .withRecordCount((byte) 0)
Jian Li18f3bce2016-08-04 17:36:41 +090050 .build();
51
52 LispMapNotify.NotifyBuilder builder2 =
Jian Lie4ba2a42016-08-29 20:24:15 +090053 new DefaultNotifyBuilder();
Jian Li18f3bce2016-08-04 17:36:41 +090054
55 sameAsNotify1 = builder2
56 .withKeyId((short) 1)
57 .withNonce(1L)
Jian Lie4ba2a42016-08-29 20:24:15 +090058 .withRecordCount((byte) 0)
Jian Li18f3bce2016-08-04 17:36:41 +090059 .build();
60
61 LispMapNotify.NotifyBuilder builder3 =
Jian Lie4ba2a42016-08-29 20:24:15 +090062 new DefaultNotifyBuilder();
Jian Li18f3bce2016-08-04 17:36:41 +090063
64 notify2 = builder3
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(notify1, sameAsNotify1)
75 .addEqualityGroup(notify2).testEquals();
76 }
77
78 @Test
79 public void testConstruction() {
80 DefaultLispMapNotify notify = (DefaultLispMapNotify) notify1;
81
82 assertThat(notify.getKeyId(), is((short) 1));
83 assertThat(notify.getNonce(), is(1L));
Jian Lie4ba2a42016-08-29 20:24:15 +090084 assertThat(notify.getRecordCount(), is((byte) 0));
85 }
86
87 @Test
88 public void testSerialization() throws LispReaderException, LispWriterException, LispParseError {
89 ByteBuf byteBuf = Unpooled.buffer();
90
91 NotifyWriter writer = new NotifyWriter();
92 writer.writeTo(byteBuf, notify1);
93
94 NotifyReader reader = new NotifyReader();
95 LispMapNotify deserialized = reader.readFrom(byteBuf);
96
97 new EqualsTester()
98 .addEqualityGroup(notify1, deserialized).testEquals();
Jian Li18f3bce2016-08-04 17:36:41 +090099 }
100}