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; |
Jian Li | 76ea057 | 2016-08-29 12:41:16 +0900 | [diff] [blame^] | 19 | import io.netty.buffer.ByteBuf; |
| 20 | import io.netty.buffer.Unpooled; |
Jian Li | e9af3b4 | 2016-08-08 15:50:01 +0900 | [diff] [blame] | 21 | import org.junit.Before; |
| 22 | import org.junit.Test; |
| 23 | import org.onlab.packet.MacAddress; |
Jian Li | 76ea057 | 2016-08-29 12:41:16 +0900 | [diff] [blame^] | 24 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
| 25 | import org.onosproject.lisp.msg.exceptions.LispWriterException; |
Jian Li | e9af3b4 | 2016-08-08 15:50:01 +0900 | [diff] [blame] | 26 | |
| 27 | import static org.hamcrest.MatcherAssert.assertThat; |
| 28 | import static org.hamcrest.Matchers.is; |
Jian Li | 76ea057 | 2016-08-29 12:41:16 +0900 | [diff] [blame^] | 29 | import static org.onosproject.lisp.msg.types.LispMacAddress.MacAddressReader; |
| 30 | import static org.onosproject.lisp.msg.types.LispMacAddress.MacAddressWriter; |
Jian Li | e9af3b4 | 2016-08-08 15:50:01 +0900 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Unit tests for LispMacAddress class. |
| 34 | */ |
| 35 | public class LispMacAddressTest { |
| 36 | |
| 37 | private LispMacAddress address1; |
| 38 | private LispMacAddress sameAsAddress1; |
| 39 | private LispMacAddress address2; |
| 40 | |
| 41 | @Before |
| 42 | public void setup() { |
| 43 | |
| 44 | address1 = new LispMacAddress(MacAddress.valueOf("00:00:00:00:00:01")); |
| 45 | sameAsAddress1 = new LispMacAddress(MacAddress.valueOf("00:00:00:00:00:01")); |
| 46 | address2 = new LispMacAddress(MacAddress.valueOf("00:00:00:00:00:02")); |
| 47 | } |
| 48 | |
| 49 | @Test |
| 50 | public void testEquality() { |
| 51 | new EqualsTester() |
| 52 | .addEqualityGroup(address1, sameAsAddress1) |
| 53 | .addEqualityGroup(address2).testEquals(); |
| 54 | } |
| 55 | |
| 56 | @Test |
| 57 | public void testConstruction() { |
| 58 | LispMacAddress macAddress = address1; |
| 59 | assertThat(macAddress.getAddress(), is(MacAddress.valueOf("00:00:00:00:00:01"))); |
| 60 | } |
Jian Li | 76ea057 | 2016-08-29 12:41:16 +0900 | [diff] [blame^] | 61 | |
| 62 | @Test |
| 63 | public void testSerialization() throws LispWriterException, LispParseError { |
| 64 | ByteBuf byteBuf = Unpooled.buffer(); |
| 65 | |
| 66 | MacAddressWriter writer = new MacAddressWriter(); |
| 67 | writer.writeTo(byteBuf, address1); |
| 68 | |
| 69 | MacAddressReader reader = new MacAddressReader(); |
| 70 | LispMacAddress deserialized = reader.readFrom(byteBuf); |
| 71 | |
| 72 | new EqualsTester() |
| 73 | .addEqualityGroup(address1, deserialized).testEquals(); |
| 74 | } |
Jian Li | e9af3b4 | 2016-08-08 15:50:01 +0900 | [diff] [blame] | 75 | } |