Kiran Ramachandra | 959353a | 2016-02-16 22:12:07 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | package org.onosproject.ospf.protocol.lsa.linksubtype; |
| 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.ospf.protocol.lsa.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 LocalInterfaceIpAddress. |
| 31 | */ |
| 32 | public class LocalInterfaceIpAddressTest { |
| 33 | |
| 34 | private final byte[] packet = {1, 1, 1, 1}; |
| 35 | private final byte[] packet1 = {}; |
| 36 | private LocalInterfaceIpAddress localInterfaceIpAddress; |
| 37 | private TlvHeader tlvHeader; |
| 38 | private byte[] result; |
| 39 | private ChannelBuffer channelBuffer; |
| 40 | |
| 41 | @Before |
| 42 | public void setUp() throws Exception { |
| 43 | localInterfaceIpAddress = new LocalInterfaceIpAddress(new TlvHeader()); |
| 44 | } |
| 45 | |
| 46 | @After |
| 47 | public void tearDown() throws Exception { |
| 48 | localInterfaceIpAddress = null; |
| 49 | tlvHeader = null; |
| 50 | result = null; |
| 51 | channelBuffer = null; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Tests to string method. |
| 56 | */ |
| 57 | @Test |
| 58 | public void testToString() throws Exception { |
| 59 | assertThat(localInterfaceIpAddress.toString(), is(notNullValue())); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Tests addLocalInterfaceIPAddress() method. |
| 64 | */ |
| 65 | @Test |
| 66 | public void testAddLocalInterfaceIPAddress() throws Exception { |
| 67 | localInterfaceIpAddress.addLocalInterfaceIPAddress("1.1.1.1"); |
| 68 | assertThat(localInterfaceIpAddress, is(notNullValue())); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Tests readFrom() method. |
| 73 | */ |
| 74 | @Test |
| 75 | public void testReadFrom() throws Exception { |
| 76 | tlvHeader = new TlvHeader(); |
| 77 | tlvHeader.setTlvType(3); |
| 78 | tlvHeader.setTlvLength(4); |
| 79 | localInterfaceIpAddress = new LocalInterfaceIpAddress(tlvHeader); |
| 80 | channelBuffer = ChannelBuffers.copiedBuffer(packet); |
| 81 | localInterfaceIpAddress.readFrom(channelBuffer); |
| 82 | assertThat(localInterfaceIpAddress, is(notNullValue())); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Tests readFrom() method. |
| 87 | */ |
| 88 | @Test |
| 89 | public void testReadFrom1() throws Exception { |
| 90 | tlvHeader = new TlvHeader(); |
| 91 | tlvHeader.setTlvType(3); |
| 92 | tlvHeader.setTlvLength(4); |
| 93 | localInterfaceIpAddress = new LocalInterfaceIpAddress(tlvHeader); |
| 94 | channelBuffer = ChannelBuffers.copiedBuffer(packet1); |
| 95 | localInterfaceIpAddress.readFrom(channelBuffer); |
| 96 | assertThat(localInterfaceIpAddress, is(notNullValue())); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Tests asBytes() method. |
| 101 | */ |
| 102 | @Test |
| 103 | public void testAsBytes() throws Exception { |
| 104 | result = localInterfaceIpAddress.asBytes(); |
| 105 | assertThat(result, is(notNullValue())); |
| 106 | } |
| 107 | |
| 108 | |
| 109 | /** |
| 110 | * Tests getLinkSubTypeTlvBodyAsByteArray() method. |
| 111 | */ |
| 112 | @Test |
| 113 | public void testGetLinkSubTypeTlvBodyAsByteArray() throws Exception { |
| 114 | result = localInterfaceIpAddress.getLinkSubTypeTlvBodyAsByteArray(); |
| 115 | assertThat(result, is(notNullValue())); |
| 116 | } |
| 117 | } |