Chidambar babu | 86b3b1a | 2016-02-16 17:39:52 +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; |
| 17 | |
| 18 | import org.hamcrest.Matchers; |
| 19 | import org.junit.After; |
| 20 | import org.junit.Before; |
| 21 | import org.junit.Test; |
| 22 | import org.onlab.packet.Ip4Address; |
| 23 | |
| 24 | import static org.hamcrest.CoreMatchers.notNullValue; |
| 25 | import static org.hamcrest.Matchers.is; |
| 26 | import static org.junit.Assert.assertThat; |
| 27 | |
| 28 | /** |
| 29 | * Unit test class for OpaqueLsaHeader. |
| 30 | */ |
| 31 | public class OpaqueLsaHeaderTest { |
| 32 | |
| 33 | private OpaqueLsaHeader opaqueHeader; |
| 34 | private OpaqueLsaHeader opaqueLsaHeader1; |
| 35 | private int num; |
| 36 | private byte[] result; |
| 37 | private int result1; |
| 38 | |
| 39 | @Before |
| 40 | public void setUp() throws Exception { |
| 41 | opaqueHeader = new OpaqueLsaHeader(); |
| 42 | } |
| 43 | |
| 44 | @After |
| 45 | public void tearDown() throws Exception { |
| 46 | opaqueHeader = null; |
| 47 | opaqueLsaHeader1 = null; |
| 48 | result = null; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Tests populateHeader() method. |
| 53 | */ |
| 54 | @Test |
| 55 | public void testPopulateHeader() throws Exception { |
| 56 | opaqueLsaHeader1 = new OpaqueLsaHeader(); |
| 57 | opaqueLsaHeader1.setLsPacketLen(10); |
| 58 | opaqueLsaHeader1.setAdvertisingRouter(Ip4Address.valueOf("1.1.1.1")); |
| 59 | opaqueLsaHeader1.setOptions(2); |
| 60 | opaqueLsaHeader1.setAge(20); |
| 61 | opaqueLsaHeader1.setLsType(3); |
| 62 | opaqueLsaHeader1.setOpaqueId(1); |
| 63 | opaqueLsaHeader1.setOpaqueType(3); |
| 64 | opaqueLsaHeader1.setLsCheckSum(1234); |
| 65 | opaqueLsaHeader1.setLsSequenceNo(456789); |
| 66 | opaqueLsaHeader1.populateHeader(opaqueLsaHeader1); |
| 67 | assertThat(opaqueLsaHeader1, is(notNullValue())); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Tests opaqueId() getter method. |
| 72 | */ |
| 73 | @Test |
| 74 | public void testGetOpaqueId() throws Exception { |
| 75 | opaqueHeader.setOpaqueId(1); |
| 76 | num = opaqueHeader.opaqueId(); |
| 77 | assertThat(num, is(1)); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Tests opaqueId() setter method. |
| 82 | */ |
| 83 | @Test |
| 84 | public void testSetOpaqueId() throws Exception { |
| 85 | opaqueHeader.setOpaqueId(1); |
| 86 | num = opaqueHeader.opaqueId(); |
| 87 | assertThat(num, is(1)); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Tests opaqueType() getter method. |
| 92 | */ |
| 93 | @Test |
| 94 | public void testGetOpaqueType() throws Exception { |
| 95 | opaqueHeader.setOpaqueType(1); |
| 96 | num = opaqueHeader.opaqueType(); |
| 97 | assertThat(num, is(1)); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Tests opaqueType() setter method. |
| 102 | */ |
| 103 | @Test |
| 104 | public void testSetOpaqueType() throws Exception { |
| 105 | opaqueHeader.setOpaqueType(1); |
| 106 | num = opaqueHeader.opaqueType(); |
| 107 | assertThat(num, is(1)); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Tests getOpaqueLsaHeaderAsByteArray() method. |
| 112 | */ |
| 113 | @Test |
| 114 | public void testGetOpaqueLsaHeaderAsByteArray() throws Exception { |
| 115 | result = opaqueHeader.getOpaqueLsaHeaderAsByteArray(); |
| 116 | assertThat(result, is(notNullValue())); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Tests to string method. |
| 121 | */ |
| 122 | @Test |
| 123 | public void testToString() throws Exception { |
| 124 | assertThat(opaqueHeader.toString(), is(notNullValue())); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Tests hashCode() method. |
| 129 | */ |
| 130 | @Test |
| 131 | public void testHashcode() throws Exception { |
| 132 | |
| 133 | result1 = opaqueHeader.hashCode(); |
| 134 | assertThat(result1, is(Matchers.notNullValue())); |
| 135 | |
| 136 | } |
| 137 | } |