Kalyankumar Asangi | 19f6449 | 2016-02-17 17:34:16 +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.controller.lsdb; |
| 17 | |
| 18 | import org.easymock.EasyMock; |
| 19 | import org.jboss.netty.channel.Channel; |
| 20 | import org.junit.After; |
| 21 | import org.junit.Before; |
| 22 | import org.junit.Test; |
| 23 | import org.onosproject.ospf.controller.LsaWrapper; |
| 24 | import org.onosproject.ospf.controller.OspfArea; |
| 25 | import org.onosproject.ospf.controller.OspfLsaType; |
| 26 | import org.onosproject.ospf.controller.area.OspfAreaImpl; |
| 27 | import org.onosproject.ospf.controller.area.OspfInterfaceImpl; |
| 28 | import org.onosproject.ospf.protocol.lsa.LsaHeader; |
| 29 | import org.onosproject.ospf.protocol.lsa.types.RouterLsa; |
| 30 | import org.onosproject.ospf.protocol.util.OspfInterfaceState; |
| 31 | |
| 32 | import java.util.concurrent.ArrayBlockingQueue; |
| 33 | import java.util.concurrent.BlockingQueue; |
| 34 | |
| 35 | import static org.hamcrest.CoreMatchers.is; |
| 36 | import static org.hamcrest.CoreMatchers.notNullValue; |
| 37 | import static org.hamcrest.MatcherAssert.assertThat; |
| 38 | |
| 39 | /** |
| 40 | * Unit test class for LsaQueueConsumer. |
| 41 | */ |
| 42 | public class LsaQueueConsumerTest { |
| 43 | private LsaQueueConsumer lsaQueueConsumer; |
| 44 | private BlockingQueue<LsaWrapper> blockingQueue; |
| 45 | private Channel channel; |
| 46 | private LsaWrapperImpl lsaWrapper; |
| 47 | private OspfArea ospfArea; |
| 48 | private RouterLsa routerLsa; |
| 49 | private OspfInterfaceImpl ospfInterface; |
| 50 | private LsaHeader lsaHeader; |
| 51 | private LsdbAgeImpl lsdbAge; |
| 52 | |
| 53 | @Before |
| 54 | public void setUp() throws Exception { |
| 55 | lsaQueueConsumer = EasyMock.createMock(LsaQueueConsumer.class); |
| 56 | } |
| 57 | |
| 58 | @After |
| 59 | public void tearDown() throws Exception { |
| 60 | lsaQueueConsumer = null; |
| 61 | blockingQueue = null; |
| 62 | channel = null; |
| 63 | lsaWrapper = null; |
| 64 | lsdbAge = null; |
| 65 | lsaHeader = null; |
| 66 | ospfInterface = null; |
| 67 | ospfArea = null; |
| 68 | routerLsa = null; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Tests run() method. |
| 73 | */ |
| 74 | @Test |
| 75 | public void testRun() throws Exception { |
| 76 | blockingQueue = new ArrayBlockingQueue(5); |
| 77 | channel = EasyMock.createMock(Channel.class); |
| 78 | ospfArea = new OspfAreaImpl(); |
| 79 | lsaWrapper = new LsaWrapperImpl(); |
| 80 | lsaWrapper.setLsaProcessing("verifyChecksum"); |
| 81 | blockingQueue.add(lsaWrapper); |
| 82 | lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea); |
| 83 | lsaQueueConsumer.run(); |
| 84 | assertThat(lsaQueueConsumer, is(notNullValue())); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Tests run() method. |
| 89 | */ |
| 90 | @Test |
| 91 | public void testRun1() throws Exception { |
| 92 | blockingQueue = new ArrayBlockingQueue(5); |
| 93 | channel = EasyMock.createMock(Channel.class); |
| 94 | ospfArea = new OspfAreaImpl(); |
| 95 | lsaWrapper = new LsaWrapperImpl(); |
| 96 | routerLsa = new RouterLsa(); |
| 97 | routerLsa.setLsType(1); |
| 98 | lsaWrapper.addLsa(OspfLsaType.ROUTER, routerLsa); |
| 99 | ospfInterface = new OspfInterfaceImpl(); |
| 100 | ospfInterface.setState(OspfInterfaceState.DR); |
| 101 | lsaWrapper.setOspfInterface(ospfInterface); |
| 102 | lsaWrapper.setIsSelfOriginated(true); |
| 103 | lsaHeader = new LsaHeader(); |
| 104 | lsaHeader.setLsType(1); |
| 105 | lsaWrapper.setLsaHeader(lsaHeader); |
| 106 | lsaWrapper.setLsaProcessing("refreshLsa"); |
| 107 | lsaWrapper.setLsdbAge(new LsdbAgeImpl(new OspfAreaImpl())); |
| 108 | blockingQueue.add(lsaWrapper); |
| 109 | lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea); |
| 110 | lsaQueueConsumer.run(); |
| 111 | assertThat(lsaQueueConsumer, is(notNullValue())); |
| 112 | } |
| 113 | |
| 114 | @Test |
| 115 | public void testRun3() throws Exception { |
| 116 | blockingQueue = new ArrayBlockingQueue(5); |
| 117 | channel = EasyMock.createMock(Channel.class); |
| 118 | ospfArea = new OspfAreaImpl(); |
| 119 | lsaWrapper = new LsaWrapperImpl(); |
| 120 | routerLsa = new RouterLsa(); |
| 121 | routerLsa.setLsType(2); |
| 122 | lsaWrapper.addLsa(OspfLsaType.NETWORK, routerLsa); |
| 123 | ospfInterface = new OspfInterfaceImpl(); |
| 124 | ospfInterface.setState(OspfInterfaceState.BDR); |
| 125 | lsaWrapper.setOspfInterface(ospfInterface); |
| 126 | lsaWrapper.setIsSelfOriginated(true); |
| 127 | lsaHeader = new LsaHeader(); |
| 128 | lsaHeader.setLsType(2); |
| 129 | lsaWrapper.setLsaHeader(lsaHeader); |
| 130 | lsaWrapper.setLsaProcessing("refreshLsa"); |
| 131 | lsaWrapper.setLsdbAge(new LsdbAgeImpl(new OspfAreaImpl())); |
| 132 | blockingQueue.add(lsaWrapper); |
| 133 | lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea); |
| 134 | lsaQueueConsumer.run(); |
| 135 | assertThat(lsaQueueConsumer, is(notNullValue())); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Tests run() method. |
| 140 | */ |
| 141 | @Test |
| 142 | public void testRun5() throws Exception { |
| 143 | blockingQueue = new ArrayBlockingQueue(5); |
| 144 | channel = EasyMock.createMock(Channel.class); |
| 145 | ospfArea = new OspfAreaImpl(); |
| 146 | lsaWrapper = new LsaWrapperImpl(); |
| 147 | routerLsa = new RouterLsa(); |
| 148 | routerLsa.setLsType(2); |
| 149 | lsaWrapper.addLsa(OspfLsaType.NETWORK, routerLsa); |
| 150 | ospfInterface = new OspfInterfaceImpl(); |
| 151 | ospfInterface.setState(OspfInterfaceState.DR); |
| 152 | lsaWrapper.setOspfInterface(ospfInterface); |
| 153 | lsaWrapper.setIsSelfOriginated(true); |
| 154 | lsaHeader = new LsaHeader(); |
| 155 | lsaHeader.setLsType(2); |
| 156 | lsaWrapper.setLsaHeader(lsaHeader); |
| 157 | lsaWrapper.setLsaProcessing("maxAgeLsa"); |
| 158 | lsaWrapper.setLsdbAge(new LsdbAgeImpl(new OspfAreaImpl())); |
| 159 | blockingQueue.add(lsaWrapper); |
| 160 | lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea); |
| 161 | lsaQueueConsumer.run(); |
| 162 | assertThat(lsaQueueConsumer, is(notNullValue())); |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Tests setChannel() method. |
| 167 | */ |
| 168 | @Test |
| 169 | public void testSetChannel() throws Exception { |
| 170 | channel = EasyMock.createMock(Channel.class); |
| 171 | lsdbAge = new LsdbAgeImpl(new OspfAreaImpl()); |
| 172 | lsdbAge.startDbAging(); |
| 173 | lsdbAge.setChannel(channel); |
| 174 | assertThat(lsaQueueConsumer, is(notNullValue())); |
| 175 | } |
| 176 | |
| 177 | } |