blob: 1dd0fe8dbee559193479b3b7c8e812626802d3d1 [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;
24import org.onlab.packet.Ip4Address;
25
26import java.util.List;
27
28import static org.hamcrest.CoreMatchers.is;
29import static org.hamcrest.CoreMatchers.notNullValue;
30import static org.junit.Assert.assertThat;
31
32/**
33 * Unit test class for IP InterfaceAddressTlv.
34 */
35public class IpInterfaceAddressTlvTest {
36 private final Ip4Address ip4Address = Ip4Address.valueOf("10.10.10.10");
37 private final byte[] tlv = {0, 0, 0, 0};
38 private TlvHeader tlvHeader;
39 private IpInterfaceAddressTlv ipInterfaceAddressTlv;
40 private List<Ip4Address> resultList;
41 private byte[] result;
42 private ChannelBuffer channelBuffer;
43
44 @Before
45 public void setUp() throws Exception {
46 tlvHeader = new TlvHeader();
47 ipInterfaceAddressTlv = new IpInterfaceAddressTlv(tlvHeader);
48 channelBuffer = EasyMock.createMock(ChannelBuffer.class);
49 }
50
51 @After
52 public void tearDown() throws Exception {
53 tlvHeader = null;
54 ipInterfaceAddressTlv = null;
55 }
56
57 /**
58 * Tests addInterfaceAddress() method.
59 */
60 @Test
61 public void testAddInterfaceAddres() throws Exception {
62 ipInterfaceAddressTlv.addInterfaceAddres(ip4Address);
63 resultList = ipInterfaceAddressTlv.interfaceAddress();
64 assertThat(resultList.size(), is(1));
65
66 }
67
68 /**
69 * Tests interfaceAddress() getter method.
70 */
71 @Test
72 public void testInterfaceAddress() throws Exception {
73 ipInterfaceAddressTlv.addInterfaceAddres(ip4Address);
74 resultList = ipInterfaceAddressTlv.interfaceAddress();
75 assertThat(resultList.size(), is(1));
76 }
77
78 /**
79 * Tests readFrom() method.
80 */
81 @Test
82 public void testReadFrom() throws Exception {
83 channelBuffer = ChannelBuffers.copiedBuffer(tlv);
84 ipInterfaceAddressTlv.readFrom(channelBuffer);
85 assertThat(ipInterfaceAddressTlv.interfaceAddress().size(), is(1));
86 }
87
88 /**
89 * Tests asBytes() method.
90 */
91 @Test
92 public void testAsBytes() throws Exception {
93 channelBuffer = ChannelBuffers.copiedBuffer(tlv);
94 ipInterfaceAddressTlv.readFrom(channelBuffer);
95 result = ipInterfaceAddressTlv.asBytes();
96 assertThat(result, is(notNullValue()));
97 }
98
99 /**
100 * Tests toString() method.
101 */
102 @Test
103 public void testToString() throws Exception {
104 assertThat(ipInterfaceAddressTlv.toString(), is(notNullValue()));
105 }
106}