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 DefaultLispMapRequest class. |
| 27 | */ |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 28 | public final class DefaultLispMapRequestTest { |
Jian Li | 18f3bce | 2016-08-04 17:36:41 +0900 | [diff] [blame] | 29 | |
| 30 | private LispMapRequest request1; |
| 31 | private LispMapRequest sameAsRequest1; |
| 32 | private LispMapRequest request2; |
| 33 | |
| 34 | @Before |
| 35 | public void setup() { |
| 36 | |
| 37 | LispMapRequest.RequestBuilder builder1 = |
| 38 | new DefaultLispMapRequest.DefaultRequestBuilder(); |
| 39 | |
| 40 | request1 = builder1 |
| 41 | .withIsAuthoritative(true) |
| 42 | .withIsMapDataPresent(true) |
| 43 | .withIsPitr(false) |
| 44 | .withIsProbe(false) |
| 45 | .withIsSmr(true) |
| 46 | .withIsSmrInvoked(false) |
| 47 | .withNonce(1L) |
| 48 | .withRecordCount((byte) 0x01) |
| 49 | .build(); |
| 50 | |
| 51 | LispMapRequest.RequestBuilder builder2 = |
| 52 | new DefaultLispMapRequest.DefaultRequestBuilder(); |
| 53 | |
| 54 | sameAsRequest1 = builder2 |
| 55 | .withIsAuthoritative(true) |
| 56 | .withIsMapDataPresent(true) |
| 57 | .withIsPitr(false) |
| 58 | .withIsProbe(false) |
| 59 | .withIsSmr(true) |
| 60 | .withIsSmrInvoked(false) |
| 61 | .withNonce(1L) |
| 62 | .withRecordCount((byte) 0x01) |
| 63 | .build(); |
| 64 | |
| 65 | LispMapRequest.RequestBuilder builder3 = |
| 66 | new DefaultLispMapRequest.DefaultRequestBuilder(); |
| 67 | |
| 68 | request2 = builder3 |
| 69 | .withIsAuthoritative(false) |
| 70 | .withIsMapDataPresent(false) |
| 71 | .withIsPitr(true) |
| 72 | .withIsProbe(true) |
| 73 | .withIsSmr(false) |
| 74 | .withIsSmrInvoked(true) |
| 75 | .withNonce(2L) |
| 76 | .withRecordCount((byte) 0x02) |
| 77 | .build(); |
| 78 | } |
| 79 | |
| 80 | @Test |
| 81 | public void testEquality() { |
| 82 | new EqualsTester() |
| 83 | .addEqualityGroup(request1, sameAsRequest1) |
| 84 | .addEqualityGroup(request2).testEquals(); |
| 85 | } |
| 86 | |
| 87 | @Test |
| 88 | public void testConstruction() { |
| 89 | DefaultLispMapRequest request = (DefaultLispMapRequest) request1; |
| 90 | |
| 91 | assertThat(request.isAuthoritative(), is(true)); |
| 92 | assertThat(request.isMapDataPresent(), is(true)); |
| 93 | assertThat(request.isPitr(), is(false)); |
| 94 | assertThat(request.isProbe(), is(false)); |
| 95 | assertThat(request.isSmr(), is(true)); |
| 96 | assertThat(request.isSmrInvoked(), is(false)); |
| 97 | assertThat(request.getNonce(), is(1L)); |
| 98 | assertThat(request.getRecordCount(), is((byte) 0x01)); |
| 99 | } |
| 100 | } |