blob: d83ecef9e89669a4d3a657b5ddb38fa757de7dfa [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.MatcherAssert.assertThat;
26import static org.hamcrest.Matchers.is;
27import static org.hamcrest.Matchers.notNullValue;
28
29/**
30 * Unit test class for HostNameTlv.
31 */
32public class HostNameTlvTest {
33 private final String hostName = "TEST";
34 private final byte[] tlv = hostName.getBytes();
35 private HostNameTlv hostNameTlv;
36 private TlvHeader tlvHeader;
37 private String result;
38 private ChannelBuffer channelBuffer;
39 private byte[] result1;
40
41 @Before
42 public void setUp() throws Exception {
43 tlvHeader = new TlvHeader();
44 tlvHeader.setTlvLength(tlv.length);
45 hostNameTlv = new HostNameTlv(tlvHeader);
46 channelBuffer = EasyMock.createMock(ChannelBuffer.class);
47 }
48
49 @After
50 public void tearDown() throws Exception {
51 tlvHeader = null;
52 hostNameTlv = null;
53 }
54
55 /**
56 * Tests hostName() getter method.
57 */
58 @Test
59 public void testHostName() throws Exception {
60 hostNameTlv.setHostName(hostName);
61 result = hostNameTlv.hostName();
62 assertThat(result, is(hostName));
63 }
64
65 /**
66 * Tests hostName() setter method.
67 */
68 @Test
69 public void testSetHostName() throws Exception {
70 hostNameTlv.setHostName(hostName);
71 result = hostNameTlv.hostName();
72 assertThat(result, is(hostName));
73 }
74
75 /**
76 * Tests readFrom() method.
77 */
78 @Test
79 public void testReadFrom() throws Exception {
80 channelBuffer = ChannelBuffers.copiedBuffer(tlv);
81 hostNameTlv.readFrom(channelBuffer);
82 assertThat(hostNameTlv.hostName(), is(hostName));
83 }
84
85 /**
86 * Tests asBytes() method.
87 */
88 @Test
89 public void testAsBytes() throws Exception {
90 channelBuffer = ChannelBuffers.copiedBuffer(tlv);
91 hostNameTlv.readFrom(channelBuffer);
92 result1 = hostNameTlv.asBytes();
93 assertThat(result1, is(notNullValue()));
94 }
95
96 /**
97 * Tests toString() method.
98 */
99 @Test
100 public void testToString() throws Exception {
101 assertThat(hostNameTlv.toString(), is(notNullValue()));
102 }
103}