blob: caafa95fdac22185c7bb30179aeb803fa301d23c [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.subtlv;
17
18import org.jboss.netty.buffer.ChannelBuffer;
19import org.jboss.netty.buffer.ChannelBuffers;
20import org.junit.After;
21import org.junit.Before;
22import org.junit.Test;
23import org.onlab.packet.Ip4Address;
24import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
25
26import static org.hamcrest.MatcherAssert.assertThat;
27import static org.hamcrest.Matchers.is;
28import static org.hamcrest.Matchers.notNullValue;
29
30/**
31 * Unit test class for InterfaceIpAddress.
32 */
33public class InterfaceIpAddressTest {
34 private final byte[] packet = {1, 1, 1, 1};
35 private final byte[] packet1 = {};
sunish vk7bdf4d42016-06-24 12:29:43 +053036 private NeighborIpAddress interfaceIpAddress;
PRASHANTH SHIVANANJAPPA491b8af2016-04-27 19:23:24 +053037 private TlvHeader tlvHeader;
38 private Ip4Address ip4Address = Ip4Address.valueOf("1.1.1.1");
39 private byte[] result;
40 private ChannelBuffer channelBuffer;
41
42 @Before
43 public void setUp() throws Exception {
sunish vk7bdf4d42016-06-24 12:29:43 +053044 interfaceIpAddress = new NeighborIpAddress(new TlvHeader());
PRASHANTH SHIVANANJAPPA491b8af2016-04-27 19:23:24 +053045 }
46
47 @After
48 public void tearDown() throws Exception {
49 interfaceIpAddress = null;
50 tlvHeader = null;
51 result = null;
52 channelBuffer = null;
53 }
54
55 /**
56 * Tests to string method.
57 */
58 @Test
59 public void testToString() throws Exception {
60 assertThat(interfaceIpAddress.toString(), is(notNullValue()));
61 }
62
63 /**
PRASHANTH SHIVANANJAPPA491b8af2016-04-27 19:23:24 +053064 * Tests readFrom() method.
65 */
66 @Test
67 public void testReadFrom() {
68 tlvHeader = new TlvHeader();
69 tlvHeader.setTlvType(3);
70 tlvHeader.setTlvLength(4);
sunish vk7bdf4d42016-06-24 12:29:43 +053071 interfaceIpAddress = new NeighborIpAddress(tlvHeader);
PRASHANTH SHIVANANJAPPA491b8af2016-04-27 19:23:24 +053072 channelBuffer = ChannelBuffers.copiedBuffer(packet);
73 interfaceIpAddress.readFrom(channelBuffer);
74 assertThat(interfaceIpAddress, is(notNullValue()));
75 }
76
77 /**
78 * Tests readFrom() method.
79 */
80 @Test
81 public void testReadFrom1() throws Exception {
82 tlvHeader = new TlvHeader();
83 tlvHeader.setTlvType(3);
84 tlvHeader.setTlvLength(4);
sunish vk7bdf4d42016-06-24 12:29:43 +053085 interfaceIpAddress = new NeighborIpAddress(tlvHeader);
PRASHANTH SHIVANANJAPPA491b8af2016-04-27 19:23:24 +053086 channelBuffer = ChannelBuffers.copiedBuffer(packet1);
87 interfaceIpAddress.readFrom(channelBuffer);
88 assertThat(interfaceIpAddress, is(notNullValue()));
89 }
90
PRASHANTH SHIVANANJAPPA491b8af2016-04-27 19:23:24 +053091
PRASHANTH SHIVANANJAPPA491b8af2016-04-27 19:23:24 +053092}