blob: e771d155f07d6e7f440e41b7606e2108d2227c29 [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;
26import org.onosproject.lisp.msg.protocols.DefaultLispMapReply.ReplyReader;
27import org.onosproject.lisp.msg.protocols.DefaultLispMapReply.ReplyWriter;
Jian Li18f3bce2016-08-04 17:36:41 +090028
29import static org.hamcrest.MatcherAssert.assertThat;
30import static org.hamcrest.Matchers.is;
31
32/**
33 * Unit tests for DefaultLispMapReply class.
34 */
Jian Li47671902016-08-11 01:18:18 +090035public final class DefaultLispMapReplyTest {
Jian Li18f3bce2016-08-04 17:36:41 +090036
37 private LispMapReply reply1;
38 private LispMapReply sameAsReply1;
39 private LispMapReply reply2;
40
41 @Before
42 public void setup() {
43
44 LispMapReply.ReplyBuilder builder1 =
45 new DefaultLispMapReply.DefaultReplyBuilder();
46
47 reply1 = builder1
48 .withIsEtr(true)
49 .withIsProbe(false)
50 .withIsSecurity(true)
51 .withNonce(1L)
Jian Li18f3bce2016-08-04 17:36:41 +090052 .build();
53
54 LispMapReply.ReplyBuilder builder2 =
55 new DefaultLispMapReply.DefaultReplyBuilder();
56
57 sameAsReply1 = builder2
58 .withIsEtr(true)
59 .withIsProbe(false)
60 .withIsSecurity(true)
61 .withNonce(1L)
Jian Li18f3bce2016-08-04 17:36:41 +090062 .build();
63
64 LispMapReply.ReplyBuilder builder3 =
65 new DefaultLispMapReply.DefaultReplyBuilder();
66 reply2 = builder3
67 .withIsEtr(false)
68 .withIsProbe(true)
69 .withIsSecurity(false)
70 .withNonce(2L)
Jian Li18f3bce2016-08-04 17:36:41 +090071 .build();
72 }
73
74 @Test
75 public void testEquality() {
76 new EqualsTester()
77 .addEqualityGroup(reply1, sameAsReply1)
78 .addEqualityGroup(reply2).testEquals();
79 }
80
81 @Test
82 public void testConstruction() {
83 DefaultLispMapReply reply = (DefaultLispMapReply) reply1;
84
85 assertThat(reply.isEtr(), is(true));
86 assertThat(reply.isProbe(), is(false));
87 assertThat(reply.isSecurity(), is(true));
88 assertThat(reply.getNonce(), is(1L));
Jian Lie4ba2a42016-08-29 20:24:15 +090089 }
90
91 @Test
92 public void testSerialization() throws LispReaderException, LispWriterException, LispParseError {
93 ByteBuf byteBuf = Unpooled.buffer();
94 ReplyWriter writer = new ReplyWriter();
95 writer.writeTo(byteBuf, reply1);
96
97 ReplyReader reader = new ReplyReader();
98 LispMapReply deserialized = reader.readFrom(byteBuf);
99
100 new EqualsTester()
101 .addEqualityGroup(reply1, deserialized).testEquals();
Jian Li18f3bce2016-08-04 17:36:41 +0900102 }
103}