blob: 080c3c50c46930dfb303ae68d71a5ef2d6b1946f [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 MetricsOfReachability.
33 */
34public class MetricsOfReachabilityTest {
35 private final Ip4Address ip4Address = Ip4Address.valueOf("10.10.10.10");
36 private final byte[] metricReachability = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
37 private MetricsOfReachability reachability;
38 private String neighborId = "2929.2929.2929";
39 private Ip4Address result;
40 private boolean result1;
41 private byte result2;
42 private ChannelBuffer channelBuffer;
43 private byte[] result3;
44 private String result4;
45
46 @Before
47 public void setUp() throws Exception {
48 reachability = new MetricsOfReachability();
49 channelBuffer = EasyMock.createMock(ChannelBuffer.class);
50 result1 = false;
51 }
52
53 @After
54 public void tearDown() throws Exception {
55 reachability = null;
56 result1 = false;
57 result3 = null;
58 channelBuffer = null;
59 }
60
61 /**
62 * Tests isDelayIsInternal() getter method.
63 */
64 @Test
65 public void testIsDelayIsInternal() throws Exception {
66 reachability.setDelayIsInternal(true);
67 result1 = reachability.isDelayIsInternal();
68 assertThat(result1, is(true));
69 }
70
71 /**
72 * Tests isDelayIsInternal() setter method.
73 */
74 @Test
75 public void testSetDelayIsInternal() throws Exception {
76 reachability.setDelayIsInternal(true);
77 result1 = reachability.isDelayIsInternal();
78 assertThat(result1, is(true));
79 }
80
81 /**
82 * Tests isExpenseIsInternal() getter method.
83 */
84 @Test
85 public void testIsExpenseIsInternal() throws Exception {
86 reachability.setExpenseIsInternal(true);
87 result1 = reachability.isExpenseIsInternal();
88 assertThat(result1, is(true));
89 }
90
91 /**
92 * Tests isExpenseIsInternal() setter method.
93 */
94 @Test
95 public void testSetExpenseIsInternal() throws Exception {
96 reachability.setExpenseIsInternal(true);
97 result1 = reachability.isExpenseIsInternal();
98 assertThat(result1, is(true));
99 }
100
101 /**
102 * Tests isErrorIsInternal() getter method.
103 */
104 @Test
105 public void testIsErrorIsInternal() throws Exception {
106 reachability.setErrorIsInternal(true);
107 result1 = reachability.isErrorIsInternal();
108 assertThat(result1, is(true));
109 }
110
111 /**
112 * Tests isErrorIsInternal() setter method.
113 */
114 @Test
115 public void testSetErrorIsInternal() throws Exception {
116 reachability.setErrorIsInternal(true);
117 result1 = reachability.isErrorIsInternal();
118 assertThat(result1, is(true));
119 }
120
121 /**
122 * Tests isDefaultIsInternal() getter method.
123 */
124 @Test
125 public void testIsDefaultIsInternal() throws Exception {
126 reachability.setDefaultIsInternal(true);
127 result1 = reachability.isDefaultIsInternal();
128 assertThat(result1, is(true));
129 }
130
131 /**
132 * Tests isDefaultIsInternal() setter method.
133 */
134 @Test
135 public void testSetDefaultIsInternal() throws Exception {
136 reachability.setDefaultIsInternal(true);
137 result1 = reachability.isDefaultIsInternal();
138 assertThat(result1, is(true));
139 }
140
141 @Test
142 public void testIsDelayMetricSupported() throws Exception {
143 reachability.setDelayMetricSupported(true);
144 result1 = reachability.isDelayMetricSupported();
145 assertThat(result1, is(true));
146 }
147
148 /**
149 * Tests isDelayMetricSupported() setter method.
150 */
151 @Test
152 public void testSetDelayMetricSupported() throws Exception {
153 reachability.setDelayMetricSupported(true);
154 result1 = reachability.isDelayMetricSupported();
155 assertThat(result1, is(true));
156 }
157
158 /**
159 * Tests isExpenseMetricSupported() getter method.
160 */
161 @Test
162 public void testIsExpenseMetricSupported() throws Exception {
163 reachability.setExpenseMetricSupported(true);
164 result1 = reachability.isExpenseMetricSupported();
165 assertThat(result1, is(true));
166 }
167
168 /**
169 * Tests isExpenseMetricSupported() setter method.
170 */
171 @Test
172 public void testSetExpenseMetricSupported() throws Exception {
173 reachability.setExpenseMetricSupported(true);
174 result1 = reachability.isExpenseMetricSupported();
175 assertThat(result1, is(true));
176 }
177
178 /**
179 * Tests isErrorMetricSupported() getter method.
180 */
181 @Test
182 public void testIsErrorMetricSupported() throws Exception {
183 reachability.setErrorMetricSupported(true);
184 result1 = reachability.isErrorMetricSupported();
185 assertThat(result1, is(true));
186 }
187
188 /**
189 * Tests isErrorMetricSupported() setter method.
190 */
191 @Test
192 public void testSetErrorMetricSupported() throws Exception {
193 reachability.setErrorMetricSupported(true);
194 result1 = reachability.isErrorMetricSupported();
195 assertThat(result1, is(true));
196 }
197
198 /**
199 * Tests neighborId() getter method.
200 */
201 @Test
202 public void testNeighborId() throws Exception {
203 reachability.setNeighborId(neighborId);
204 result4 = reachability.neighborId();
205 assertThat(result4, is(neighborId));
206 }
207
208 /**
209 * Tests neighborId() setter method.
210 */
211 @Test
212 public void testSetNeighborId() throws Exception {
213 reachability.setNeighborId(neighborId);
214 result4 = reachability.neighborId();
215 assertThat(result4, is(neighborId));
216 }
217
218 /**
219 * Tests defaultMetric() getter method.
220 */
221 @Test
222 public void testDefaultMetric() throws Exception {
223 reachability.setDefaultMetric((byte) 0);
224 result2 = reachability.defaultMetric();
225 assertThat(result2, is((byte) 0));
226 }
227
228 /**
229 * Tests defaultMetric() setter method.
230 */
231 @Test
232 public void testSetDefaultMetric() throws Exception {
233 reachability.setDefaultMetric((byte) 0);
234 result2 = reachability.defaultMetric();
235 assertThat(result2, is((byte) 0));
236 }
237
238 /**
239 * Tests delayMetric() getter method.
240 */
241 @Test
242 public void testDelayMetric() throws Exception {
243 reachability.setDelayMetric((byte) 0);
244 result2 = reachability.delayMetric();
245 assertThat(result2, is((byte) 0));
246 }
247
248 /**
249 * Tests delayMetric() setter method.
250 */
251 @Test
252 public void testSetDelayMetric() throws Exception {
253 reachability.setDelayMetric((byte) 0);
254 result2 = reachability.delayMetric();
255 assertThat(result2, is((byte) 0));
256 }
257
258 /**
259 * Tests expenseMetric() getter method.
260 */
261 @Test
262 public void testExpenseMetric() throws Exception {
263 reachability.setExpenseMetric((byte) 0);
264 result2 = reachability.expenseMetric();
265 assertThat(result2, is((byte) 0));
266 }
267
268 /**
269 * Tests expenseMetric() setter method.
270 */
271 @Test
272 public void testSetExpenseMetric() throws Exception {
273 reachability.setExpenseMetric((byte) 0);
274 result2 = reachability.expenseMetric();
275 assertThat(result2, is((byte) 0));
276 }
277
278 /**
279 * Tests errorMetric() getter method.
280 */
281 @Test
282 public void testErrorMetric() throws Exception {
283 reachability.setErrorMetric((byte) 0);
284 result2 = reachability.errorMetric();
285 assertThat(result2, is((byte) 0));
286 }
287
288 /**
289 * Tests errorMetric() setter method.
290 */
291 @Test
292 public void testSetErrorMetric() throws Exception {
293 reachability.setErrorMetric((byte) 0);
294 result2 = reachability.errorMetric();
295 assertThat(result2, is((byte) 0));
296 }
297
298 /**
299 * Tests readFrom() method.
300 */
301 @Test
302 public void testReadFrom() throws Exception {
303 channelBuffer = ChannelBuffers.copiedBuffer(metricReachability);
304 reachability.readFrom(channelBuffer);
305 assertThat(reachability, is(notNullValue()));
306 }
307
308 /**
309 * Tests asBytes() method.
310 */
311 @Test
312 public void testAsBytes() throws Exception {
313 channelBuffer = ChannelBuffers.copiedBuffer(metricReachability);
314 reachability.readFrom(channelBuffer);
315 result3 = reachability.asBytes();
316 assertThat(result3, is(notNullValue()));
317 }
318
319 /**
320 * Tests toString() method.
321 */
322 @Test
323 public void testToString() throws Exception {
324 assertThat(reachability.toString(), is(notNullValue()));
325 }
326}