blob: 268e09fbfbd6bd640ccef044e617371fa6237919 [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.subtlv;
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;
23import org.onosproject.isis.io.isispacket.tlv.TlvHeader;
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 UnreservedBandwidth.
31 */
32public class UnreservedBandwidthTest {
33
34 private final byte[] packet = {0, 0, 0, 1};
35 private UnreservedBandwidth unreservedBandwidth;
36 private TlvHeader header;
37 private byte[] result;
38 private ChannelBuffer channelBuffer;
39
40 @Before
41 public void setUp() throws Exception {
42 unreservedBandwidth = new UnreservedBandwidth(new TlvHeader());
43 }
44
45 @After
46 public void tearDown() throws Exception {
47 unreservedBandwidth = null;
48 header = null;
49 result = null;
50 channelBuffer = null;
51 }
52
53 /**
54 * Tests to string method.
55 */
56 @Test
57 public void testToString() throws Exception {
58 assertThat(unreservedBandwidth.toString(), is(notNullValue()));
59 }
60
61 /**
62 * Tests addUnReservedBandwidth() method.
63 */
64 @Test
65 public void testAddUnReservedBandwidth() throws Exception {
66 unreservedBandwidth.addUnReservedBandwidth(123456.78f);
67 assertThat(unreservedBandwidth, is(notNullValue()));
68 }
69
70 /**
71 * Tests readFrom() method.
72 */
73 @Test
74 public void testReadFrom() throws Exception {
75 header = new TlvHeader();
76 header.setTlvLength(4);
77 header.setTlvType(8);
78 channelBuffer = ChannelBuffers.copiedBuffer(packet);
79 unreservedBandwidth = new UnreservedBandwidth(header);
80 unreservedBandwidth.readFrom(channelBuffer);
81 unreservedBandwidth.readFrom(channelBuffer);
82 assertThat(unreservedBandwidth, is(notNullValue()));
83 }
84
85 /**
86 * Tests asBytes() method.
87 */
88 @Test
89 public void testAsBytes() throws Exception {
90 result = unreservedBandwidth.asBytes();
91 assertThat(result, is(notNullValue()));
92 }
93
94 /**
95 * Tests getLinkSubTypeTlvBodyAsByteArray() method.
96 */
97 @Test
98 public void testGetLinkSubTypeTlvBodyAsByteArray() throws Exception {
99 result = unreservedBandwidth.asBytes();
100 assertThat(result, is(notNullValue()));
101 }
102}