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