blob: 718492f5aca73e05846c17b248222f4aa6beb4a5 [file] [log] [blame]
Kiran Ramachandra959353a2016-02-16 22:12:07 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Kiran Ramachandra959353a2016-02-16 22:12:07 +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.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 LinkId.
31 */
32public class LinkIdTest {
33
34 private final byte[] packet = {1, 1, 1, 1};
35 private final byte[] packet1 = {0, 0, 1};
36 private LinkId linkId;
37 private TlvHeader tlvHeader;
38 private ChannelBuffer channelBuffer;
39 private byte[] result;
40
41 @Before
42 public void setUp() throws Exception {
43 linkId = new LinkId(new TlvHeader());
44 }
45
46 @After
47 public void tearDown() throws Exception {
48 linkId = null;
49 channelBuffer = null;
50 tlvHeader = null;
51 }
52
53 /**
54 * Tests to string method.
55 */
56 @Test
57 public void testToString() throws Exception {
58 assertThat(linkId.toString(), is(notNullValue()));
59 }
60
61 /**
62 * Tests linkId() getter method.
63 */
64 @Test
65 public void testGetLinkId() throws Exception {
66 linkId.setLinkId("1.1.1.1");
67 assertThat(linkId, is(notNullValue()));
68 }
69
70 /**
71 * Tests linkId() setter method.
72 */
73 @Test
74 public void testSetLinkId() throws Exception {
75 linkId.setLinkId("1.1.1.1");
76 assertThat(linkId, is(notNullValue()));
77 }
78
79 /**
80 * Tests readFrom() method.
81 */
82 @Test
83 public void testReadFrom() throws Exception {
84 tlvHeader = new TlvHeader();
85 tlvHeader.setTlvType(2);
86 tlvHeader.setTlvLength(4);
87 linkId = new LinkId(tlvHeader);
88 channelBuffer = ChannelBuffers.copiedBuffer(packet);
89 linkId.readFrom(channelBuffer);
90 assertThat(linkId, is(notNullValue()));
91 }
92
93 /**
94 * Tests readFrom() method.
95 */
96 @Test(expected = Exception.class)
97 public void testReadFrom1() throws Exception {
98 tlvHeader = new TlvHeader();
99 tlvHeader.setTlvType(2);
100 tlvHeader.setTlvLength(4);
101 linkId = new LinkId(tlvHeader);
102 channelBuffer = ChannelBuffers.copiedBuffer(packet1);
103 linkId.readFrom(channelBuffer);
104 assertThat(linkId, is(notNullValue()));
105 }
106
107 /**
108 * Tests asBytes() method.
109 */
110 @Test
111 public void testAsBytes() throws Exception {
112 result = linkId.asBytes();
113 assertThat(result, is(notNullValue()));
114 }
115
116 /**
117 * Tests getLinkSubTypeTlvBodyAsByteArray() method.
118 */
119 @Test
120 public void testGetLinkSubTypeTlvBodyAsByteArray() throws Exception {
121 result = linkId.getLinkSubTypeTlvBodyAsByteArray();
122 assertThat(result, is(notNullValue()));
123 }
124}