blob: b38ddfbf27f0fe3fe48977ab31f1ebca7cbfea59 [file] [log] [blame]
Dhruv Dhodyb5850122016-02-17 17:51:19 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Dhruv Dhodyb5850122016-02-17 17:51:19 +05303 *
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;
Dhruv Dhodyb5850122016-02-17 17:51:19 +053049 private List<OspfProcess> ospfProcesses;
50 private OspfProcess process1;
Dhruv Dhodyb5850122016-02-17 17:51:19 +053051 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 Dhodyb5850122016-02-17 17:51:19 +053062 }
63
64 @After
65 public void tearDown() throws Exception {
66 ospfController = null;
67 ospfRouterListener = null;
68 ospfLinkListener = null;
Dhruv Dhodyb5850122016-02-17 17:51:19 +053069 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 Dhodyb5850122016-02-17 17:51:19 +0530139 * 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"));
sunishvkf7c56552016-07-18 16:02:39 +0530150 ospfArea.setOspfInterfaceList(ospfInterfaces);
Dhruv Dhodyb5850122016-02-17 17:51:19 +0530151 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"));
sunishvkf7c56552016-07-18 16:02:39 +0530161 ospfArea1.setOspfInterfaceList(ospfInterfaces);
Dhruv Dhodyb5850122016-02-17 17:51:19 +0530162 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());
sunishvkf7c56552016-07-18 16:02:39 +0530188 ospfController.agent.deleteLink(ospfRouter, new OspfLinkTedImpl());
Dhruv Dhodyb5850122016-02-17 17:51:19 +0530189 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}