blob: 51529753180bf72e7524e3c3d4ee04db082e4bf6 [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.MatcherAssert.assertThat;
26import static org.hamcrest.Matchers.is;
27import static org.hamcrest.Matchers.notNullValue;
28
29/**
30 * Unit test class for AdjacencyStateTlv.
31 */
32public class AdjacencyStateTlvTest {
33
34 private final String neighborSystemId = "2929.2929.2929";
35 private final byte[] tlv = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
36 private AdjacencyStateTlv adjacencyStateTlv;
37 private TlvHeader tlvHeader;
38 private int result;
39 private byte result2;
40 private String result1;
41 private ChannelBuffer channelBuffer;
42 private byte[] result3;
43
44 @Before
45 public void setUp() throws Exception {
46 tlvHeader = new TlvHeader();
47 adjacencyStateTlv = new AdjacencyStateTlv(tlvHeader);
48 channelBuffer = EasyMock.createMock(ChannelBuffer.class);
49 }
50
51 @After
52 public void tearDown() throws Exception {
53 tlvHeader = null;
54 adjacencyStateTlv = null;
55 channelBuffer = null;
56 }
57
58 /**
59 * Tests localCircuitId() getter method.
60 */
61 @Test
62 public void testLocalCircuitId() throws Exception {
63 adjacencyStateTlv.setLocalCircuitId(1);
64 result = adjacencyStateTlv.localCircuitId();
65 assertThat(result, is(1));
66 }
67
68 /**
69 * Tests localCircuitId() setter method.
70 */
71 @Test
72 public void testSetLocalCircuitId() throws Exception {
73 adjacencyStateTlv.setLocalCircuitId(1);
74 result = adjacencyStateTlv.localCircuitId();
75 assertThat(result, is(1));
76 }
77
78 /**
79 * Tests neighborSystemId() getter method.
80 */
81 @Test
82 public void testNeighborSystemId() throws Exception {
83 adjacencyStateTlv.setNeighborSystemId(neighborSystemId);
84 result1 = adjacencyStateTlv.neighborSystemId();
85 assertThat(result1, is(neighborSystemId));
86 }
87
88 /**
89 * Tests neighborSystemId() setter method.
90 */
91 @Test
92 public void testSetNeighborSystemId() throws Exception {
93 adjacencyStateTlv.setNeighborSystemId(neighborSystemId);
94 result1 = adjacencyStateTlv.neighborSystemId();
95 assertThat(result1, is(neighborSystemId));
96 }
97
98 /**
99 * Tests neighborLocalCircuitId() getter method.
100 */
101 @Test
102 public void testNeighborLocalCircuitId() throws Exception {
103 adjacencyStateTlv.setNeighborLocalCircuitId(1);
104 result = adjacencyStateTlv.neighborLocalCircuitId();
105 assertThat(result, is(1));
106 }
107
108 /**
109 * Tests neighborLocalCircuitId() setter method.
110 */
111 @Test
112 public void testSetNeighborLocalCircuitId() throws Exception {
113 adjacencyStateTlv.setNeighborLocalCircuitId(1);
114 result = adjacencyStateTlv.neighborLocalCircuitId();
115 assertThat(result, is(1));
116 }
117
118 /**
119 * Tests adjacencyType() getter method.
120 */
121 @Test
122 public void testAdjacencyType() throws Exception {
123 adjacencyStateTlv.setAdjacencyType((byte) 1);
124 result2 = adjacencyStateTlv.adjacencyType();
125 assertThat(result2, is((byte) 1));
126 }
127
128 /**
129 * Tests adjacencyType() setter method.
130 */
131 @Test
132 public void testSetAdjacencyType() throws Exception {
133 adjacencyStateTlv.setAdjacencyType((byte) 1);
134 result2 = adjacencyStateTlv.adjacencyType();
135 assertThat(result2, is((byte) 1));
136 }
137
138 /**
139 * Tests readFrom() method.
140 */
141 @Test
142 public void testReadFrom() throws Exception {
143 channelBuffer = ChannelBuffers.copiedBuffer(tlv);
144 adjacencyStateTlv.readFrom(channelBuffer);
145 assertThat(adjacencyStateTlv.adjacencyType(), is((byte) 0));
146 }
147
148 /**
149 * Tests asBytes() method.
150 */
151 @Test
152 public void testAsBytes() throws Exception {
153 channelBuffer = ChannelBuffers.copiedBuffer(tlv);
154 adjacencyStateTlv.readFrom(channelBuffer);
155 result3 = adjacencyStateTlv.asBytes();
156 assertThat(result3, is(notNullValue()));
157 }
158
159 /**
160 * Tests toString() method.
161 */
162 @Test
163 public void testToString() throws Exception {
164 assertThat(adjacencyStateTlv.toString(), is(notNullValue()));
165 }
166}