blob: b81370a8a9bfc5a986c9f2d56d3b27d598300d4c [file] [log] [blame]
Teruab4b01a2013-06-20 10:09:57 -07001package net.onrc.onos.ofcontroller.devicemanager.internal;
2
HIGUCHI Yuta5fdd9152013-06-17 15:48:09 -07003import static org.easymock.EasyMock.createMock;
4import static org.easymock.EasyMock.expect;
5import static org.easymock.EasyMock.replay;
6import static org.easymock.EasyMock.verify;
7import static org.junit.Assert.assertNotNull;
8import static org.junit.Assert.assertNull;
Teruab4b01a2013-06-20 10:09:57 -07009
10import java.util.ArrayList;
Jonathan Hart56d15772013-11-03 19:09:59 -080011import java.util.Collections;
Teruab4b01a2013-06-20 10:09:57 -070012import java.util.List;
13
Teruab4b01a2013-06-20 10:09:57 -070014import net.floodlightcontroller.devicemanager.IDevice;
15import net.floodlightcontroller.devicemanager.SwitchPort;
Pankaj Berde38646d62013-06-21 11:34:04 -070016import net.onrc.onos.graph.GraphDBConnection;
17import net.onrc.onos.graph.GraphDBOperation;
HIGUCHI Yuta5fdd9152013-06-17 15:48:09 -070018import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IDeviceObject;
Jonathan Hart56d15772013-11-03 19:09:59 -080019import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IIpv4Address;
HIGUCHI Yuta5fdd9152013-06-17 15:48:09 -070020import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
21import net.onrc.onos.ofcontroller.core.internal.DeviceStorageImpl;
22import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
Jonathan Hart56d15772013-11-03 19:09:59 -080023
Teruab4b01a2013-06-20 10:09:57 -070024import org.easymock.EasyMock;
25import org.junit.After;
26import org.junit.Before;
Teru4fd58642013-06-21 07:54:49 -070027import org.junit.Ignore;
Teruab4b01a2013-06-20 10:09:57 -070028import org.junit.Test;
29import org.junit.runner.RunWith;
30import org.openflow.util.HexString;
31import org.powermock.api.easymock.PowerMock;
32import org.powermock.core.classloader.annotations.PrepareForTest;
33import org.powermock.modules.junit4.PowerMockRunner;
34import org.slf4j.Logger;
35import org.slf4j.LoggerFactory;
Jonathan Hart56d15772013-11-03 19:09:59 -080036
37import com.google.common.net.InetAddresses;
Teruab4b01a2013-06-20 10:09:57 -070038import com.thinkaurelius.titan.core.TitanFactory;
39
40//Add Powermock preparation
41@RunWith(PowerMockRunner.class)
42@PrepareForTest({TitanFactory.class, GraphDBConnection.class, GraphDBOperation.class, DeviceStorageImpl.class})
Jonathan Hart56d15772013-11-03 19:09:59 -080043public class DeviceStorageImplTest{
Teruab4b01a2013-06-20 10:09:57 -070044
Yuta HIGUCHI6ac8d182013-10-22 15:24:56 -070045 protected final static Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
Teruab4b01a2013-06-20 10:09:57 -070046
47 String conf;
48 DeviceStorageImpl deviceImpl;
49 private GraphDBConnection mockConn;
50 private GraphDBOperation mockOpe;
51
52 @Before
53 public void setUp() throws Exception {
Teru4fd58642013-06-21 07:54:49 -070054 deviceImpl = new DeviceStorageImpl();
55 conf = "/dummy/path/to/db";
56
Teruab4b01a2013-06-20 10:09:57 -070057 PowerMock.mockStatic(GraphDBConnection.class);
58 mockConn = createMock(GraphDBConnection.class);
59 PowerMock.suppress(PowerMock.constructor(GraphDBConnection.class));
60 EasyMock.expect(GraphDBConnection.getInstance((String)EasyMock.anyObject())).andReturn(mockConn);
61 PowerMock.replay(GraphDBConnection.class);
62
63 //PowerMock.mockStatic(GraphDBOperation.class);
64 mockOpe = PowerMock.createMock(GraphDBOperation.class);
Teru4fd58642013-06-21 07:54:49 -070065 PowerMock.expectNew(GraphDBOperation.class, new Class<?>[]{String.class}, conf).andReturn(mockOpe);
Jonathan Hart56d15772013-11-03 19:09:59 -080066 //mockOpe.close();
Teruab4b01a2013-06-20 10:09:57 -070067 PowerMock.replay(GraphDBOperation.class);
68 // Replace the conf to dummy conf
69 // String conf = "/tmp/cassandra.titan";
Teru4fd58642013-06-21 07:54:49 -070070
Jonathan Hart56d15772013-11-03 19:09:59 -080071 deviceImpl.init(conf);
Teru4fd58642013-06-21 07:54:49 -070072
Teruab4b01a2013-06-20 10:09:57 -070073 }
74
75 @After
76 public void tearDown() throws Exception {
Teru4fd58642013-06-21 07:54:49 -070077 verify(mockOpe);
Teruab4b01a2013-06-20 10:09:57 -070078 }
79
Jonathan Hart56d15772013-11-03 19:09:59 -080080 private IPortObject getMockPort(long dpid, short port) {
81 IPortObject mockPortObject = createMock(IPortObject.class);
82 expect(mockPortObject.getNumber()).andReturn(port).anyTimes();
83 expect(mockPortObject.getDesc()).andReturn("test port").anyTimes();
84 return mockPortObject;
Teruab4b01a2013-06-20 10:09:57 -070085 }
86
Jonathan Hart56d15772013-11-03 19:09:59 -080087 private IDevice getMockDevice(String strMacAddress, long attachmentDpid,
88 short attachmentPort, int ipv4Address) {
89 IDevice mockIDevice = createMock(IDevice.class);
90
91
92 long longMacAddress = HexString.toLong(strMacAddress);
93
94 SwitchPort[] attachmentSwitchPorts = {new SwitchPort(attachmentDpid, attachmentPort)};
95
96 expect(mockIDevice.getMACAddress()).andReturn(longMacAddress).anyTimes();
97 expect(mockIDevice.getMACAddressString()).andReturn(strMacAddress).anyTimes();
98 expect(mockIDevice.getAttachmentPoints()).andReturn(attachmentSwitchPorts).anyTimes();
99 expect(mockIDevice.getIPv4Addresses()).andReturn(new Integer[] {ipv4Address}).anyTimes();
100
101 replay(mockIDevice);
102
103 return mockIDevice;
104 }
105
Teruab4b01a2013-06-20 10:09:57 -0700106 /**
Jonathan Hart56d15772013-11-03 19:09:59 -0800107 * Description:
Teruab4b01a2013-06-20 10:09:57 -0700108 * Test method for addDevice method.
Jonathan Hart56d15772013-11-03 19:09:59 -0800109 * Condition:
110 * The device does not already exist in the database
Teruab4b01a2013-06-20 10:09:57 -0700111 * Expect:
112 * Get proper IDeviceObject
113 */
Teruab4b01a2013-06-20 10:09:57 -0700114 @Test
115 public void testAddNewDevice() {
Jonathan Hart56d15772013-11-03 19:09:59 -0800116 String strMacAddress = "99:99:99:99:99:99";
117 long attachmentDpid = HexString.toLong("00:00:00:00:00:00:0a:01");
118 short attachmentPort = 2;
119 int intIpv4Address = InetAddresses.coerceToInteger(InetAddresses.forString("192.168.100.1"));
Teruab4b01a2013-06-20 10:09:57 -0700120
Jonathan Hart56d15772013-11-03 19:09:59 -0800121 IDevice device = getMockDevice(strMacAddress, attachmentDpid, attachmentPort, intIpv4Address);
122
123 IDeviceObject mockDeviceObject = createMock(IDeviceObject.class);
124 IPortObject mockPortObject = getMockPort(attachmentDpid, attachmentPort);
125 IIpv4Address mockIpv4Address = createMock(IIpv4Address.class);
126
127 expect(mockOpe.searchDevice(strMacAddress)).andReturn(null);
128 expect(mockOpe.newDevice()).andReturn(mockDeviceObject);
129 expect(mockDeviceObject.getAttachedPorts()).andReturn(Collections.<IPortObject>emptyList());
130 expect(mockOpe.searchPort(HexString.toHexString(attachmentDpid), attachmentPort)).andReturn(mockPortObject);
131 mockPortObject.setDevice(mockDeviceObject);
132 expect(mockDeviceObject.getIpv4Address(intIpv4Address)).andReturn(null);
133 expect(mockOpe.ensureIpv4Address(intIpv4Address)).andReturn(mockIpv4Address);
134 mockDeviceObject.addIpv4Address(mockIpv4Address);
135 expect(mockDeviceObject.getIpv4Addresses()).andReturn(Collections.singleton(mockIpv4Address));
136 expect(mockIpv4Address.getIpv4Address()).andReturn(intIpv4Address);
137
138 mockDeviceObject.setMACAddress(strMacAddress);
139 mockDeviceObject.setType("device");
140 mockDeviceObject.setState("ACTIVE");
141 mockOpe.commit();
142
143 replay(mockDeviceObject);
144 replay(mockPortObject);
145 replay(mockIpv4Address);
146 replay(mockOpe);
147
148 IDeviceObject addedObject = deviceImpl.addDevice(device);
149 assertNotNull(addedObject);
150
151 verify(mockDeviceObject);
Teruab4b01a2013-06-20 10:09:57 -0700152 }
153
154 /**
Jonathan Hart56d15772013-11-03 19:09:59 -0800155 * Description:
Teruab4b01a2013-06-20 10:09:57 -0700156 * Test method for addDevice method.
157 * Condition:
Jonathan Hart56d15772013-11-03 19:09:59 -0800158 * The device already exists in the database.
Teruab4b01a2013-06-20 10:09:57 -0700159 * Expect:
160 * Get proper IDeviceObject still.
161 * Check the IDeviceObject properties set expectedly.
162 */
Teruab4b01a2013-06-20 10:09:57 -0700163 @Test
Jonathan Hart56d15772013-11-03 19:09:59 -0800164 public void testAddExistingDevice() {
165 String strMacAddress = "99:99:99:99:99:99";
166 long attachmentDpid = HexString.toLong("00:00:00:00:00:00:0a:01");
167 short attachmentPort = 2;
168 int intIpv4Address = InetAddresses.coerceToInteger(InetAddresses.forString("192.168.100.1"));
Teruab4b01a2013-06-20 10:09:57 -0700169
Jonathan Hart56d15772013-11-03 19:09:59 -0800170 IDevice device = getMockDevice(strMacAddress, attachmentDpid, attachmentPort, intIpv4Address);
171
172 IDeviceObject mockDeviceObject = createMock(IDeviceObject.class);
173 IPortObject mockPortObject = getMockPort(attachmentDpid, attachmentPort);
174 IIpv4Address mockIpv4Address = createMock(IIpv4Address.class);
175
176 expect(mockOpe.searchDevice(strMacAddress)).andReturn(mockDeviceObject);
177 expect(mockDeviceObject.getAttachedPorts()).andReturn(Collections.singleton(mockPortObject));
178 expect(mockOpe.searchPort(HexString.toHexString(attachmentDpid), attachmentPort)).andReturn(mockPortObject);
179 expect(mockDeviceObject.getIpv4Address(intIpv4Address)).andReturn(mockIpv4Address);
180 expect(mockDeviceObject.getIpv4Addresses()).andReturn(Collections.singleton(mockIpv4Address));
181 expect(mockIpv4Address.getIpv4Address()).andReturn(intIpv4Address);
182
183 mockDeviceObject.setMACAddress(strMacAddress);
184 mockDeviceObject.setType("device");
185 mockDeviceObject.setState("ACTIVE");
186 mockOpe.commit();
187
188 replay(mockDeviceObject);
189 replay(mockPortObject);
190 replay(mockIpv4Address);
191 replay(mockOpe);
192
193 IDeviceObject addedObject = deviceImpl.addDevice(device);
194 assertNotNull(addedObject);
195
196 verify(mockDeviceObject);
Teruab4b01a2013-06-20 10:09:57 -0700197 }
198
199 /**
Jonathan Hart56d15772013-11-03 19:09:59 -0800200 * Description:
Teruab4b01a2013-06-20 10:09:57 -0700201 * Test method for updateDevice method.
Jonathan Hart56d15772013-11-03 19:09:59 -0800202 * NB. this is the same test as testAddExistingDevice
Teruab4b01a2013-06-20 10:09:57 -0700203 * Condition:
Jonathan Hart56d15772013-11-03 19:09:59 -0800204 * The MAC address and attachment point are the same.
Teruab4b01a2013-06-20 10:09:57 -0700205 * All of the other parameter are different.
206 * Expect:
207 * Changed parameters are set expectedly.
208 */
Teruab4b01a2013-06-20 10:09:57 -0700209 @Test
Jonathan Hart56d15772013-11-03 19:09:59 -0800210 public void testAddUpdateDevice() {
211 String strMacAddress = "99:99:99:99:99:99";
212 long attachmentDpid = HexString.toLong("00:00:00:00:00:00:0a:01");
213 short attachmentPort = 2;
214 int intIpv4Address = InetAddresses.coerceToInteger(InetAddresses.forString("192.168.100.1"));
215
216 IDevice device = getMockDevice(strMacAddress, attachmentDpid, attachmentPort, intIpv4Address);
217
218 IDeviceObject mockDeviceObject = createMock(IDeviceObject.class);
219 IPortObject mockPortObject = getMockPort(attachmentDpid, attachmentPort);
220 IIpv4Address mockIpv4Address = createMock(IIpv4Address.class);
221
222 expect(mockOpe.searchDevice(strMacAddress)).andReturn(mockDeviceObject);
223 expect(mockDeviceObject.getAttachedPorts()).andReturn(Collections.singleton(mockPortObject));
224 expect(mockOpe.searchPort(HexString.toHexString(attachmentDpid), attachmentPort)).andReturn(mockPortObject);
225 expect(mockDeviceObject.getIpv4Address(intIpv4Address)).andReturn(mockIpv4Address);
226 expect(mockDeviceObject.getIpv4Addresses()).andReturn(Collections.singleton(mockIpv4Address));
227 expect(mockIpv4Address.getIpv4Address()).andReturn(intIpv4Address);
228
229 mockDeviceObject.setMACAddress(strMacAddress);
230 mockDeviceObject.setType("device");
231 mockDeviceObject.setState("ACTIVE");
232 mockOpe.commit();
233
234 replay(mockDeviceObject);
235 replay(mockPortObject);
236 replay(mockIpv4Address);
237 replay(mockOpe);
238
239 IDeviceObject addedObject = deviceImpl.updateDevice(device);
240 assertNotNull(addedObject);
241
242 verify(mockDeviceObject);
Teruab4b01a2013-06-20 10:09:57 -0700243 }
244
245 /**
Jonathan Hart56d15772013-11-03 19:09:59 -0800246 * Description:
Teruab4b01a2013-06-20 10:09:57 -0700247 * Test method for testRemoveDevice method.
248 * Condition:
249 * 1. Unregistered IDeviceObject argument is put.
250 * Expect:
251 * 1. Nothing happen when unregistered IDeviceObject is put
252 * 2. IDeviceObject will be removed.
253 */
Teruab4b01a2013-06-20 10:09:57 -0700254 @Test
255 public void testRemoveDevice() {
Jonathan Hart56d15772013-11-03 19:09:59 -0800256 String strMacAddress = "99:99:99:99:99:99";
257 long attachmentDpid = HexString.toLong("00:00:00:00:00:00:0a:01");
258 short attachmentPort = 2;
259 int intIpv4Address = InetAddresses.coerceToInteger(InetAddresses.forString("192.168.100.1"));
260
261 IIpv4Address ipv4AddressObject = createMock(IIpv4Address.class);
262 IDeviceObject deviceObject = createMock(IDeviceObject.class);
263 expect(deviceObject.getIpv4Addresses()).andReturn(Collections.singleton(ipv4AddressObject));
264 replay(deviceObject);
265
266 expect(mockOpe.searchDevice(strMacAddress)).andReturn(deviceObject);
267 mockOpe.removeIpv4Address(ipv4AddressObject);
268 mockOpe.removeDevice(deviceObject);
269 mockOpe.commit();
270 replay(mockOpe);
271
272 IDevice device = getMockDevice(strMacAddress, attachmentDpid, attachmentPort, intIpv4Address);
Teruab4b01a2013-06-20 10:09:57 -0700273
Jonathan Hart56d15772013-11-03 19:09:59 -0800274 deviceImpl.removeDevice(device);
275
276 verify(mockOpe);
Teruab4b01a2013-06-20 10:09:57 -0700277 }
278
279 /**
Jonathan Hart56d15772013-11-03 19:09:59 -0800280 * Description:
Teruab4b01a2013-06-20 10:09:57 -0700281 * Test method for getDeviceByMac
282 * Condition:
Jonathan Hart56d15772013-11-03 19:09:59 -0800283 * 1. Unregistered MAC address argument is set
Teruab4b01a2013-06-20 10:09:57 -0700284 * Expect:
Jonathan Hart56d15772013-11-03 19:09:59 -0800285 * 1.Nothing happen when you put unregistered MAC address
Teruab4b01a2013-06-20 10:09:57 -0700286 * 2.Get the proper IDeviceObject.
287 * 3.Check the IDeviceObject properties set expectedly.
288 */
Teruab4b01a2013-06-20 10:09:57 -0700289 @Test
290 public void testGetDeviceByMac() {
Jonathan Hart56d15772013-11-03 19:09:59 -0800291 String mac = "99:99:99:99:99:99";
292
293 IDeviceObject mockDevice = createMock(IDeviceObject.class);
294
295 expect(mockOpe.searchDevice(mac)).andReturn(mockDevice);
296
297 replay(mockOpe);
298
299 IDeviceObject result = deviceImpl.getDeviceByMac(mac);
300 assertNotNull(result);
301
302 verify(mockOpe);
Teruab4b01a2013-06-20 10:09:57 -0700303 }
Jonathan Hart56d15772013-11-03 19:09:59 -0800304
Teruab4b01a2013-06-20 10:09:57 -0700305 /**
Jonathan Hart56d15772013-11-03 19:09:59 -0800306 * Description:
Teruab4b01a2013-06-20 10:09:57 -0700307 * Test method for getDeviceByIP method.
308 * Condition:
Jonathan Hart56d15772013-11-03 19:09:59 -0800309 * 1. Unregistered IP address argument is set
Teruab4b01a2013-06-20 10:09:57 -0700310 * Expect:
Jonathan Hart56d15772013-11-03 19:09:59 -0800311 * 1. Nothing happen when you put unregistered IP address
Teruab4b01a2013-06-20 10:09:57 -0700312 * 2. Get the proper IDeviceObject.
313 * 3. Check the IDeviceObject properties set expectedly.
314 */
Teruab4b01a2013-06-20 10:09:57 -0700315 @Test
316 public void testGetDeviceByIP() {
Jonathan Hart56d15772013-11-03 19:09:59 -0800317 int nonExistingIp = InetAddresses.coerceToInteger(InetAddresses.forString("192.168.10.50"));
318 int existingIp = InetAddresses.coerceToInteger(InetAddresses.forString("10.5.12.128"));
319
320 IDeviceObject mockDevice = createMock(IDeviceObject.class);
321 IIpv4Address mockExistingIp = createMock(IIpv4Address.class);
322 expect(mockExistingIp.getDevice()).andReturn(mockDevice);
323
324 expect(mockOpe.searchIpv4Address(nonExistingIp)).andReturn(null);
325 expect(mockOpe.searchIpv4Address(existingIp)).andReturn(mockExistingIp);
326
327 replay(mockExistingIp);
328 replay(mockOpe);
329
330 IDeviceObject result = deviceImpl.getDeviceByIP(nonExistingIp);
331 assertNull(result);
332
333 result = deviceImpl.getDeviceByIP(existingIp);
334 assertNotNull(result);
335
336 verify(mockOpe);
Teruab4b01a2013-06-20 10:09:57 -0700337 }
338
339 /**
Jonathan Hart56d15772013-11-03 19:09:59 -0800340 * Description:
Teruab4b01a2013-06-20 10:09:57 -0700341 * Test method for testChangeDeviceAttachmentsIDevice
342 * Condition:
Jonathan Hart56d15772013-11-03 19:09:59 -0800343 * 1. The device is not currently attached to any point.
Teruab4b01a2013-06-20 10:09:57 -0700344 * Expect:
Jonathan Hart56d15772013-11-03 19:09:59 -0800345 * 1. Nothing happen when you put nonexistent attachment point.
Teruab4b01a2013-06-20 10:09:57 -0700346 * 2. Set the attachment point expectedly;
347 */
Teruab4b01a2013-06-20 10:09:57 -0700348 @Test
Jonathan Hart56d15772013-11-03 19:09:59 -0800349 public void testChangeDeviceAttachementsWhenUnattached() {
350 String strMacAddress = "99:99:99:99:99:99";
351 long attachmentDpid = HexString.toLong("00:00:00:00:00:00:0a:01");
352 short attachmentPort = 2;
353 int intIpv4Address = InetAddresses.coerceToInteger(InetAddresses.forString("192.168.100.1"));
354
355 IDevice device = getMockDevice(strMacAddress, attachmentDpid, attachmentPort, intIpv4Address);
356
357 IDeviceObject mockDeviceObject = createMock(IDeviceObject.class);
358 IPortObject mockPortObject = getMockPort(attachmentDpid, attachmentPort);
359
360 expect(mockOpe.searchDevice(strMacAddress)).andReturn(mockDeviceObject);
361 expect(mockDeviceObject.getAttachedPorts()).andReturn(Collections.<IPortObject>emptyList());
362 expect(mockOpe.searchPort(HexString.toHexString(attachmentDpid), attachmentPort)).andReturn(mockPortObject);
363 mockPortObject.setDevice(mockDeviceObject);
364 mockOpe.commit();
365
366 replay(mockDeviceObject);
367 replay(mockPortObject);
368 replay(mockOpe);
369
370 deviceImpl.changeDeviceAttachments(device);
371
372 verify(mockDeviceObject);
373 verify(mockPortObject);
374 verify(mockOpe);
375 }
Teruab4b01a2013-06-20 10:09:57 -0700376
Jonathan Hart56d15772013-11-03 19:09:59 -0800377 /**
378 * Description:
379 * Test method for testChangeDeviceAttachmentsIDevice
380 * Condition:
381 * 1. The device is currently attached to a switch, but this attachment point
382 * has now changed.
383 * Expect:
384 * 1. The device should be removed from the old attachment point.
385 * 2. Set the attachment point expectedly;
386 */
387 @Test
388 public void testChangeDeviceAttachementsWhenAttached() {
389 String strMacAddress = "99:99:99:99:99:99";
390 long attachmentDpid = HexString.toLong("00:00:00:00:00:00:0a:01");
391 short attachmentPort = 2;
392 int intIpv4Address = InetAddresses.coerceToInteger(InetAddresses.forString("192.168.100.1"));
393
394 //Details for the port the device will be moved from
395 long alreadyAttachedDpid = HexString.toLong("00:00:00:00:00:00:0b:01");
396 short alreadyAttachedPort = 5;
397
398 IDevice device = getMockDevice(strMacAddress, attachmentDpid, attachmentPort, intIpv4Address);
399
400 IDeviceObject mockDeviceObject = createMock(IDeviceObject.class);
401 IPortObject mockPortObject = getMockPort(attachmentDpid, attachmentPort);
402 IPortObject alreadyAttachedPortObject = getMockPort(alreadyAttachedDpid, alreadyAttachedPort);
403
404 expect(mockOpe.searchDevice(strMacAddress)).andReturn(mockDeviceObject);
405 expect(mockDeviceObject.getAttachedPorts()).andReturn(Collections.singletonList(alreadyAttachedPortObject));
406 expect(mockOpe.searchPort(HexString.toHexString(attachmentDpid), attachmentPort)).andReturn(mockPortObject);
407 mockPortObject.setDevice(mockDeviceObject);
408 alreadyAttachedPortObject.removeDevice(mockDeviceObject);
409 mockOpe.commit();
410
411 replay(mockDeviceObject);
412 replay(alreadyAttachedPortObject);
413 replay(mockPortObject);
414 replay(mockOpe);
415
416 deviceImpl.changeDeviceAttachments(device);
417
418 verify(mockDeviceObject);
419 verify(alreadyAttachedPortObject);
420 verify(mockPortObject);
421 verify(mockOpe);
Teruab4b01a2013-06-20 10:09:57 -0700422 }
423
Teru4fd58642013-06-21 07:54:49 -0700424 @Ignore
Teruab4b01a2013-06-20 10:09:57 -0700425 @Test
426 public void testChangeDeviceAttachmentsIDeviceIDeviceObject() {
427 //It is tested by the testChangeDeviceAttachmentsIDevice
Teruab4b01a2013-06-20 10:09:57 -0700428 }
429
430 /**
Jonathan Hart56d15772013-11-03 19:09:59 -0800431 * Description:
Teruab4b01a2013-06-20 10:09:57 -0700432 * Test method for testChangeDeviceIPv4Address
433 * Condition:
434 * N/A
435 * Expect:
Jonathan Hart56d15772013-11-03 19:09:59 -0800436 * 1. Set the IP address expectedly.
Teruab4b01a2013-06-20 10:09:57 -0700437 */
Teruab4b01a2013-06-20 10:09:57 -0700438 @Test
Jonathan Hart56d15772013-11-03 19:09:59 -0800439 public void testChangeDeviceIpv4Address() {
440 String strMacAddress = "99:99:99:99:99:99";
441 long attachmentDpid = HexString.toLong("00:00:00:00:00:00:0a:01");
442 short attachmentPort = 2;
443 int intIpv4Address = InetAddresses.coerceToInteger(InetAddresses.forString("192.168.100.1"));
444
445 IDevice device = getMockDevice(strMacAddress, attachmentDpid, attachmentPort, intIpv4Address);
446
447 IDeviceObject mockDeviceObject = createMock(IDeviceObject.class);
448 IIpv4Address mockIpv4Address = createMock(IIpv4Address.class);
449
450 expect(mockOpe.searchDevice(strMacAddress)).andReturn(mockDeviceObject);
451 expect(mockDeviceObject.getIpv4Address(intIpv4Address)).andReturn(null);
452 expect(mockOpe.ensureIpv4Address(intIpv4Address)).andReturn(mockIpv4Address);
453 mockDeviceObject.addIpv4Address(mockIpv4Address);
454 expect(mockDeviceObject.getIpv4Addresses()).andReturn(Collections.singletonList(mockIpv4Address));
455 expect(mockIpv4Address.getIpv4Address()).andReturn(intIpv4Address);
456 mockOpe.commit();
457
458 replay(mockDeviceObject);
459 replay(mockIpv4Address);
460 replay(mockOpe);
461
462 deviceImpl.changeDeviceIPv4Address(device);
463
464 verify(mockDeviceObject);
465 verify(mockIpv4Address);
466 verify(mockOpe);
467 }
468
469 /**
470 * Description:
471 * Test method for testChangeDeviceIPv4Address
472 * Condition:
473 * 1. The device had an old IP address which has now changed.
474 * Expect:
475 * 1. The old IP address should be removed from the device.
476 * 2. Set the IP address expectedly.
477 */
478 @Test
479 public void testChangeDeviceIpv4AddressAndRemoveExisting() {
480 String strMacAddress = "99:99:99:99:99:99";
481 long attachmentDpid = HexString.toLong("00:00:00:00:00:00:0a:01");
482 short attachmentPort = 2;
483 int intIpv4Address = InetAddresses.coerceToInteger(InetAddresses.forString("192.168.100.1"));
484
485 IDevice device = getMockDevice(strMacAddress, attachmentDpid, attachmentPort, intIpv4Address);
486
487 IDeviceObject mockDeviceObject = createMock(IDeviceObject.class);
488
489 IIpv4Address mockIpv4Address = createMock(IIpv4Address.class);
490 IIpv4Address mockDeletingIpv4Address = createMock(IIpv4Address.class);
491 List<IIpv4Address> ipv4Vertices = new ArrayList<IIpv4Address>(2);
492 ipv4Vertices.add(mockIpv4Address);
493 ipv4Vertices.add(mockDeletingIpv4Address);
494
495 expect(mockOpe.searchDevice(strMacAddress)).andReturn(mockDeviceObject);
496 expect(mockDeviceObject.getIpv4Address(intIpv4Address)).andReturn(null);
497 expect(mockOpe.ensureIpv4Address(intIpv4Address)).andReturn(mockIpv4Address);
498 mockDeviceObject.addIpv4Address(mockIpv4Address);
499 expect(mockDeviceObject.getIpv4Addresses()).andReturn(ipv4Vertices);
500 expect(mockIpv4Address.getIpv4Address()).andReturn(intIpv4Address);
501 expect(mockDeletingIpv4Address.getIpv4Address()).andReturn(1);
502 mockDeviceObject.removeIpv4Address(mockDeletingIpv4Address);
503 mockOpe.commit();
504
505 replay(mockDeviceObject);
506 replay(mockIpv4Address);
507 replay(mockOpe);
508
509 deviceImpl.changeDeviceIPv4Address(device);
510
511 verify(mockDeviceObject);
512 verify(mockIpv4Address);
513 verify(mockOpe);
Teruab4b01a2013-06-20 10:09:57 -0700514 }
515
516}