blob: ba24d82bbed45e92d14864d68c41358021f59a2e [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;
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 LspEntry.
31 */
32public class LspEntryTest {
33
34 private final String lspId = "10.10.10.10";
35 private final byte[] entry = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
36 private LspEntry lspEntry;
37 private int result;
38 private String result2;
39 private ChannelBuffer channelBuffer;
40 private byte[] result3;
41
42 @Before
43 public void setUp() throws Exception {
44 lspEntry = new LspEntry();
45 channelBuffer = EasyMock.createMock(ChannelBuffer.class);
46 }
47
48 @After
49 public void tearDown() throws Exception {
50 lspEntry = null;
51 channelBuffer = null;
52 }
53
54 /**
55 * Tests lspSequenceNumber() getter method.
56 */
57 @Test
58 public void testLspSequenceNumber() throws Exception {
59 lspEntry.setLspSequenceNumber(0);
60 result = lspEntry.lspSequenceNumber();
61 assertThat(result, is(0));
62 }
63
64 /**
65 * Tests lspSequenceNumber() setter method.
66 */
67 @Test
68 public void testSetLspSequenceNumber() throws Exception {
69 lspEntry.setLspSequenceNumber(0);
70 result = lspEntry.lspSequenceNumber();
71 assertThat(result, is(0));
72 }
73
74 /**
75 * Tests lspChecksum() getter method.
76 */
77 @Test
78 public void testLspChecksum() throws Exception {
79 lspEntry.setLspChecksum(0);
80 result = lspEntry.lspChecksum();
81 assertThat(result, is(0));
82 }
83
84 /**
85 * Tests lspChecksum() setter method.
86 */
87 @Test
88 public void testSetLspChecksum() throws Exception {
89 lspEntry.setLspChecksum(0);
90 result = lspEntry.lspChecksum();
91 assertThat(result, is(0));
92 }
93
94 /**
95 * Tests remainingTime() getter method.
96 */
97 @Test
98 public void testRemainingTime() throws Exception {
99 lspEntry.setRemainingTime(0);
100 result = lspEntry.remainingTime();
101 assertThat(result, is(0));
102 }
103
104 /**
105 * Tests remainingTime() setter method.
106 */
107 @Test
108 public void testSetRemainingTime() throws Exception {
109 lspEntry.setRemainingTime(0);
110 result = lspEntry.remainingTime();
111 assertThat(result, is(0));
112 }
113
114 /**
115 * Tests lspId() getter method.
116 */
117 @Test
118 public void testLspId() throws Exception {
119 lspEntry.setLspId(lspId);
120 result2 = lspEntry.lspId();
121 assertThat(result2, is("10.10.10.10"));
122 }
123
124 /**
125 * Tests lspId() getter method.
126 */
127 @Test
128 public void testSetLspId() throws Exception {
129 lspEntry.setLspId(lspId);
130 result2 = lspEntry.lspId();
131 assertThat(result2, is("10.10.10.10"));
132 }
133
134 /**
135 * Tests readFrom() method.
136 */
137 @Test
138 public void testReadFrom() throws Exception {
139 channelBuffer = ChannelBuffers.copiedBuffer(entry);
140 lspEntry.readFrom(channelBuffer);
141 assertThat(lspEntry, is(notNullValue()));
142 }
143
144 /**
145 * Tests lspEntryAsBytes() method.
146 */
147 @Test
148 public void testLspEntryAsBytes() throws Exception {
149 channelBuffer = ChannelBuffers.copiedBuffer(entry);
150 lspEntry.readFrom(channelBuffer);
151 result3 = lspEntry.lspEntryAsBytes();
152 assertThat(lspEntry, is(notNullValue()));
153 }
154
155 /**
156 * Tests toString() method.
157 */
158 @Test
159 public void testToString() throws Exception {
160 assertThat(lspEntry.toString(), is(notNullValue()));
161 }
162}