Dhruv Dhody | b585012 | 2016-02-17 17:51:19 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Dhruv Dhody | b585012 | 2016-02-17 17:51:19 +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.impl; |
| 17 | |
| 18 | |
| 19 | import org.easymock.EasyMock; |
| 20 | import org.junit.After; |
| 21 | import org.junit.Before; |
| 22 | import org.junit.Test; |
| 23 | import org.onlab.packet.Ip4Address; |
| 24 | import org.onosproject.ospf.controller.OspfArea; |
| 25 | import org.onosproject.ospf.controller.OspfInterface; |
| 26 | import org.onosproject.ospf.controller.OspfLinkListener; |
| 27 | import org.onosproject.ospf.controller.OspfProcess; |
| 28 | import org.onosproject.ospf.controller.OspfRouter; |
| 29 | import org.onosproject.ospf.controller.OspfRouterListener; |
| 30 | import org.onosproject.ospf.controller.area.OspfAreaImpl; |
| 31 | import org.onosproject.ospf.controller.area.OspfInterfaceImpl; |
| 32 | import org.onosproject.ospf.controller.area.OspfProcessImpl; |
| 33 | |
| 34 | import java.util.ArrayList; |
| 35 | import java.util.List; |
| 36 | |
| 37 | import static org.hamcrest.CoreMatchers.is; |
| 38 | import static org.hamcrest.CoreMatchers.notNullValue; |
| 39 | import static org.hamcrest.MatcherAssert.assertThat; |
| 40 | |
| 41 | /** |
| 42 | * Unit test class for OspfRouterId. |
| 43 | */ |
| 44 | public class OspfControllerImplTest { |
| 45 | |
| 46 | private OspfControllerImpl ospfController; |
| 47 | private OspfRouterListener ospfRouterListener; |
| 48 | private OspfLinkListener ospfLinkListener; |
Dhruv Dhody | b585012 | 2016-02-17 17:51:19 +0530 | [diff] [blame] | 49 | private List<OspfProcess> ospfProcesses; |
| 50 | private OspfProcess process1; |
Dhruv Dhody | b585012 | 2016-02-17 17:51:19 +0530 | [diff] [blame] | 51 | private List<OspfArea> areas; |
| 52 | private OspfAreaImpl ospfArea; |
| 53 | private List<OspfInterface> ospfInterfaces; |
| 54 | private OspfInterfaceImpl ospfInterface; |
| 55 | private OspfProcess ospfProcess; |
| 56 | private OspfArea ospfArea1; |
| 57 | private OspfRouter ospfRouter; |
| 58 | |
| 59 | @Before |
| 60 | public void setUp() throws Exception { |
| 61 | ospfController = new OspfControllerImpl(); |
Dhruv Dhody | b585012 | 2016-02-17 17:51:19 +0530 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | @After |
| 65 | public void tearDown() throws Exception { |
| 66 | ospfController = null; |
| 67 | ospfRouterListener = null; |
| 68 | ospfLinkListener = null; |
Dhruv Dhody | b585012 | 2016-02-17 17:51:19 +0530 | [diff] [blame] | 69 | ospfProcesses = null; |
| 70 | areas = null; |
| 71 | ospfArea = null; |
| 72 | ospfInterfaces = null; |
| 73 | ospfInterface = null; |
| 74 | ospfProcess = null; |
| 75 | ospfProcess = null; |
| 76 | ospfArea1 = null; |
| 77 | ospfRouter = null; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Tests activate() method. |
| 82 | */ |
| 83 | @Test |
| 84 | public void testActivate() throws Exception { |
| 85 | ospfController.activate(); |
| 86 | assertThat(ospfController, is(notNullValue())); |
| 87 | } |
| 88 | |
| 89 | @Test(expected = Exception.class) |
| 90 | public void testDeactivate() throws Exception { |
| 91 | ospfController.activate(); |
| 92 | ospfController.deactivate(); |
| 93 | assertThat(ospfController, is(notNullValue())); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Tests addRouterListener() method. |
| 98 | */ |
| 99 | @Test |
| 100 | public void testAddRouterListener() throws Exception { |
| 101 | ospfRouterListener = EasyMock.createMock(OspfRouterListener.class); |
| 102 | ospfController.addRouterListener(ospfRouterListener); |
| 103 | assertThat(ospfController, is(notNullValue())); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Tests removeRouterListener() method. |
| 108 | */ |
| 109 | @Test |
| 110 | public void testRemoveRouterListener() throws Exception { |
| 111 | ospfRouterListener = EasyMock.createMock(OspfRouterListener.class); |
| 112 | ospfController.addRouterListener(ospfRouterListener); |
| 113 | ospfController.removeRouterListener(ospfRouterListener); |
| 114 | assertThat(ospfController, is(notNullValue())); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Tests addLinkListener() method. |
| 119 | */ |
| 120 | @Test |
| 121 | public void testAddLinkListener() throws Exception { |
| 122 | ospfLinkListener = EasyMock.createMock(OspfLinkListener.class); |
| 123 | ospfController.addLinkListener(ospfLinkListener); |
| 124 | assertThat(ospfController, is(notNullValue())); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Tests removeLinkListener() method. |
| 129 | */ |
| 130 | @Test |
| 131 | public void testRemoveLinkListener() throws Exception { |
| 132 | ospfLinkListener = EasyMock.createMock(OspfLinkListener.class); |
| 133 | ospfController.addLinkListener(ospfLinkListener); |
| 134 | ospfController.removeLinkListener(ospfLinkListener); |
| 135 | assertThat(ospfController, is(notNullValue())); |
| 136 | } |
| 137 | |
| 138 | /** |
Dhruv Dhody | b585012 | 2016-02-17 17:51:19 +0530 | [diff] [blame] | 139 | * Tests deleteConfig() method. |
| 140 | */ |
| 141 | @Test |
| 142 | public void testDeleteConfig() throws Exception { |
| 143 | ospfProcess = new OspfProcessImpl(); |
| 144 | ospfArea = new OspfAreaImpl(); |
| 145 | ospfInterface = new OspfInterfaceImpl(); |
| 146 | ospfInterfaces = new ArrayList(); |
| 147 | ospfInterface.setIpAddress(Ip4Address.valueOf("10.10.10.5")); |
| 148 | ospfInterfaces.add(ospfInterface); |
| 149 | ospfArea.setAreaId(Ip4Address.valueOf("2.2.2.2")); |
sunishvk | f7c5655 | 2016-07-18 16:02:39 +0530 | [diff] [blame] | 150 | ospfArea.setOspfInterfaceList(ospfInterfaces); |
Dhruv Dhody | b585012 | 2016-02-17 17:51:19 +0530 | [diff] [blame] | 151 | ospfProcess.setProcessId("10.10.10.10"); |
| 152 | areas = new ArrayList(); |
| 153 | areas.add(ospfArea); |
| 154 | ospfProcess.setAreas(areas); |
| 155 | ospfProcesses = new ArrayList(); |
| 156 | ospfProcesses.add(ospfProcess); |
| 157 | process1 = new OspfProcessImpl(); |
| 158 | process1.setProcessId("11.11.11.11"); |
| 159 | ospfArea1 = new OspfAreaImpl(); |
| 160 | ospfArea1.setAreaId(Ip4Address.valueOf("2.2.2.2")); |
sunishvk | f7c5655 | 2016-07-18 16:02:39 +0530 | [diff] [blame] | 161 | ospfArea1.setOspfInterfaceList(ospfInterfaces); |
Dhruv Dhody | b585012 | 2016-02-17 17:51:19 +0530 | [diff] [blame] | 162 | areas.add(ospfArea1); |
| 163 | process1.setAreas(areas); |
| 164 | ospfProcesses.add(process1); |
| 165 | ospfController.deleteConfig(ospfProcesses, "INTERFACE"); |
| 166 | assertThat(ospfController, is(notNullValue())); |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Tests addLink() method. |
| 171 | */ |
| 172 | @Test |
| 173 | public void testAddLink() throws Exception { |
| 174 | ospfRouter = new OspfRouterImpl(); |
| 175 | |
| 176 | ospfController.agent.addLink(ospfRouter, new OspfLinkTedImpl()); |
| 177 | assertThat(ospfController, is(notNullValue())); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Tests deleteLink() method. |
| 182 | */ |
| 183 | @Test |
| 184 | public void testDeleteLink() throws Exception { |
| 185 | ospfRouter = new OspfRouterImpl(); |
| 186 | |
| 187 | ospfController.agent.addLink(ospfRouter, new OspfLinkTedImpl()); |
sunishvk | f7c5655 | 2016-07-18 16:02:39 +0530 | [diff] [blame] | 188 | ospfController.agent.deleteLink(ospfRouter, new OspfLinkTedImpl()); |
Dhruv Dhody | b585012 | 2016-02-17 17:51:19 +0530 | [diff] [blame] | 189 | assertThat(ospfController, is(notNullValue())); |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Tests listener() method. |
| 194 | */ |
| 195 | @Test |
| 196 | public void testListener() throws Exception { |
| 197 | assertThat(ospfController.listener().size(), is(0)); |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Tests linkListener() method. |
| 202 | */ |
| 203 | @Test |
| 204 | public void testLinkListener() throws Exception { |
| 205 | assertThat(ospfController.linkListener().size(), is(0)); |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Tests addConnectedRouter() method. |
| 210 | */ |
| 211 | @Test |
| 212 | public void testaddConnectedRouter() throws Exception { |
| 213 | ospfRouter = new OspfRouterImpl(); |
| 214 | |
| 215 | ospfController.agent.addConnectedRouter(ospfRouter); |
| 216 | assertThat(ospfController, is(notNullValue())); |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Tests removeConnectedRouter() method. |
| 221 | */ |
| 222 | @Test |
| 223 | public void testRemoveConnectedRouter() throws Exception { |
| 224 | ospfRouter = new OspfRouterImpl(); |
| 225 | |
| 226 | ospfController.agent.addConnectedRouter(ospfRouter); |
| 227 | ospfController.agent.removeConnectedRouter(ospfRouter); |
| 228 | assertThat(ospfController, is(notNullValue())); |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Tests getAllConfiguredProcesses() method. |
| 233 | */ |
| 234 | @Test(expected = Exception.class) |
| 235 | public void testGetAllConfiguredProcesses() throws Exception { |
| 236 | assertThat(ospfController.getAllConfiguredProcesses().size(), is(0)); |
| 237 | } |
| 238 | } |