PRASHANTH SHIVANANJAPPA | 491b8af | 2016-04-27 19:23:24 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
PRASHANTH SHIVANANJAPPA | 491b8af | 2016-04-27 19:23:24 +0530 | [diff] [blame] | 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 | package org.onosproject.isis.io.isispacket.tlv.subtlv; |
| 17 | |
| 18 | import org.jboss.netty.buffer.ChannelBuffer; |
| 19 | import org.jboss.netty.buffer.ChannelBuffers; |
| 20 | import org.junit.After; |
| 21 | import org.junit.Before; |
| 22 | import org.junit.Test; |
| 23 | import org.onosproject.isis.io.isispacket.tlv.TlvHeader; |
| 24 | |
| 25 | import static org.hamcrest.MatcherAssert.assertThat; |
| 26 | import static org.hamcrest.Matchers.is; |
| 27 | import static org.hamcrest.Matchers.notNullValue; |
| 28 | |
| 29 | /** |
| 30 | * Unit test class for AdministrativeGroup. |
| 31 | */ |
| 32 | public 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 | } |