blob: d27192639ea792871616e1e3c66af1e09a6d4c49 [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;
24
25import static org.hamcrest.CoreMatchers.is;
26import static org.hamcrest.CoreMatchers.notNullValue;
27import static org.junit.Assert.assertThat;
28
29/**
30 * Unit test class for IS ReachabilityTlv.
31 */
32public class IsReachabilityTlvTest {
33 private final byte[] tlv = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
34 private TlvHeader tlvHeader;
35 private IsReachabilityTlv isReachabilityTlv;
36 private MetricsOfReachability metricsOfReachability;
37 private int resultInt;
38 private ChannelBuffer channelBuffer;
39 private byte[] result;
40
41 @Before
42 public void setUp() throws Exception {
43 tlvHeader = new TlvHeader();
44 isReachabilityTlv = new IsReachabilityTlv(tlvHeader);
45 metricsOfReachability = new MetricsOfReachability();
46 channelBuffer = EasyMock.createMock(ChannelBuffer.class);
47 }
48
49 @After
50 public void tearDown() throws Exception {
51 tlvHeader = null;
52 isReachabilityTlv = null;
53 }
54
55 /**
56 * Tests reserved() getter method.
57 */
58 @Test
59 public void testReserved() throws Exception {
60 isReachabilityTlv.setReserved(10);
61 resultInt = isReachabilityTlv.reserved();
62 assertThat(resultInt, is(10));
63 }
64
65 /**
66 * Tests reserved() setter method.
67 */
68 @Test
69 public void testSetReserved() throws Exception {
70 isReachabilityTlv.setReserved(10);
71 resultInt = isReachabilityTlv.reserved();
72 assertThat(resultInt, is(10));
73 }
74
75 /**
76 * Tests addMeticsOfReachability() getter method.
77 */
78 @Test
79 public void testAddMeticsOfReachability() throws Exception {
80 isReachabilityTlv.addMeticsOfReachability(metricsOfReachability);
81 assertThat(isReachabilityTlv, is(notNullValue()));
82 }
83
84 /**
85 * Tests readFrom() method.
86 */
87 @Test
88 public void testReadFrom() throws Exception {
89 channelBuffer = ChannelBuffers.copiedBuffer(tlv);
90 isReachabilityTlv.readFrom(channelBuffer);
91 assertThat(isReachabilityTlv, is(notNullValue()));
92 }
93
94 /**
95 * Tests asBytes() method.
96 */
97 @Test
98 public void testAsBytes() throws Exception {
99 channelBuffer = ChannelBuffers.copiedBuffer(tlv);
100 isReachabilityTlv.readFrom(channelBuffer);
101 result = isReachabilityTlv.asBytes();
102 assertThat(result, is(notNullValue()));
103 }
104
105 /**
106 * Tests toString() method.
107 */
108 @Test
109 public void testToString() throws Exception {
110 assertThat(isReachabilityTlv.toString(), is(notNullValue()));
111 }
112}