blob: 223ac67df99ebf35ae54d24555171cabe1a65e2c [file] [log] [blame]
Toshio Koide9d8856e2013-06-12 16:48:11 -07001/**
2 *
3 */
4package net.onrc.onos.util;
5
6import static org.junit.Assert.*;
7
Toshio Koide880f4c72013-06-17 14:43:11 -07008import java.util.*;
Toshio Koide3c460e12013-06-13 11:55:12 -07009
Toshio Koide880f4c72013-06-17 14:43:11 -070010import junit.framework.TestCase;
11
12import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IDeviceObject;
13import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
14import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
15import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
Toshio Koideb29b9b32013-06-13 14:37:46 -070016import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
17import net.onrc.onos.ofcontroller.core.ISwitchStorage.SwitchState;
HIGUCHI Yuta08137932013-06-17 14:11:50 -070018import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager;
Toshio Koide880f4c72013-06-17 14:43:11 -070019import net.onrc.onos.ofcontroller.util.FlowEntryId;
20import net.onrc.onos.ofcontroller.util.FlowId;
Toshio Koide9d8856e2013-06-12 16:48:11 -070021
22import org.easymock.EasyMock;
23import org.junit.After;
24import org.junit.AfterClass;
25import org.junit.Before;
26import org.junit.BeforeClass;
27import org.junit.Test;
28import org.junit.runner.RunWith;
29import org.powermock.api.easymock.PowerMock;
30import org.powermock.core.classloader.annotations.PrepareForTest;
31import org.powermock.modules.junit4.PowerMockRunner;
32
33import com.thinkaurelius.titan.core.TitanFactory;
34import com.thinkaurelius.titan.core.TitanGraph;
Toshio Koide3c460e12013-06-13 11:55:12 -070035import com.tinkerpop.blueprints.Vertex;
Toshio Koide9d8856e2013-06-12 16:48:11 -070036
37/**
38 * @author Toshio Koide
39 *
40 */
Toshio Koide880f4c72013-06-17 14:43:11 -070041
Toshio Koide9d8856e2013-06-12 16:48:11 -070042@RunWith(PowerMockRunner.class)
43@PrepareForTest({TitanFactory.class})
Toshio Koide880f4c72013-06-17 14:43:11 -070044public class GraphDBOperationTest extends TestCase {
Toshio Koide3c460e12013-06-13 11:55:12 -070045 private static TitanGraph testdb;
Toshio Koide9d8856e2013-06-12 16:48:11 -070046 private static GraphDBOperation op;
47
48 /**
49 * @throws java.lang.Exception
50 */
51 @BeforeClass
52 public static void setUpBeforeClass() throws Exception {
53 }
54
55 /**
56 * @throws java.lang.Exception
57 */
58 @AfterClass
59 public static void tearDownAfterClass() throws Exception {
60 }
61
62 /**
63 * @throws java.lang.Exception
64 */
65 @Before
66 public void setUp() throws Exception {
67 TestDatabaseManager.deleteTestDatabase();
Toshio Koide3c460e12013-06-13 11:55:12 -070068 testdb = TestDatabaseManager.getTestDatabase();
Toshio Koide9d8856e2013-06-12 16:48:11 -070069// TestDatabaseManager.populateTestData(titanGraph);
Toshio Koide880f4c72013-06-17 14:43:11 -070070
71 String dummyPath = "/dummy/to/conf";
Toshio Koide9d8856e2013-06-12 16:48:11 -070072 // replace return value of TitanFactory.open() to dummy DB created above
73 PowerMock.mockStatic(TitanFactory.class);
Toshio Koide880f4c72013-06-17 14:43:11 -070074 EasyMock.expect(TitanFactory.open(dummyPath)).andReturn(testdb);
Toshio Koide9d8856e2013-06-12 16:48:11 -070075 PowerMock.replay(TitanFactory.class);
76
Toshio Koidebfe9b922013-06-18 10:56:05 -070077 op = new GraphDBOperation(dummyPath);
Toshio Koide9d8856e2013-06-12 16:48:11 -070078 }
79
80 /**
81 * @throws java.lang.Exception
82 */
83 @After
84 public void tearDown() throws Exception {
Toshio Koidebfe9b922013-06-18 10:56:05 -070085 op.close();
Toshio Koide3c460e12013-06-13 11:55:12 -070086 testdb.shutdown();
Toshio Koide880f4c72013-06-17 14:43:11 -070087 PowerMock.verifyAll();
Toshio Koide9d8856e2013-06-12 16:48:11 -070088 }
89
90 /**
91 * Test method for {@link net.onrc.onos.util.GraphDBOperation#newSwitch(net.onrc.onos.util.GraphDBConnection)}.
92 */
93 @Test
94 public final void testNewSwitch() {
Toshio Koide880f4c72013-06-17 14:43:11 -070095 assertNull(op.searchSwitch("123"));
Toshio Koide9d8856e2013-06-12 16:48:11 -070096
Toshio Koide880f4c72013-06-17 14:43:11 -070097 op.newSwitch("123");
Toshio Koidea9a03002013-06-13 13:10:48 -070098 op.commit();
Toshio Koide9d8856e2013-06-12 16:48:11 -070099
Toshio Koide880f4c72013-06-17 14:43:11 -0700100 ISwitchObject sw = op.searchSwitch("123");
101 assertNotNull(op);
102 assertEquals("123", sw.getDPID());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700103 }
104
105 /**
106 * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchSwitch(net.onrc.onos.util.GraphDBConnection, java.lang.String)}.
107 */
108 @Test
109 public final void testSearchSwitch() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700110 op.newSwitch("123");
111 op.newSwitch("456");
Toshio Koidea9a03002013-06-13 13:10:48 -0700112 op.commit();
Toshio Koide880f4c72013-06-17 14:43:11 -0700113
114 ISwitchObject sw = op.searchSwitch("123");
Toshio Koide3c460e12013-06-13 11:55:12 -0700115 assertNotNull(sw);
116 assertEquals("123", sw.getDPID());
Toshio Koide880f4c72013-06-17 14:43:11 -0700117
118 sw = op.searchSwitch("789");
119 assertNull(sw);
Toshio Koide3c460e12013-06-13 11:55:12 -0700120 }
121
122 /**
123 * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchActiveSwitch(net.onrc.onos.util.GraphDBConnection, java.lang.String)}.
124 */
125 @Test
126 public final void testSearchActiveSwitch() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700127 op.newSwitch("111").setState(SwitchState.ACTIVE.toString());
128 op.newSwitch("222").setState(SwitchState.INACTIVE.toString());
Toshio Koidea9a03002013-06-13 13:10:48 -0700129 op.commit();
130
Toshio Koide880f4c72013-06-17 14:43:11 -0700131 ISwitchObject sw = op.searchActiveSwitch("111");
Toshio Koide3c460e12013-06-13 11:55:12 -0700132 assertNotNull(sw);
133 assertEquals("111", sw.getDPID());
134
135 sw = op.searchActiveSwitch("222");
136 assertNull(sw);
137 }
138
139 /**
140 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getActiveSwitches(net.onrc.onos.util.GraphDBConnection)}.
141 */
142 @Test
143 public final void testGetActiveSwitches() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700144 op.newSwitch("111").setState(SwitchState.ACTIVE.toString());
145 op.newSwitch("222").setState(SwitchState.INACTIVE.toString());
Toshio Koidea9a03002013-06-13 13:10:48 -0700146 op.commit();
Toshio Koide3c460e12013-06-13 11:55:12 -0700147
148 Iterator<ISwitchObject> i = op.getActiveSwitches().iterator();
Toshio Koide880f4c72013-06-17 14:43:11 -0700149
Toshio Koide3c460e12013-06-13 11:55:12 -0700150 assertTrue(i.hasNext());
151 assertEquals("111", i.next().getDPID());
Toshio Koide880f4c72013-06-17 14:43:11 -0700152 assertFalse(i.hasNext());
153 }
154
155 /**
156 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllSwitches(net.onrc.onos.util.GraphDBConnection)}.
157 */
158 @Test
159 public final void testGetAllSwitches() {
160 List<String> dpids = Arrays.asList("111", "222", "333");
161 Collections.sort(dpids);
162
163 for (String dpid: dpids) op.newSwitch(dpid);
164 op.commit();
165
166 List<String> actual_ids = new ArrayList<String>();
167 for (ISwitchObject switchObj: op.getAllSwitches()) actual_ids.add(switchObj.getDPID());
168 Collections.sort(actual_ids);
169
170 assertArrayEquals(dpids.toArray(), actual_ids.toArray());
171 }
172
173 /**
174 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getInactiveSwitches(net.onrc.onos.util.GraphDBConnection)}.
175 */
176 @Test
177 public final void testGetInactiveSwitches() {
178 op.newSwitch("111").setState(SwitchState.ACTIVE.toString());
179 op.newSwitch("222").setState(SwitchState.INACTIVE.toString());
180 op.commit();
181
182 Iterator<ISwitchObject> i = op.getInactiveSwitches().iterator();
183
184 assertTrue(i.hasNext());
185 assertEquals("222", i.next().getDPID());
186 assertFalse(i.hasNext());
187 }
188
189 /**
190 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllSwitchNotUpdatedFlowEntries(net.onrc.onos.util.GraphDBConnection)}.
191 */
192 @Test
193 public final void testGetAllSwitchNotUpdatedFlowEntries() {
194 FlowEntryId flowEntryId10 = new FlowEntryId(10);
195 FlowEntryId flowEntryId20 = new FlowEntryId(20);
196 IFlowEntry flowEntry10 = op.newFlowEntry();
197 IFlowEntry flowEntry20 = op.newFlowEntry();
198 flowEntry10.setFlowEntryId(flowEntryId10.toString());
199 flowEntry20.setFlowEntryId(flowEntryId20.toString());
200 flowEntry10.setSwitchState("FE_SWITCH_NOT_UPDATED");
201 flowEntry20.setSwitchState("FE_SWITCH_UPDATED");
202 op.commit();
203
204 Iterator<IFlowEntry> flowEntries = op.getAllSwitchNotUpdatedFlowEntries().iterator();
205 assertNotNull(flowEntries);
206 assertTrue(flowEntries.hasNext());
207 assertEquals(flowEntryId10.toString(), flowEntries.next().getFlowEntryId());
208 assertFalse(flowEntries.hasNext());
Toshio Koide3c460e12013-06-13 11:55:12 -0700209 }
210
211 /**
212 * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeSwitch(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject)}.
213 */
214 @Test
215 public final void testRemoveSwitch() {
216 ISwitchObject sw = op.newSwitch("123");
Toshio Koidea9a03002013-06-13 13:10:48 -0700217 op.commit();
Toshio Koide3c460e12013-06-13 11:55:12 -0700218 sw = op.searchSwitch("123");
Toshio Koide880f4c72013-06-17 14:43:11 -0700219 assertNotNull(sw);
220
Toshio Koide3c460e12013-06-13 11:55:12 -0700221 op.removeSwitch(sw);
Toshio Koide880f4c72013-06-17 14:43:11 -0700222 op.commit();
223
224 assertNull(op.searchSwitch("123"));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700225 }
226
227 /**
228 * Test method for {@link net.onrc.onos.util.GraphDBOperation#newPort(net.onrc.onos.util.GraphDBConnection)}.
229 */
230 @Test
231 public final void testNewPort() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700232 assertFalse(testdb.getVertices("type", "port").iterator().hasNext());
233
234 IPortObject port = op.newPort((short) 10);
235 assertTrue(port.getNumber() == 10);
236 op.commit();
237
238 Iterator<Vertex> vertices = testdb.getVertices("type", "port").iterator();
239 assertTrue(vertices.hasNext());
240 assertEquals(vertices.next().getProperty("number").toString(), "10");
Toshio Koide9d8856e2013-06-12 16:48:11 -0700241 }
242
243 /**
Toshio Koide880f4c72013-06-17 14:43:11 -0700244 * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchPort(net.onrc.onos.util.GraphDBConnection, java.lang.String, short)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700245 */
246 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700247 public final void testSearchPort() {
248 ISwitchObject sw;
249 IPortObject port;
250
251 sw = op.newSwitch("1");
252 sw.addPort(op.newPort((short) 1));
253 sw.addPort(op.newPort((short) 2));
254
255 sw = op.newSwitch("2");
256 sw.addPort(op.newPort((short) 1));
257 sw.addPort(op.newPort((short) 2));
258
259 op.commit();
260
261 assertNull(op.searchPort("3", (short) 1));
262 assertNull(op.searchPort("1", (short) 3));
263
264 port = op.searchPort("1", (short) 1);
265 assertNotNull(port);
266 assertTrue(port.getNumber() == 1);
267 sw = port.getSwitch();
268 assertNotNull(sw);
269 assertEquals("1", sw.getDPID());
270
271 port = op.searchPort("1", (short) 2);
272 assertNotNull(port);
273 assertTrue(port.getNumber() == 2);
274 sw = port.getSwitch();
275 assertNotNull(sw);
276 assertEquals("1", sw.getDPID());
277
278 port = op.searchPort("2", (short) 1);
279 assertNotNull(port);
280 assertTrue(port.getNumber() == 1);
281 sw = port.getSwitch();
282 assertNotNull(sw);
283 assertEquals("2", sw.getDPID());
284
285 port = op.searchPort("2", (short) 2);
286 assertNotNull(port);
287 assertTrue(port.getNumber() == 2);
288 sw = port.getSwitch();
289 assertNotNull(sw);
290 assertEquals("2", sw.getDPID());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700291 }
292
293 /**
294 * Test method for {@link net.onrc.onos.util.GraphDBOperation#removePort(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IPortObject)}.
295 */
296 @Test
297 public final void testRemovePort() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700298 ISwitchObject sw;
299 IPortObject port;
300
301 sw = op.newSwitch("1");
302 sw.addPort(op.newPort((short) 1));
303 sw.addPort(op.newPort((short) 2));
304
305 op.commit();
306
307 port = op.searchPort("1", (short) 1);
308 assertNotNull(port);
309 assertNotNull(op.searchPort("1", (short) 2));
310 assertNull(op.searchPort("1", (short) 3));
311
312 op.removePort(port);
313 op.commit();
314
315 assertNull(op.searchPort("1", (short) 1));
316 port = op.searchPort("1", (short) 2);
317 assertNotNull(port);
318
319 op.removePort(port);
320 op.commit();
321
322 assertNull(op.searchPort("1", (short) 1));
323 assertNull(op.searchPort("1", (short) 2));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700324 }
325
326 /**
Toshio Koide880f4c72013-06-17 14:43:11 -0700327 * Test method for {@link net.onrc.onos.util.GraphDBOperation#newDevice(net.onrc.onos.util.GraphDBConnection)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700328 */
329 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700330 public final void testNewDevice() {
331 assertFalse(testdb.getVertices("type", "device").iterator().hasNext());
332
333 IDeviceObject device = op.newDevice();
334 device.setMACAddress("11:22:33:44:55:66");
335 device.setIPAddress("192.168.1.1");
336 op.commit();
337
338 Iterator<Vertex> vertices = testdb.getVertices("type", "device").iterator();
339 assertTrue(vertices.hasNext());
340 Vertex v = vertices.next();
341 assertEquals("11:22:33:44:55:66", v.getProperty("dl_addr").toString());
342 assertEquals("192.168.1.1", v.getProperty("nw_addr").toString());
343 }
344
345 /**
346 * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchDevice(net.onrc.onos.util.GraphDBConnection, java.lang.String)}.
347 */
348 @Test
349 public final void testSearchDevice() {
350 assertNull(op.searchDevice("11:22:33:44:55:66"));
351 assertNull(op.searchDevice("66:55:44:33:22:11"));
352
353 op.newDevice().setMACAddress("11:22:33:44:55:66");
354 op.commit();
355
356 IDeviceObject device = op.searchDevice("11:22:33:44:55:66");
357 assertNotNull(device);
358 assertEquals("11:22:33:44:55:66", device.getMACAddress());
359
360 assertNull(op.searchDevice("66:55:44:33:22:11"));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700361 }
362
363 /**
364 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getDevices(net.onrc.onos.util.GraphDBConnection)}.
365 */
366 @Test
367 public final void testGetDevices() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700368 List<String> original_macs = Arrays.asList(
369 "11:11:11:11:11:11",
370 "22:22:22:22:22:22",
371 "33:33:33:33:33:33"
372 );
373
374 for (String mac: original_macs) op.newDevice().setMACAddress(mac);
375 op.commit();
376
377 Iterable<IDeviceObject> devices = op.getDevices();
378 List<String> macs = new ArrayList<String>();
379 for (IDeviceObject device: devices) macs.add(device.getMACAddress());
380 Collections.sort(macs);
381 assertArrayEquals(original_macs.toArray(), macs.toArray());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700382 }
383
384 /**
Toshio Koide880f4c72013-06-17 14:43:11 -0700385 * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeDevice(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IDeviceObject)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700386 */
387 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700388 public final void testRemoveDevice() {
389 op.newDevice().setMACAddress("11:22:33:44:55:66");
390 op.commit();
391
392 op.removeDevice(op.searchDevice("11:22:33:44:55:66"));
393 op.commit();
394 assertNull(op.searchDevice("11:22:33:44:55:66"));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700395 }
396
397 /**
398 * Test method for {@link net.onrc.onos.util.GraphDBOperation#newFlowPath(net.onrc.onos.util.GraphDBConnection)}.
399 */
400 @Test
401 public final void testNewFlowPath() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700402 FlowId flowId = new FlowId(10);
403 IFlowPath flowPath = op.newFlowPath();
404 flowPath.setFlowId(flowId.toString());
405 op.commit();
406
407 Iterator<IFlowPath> flows = op.getAllFlowPaths().iterator();
408 assertTrue(flows.hasNext());
409 assertEquals(flowId.toString(), flows.next().getFlowId());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700410 }
411
412 /**
Toshio Koide880f4c72013-06-17 14:43:11 -0700413 * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchFlowPath(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.util.FlowId)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700414 */
415 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700416 public final void testSearchFlowPath() {
417 FlowId flowId = new FlowId(20);
418 assertNull(op.searchFlowPath(flowId));
419
420 op.newFlowPath().setFlowId(flowId.toString());
421 op.commit();
422
423 IFlowPath flowPath = op.searchFlowPath(flowId);
424 assertNotNull(flowPath);
425 assertEquals(flowId.toString(), flowPath.getFlowId());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700426 }
427
428 /**
429 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getFlowPathByFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry)}.
430 */
431 @Test
432 public final void testGetFlowPathByFlowEntry() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700433 FlowId flowId10 = new FlowId(10);
434 FlowId flowId20 = new FlowId(20);
435 IFlowPath flowPath10 = op.newFlowPath();
436 IFlowPath flowPath20 = op.newFlowPath();
437 IFlowEntry flowEntry10 = op.newFlowEntry();
438 IFlowEntry flowEntry20 = op.newFlowEntry();
439 IFlowEntry flowEntry30 = op.newFlowEntry();
440 FlowEntryId flowEntryId10 = new FlowEntryId(10);
441 FlowEntryId flowEntryId20 = new FlowEntryId(20);
442 FlowEntryId flowEntryId30 = new FlowEntryId(30);
443 flowEntry10.setFlowEntryId(flowEntryId10.toString());
444 flowEntry20.setFlowEntryId(flowEntryId20.toString());
445 flowEntry30.setFlowEntryId(flowEntryId30.toString());
446 flowPath10.setFlowId(flowId10.toString());
447 flowPath10.addFlowEntry(flowEntry10);
448 flowPath20.setFlowId(flowId20.toString());
449 flowPath20.addFlowEntry(flowEntry20);
450 op.commit();
451
452 flowEntry10 = op.searchFlowEntry(flowEntryId10);
453 IFlowPath obtainedFlowPath = op.getFlowPathByFlowEntry(flowEntry10);
454 assertNotNull(obtainedFlowPath);
455 assertEquals(flowId10.toString(), obtainedFlowPath.getFlowId());
456
457 flowEntry20 = op.searchFlowEntry(flowEntryId20);
458 obtainedFlowPath = op.getFlowPathByFlowEntry(flowEntry20);
459 assertNotNull(obtainedFlowPath);
460 assertEquals(flowId20.toString(), obtainedFlowPath.getFlowId());
461
462 flowEntry30 = op.searchFlowEntry(flowEntryId30);
463 obtainedFlowPath = op.getFlowPathByFlowEntry(flowEntry30);
464 assertNull(obtainedFlowPath);
Toshio Koide9d8856e2013-06-12 16:48:11 -0700465 }
466
467 /**
468 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllFlowPaths(net.onrc.onos.util.GraphDBConnection)}.
469 */
470 @Test
471 public final void testGetAllFlowPaths() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700472 List<FlowId> flowids = Arrays.asList(
473 new FlowId(10), new FlowId(20), new FlowId(30)
474 );
475
476 for (FlowId flowId: flowids)
477 op.newFlowPath().setFlowId(flowId.toString());
478 op.commit();
479
480 List<String> actual_ids = new ArrayList<String>();
481 for (IFlowPath flowPath: op.getAllFlowPaths()) actual_ids.add(flowPath.getFlowId());
482 Collections.sort(actual_ids);
483
484 List<String> expected_ids = new ArrayList<String>();
485 for (FlowId flowid: flowids) expected_ids.add(flowid.toString());
486 Collections.sort(expected_ids);
487
488 assertArrayEquals(expected_ids.toArray(), actual_ids.toArray());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700489 }
490
491 /**
Toshio Koide880f4c72013-06-17 14:43:11 -0700492 * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeFlowPath(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowPath)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700493 */
494 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700495 public final void testRemoveFlowPath() {
496 FlowId flowId10 = new FlowId(10);
497 FlowId flowId20 = new FlowId(20);
498 op.newFlowPath().setFlowId(flowId10.toString());
499 op.newFlowPath().setFlowId(flowId20.toString());
500 op.commit();
501
502 IFlowPath flowPath = op.searchFlowPath(flowId10);
503 assertNotNull(flowPath);
504 op.removeFlowPath(flowPath);
505 op.commit();
506
507 assertNull(op.searchFlowPath(flowId10));
508 assertNotNull(op.searchFlowPath(flowId20));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700509 }
510
511 /**
512 * Test method for {@link net.onrc.onos.util.GraphDBOperation#newFlowEntry(net.onrc.onos.util.GraphDBConnection)}.
513 */
514 @Test
515 public final void testNewFlowEntry() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700516 IFlowEntry flowEntry = op.newFlowEntry();
517 FlowEntryId flowEntryId = new FlowEntryId();
518 flowEntryId.setValue(12345);
519 flowEntry.setFlowEntryId(flowEntryId.toString());
520 op.commit();
521
522 flowEntry = op.searchFlowEntry(flowEntryId);
523 assertNotNull(flowEntry);
524 assertEquals(flowEntry.getFlowEntryId(), flowEntryId.toString());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700525 }
526
527 /**
Toshio Koide880f4c72013-06-17 14:43:11 -0700528 * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.util.FlowEntryId)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700529 */
530 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700531 public final void testSearchFlowEntry() {
532 FlowEntryId flowEntryId10 = new FlowEntryId();
533 flowEntryId10.setValue(10);
534 FlowEntryId flowEntryId20 = new FlowEntryId();
535 flowEntryId20.setValue(20);
536 FlowEntryId flowEntryId30 = new FlowEntryId();
537 flowEntryId30.setValue(30);
538
539 op.newFlowEntry().setFlowEntryId(flowEntryId10.toString());
540 op.newFlowEntry().setFlowEntryId(flowEntryId20.toString());
541 op.commit();
542
543 assertNull(op.searchFlowEntry(flowEntryId30));
544 IFlowEntry flowEntry = op.searchFlowEntry(flowEntryId10);
545 assertEquals(flowEntry.getFlowEntryId(), flowEntryId10.toString());
546 flowEntry = op.searchFlowEntry(flowEntryId20);
547 assertEquals(flowEntry.getFlowEntryId(), flowEntryId20.toString());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700548 }
549
550 /**
551 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllFlowEntries(net.onrc.onos.util.GraphDBConnection)}.
552 */
553 @Test
554 public final void testGetAllFlowEntries() {
Toshio Koide880f4c72013-06-17 14:43:11 -0700555 List<FlowEntryId> flowEntryIds = Arrays.asList(
556 new FlowEntryId(10), new FlowEntryId(20), new FlowEntryId(30)
557 );
558
559 for (FlowEntryId flowEntryId: flowEntryIds)
560 op.newFlowEntry().setFlowEntryId(flowEntryId.toString());
561 op.commit();
562
563 List<String> actual_ids = new ArrayList<String>();
564 for (IFlowEntry flowEntry: op.getAllFlowEntries()) actual_ids.add(flowEntry.getFlowEntryId());
565 Collections.sort(actual_ids);
566
567 List<String> expected_ids = new ArrayList<String>();
568 for (FlowEntryId flowEntryId: flowEntryIds) expected_ids.add(flowEntryId.toString());
569 Collections.sort(expected_ids);
570
571 assertArrayEquals(expected_ids.toArray(), actual_ids.toArray());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700572 }
573
574 /**
Toshio Koide880f4c72013-06-17 14:43:11 -0700575 * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry)}.
Toshio Koide9d8856e2013-06-12 16:48:11 -0700576 */
577 @Test
Toshio Koide880f4c72013-06-17 14:43:11 -0700578 public final void testRemoveFlowEntry() {
579 FlowEntryId flowEntryId10 = new FlowEntryId(10);
580 FlowEntryId flowEntryId20 = new FlowEntryId(20);
581 op.newFlowEntry().setFlowEntryId(flowEntryId10.toString());
582 op.newFlowEntry().setFlowEntryId(flowEntryId20.toString());
583 op.commit();
584
585 IFlowEntry flowEntry = op.searchFlowEntry(flowEntryId10);
586 assertNotNull(flowEntry);
587 op.removeFlowEntry(flowEntry);
588 op.commit();
589
590 assertNull(op.searchFlowEntry(flowEntryId10));
591 assertNotNull(op.searchFlowEntry(flowEntryId20));
Toshio Koide9d8856e2013-06-12 16:48:11 -0700592 }
593
Toshio Koide9d8856e2013-06-12 16:48:11 -0700594}