blob: 3ece0e013adef539cb61d31d1013b8137b2bc418 [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 */
16
17package org.onosproject.isis.io.isispacket.tlv;
18
19import org.easymock.EasyMock;
20import org.jboss.netty.buffer.ChannelBuffer;
21import org.jboss.netty.buffer.ChannelBuffers;
22import org.junit.After;
23import org.junit.Before;
24import org.junit.Test;
25import org.onlab.packet.Ip4Address;
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 MetricOfInternalReachability.
33 */
34public class MetricOfInternalReachabilityTest {
35
36 private final Ip4Address ip4Address = Ip4Address.valueOf("10.10.10.10");
37 private final byte[] internalReachability = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
38 private MetricOfInternalReachability reachability;
39 private Ip4Address result;
40 private boolean result1;
41 private byte result2;
42 private ChannelBuffer channelBuffer;
43 private byte[] result3;
44
45 @Before
46 public void setUp() throws Exception {
47 reachability = new MetricOfInternalReachability();
48 channelBuffer = EasyMock.createMock(ChannelBuffer.class);
49 }
50
51 @After
52 public void tearDown() throws Exception {
53 reachability = null;
54 result = null;
55 result1 = false;
56 }
57
58 /**
59 * Tests getIpAddress() getter method.
60 */
61 @Test
62 public void testGetIpAddress() throws Exception {
63 reachability.setIpAddress(ip4Address);
64 result = reachability.getIpAddress();
65 assertThat(result, is(ip4Address));
66 }
67
68 /**
69 * Tests setIpAddress() setter method.
70 */
71 @Test
72 public void testSetIpAddress() throws Exception {
73 reachability.setIpAddress(ip4Address);
74 result = reachability.getIpAddress();
75 assertThat(result, is(ip4Address));
76 }
77
78 /**
Ray Milkeyc108a6b2017-08-23 15:23:50 -070079 * Tests getSubnetAddress() getter method.
PRASHANTH SHIVANANJAPPA491b8af2016-04-27 19:23:24 +053080 */
81 @Test
82 public void testGetSubnetAddres() throws Exception {
Ray Milkeyc108a6b2017-08-23 15:23:50 -070083 reachability.setSubnetAddress(ip4Address);
84 result = reachability.getSubnetAddress();
PRASHANTH SHIVANANJAPPA491b8af2016-04-27 19:23:24 +053085 assertThat(result, is(ip4Address));
86 }
87
88 /**
Ray Milkeyc108a6b2017-08-23 15:23:50 -070089 * Tests setSubnetAddress() setter method.
PRASHANTH SHIVANANJAPPA491b8af2016-04-27 19:23:24 +053090 */
91 @Test
92 public void testSetSubnetAddres() throws Exception {
Ray Milkeyc108a6b2017-08-23 15:23:50 -070093 reachability.setSubnetAddress(ip4Address);
94 result = reachability.getSubnetAddress();
PRASHANTH SHIVANANJAPPA491b8af2016-04-27 19:23:24 +053095 assertThat(result, is(ip4Address));
96 }
97
98 /**
99 * Tests isErrorIsInternal() getter method.
100 */
101 @Test
102 public void testIsErrorIsInternal() throws Exception {
103 reachability.setErrorIsInternal(true);
104 result1 = reachability.isErrorIsInternal();
105 assertThat(result1, is(true));
106 }
107
108 /**
109 * Tests isErrorIsInternal() setter method.
110 */
111 @Test
112 public void testSetErrorIsInternal() throws Exception {
113 reachability.setErrorIsInternal(true);
114 result1 = reachability.isErrorIsInternal();
115 assertThat(result1, is(true));
116 }
117
118 /**
119 * Tests isExpenseIsInternal() getter method.
120 */
121 @Test
122 public void testIsExpenseIsInternal() throws Exception {
123 reachability.setExpenseIsInternal(true);
124 result1 = reachability.isExpenseIsInternal();
125 assertThat(result1, is(true));
126 }
127
128 /**
129 * Tests isExpenseIsInternal() setter method.
130 */
131 @Test
132 public void testSetExpenseIsInternal() throws Exception {
133 reachability.setExpenseIsInternal(true);
134 result1 = reachability.isExpenseIsInternal();
135 assertThat(result1, is(true));
136 }
137
138 /**
139 * Tests isDelayIsInternal() getter method.
140 */
141 @Test
142 public void testIsDelayIsInternal() throws Exception {
143 reachability.setDelayIsInternal(true);
144 result1 = reachability.isDelayIsInternal();
145 assertThat(result1, is(true));
146 }
147
148 /**
149 * Tests isDelayIsInternal() setter method.
150 */
151 @Test
152 public void testSetDelayIsInternal() throws Exception {
153 reachability.setDelayIsInternal(true);
154 result1 = reachability.isDelayIsInternal();
155 assertThat(result1, is(true));
156 }
157
158 /**
159 * Tests isDefaultDistributionDown() getter method.
160 */
161 @Test
162 public void testIsDefaultDistributionDown() throws Exception {
163 reachability.setDefaultDistributionDown(true);
164 result1 = reachability.isDefaultDistributionDown();
165 assertThat(result1, is(true));
166 }
167
168 /**
169 * Tests isDefaultDistributionDown() setter method.
170 */
171 @Test
172 public void testSetDefaultDistributionDown() throws Exception {
173 reachability.setDefaultDistributionDown(true);
174 result1 = reachability.isDefaultDistributionDown();
175 assertThat(result1, is(true));
176 }
177
178 /**
179 * Tests isDefaultIsInternal() getter method.
180 */
181 @Test
182 public void testIsDefaultIsInternal() throws Exception {
183 reachability.setDefaultIsInternal(true);
184 result1 = reachability.isDefaultIsInternal();
185 assertThat(result1, is(true));
186 }
187
188 /**
189 * Tests isDefaultIsInternal() setter method.
190 */
191 @Test
192 public void testSetDefaultIsInternal() throws Exception {
193 reachability.setDefaultIsInternal(true);
194 result1 = reachability.isDefaultIsInternal();
195 assertThat(result1, is(true));
196 }
197
198 /**
199 * Tests isErrorMetricSupported() getter method.
200 */
201 @Test
202 public void testIsErrorMetricSupported() throws Exception {
203 reachability.setErrorMetricSupported(true);
204 result1 = reachability.isErrorMetricSupported();
205 assertThat(result1, is(true));
206 }
207
208 /**
209 * Tests isErrorMetricSupported() setter method.
210 */
211 @Test
212 public void testSetErrorMetricSupported() throws Exception {
213 reachability.setErrorMetricSupported(true);
214 result1 = reachability.isErrorMetricSupported();
215 assertThat(result1, is(true));
216 }
217
218 /**
219 * Tests isExpenseMetricSupported() setter method.
220 */
221 @Test
222 public void testIsExpenseMetricSupported() throws Exception {
223 reachability.setExpenseMetricSupported(true);
224 result1 = reachability.isExpenseMetricSupported();
225 assertThat(result1, is(true));
226 }
227
228 /**
229 * Tests isExpenseMetricSupported() setter method.
230 */
231 @Test
232 public void testSetExpenseMetricSupported() throws Exception {
233 reachability.setExpenseMetricSupported(true);
234 result1 = reachability.isExpenseMetricSupported();
235 assertThat(result1, is(true));
236 }
237
238 /**
239 * Tests isDelayMetricSupported() getter method.
240 */
241 @Test
242 public void testIsDelayMetricSupported() throws Exception {
243 reachability.setDelayMetricSupported(true);
244 result1 = reachability.isDelayMetricSupported();
245 assertThat(result1, is(true));
246 }
247
248 /**
249 * Tests isDelayMetricSupported() setter method.
250 */
251 @Test
252 public void testSetDelayMetricSupported() throws Exception {
253 reachability.setDelayMetricSupported(true);
254 result1 = reachability.isDelayMetricSupported();
255 assertThat(result1, is(true));
256 }
257
258 /**
259 * Tests errorMetric() getter method.
260 */
261 @Test
262 public void testErrorMetric() throws Exception {
263 reachability.setErrorMetric((byte) 0);
264 result2 = reachability.errorMetric();
265 assertThat(result2, is((byte) 0));
266 }
267
268 /**
269 * Tests errorMetric() setter method.
270 */
271 @Test
272 public void testSetErrorMetric() throws Exception {
273 reachability.setErrorMetric((byte) 0);
274 result2 = reachability.errorMetric();
275 assertThat(result2, is((byte) 0));
276 }
277
278 /**
279 * Tests delayMetric() getter method.
280 */
281 @Test
282 public void testDelayMetric() throws Exception {
283 reachability.setDelayMetric((byte) 0);
284 result2 = reachability.delayMetric();
285 assertThat(result2, is((byte) 0));
286 }
287
288 /**
289 * Tests delayMetric() setter method.
290 */
291 @Test
292 public void testSetDelayMetric() throws Exception {
293 reachability.setDelayMetric((byte) 0);
294 result2 = reachability.delayMetric();
295 assertThat(result2, is((byte) 0));
296 }
297
298 /**
299 * Tests defaultMetric() getter method.
300 */
301 @Test
302 public void testDefaultMetric() throws Exception {
303 reachability.setDefaultMetric((byte) 0);
304 result2 = reachability.defaultMetric();
305 assertThat(result2, is((byte) 0));
306 }
307
308 /**
309 * Tests defaultMetric() setter method.
310 */
311 @Test
312 public void testSetDefaultMetric() throws Exception {
313 reachability.setDefaultMetric((byte) 0);
314 result2 = reachability.defaultMetric();
315 assertThat(result2, is((byte) 0));
316 }
317
318 /**
319 * Tests readFrom() method.
320 */
321 @Test
322 public void testReadFrom() throws Exception {
323 channelBuffer = ChannelBuffers.copiedBuffer(internalReachability);
324 reachability.readFrom(channelBuffer);
325 assertThat(reachability, is(notNullValue()));
326 }
327
328 /**
329 * Tests asBytes() method.
330 */
331 @Test
332 public void testAsBytes() throws Exception {
333 channelBuffer = ChannelBuffers.copiedBuffer(internalReachability);
334 reachability.readFrom(channelBuffer);
335 result3 = reachability.asBytes();
336 assertThat(result3, is(notNullValue()));
337 }
338
339 /**
340 * Tests toString() method.
341 */
342 @Test
343 public void testToString() throws Exception {
344 assertThat(reachability.toString(), is(notNullValue()));
345 }
Ray Milkeyc108a6b2017-08-23 15:23:50 -0700346}