blob: da1664b2dfbd668d9ccc386c3bea8531cbbb594e [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.onosproject.isis.io.isispacket.tlv.subtlv.AdministrativeGroup;
25import org.onosproject.isis.io.isispacket.tlv.subtlv.TrafficEngineeringSubTlv;
26
27import static org.hamcrest.CoreMatchers.is;
28import static org.hamcrest.CoreMatchers.notNullValue;
29import static org.junit.Assert.assertThat;
30
31/**
32 * Unit test class for IP ExtendedReachabilityTlv.
33 */
34public class IpExtendedReachabilityTlvTest {
35 private final String prefix = "00";
36 private final byte[] tlv = {0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0};
37 private final byte[] tlv1 = {0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0};
38 private final byte[] tlv2 = {0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0};
39 private final byte[] tlv3 = {0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0};
40 private TlvHeader tlvHeader;
41 private IpExtendedReachabilityTlv ipExtendedReachabilityTlv;
42 private String result;
43 private boolean result1;
44 private int result2;
45 private TrafficEngineeringSubTlv trafficEngineeringSubTlv;
46 private byte result4;
47 private ChannelBuffer channelBuffer;
48 private byte[] result3;
49
50 @Before
51 public void setUp() throws Exception {
52 tlvHeader = new TlvHeader();
53 ipExtendedReachabilityTlv = new IpExtendedReachabilityTlv(tlvHeader);
54 trafficEngineeringSubTlv = new AdministrativeGroup(tlvHeader);
55 channelBuffer = EasyMock.createMock(ChannelBuffer.class);
56 }
57
58 @After
59 public void tearDown() throws Exception {
60 tlvHeader = null;
61 ipExtendedReachabilityTlv = null;
62
63 }
64
65 /**
66 * Tests prefix() getter method.
67 */
68 @Test
69 public void testPrefix() throws Exception {
70 ipExtendedReachabilityTlv.setPrefix(prefix);
71 result = ipExtendedReachabilityTlv.prefix();
72 assertThat(result, is("00"));
73 }
74
75 /**
76 * Tests prefix() setter method.
77 */
78 @Test
79 public void testSetPrefix() throws Exception {
80 ipExtendedReachabilityTlv.setPrefix(prefix);
81 result = ipExtendedReachabilityTlv.prefix();
82 assertThat(result, is("00"));
83 }
84
85 /**
86 * Tests isDown() getter method.
87 */
88
89 @Test
90 public void testIsDown() throws Exception {
91 ipExtendedReachabilityTlv.setDown(true);
92 result1 = ipExtendedReachabilityTlv.isDown();
93 assertThat(result1, is(true));
94 }
95
96 /**
97 * Tests isDown() setter method.
98 */
99 @Test
100 public void testSetDown() throws Exception {
101 ipExtendedReachabilityTlv.setDown(true);
102 result1 = ipExtendedReachabilityTlv.isDown();
103 assertThat(result1, is(true));
104 }
105
106 /**
107 * Tests isSubTlvPresence() getter method.
108 */
109 @Test
110 public void testIsSubTlvPresence() throws Exception {
111 ipExtendedReachabilityTlv.setSubTlvPresence(true);
112 result1 = ipExtendedReachabilityTlv.isSubTlvPresence();
113 assertThat(result1, is(true));
114 }
115
116 /**
117 * Tests isSubTlvPresence() setter method.
118 */
119 @Test
120 public void testSetSubTlvPresence() throws Exception {
121 ipExtendedReachabilityTlv.setSubTlvPresence(true);
122 result1 = ipExtendedReachabilityTlv.isSubTlvPresence();
123 assertThat(result1, is(true));
124 }
125
126 /**
127 * Tests prefixLength() getter method.
128 */
129 @Test
130 public void testPrefixLength() throws Exception {
131 ipExtendedReachabilityTlv.setPrefixLength(10);
132 result2 = ipExtendedReachabilityTlv.prefixLength();
133 assertThat(result2, is(10));
134
135 }
136
137 /**
138 * Tests prefixLength() setter method.
139 */
140 @Test
141 public void testSetPrefixLength() throws Exception {
142 ipExtendedReachabilityTlv.setPrefixLength(10);
143 result2 = ipExtendedReachabilityTlv.prefixLength();
144 assertThat(result2, is(10));
145 }
146
147 /**
148 * Tests addNeighbor() method.
149 */
150 @Test
151 public void testAddSubTlv() throws Exception {
152 ipExtendedReachabilityTlv.addSubTlv(trafficEngineeringSubTlv);
153 assertThat(ipExtendedReachabilityTlv, is(notNullValue()));
154
155 }
156
157 /**
158 * Tests subTlvLength() getter method.
159 */
160 @Test
161 public void testSubTlvLength() throws Exception {
162 ipExtendedReachabilityTlv.setSubTlvLength((byte) 10);
163 result4 = ipExtendedReachabilityTlv.subTlvLength();
164 assertThat(result4, is((byte) 10));
165 }
166
167 /**
168 * Tests subTlvLength() setter method.
169 */
170 @Test
171 public void testSetSubTlvLength() throws Exception {
172 ipExtendedReachabilityTlv.setSubTlvLength((byte) 10);
173 result4 = ipExtendedReachabilityTlv.subTlvLength();
174 assertThat(result4, is((byte) 10));
175 }
176
177 /**
178 * Tests metric() getter method.
179 */
180 @Test
181 public void testMetric() throws Exception {
182 ipExtendedReachabilityTlv.setMetric(10);
183 result2 = ipExtendedReachabilityTlv.metric();
184 assertThat(result2, is(10));
185 }
186
187 /**
188 * Tests metric() setter method.
189 */
190 @Test
191 public void testSetMetric() throws Exception {
192 ipExtendedReachabilityTlv.setMetric(10);
193 result2 = ipExtendedReachabilityTlv.metric();
194 assertThat(result2, is(10));
195 }
196
197 /**
198 * Tests readFrom() method.
199 */
200 @Test
201 public void testReadFrom() throws Exception {
202 channelBuffer = ChannelBuffers.copiedBuffer(tlv);
203 ipExtendedReachabilityTlv.readFrom(channelBuffer);
204 assertThat(ipExtendedReachabilityTlv.metric(), is(0));
205 channelBuffer = ChannelBuffers.copiedBuffer(tlv1);
206 ipExtendedReachabilityTlv.readFrom(channelBuffer);
207 assertThat(ipExtendedReachabilityTlv.metric(), is(0));
208 channelBuffer = ChannelBuffers.copiedBuffer(tlv2);
209 ipExtendedReachabilityTlv.readFrom(channelBuffer);
210 assertThat(ipExtendedReachabilityTlv.metric(), is(0));
211 channelBuffer = ChannelBuffers.copiedBuffer(tlv3);
212 ipExtendedReachabilityTlv.readFrom(channelBuffer);
213 assertThat(ipExtendedReachabilityTlv.metric(), is(0));
214 }
215
216 /**
217 * Tests asBytes() method.
218 */
219 @Test
220 public void testAsBytes() throws Exception {
221 channelBuffer = ChannelBuffers.copiedBuffer(tlv);
222 ipExtendedReachabilityTlv.readFrom(channelBuffer);
223 ipExtendedReachabilityTlv.setPrefix(prefix);
224 result3 = ipExtendedReachabilityTlv.asBytes();
225 assertThat(result3, is(notNullValue()));
226 }
227
228 /**
229 * Tests toString() method.
230 */
231 @Test
232 public void testToString() throws Exception {
233 assertThat(ipExtendedReachabilityTlv.toString(), is(notNullValue()));
234 }
235
236}