blob: 8f2b31bce25c26f5e7d304264ef41fb1474e37b2 [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 UnknownLinkSubType.
31 */
32public class UnknownLinkSubTypeTest {
33 private final byte[] packet = {0, 114, 0, 4, 0, 0, 0, 1};
34 private UnknownLinkSubType unknownLinkSubType;
35 private TlvHeader header;
36 private ChannelBuffer channelBuffer;
37 private byte[] result;
38
39 @Before
40 public void setUp() throws Exception {
41 unknownLinkSubType = new UnknownLinkSubType(new TlvHeader());
42 }
43
44 @After
45 public void tearDown() throws Exception {
46 unknownLinkSubType = null;
47 header = null;
48 }
49
50 /**
51 * Tests value() getter method.
52 */
53 @Test
54 public void testValue() throws Exception {
55 unknownLinkSubType.setValue(packet);
56 assertThat(unknownLinkSubType.value(), is(notNullValue()));
57 }
58
59 /**
60 * Tests value() setter method.
61 */
62 @Test
63 public void testSetValue() throws Exception {
64 unknownLinkSubType.setValue(packet);
65 assertThat(unknownLinkSubType.value(), is(notNullValue()));
66 }
67
68 /**
69 * Tests readFrom() method.
70 */
71 @Test
72 public void testReadFrom() throws Exception {
73 header = new TlvHeader();
74 header.setTlvLength(8);
75 header.setTlvType(114);
76 unknownLinkSubType = new UnknownLinkSubType(header);
77 channelBuffer = ChannelBuffers.copiedBuffer(packet);
78 unknownLinkSubType.readFrom(channelBuffer);
79 assertThat(unknownLinkSubType, is(notNullValue()));
80 }
81
82 /**
83 * Tests asBytes() method.
84 */
85 @Test(expected = Exception.class)
86 public void testAsBytes() throws Exception {
87 result = unknownLinkSubType.asBytes();
88 assertThat(result, is(notNullValue()));
89 }
90
91
92 /**
93 * Tests getLinkSubTypeTlvBodyAsByteArray() method.
94 */
95 @Test
96 public void testGetLinkSubTypeTlvBodyAsByteArray() throws Exception {
97 channelBuffer = ChannelBuffers.copiedBuffer(packet);
98 unknownLinkSubType.readFrom(channelBuffer);
99 result = unknownLinkSubType.getLinkSubTypeTlvBodyAsByteArray();
100 assertThat(result, is(notNullValue()));
101 }
102
103 /**
104 * Tests to string method.
105 */
106 @Test
107 public void testToString() throws Exception {
108 assertThat(unknownLinkSubType.toString(), is(notNullValue()));
109 }
110}