blob: c33f5e4894a22b29d2e4683486acd101cb8265c6 [file] [log] [blame]
PRASHANTH SHIVANANJAPPA491b8af2016-04-27 19:23:24 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
PRASHANTH SHIVANANJAPPA491b8af2016-04-27 19:23:24 +05303 *
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 */
16package org.onosproject.isis.io.isispacket.tlv;
17
18import org.easymock.EasyMock;
19import org.jboss.netty.buffer.ChannelBuffer;
20import org.jboss.netty.buffer.ChannelBuffers;
21import org.junit.After;
22import org.junit.Before;
23import org.junit.Test;
24
25import java.util.List;
26
27import static org.hamcrest.MatcherAssert.assertThat;
28import static org.hamcrest.Matchers.is;
29import static org.hamcrest.Matchers.notNullValue;
30
31/**
32 * Unit test class for AreaAddressTlv.
33 */
34public class AreaAddressTlvTest {
35
Ray Milkeyc108a6b2017-08-23 15:23:50 -070036 private final String areaAddress = "490001";
PRASHANTH SHIVANANJAPPA491b8af2016-04-27 19:23:24 +053037 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 Milkeyc108a6b2017-08-23 15:23:50 -070062 areaAddressTlv.addAddress(areaAddress);
PRASHANTH SHIVANANJAPPA491b8af2016-04-27 19:23:24 +053063 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 Milkeyc108a6b2017-08-23 15:23:50 -070072 areaAddressTlv.addAddress(areaAddress);
PRASHANTH SHIVANANJAPPA491b8af2016-04-27 19:23:24 +053073 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 Milkeyc108a6b2017-08-23 15:23:50 -0700105}