Kalyankumar Asangi | 19f6449 | 2016-02-17 17:34:16 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Kalyankumar Asangi | 19f6449 | 2016-02-17 17:34:16 +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.controller.lsdb; |
| 17 | |
| 18 | import org.junit.After; |
| 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
| 21 | import org.onosproject.ospf.controller.LsaWrapper; |
| 22 | import org.onosproject.ospf.protocol.lsa.LsaHeader; |
| 23 | |
| 24 | import static org.hamcrest.CoreMatchers.is; |
| 25 | import static org.hamcrest.CoreMatchers.notNullValue; |
| 26 | import static org.hamcrest.MatcherAssert.assertThat; |
| 27 | |
| 28 | /** |
| 29 | * Unit test class for LsaBinImpl. |
| 30 | */ |
| 31 | public class LsaBinImplTest { |
| 32 | private LsaBinImpl lsaBin; |
| 33 | private LsaHeader ospflsa1; |
| 34 | private LsaWrapper lsaWrapper; |
| 35 | |
| 36 | |
| 37 | @Before |
| 38 | public void setUp() throws Exception { |
| 39 | ospflsa1 = new LsaHeader(); |
| 40 | ospflsa1.setAge(20); |
| 41 | lsaBin = new LsaBinImpl(1); |
| 42 | } |
| 43 | |
| 44 | @After |
| 45 | public void tearDown() throws Exception { |
| 46 | ospflsa1 = null; |
| 47 | lsaBin = null; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Tests binNumber() getter method. |
| 52 | */ |
| 53 | @Test |
| 54 | public void testGetBinNumber() throws Exception { |
| 55 | lsaWrapper = new LsaWrapperImpl(); |
| 56 | lsaBin.addOspfLsa("lsa1", lsaWrapper); |
| 57 | assertThat(lsaBin.binNumber(), is(1)); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Tests addOspfLsa() method. |
| 62 | */ |
| 63 | @Test |
| 64 | public void testAddOspfLsa() throws Exception { |
| 65 | LsaWrapper lsaWrapper = new LsaWrapperImpl(); |
| 66 | lsaBin.addOspfLsa("lsa1", lsaWrapper); |
| 67 | assertThat(lsaBin, is(notNullValue())); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Tests ospfLsa() getter method. |
| 72 | */ |
| 73 | @Test |
| 74 | public void testGetOspfLsa() throws Exception { |
| 75 | lsaWrapper = new LsaWrapperImpl(); |
| 76 | lsaBin.addOspfLsa("lsa1", lsaWrapper); |
| 77 | assertThat(lsaBin, is(notNullValue())); |
| 78 | assertThat(lsaBin.ospfLsa("lsa1"), is(lsaWrapper)); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Tests removeOspfLsa() method. |
| 83 | */ |
| 84 | @Test |
| 85 | public void testRemoveOspfLsa() throws Exception { |
| 86 | lsaWrapper = new LsaWrapperImpl(); |
| 87 | lsaBin.addOspfLsa("lsa1", lsaWrapper); |
| 88 | lsaBin.removeOspfLsa("lsa1", lsaWrapper); |
| 89 | assertThat(lsaBin, is(notNullValue())); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Tests listOfLsa() method. |
| 94 | */ |
| 95 | @Test |
| 96 | public void testGetListOfLsa() throws Exception { |
| 97 | lsaWrapper = new LsaWrapperImpl(); |
| 98 | lsaBin.addOspfLsa("lsa1", lsaWrapper); |
| 99 | assertThat(lsaBin.listOfLsa().size(), is(1)); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Tests to string method. |
| 104 | */ |
| 105 | @Test |
| 106 | public void testToString() throws Exception { |
| 107 | assertThat(lsaBin.toString(), is(notNullValue())); |
| 108 | } |
| 109 | } |