blob: 5acb728a9934742cdd2a70c4d10c4a432a503677 [file] [log] [blame]
PRASHANTH SHIVANANJAPPA491b8af2016-04-27 19:23:24 +05301/*
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 */
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 = {};
36 private InterfaceIpAddress interfaceIpAddress;
37 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 {
44 interfaceIpAddress = new InterfaceIpAddress(new TlvHeader());
45 }
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 /**
64 * Tests addLocalInterfaceIPAddress() method.
65 */
66 @Test
67 public void testAddLocalInterfaceIPAddress() throws Exception {
68 interfaceIpAddress.addLocalInterfaceIPAddress(ip4Address);
69 assertThat(interfaceIpAddress, is(notNullValue()));
70 }
71
72 /**
73 * Tests readFrom() method.
74 */
75 @Test
76 public void testReadFrom() {
77 tlvHeader = new TlvHeader();
78 tlvHeader.setTlvType(3);
79 tlvHeader.setTlvLength(4);
80 interfaceIpAddress = new InterfaceIpAddress(tlvHeader);
81 channelBuffer = ChannelBuffers.copiedBuffer(packet);
82 interfaceIpAddress.readFrom(channelBuffer);
83 assertThat(interfaceIpAddress, is(notNullValue()));
84 }
85
86 /**
87 * Tests readFrom() method.
88 */
89 @Test
90 public void testReadFrom1() throws Exception {
91 tlvHeader = new TlvHeader();
92 tlvHeader.setTlvType(3);
93 tlvHeader.setTlvLength(4);
94 interfaceIpAddress = new InterfaceIpAddress(tlvHeader);
95 channelBuffer = ChannelBuffers.copiedBuffer(packet1);
96 interfaceIpAddress.readFrom(channelBuffer);
97 assertThat(interfaceIpAddress, is(notNullValue()));
98 }
99
100 /**
101 * Tests asBytes() method.
102 */
103 @Test
104 public void testAsBytes() throws Exception {
105 result = interfaceIpAddress.asBytes();
106 assertThat(result, is(notNullValue()));
107 }
108
109 /**
110 * Tests getLinkSubTypeTlvBodyAsByteArray() method.
111 */
112 @Test
113 public void testGetLinkSubTypeTlvBodyAsByteArray() throws Exception {
114 result = interfaceIpAddress.tlvBodyAsBytes();
115 assertThat(result, is(notNullValue()));
116 }
117}