Jian Li | 18f3bce | 2016-08-04 17:36:41 +0900 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.lisp.msg.protocols; |
| 17 | |
| 18 | import com.google.common.testing.EqualsTester; |
| 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
| 21 | |
| 22 | import static org.hamcrest.MatcherAssert.assertThat; |
| 23 | import static org.hamcrest.Matchers.is; |
| 24 | |
| 25 | /** |
| 26 | * Unit tests for DefaultLispMapReply class. |
| 27 | */ |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame^] | 28 | public final class DefaultLispMapReplyTest { |
Jian Li | 18f3bce | 2016-08-04 17:36:41 +0900 | [diff] [blame] | 29 | |
| 30 | private LispMapReply reply1; |
| 31 | private LispMapReply sameAsReply1; |
| 32 | private LispMapReply reply2; |
| 33 | |
| 34 | @Before |
| 35 | public void setup() { |
| 36 | |
| 37 | LispMapReply.ReplyBuilder builder1 = |
| 38 | new DefaultLispMapReply.DefaultReplyBuilder(); |
| 39 | |
| 40 | reply1 = builder1 |
| 41 | .withIsEtr(true) |
| 42 | .withIsProbe(false) |
| 43 | .withIsSecurity(true) |
| 44 | .withNonce(1L) |
| 45 | .withRecordCount((byte) 0x01) |
| 46 | .build(); |
| 47 | |
| 48 | LispMapReply.ReplyBuilder builder2 = |
| 49 | new DefaultLispMapReply.DefaultReplyBuilder(); |
| 50 | |
| 51 | sameAsReply1 = builder2 |
| 52 | .withIsEtr(true) |
| 53 | .withIsProbe(false) |
| 54 | .withIsSecurity(true) |
| 55 | .withNonce(1L) |
| 56 | .withRecordCount((byte) 0x01) |
| 57 | .build(); |
| 58 | |
| 59 | LispMapReply.ReplyBuilder builder3 = |
| 60 | new DefaultLispMapReply.DefaultReplyBuilder(); |
| 61 | reply2 = builder3 |
| 62 | .withIsEtr(false) |
| 63 | .withIsProbe(true) |
| 64 | .withIsSecurity(false) |
| 65 | .withNonce(2L) |
| 66 | .withRecordCount((byte) 0x02) |
| 67 | .build(); |
| 68 | } |
| 69 | |
| 70 | @Test |
| 71 | public void testEquality() { |
| 72 | new EqualsTester() |
| 73 | .addEqualityGroup(reply1, sameAsReply1) |
| 74 | .addEqualityGroup(reply2).testEquals(); |
| 75 | } |
| 76 | |
| 77 | @Test |
| 78 | public void testConstruction() { |
| 79 | DefaultLispMapReply reply = (DefaultLispMapReply) reply1; |
| 80 | |
| 81 | assertThat(reply.isEtr(), is(true)); |
| 82 | assertThat(reply.isProbe(), is(false)); |
| 83 | assertThat(reply.isSecurity(), is(true)); |
| 84 | assertThat(reply.getNonce(), is(1L)); |
| 85 | assertThat(reply.getRecordCount(), is((byte) 0x01)); |
| 86 | } |
| 87 | } |