PRASHANTH SHIVANANJAPPA | 491b8af | 2016-04-27 19:23:24 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
PRASHANTH SHIVANANJAPPA | 491b8af | 2016-04-27 19:23:24 +0530 | [diff] [blame] | 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.isis.io.isispacket.tlv; |
| 17 | |
| 18 | import org.easymock.EasyMock; |
| 19 | import org.jboss.netty.buffer.ChannelBuffer; |
| 20 | import org.jboss.netty.buffer.ChannelBuffers; |
| 21 | import org.junit.After; |
| 22 | import org.junit.Before; |
| 23 | import org.junit.Test; |
| 24 | |
| 25 | import java.util.List; |
| 26 | |
| 27 | import static org.hamcrest.MatcherAssert.assertThat; |
| 28 | import static org.hamcrest.Matchers.is; |
| 29 | import static org.hamcrest.Matchers.notNullValue; |
| 30 | |
| 31 | /** |
| 32 | * Unit test class for AreaAddressTlv. |
| 33 | */ |
| 34 | public class AreaAddressTlvTest { |
| 35 | |
Ray Milkey | c108a6b | 2017-08-23 15:23:50 -0700 | [diff] [blame] | 36 | private final String areaAddress = "490001"; |
PRASHANTH SHIVANANJAPPA | 491b8af | 2016-04-27 19:23:24 +0530 | [diff] [blame] | 37 | private final byte[] tlv = {1, 49}; |
| 38 | private AreaAddressTlv areaAddressTlv; |
| 39 | private TlvHeader tlvHeader; |
| 40 | private List<String> result; |
| 41 | private ChannelBuffer channelBuffer; |
| 42 | private byte[] result1; |
| 43 | |
| 44 | @Before |
| 45 | public void setUp() throws Exception { |
| 46 | tlvHeader = new TlvHeader(); |
| 47 | areaAddressTlv = new AreaAddressTlv(tlvHeader); |
| 48 | channelBuffer = EasyMock.createMock(ChannelBuffer.class); |
| 49 | } |
| 50 | |
| 51 | @After |
| 52 | public void tearDown() throws Exception { |
| 53 | tlvHeader = null; |
| 54 | areaAddressTlv = null; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Tests addAddress() method. |
| 59 | */ |
| 60 | @Test |
| 61 | public void testAddAddress() throws Exception { |
Ray Milkey | c108a6b | 2017-08-23 15:23:50 -0700 | [diff] [blame] | 62 | areaAddressTlv.addAddress(areaAddress); |
PRASHANTH SHIVANANJAPPA | 491b8af | 2016-04-27 19:23:24 +0530 | [diff] [blame] | 63 | result = areaAddressTlv.areaAddress(); |
| 64 | assertThat(result.size(), is(1)); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Tests areaAddress() setter method. |
| 69 | */ |
| 70 | @Test |
| 71 | public void testSetAreaAddress() throws Exception { |
Ray Milkey | c108a6b | 2017-08-23 15:23:50 -0700 | [diff] [blame] | 72 | areaAddressTlv.addAddress(areaAddress); |
PRASHANTH SHIVANANJAPPA | 491b8af | 2016-04-27 19:23:24 +0530 | [diff] [blame] | 73 | result = areaAddressTlv.areaAddress(); |
| 74 | assertThat(result.size(), is(1)); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Tests readFrom() method. |
| 79 | */ |
| 80 | @Test |
| 81 | public void testReadFrom() throws Exception { |
| 82 | channelBuffer = ChannelBuffers.copiedBuffer(tlv); |
| 83 | areaAddressTlv.readFrom(channelBuffer); |
| 84 | assertThat(areaAddressTlv.areaAddress().size(), is(1)); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Tests asBytes() method. |
| 89 | */ |
| 90 | @Test |
| 91 | public void testAsBytes() throws Exception { |
| 92 | channelBuffer = ChannelBuffers.copiedBuffer(tlv); |
| 93 | areaAddressTlv.readFrom(channelBuffer); |
| 94 | result1 = areaAddressTlv.asBytes(); |
| 95 | assertThat(result1, is(notNullValue())); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Tests toString() method. |
| 100 | */ |
| 101 | @Test |
| 102 | public void testToString() throws Exception { |
| 103 | assertThat(areaAddressTlv.toString(), is(notNullValue())); |
| 104 | } |
Ray Milkey | c108a6b | 2017-08-23 15:23:50 -0700 | [diff] [blame] | 105 | } |