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