Jian Li | e9af3b4 | 2016-08-08 15:50:01 +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.types; |
| 17 | |
| 18 | import com.google.common.testing.EqualsTester; |
| 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
| 21 | import org.onlab.packet.IpAddress; |
| 22 | |
| 23 | import static org.hamcrest.MatcherAssert.assertThat; |
| 24 | import static org.hamcrest.Matchers.is; |
| 25 | |
| 26 | /** |
| 27 | * Unit tests for LispSegmentLcafAddress class. |
| 28 | */ |
| 29 | public class LispSegmentLcafAddressTest { |
| 30 | |
| 31 | private LispSegmentLcafAddress address1; |
| 32 | private LispSegmentLcafAddress sameAsAddress1; |
| 33 | private LispSegmentLcafAddress address2; |
| 34 | |
| 35 | @Before |
| 36 | public void setup() { |
| 37 | |
| 38 | LispIpv4Address ipv4Address1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); |
| 39 | address1 = new LispSegmentLcafAddress((byte) 0x01, 1, ipv4Address1); |
| 40 | |
| 41 | sameAsAddress1 = new LispSegmentLcafAddress((byte) 0x01, 1, ipv4Address1); |
| 42 | |
| 43 | LispIpv4Address ipv4Address2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.1")); |
| 44 | address2 = new LispSegmentLcafAddress((byte) 0x02, 2, ipv4Address2); |
| 45 | } |
| 46 | |
| 47 | @Test |
| 48 | public void testEquality() { |
| 49 | new EqualsTester() |
| 50 | .addEqualityGroup(address1, sameAsAddress1) |
| 51 | .addEqualityGroup(address2).testEquals(); |
| 52 | } |
| 53 | |
| 54 | @Test |
| 55 | public void testConstruction() { |
| 56 | LispSegmentLcafAddress segmentLcafAddress = address1; |
| 57 | |
| 58 | LispIpv4Address ipv4Address = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); |
| 59 | |
| 60 | assertThat(segmentLcafAddress.getIdMaskLength(), is((byte) 0x01)); |
| 61 | assertThat(segmentLcafAddress.getInstanceId(), is(1)); |
| 62 | assertThat(segmentLcafAddress.getAddress(), is(ipv4Address)); |
| 63 | } |
| 64 | } |