blob: d38a7c895280cfb9ba2ee44383a251cf4f6183d1 [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 */
16
17package org.onosproject.isis.io.isispacket.tlv;
18
19import org.easymock.EasyMock;
20import org.jboss.netty.buffer.ChannelBuffer;
21import org.jboss.netty.buffer.ChannelBuffers;
22import org.junit.After;
23import org.junit.Before;
24import org.junit.Test;
25
26import java.util.ArrayList;
27import java.util.List;
28
29import static org.hamcrest.CoreMatchers.is;
30import static org.hamcrest.CoreMatchers.notNullValue;
31import static org.junit.Assert.assertThat;
32
33/**
34 * Unit test class for LspEntriesTlv.
35 */
36public class LspEntriesTlvTest {
37
38 private final byte[] entry = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
39 private LspEntriesTlv lspEntriesTlv;
40 private TlvHeader tlvHeader;
41 private List<LspEntry> lspEntries = new ArrayList();
42 private ChannelBuffer channelBuffer;
43
44 @Before
45 public void setUp() throws Exception {
46 tlvHeader = new TlvHeader();
47 lspEntriesTlv = new LspEntriesTlv(tlvHeader);
48 channelBuffer = EasyMock.createMock(ChannelBuffer.class);
49 }
50
51 @After
52 public void tearDown() throws Exception {
53 tlvHeader = null;
54 lspEntriesTlv = null;
55 lspEntries.clear();
56 }
57
58 /**
59 * Tests lspEntry() getter method.
60 */
61 @Test
62 public void testLspEntry() throws Exception {
63 lspEntriesTlv.addLspEntry(new LspEntry());
64 assertThat(lspEntriesTlv.lspEntry().size(), is(1));
65 }
66
67 /**
68 * Tests lspEntry() add method.
69 */
70 @Test
71 public void testAddLspEntry() throws Exception {
72 lspEntriesTlv.addLspEntry(new LspEntry());
73 assertThat(lspEntriesTlv.lspEntry().size(), is(1));
74 }
75
76 /**
77 * Tests readFrom() method.
78 */
79 @Test
80 public void testReadFrom() throws Exception {
81 channelBuffer = ChannelBuffers.copiedBuffer(entry);
82 lspEntriesTlv.readFrom(channelBuffer);
83 lspEntries = lspEntriesTlv.lspEntry();
84 assertThat(lspEntriesTlv.lspEntry().size(), is(1));
85 }
86
87 /**
88 * Tests asBytes() method.
89 */
90 @Test
91 public void testAsBytes() throws Exception {
92 channelBuffer = ChannelBuffers.copiedBuffer(entry);
93 lspEntriesTlv.readFrom(channelBuffer);
94 lspEntriesTlv.asBytes();
95 }
96
97 /**
98 * Tests toString() method.
99 */
100 @Test
101 public void testToString() throws Exception {
102 assertThat(lspEntriesTlv.toString(), is(notNullValue()));
103 }
104
105}