blob: cc21712e45171ed7fd8022f5d22aac702adec129 [file] [log] [blame]
Kiran Ramachandra959353a2016-02-16 22:12:07 +05301/*
2 * Copyright 2016 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.ospf.protocol.lsa.linksubtype;
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.ospf.protocol.lsa.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 OspfRouterId.
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 /**
72 * Tests readFrom() method.
73 */
74 @Test
75 public void testReadFrom() throws Exception {
76 header = new TlvHeader();
77 header.setTlvLength(4);
78 header.setTlvType(8);
79 channelBuffer = ChannelBuffers.copiedBuffer(packet);
80 unreservedBandwidth = new UnreservedBandwidth(header);
81 unreservedBandwidth.readFrom(channelBuffer);
82 unreservedBandwidth.readFrom(channelBuffer);
83 assertThat(unreservedBandwidth, is(notNullValue()));
84 }
85
86 /**
87 * Tests asBytes() method.
88 */
89 @Test
90 public void testAsBytes() throws Exception {
91 result = unreservedBandwidth.asBytes();
92 assertThat(result, is(notNullValue()));
93 }
94
95
96 /**
97 * Tests getLinkSubTypeTlvBodyAsByteArray() method.
98 */
99 @Test
sunish vkaa48da82016-03-02 23:17:06 +0530100 public void testGetLinkSubTypeTlvBodyAsByteArray() throws Exception {
Kiran Ramachandra959353a2016-02-16 22:12:07 +0530101 result = unreservedBandwidth.getLinkSubTypeTlvBodyAsByteArray();
102 assertThat(result, is(notNullValue()));
103 }
104}