blob: c0b5db882a80a5bd8fb37896a8e02ba6ce7f813a [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.net.driver.DriverService;
25import org.onosproject.ospf.controller.OspfAgent;
26import org.onosproject.ospf.controller.OspfArea;
27import org.onosproject.ospf.controller.OspfInterface;
28import org.onosproject.ospf.controller.OspfProcess;
29import org.onosproject.ospf.controller.OspfRouter;
30import org.onosproject.ospf.controller.area.OspfAreaImpl;
31import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
32import org.onosproject.ospf.controller.area.OspfProcessImpl;
33
34import java.nio.channels.Channel;
35import java.util.ArrayList;
36import java.util.HashMap;
37import java.util.List;
38import java.util.Map;
39
40import static org.hamcrest.CoreMatchers.*;
41import static org.hamcrest.MatcherAssert.assertThat;
42
43/**
44 * Unit test class for Controller.
45 */
46public class ControllerTest {
47 private Controller controller;
48 private Map<String, Long> maps;
49 private OspfAgent ospfAgent;
50 private DriverService driverService;
51 private List<Channel> connectedChannels;
52 private List<OspfProcess> process;
53 private OspfProcess ospfProcess;
54 private OspfArea ospfArea;
55 private OspfInterface ospfInterface;
56 private List<OspfInterface> ospfInterfaces;
57 private List<OspfArea> ospfAreas;
58 private List<OspfProcess> ospfProcesses;
59 private OspfProcess ospfProcess1;
60 private OspfArea ospfArea1;
61 private OspfRouter ospfRouter;
62
63 @Before
64 public void setUp() throws Exception {
65 controller = new Controller();
66 maps = new HashMap<String, Long>();
67 ospfProcess = new OspfProcessImpl();
68 ospfArea = new OspfAreaImpl();
69 ospfInterface = new OspfInterfaceImpl();
70 ospfInterfaces = new ArrayList();
71 ospfInterface.setIpAddress(Ip4Address.valueOf("1.1.1.1"));
72 ospfInterfaces.add(ospfInterface);
73 ospfArea.setAreaId(Ip4Address.valueOf("2.2.2.2"));
sunishvkf7c56552016-07-18 16:02:39 +053074 ospfArea.setOspfInterfaceList(ospfInterfaces);
Dhruv Dhodyb5850122016-02-17 17:51:19 +053075 ospfProcess.setProcessId("10.10.10.10");
76 ospfAreas = new ArrayList();
77 ospfAreas.add(ospfArea);
78 ospfProcess.setAreas(ospfAreas);
79 ospfProcesses = new ArrayList();
80 ospfProcesses.add(ospfProcess);
81 ospfProcess1 = new OspfProcessImpl();
82 ospfProcess1.setProcessId("11.11.11.11");
83 ospfArea1 = new OspfAreaImpl();
84 ospfArea1.setAreaId(Ip4Address.valueOf("2.2.2.2"));
sunishvkf7c56552016-07-18 16:02:39 +053085 ospfArea1.setOspfInterfaceList(ospfInterfaces);
Dhruv Dhodyb5850122016-02-17 17:51:19 +053086 ospfAreas.add(ospfArea1);
87 ospfProcess1.setAreas(ospfAreas);
88 ospfProcesses.add(ospfProcess1);
89 connectedChannels = new ArrayList<>();
90 }
91
92 @After
93 public void tearDown() throws Exception {
94 controller = null;
95 maps.clear();
96 connectedChannels.clear();
97 controller = null;
98 maps = null;
99 ospfAgent = null;
100 driverService = null;
101 connectedChannels = null;
102 process = null;
103 ospfProcess = null;
104 ospfArea = null;
105 ospfInterface = null;
106 ospfInterfaces = null;
107 ospfAreas = null;
108 ospfProcesses = null;
109 ospfProcess1 = null;
110 ospfArea1 = null;
111 }
112
113 /**
114 * Tests getAllConfiguredProcesses() method.
115 */
116 @Test
117 public void testGetAllConfiguredProcesses() throws Exception {
118 process = controller.getAllConfiguredProcesses();
119 assertThat(process, is(nullValue()));
120 }
121
122 /**
123 * Tests addDeviceDetails() method.
124 */
125 @Test(expected = Exception.class)
126 public void testAddDeviceDetails() throws Exception {
127 controller.addDeviceDetails(new OspfRouterImpl());
128 assertThat(controller, is(notNullValue()));
129 }
130
131 /**
132 * Tests removeDeviceDetails() method.
133 */
134 @Test(expected = Exception.class)
135 public void testRemoveDeviceDetails() throws Exception {
136 controller.removeDeviceDetails(new OspfRouterImpl());
137 assertThat(controller, is(notNullValue()));
138 }
139
140 /**
141 * Tests init() method.
142 */
143 @Test
144 public void testInit() throws Exception {
145 controller.init();
146 assertThat(controller.systemStartTime, is(notNullValue()));
147 }
148
149 /**
150 * Tests start() method.
151 */
152 @Test
153 public void testStart() throws Exception {
154 ospfAgent = EasyMock.createMock(OspfAgent.class);
155 controller.start(ospfAgent, driverService);
156 controller.updateConfig(ospfProcesses);
157 assertThat(controller, is(notNullValue()));
158 }
159
160 /**
161 * Tests stop() method.
162 */
163 @Test(expected = Exception.class)
164 public void testStop() throws Exception {
165 controller.start(ospfAgent, driverService);
166 controller.stop();
167 assertThat(controller, is(notNullValue()));
168 }
169
Dhruv Dhodyb5850122016-02-17 17:51:19 +0530170
171 /**
172 * Tests updateConfig() method.
173 */
174 @Test
175 public void testUpdateConfig1() throws Exception {
176 ospfProcess = new OspfProcessImpl();
177 ospfArea = new OspfAreaImpl();
178 ospfInterface = new OspfInterfaceImpl();
179 ospfInterfaces = new ArrayList();
180 ospfInterface.setIpAddress(Ip4Address.valueOf("10.10.10.5"));
181 ospfInterfaces.add(ospfInterface);
182 ospfArea.setAreaId(Ip4Address.valueOf("2.2.2.2"));
sunishvkf7c56552016-07-18 16:02:39 +0530183 ospfArea.setOspfInterfaceList(ospfInterfaces);
Dhruv Dhodyb5850122016-02-17 17:51:19 +0530184 ospfProcess.setProcessId("10.10.10.10");
185 ospfAreas = new ArrayList();
186 ospfAreas.add(ospfArea);
187 ospfProcess.setAreas(ospfAreas);
188 ospfProcesses = new ArrayList();
189 ospfProcesses.add(ospfProcess);
190 controller.updateConfig(ospfProcesses);
191 assertThat(controller, is(notNullValue()));
192 }
193
194 /**
Dhruv Dhodyb5850122016-02-17 17:51:19 +0530195 * Tests addLinkDetails() method.
196 */
197 @Test
198 public void testAddLinkDetails() throws Exception {
199 ospfAgent = EasyMock.createMock(OspfAgent.class);
200 controller.start(ospfAgent, driverService);
201 ospfRouter = new OspfRouterImpl();
202 controller.addLinkDetails(ospfRouter, new OspfLinkTedImpl());
203 assertThat(controller, is(notNullValue()));
204 }
205
206 /**
207 * Tests removeLinkDetails() method.
208 */
209 @Test
210 public void testRemoveLinkDetails() throws Exception {
211 ospfAgent = EasyMock.createMock(OspfAgent.class);
212 controller.start(ospfAgent, driverService);
213 ospfRouter = new OspfRouterImpl();
214 controller.addLinkDetails(ospfRouter, new OspfLinkTedImpl());
sunishvkf7c56552016-07-18 16:02:39 +0530215 controller.removeLinkDetails(ospfRouter, new OspfLinkTedImpl());
Dhruv Dhodyb5850122016-02-17 17:51:19 +0530216 assertThat(controller, is(notNullValue()));
217 }
218}