blob: c1b211732521523355bf32488c66c86d8714db1e [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.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 IP InternalReachabilityTlv.
31 */
32public class IpInternalReachabilityTlvTest {
33 private final byte[] tlv = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
34 private TlvHeader tlvHeader;
35 private IpInternalReachabilityTlv ipInternalReachabilityTlv;
36 private MetricOfInternalReachability metricOfInternalReachability;
37 private byte[] result;
38 private ChannelBuffer channelBuffer;
39
40 @Before
41 public void setUp() throws Exception {
42 tlvHeader = new TlvHeader();
43 ipInternalReachabilityTlv = new IpInternalReachabilityTlv(tlvHeader);
44 metricOfInternalReachability = new MetricOfInternalReachability();
45 channelBuffer = EasyMock.createMock(ChannelBuffer.class);
46 }
47
48 @After
49 public void tearDown() throws Exception {
50 tlvHeader = null;
51 ipInternalReachabilityTlv = null;
52 }
53
54 /**
55 * Tests addInternalReachabilityMetric() method.
56 */
57 @Test
58 public void testAddInternalReachabilityMetric() throws Exception {
59 ipInternalReachabilityTlv.addInternalReachabilityMetric(metricOfInternalReachability);
60 assertThat(ipInternalReachabilityTlv, is(notNullValue()));
61
62 }
63
64 /**
65 * Tests readFrom() method.
66 */
67 @Test
68 public void testReadFrom() throws Exception {
69 channelBuffer = ChannelBuffers.copiedBuffer(tlv);
70 ipInternalReachabilityTlv.readFrom(channelBuffer);
71 assertThat(ipInternalReachabilityTlv, is(notNullValue()));
72 }
73
74 /**
75 * Tests asBytes() method.
76 */
77 @Test
78 public void testAsBytes() throws Exception {
79 channelBuffer = ChannelBuffers.copiedBuffer(tlv);
80 ipInternalReachabilityTlv.readFrom(channelBuffer);
81 result = ipInternalReachabilityTlv.asBytes();
82 assertThat(result, is(notNullValue()));
83 }
84
85 /**
86 * Tests toString() method.
87 */
88 @Test
89 public void testToString() throws Exception {
90 assertThat(ipInternalReachabilityTlv.toString(), is(notNullValue()));
91 }
92}