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