blob: b55718f58e41387819e35831c7eb5a39be99b2c8 [file] [log] [blame]
PRASHANTH SHIVANANJAPPA491b8af2016-04-27 19:23:24 +05301/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
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.jboss.netty.buffer.ChannelBuffer;
19import org.jboss.netty.buffer.ChannelBuffers;
20import org.junit.After;
21import org.junit.Before;
22import org.junit.Test;
23
24import java.util.List;
25
26import static org.hamcrest.MatcherAssert.assertThat;
27import static org.hamcrest.Matchers.is;
28import static org.hamcrest.Matchers.notNullValue;
29
30/**
31 * Unit test class for ProtocolSupportedTlv.
32 */
33public class ProtocolSupportedTlvTest {
34 private final byte[] tlv = {0};
35 private ProtocolSupportedTlv protocolSupportedTlv;
36 private TlvHeader tlvHeader;
37 private List<Byte> supported;
38 private ChannelBuffer channelBuffer;
39 private byte[] result;
40
41 @Before
42 public void setUp() throws Exception {
43 tlvHeader = new TlvHeader();
44 protocolSupportedTlv = new ProtocolSupportedTlv(tlvHeader);
45 }
46
47 @After
48 public void tearDown() throws Exception {
49 tlvHeader = null;
50 protocolSupportedTlv = null;
51 channelBuffer = null;
52 }
53
54 /**
55 * Tests addProtocolSupported() method.
56 */
57 @Test
58 public void testAddProtocolSupported() throws Exception {
59 protocolSupportedTlv.addProtocolSupported((byte) 1);
60 supported = protocolSupportedTlv.protocolSupported();
61 assertThat(supported.size(), is(1));
62 }
63
64 /**
65 * Tests addProtocolSupported() getter method.
66 */
67 @Test
68 public void testProtocolSupported() throws Exception {
69 protocolSupportedTlv.addProtocolSupported((byte) 1);
70 supported = protocolSupportedTlv.protocolSupported();
71 assertThat(supported.size(), is(1));
72 }
73
74 /**
75 * Tests readFrom() method.
76 */
77 @Test
78 public void testReadFrom() throws Exception {
79 channelBuffer = ChannelBuffers.copiedBuffer(tlv);
80 protocolSupportedTlv.readFrom(channelBuffer);
81 supported = protocolSupportedTlv.protocolSupported();
82 assertThat(supported.size(), is(1));
83 }
84
85 /**
86 * Tests asBytes() method.
87 */
88 @Test
89 public void testAsBytes() throws Exception {
90 channelBuffer = ChannelBuffers.copiedBuffer(tlv);
91 protocolSupportedTlv.readFrom(channelBuffer);
92 result = protocolSupportedTlv.asBytes();
93 assertThat(result, is(notNullValue()));
94 }
95
96 /**
97 * Tests toString() method.
98 */
99 @Test
100 public void testToString() throws Exception {
101 assertThat(protocolSupportedTlv.toString(), is(notNullValue()));
102 }
103}