blob: d1e1c39b7f7a198258a8aa0b6bfedeb332458e93 [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 Koide3c460e12013-06-13 11:55:12 -07008import java.util.Iterator;
9
Toshio Koideb29b9b32013-06-13 14:37:46 -070010import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
11import net.onrc.onos.ofcontroller.core.ISwitchStorage.SwitchState;
Toshio Koide9d8856e2013-06-12 16:48:11 -070012import net.floodlightcontroller.core.internal.TestDatabaseManager;
Toshio Koide9d8856e2013-06-12 16:48:11 -070013
14import org.easymock.EasyMock;
15import org.junit.After;
16import org.junit.AfterClass;
17import org.junit.Before;
18import org.junit.BeforeClass;
19import org.junit.Test;
20import org.junit.runner.RunWith;
21import org.powermock.api.easymock.PowerMock;
22import org.powermock.core.classloader.annotations.PrepareForTest;
23import org.powermock.modules.junit4.PowerMockRunner;
24
25import com.thinkaurelius.titan.core.TitanFactory;
26import com.thinkaurelius.titan.core.TitanGraph;
Toshio Koide3c460e12013-06-13 11:55:12 -070027import com.tinkerpop.blueprints.Vertex;
Toshio Koide9d8856e2013-06-12 16:48:11 -070028
29/**
30 * @author Toshio Koide
31 *
32 */
33@RunWith(PowerMockRunner.class)
34@PrepareForTest({TitanFactory.class})
35public class GraphDBOperationTest {
Toshio Koide3c460e12013-06-13 11:55:12 -070036 private static TitanGraph testdb;
Toshio Koide9d8856e2013-06-12 16:48:11 -070037 private static GraphDBConnection conn;
38 private static GraphDBOperation op;
39
40 /**
41 * @throws java.lang.Exception
42 */
43 @BeforeClass
44 public static void setUpBeforeClass() throws Exception {
45 }
46
47 /**
48 * @throws java.lang.Exception
49 */
50 @AfterClass
51 public static void tearDownAfterClass() throws Exception {
52 }
53
54 /**
55 * @throws java.lang.Exception
56 */
57 @Before
58 public void setUp() throws Exception {
59 TestDatabaseManager.deleteTestDatabase();
Toshio Koide3c460e12013-06-13 11:55:12 -070060 testdb = TestDatabaseManager.getTestDatabase();
Toshio Koide9d8856e2013-06-12 16:48:11 -070061// TestDatabaseManager.populateTestData(titanGraph);
62
63 // replace return value of TitanFactory.open() to dummy DB created above
64 PowerMock.mockStatic(TitanFactory.class);
Toshio Koide3c460e12013-06-13 11:55:12 -070065 EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(testdb);
Toshio Koide9d8856e2013-06-12 16:48:11 -070066 PowerMock.replay(TitanFactory.class);
67
68 conn = GraphDBConnection.getInstance("/dummy/to/conf");
69 op = new GraphDBOperation(conn);
70 }
71
72 /**
73 * @throws java.lang.Exception
74 */
75 @After
76 public void tearDown() throws Exception {
77 conn.close();
Toshio Koide3c460e12013-06-13 11:55:12 -070078 testdb.shutdown();
Toshio Koide9d8856e2013-06-12 16:48:11 -070079 }
80
Toshio Koide3c460e12013-06-13 11:55:12 -070081 private Iterator<Vertex> enumerateVertices(String vertexType) {
82 return testdb.getVertices("type", vertexType).iterator();
83 }
84
Toshio Koide9d8856e2013-06-12 16:48:11 -070085 /**
86 * Test method for {@link net.onrc.onos.util.GraphDBOperation#newSwitch(net.onrc.onos.util.GraphDBConnection)}.
87 */
88 @Test
89 public final void testNewSwitch() {
Toshio Koide3c460e12013-06-13 11:55:12 -070090 Iterator<Vertex> vertices;
91 assertFalse(enumerateVertices("switch").hasNext());
Toshio Koide9d8856e2013-06-12 16:48:11 -070092
Toshio Koide727acfc2013-06-12 18:32:47 -070093 ISwitchObject sw = op.newSwitch("123");
Toshio Koide3c460e12013-06-13 11:55:12 -070094
95 assertEquals("123", sw.getDPID());
Toshio Koidea9a03002013-06-13 13:10:48 -070096 op.commit();
Toshio Koide9d8856e2013-06-12 16:48:11 -070097
Toshio Koide3c460e12013-06-13 11:55:12 -070098 vertices = enumerateVertices("switch");
99 assertTrue(vertices.hasNext());
100 assertEquals(vertices.next().getProperty("dpid").toString(), "123");
Toshio Koide9d8856e2013-06-12 16:48:11 -0700101 }
102
103 /**
104 * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchSwitch(net.onrc.onos.util.GraphDBConnection, java.lang.String)}.
105 */
106 @Test
107 public final void testSearchSwitch() {
Toshio Koide3c460e12013-06-13 11:55:12 -0700108 ISwitchObject sw = op.newSwitch("123");
Toshio Koidea9a03002013-06-13 13:10:48 -0700109 op.commit();
110
Toshio Koide3c460e12013-06-13 11:55:12 -0700111 sw = op.searchSwitch("123");
112
113 assertNotNull(sw);
114 assertEquals("123", sw.getDPID());
115 }
116
117 /**
118 * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchActiveSwitch(net.onrc.onos.util.GraphDBConnection, java.lang.String)}.
119 */
120 @Test
121 public final void testSearchActiveSwitch() {
122 ISwitchObject sw = op.newSwitch("111");
123 sw.setState(SwitchState.ACTIVE.toString());
124 sw = op.newSwitch("222");
125 sw.setState(SwitchState.INACTIVE.toString());
Toshio Koidea9a03002013-06-13 13:10:48 -0700126 op.commit();
127
Toshio Koide3c460e12013-06-13 11:55:12 -0700128 sw = op.searchActiveSwitch("111");
129 assertNotNull(sw);
130 assertEquals("111", sw.getDPID());
131
132 sw = op.searchActiveSwitch("222");
133 assertNull(sw);
134 }
135
136 /**
137 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getActiveSwitches(net.onrc.onos.util.GraphDBConnection)}.
138 */
139 @Test
140 public final void testGetActiveSwitches() {
141 ISwitchObject sw = op.newSwitch("111");
142 sw.setState(SwitchState.ACTIVE.toString());
143 sw = op.newSwitch("222");
144 sw.setState(SwitchState.INACTIVE.toString());
Toshio Koidea9a03002013-06-13 13:10:48 -0700145 op.commit();
Toshio Koide3c460e12013-06-13 11:55:12 -0700146
147 Iterator<ISwitchObject> i = op.getActiveSwitches().iterator();
148 assertTrue(i.hasNext());
149 assertEquals("111", i.next().getDPID());
150 assertFalse(i.hasNext());
151 }
152
153 /**
154 * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeSwitch(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject)}.
155 */
156 @Test
157 public final void testRemoveSwitch() {
158 ISwitchObject sw = op.newSwitch("123");
Toshio Koidea9a03002013-06-13 13:10:48 -0700159 op.commit();
Toshio Koide3c460e12013-06-13 11:55:12 -0700160 sw = op.searchSwitch("123");
161
162 op.removeSwitch(sw);
163
164 assertFalse(enumerateVertices("switch").hasNext());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700165 }
166
167 /**
168 * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchDevice(net.onrc.onos.util.GraphDBConnection, java.lang.String)}.
169 */
170 @Test
171 public final void testSearchDevice() {
172 fail("Not yet implemented");
173 }
174
175 /**
176 * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchPort(net.onrc.onos.util.GraphDBConnection, java.lang.String, short)}.
177 */
178 @Test
179 public final void testSearchPort() {
180 fail("Not yet implemented");
181 }
182
183 /**
184 * Test method for {@link net.onrc.onos.util.GraphDBOperation#newPort(net.onrc.onos.util.GraphDBConnection)}.
185 */
186 @Test
187 public final void testNewPort() {
188 fail("Not yet implemented");
189 }
190
191 /**
192 * Test method for {@link net.onrc.onos.util.GraphDBOperation#newDevice(net.onrc.onos.util.GraphDBConnection)}.
193 */
194 @Test
195 public final void testNewDevice() {
196 fail("Not yet implemented");
197 }
198
199 /**
200 * Test method for {@link net.onrc.onos.util.GraphDBOperation#removePort(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IPortObject)}.
201 */
202 @Test
203 public final void testRemovePort() {
204 fail("Not yet implemented");
205 }
206
207 /**
208 * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeDevice(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IDeviceObject)}.
209 */
210 @Test
211 public final void testRemoveDevice() {
212 fail("Not yet implemented");
213 }
214
215 /**
216 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getDevices(net.onrc.onos.util.GraphDBConnection)}.
217 */
218 @Test
219 public final void testGetDevices() {
220 fail("Not yet implemented");
221 }
222
223 /**
224 * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchFlowPath(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.util.FlowId)}.
225 */
226 @Test
227 public final void testSearchFlowPath() {
228 fail("Not yet implemented");
229 }
230
231 /**
232 * Test method for {@link net.onrc.onos.util.GraphDBOperation#newFlowPath(net.onrc.onos.util.GraphDBConnection)}.
233 */
234 @Test
235 public final void testNewFlowPath() {
236 fail("Not yet implemented");
237 }
238
239 /**
240 * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeFlowPath(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowPath)}.
241 */
242 @Test
243 public final void testRemoveFlowPath() {
244 fail("Not yet implemented");
245 }
246
247 /**
248 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getFlowPathByFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry)}.
249 */
250 @Test
251 public final void testGetFlowPathByFlowEntry() {
252 fail("Not yet implemented");
253 }
254
255 /**
256 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllFlowPaths(net.onrc.onos.util.GraphDBConnection)}.
257 */
258 @Test
259 public final void testGetAllFlowPaths() {
260 fail("Not yet implemented");
261 }
262
263 /**
264 * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.util.FlowEntryId)}.
265 */
266 @Test
267 public final void testSearchFlowEntry() {
268 fail("Not yet implemented");
269 }
270
271 /**
272 * Test method for {@link net.onrc.onos.util.GraphDBOperation#newFlowEntry(net.onrc.onos.util.GraphDBConnection)}.
273 */
274 @Test
275 public final void testNewFlowEntry() {
276 fail("Not yet implemented");
277 }
278
279 /**
280 * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry)}.
281 */
282 @Test
283 public final void testRemoveFlowEntry() {
284 fail("Not yet implemented");
285 }
286
287 /**
288 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllFlowEntries(net.onrc.onos.util.GraphDBConnection)}.
289 */
290 @Test
291 public final void testGetAllFlowEntries() {
292 fail("Not yet implemented");
293 }
294
295 /**
296 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllSwitchNotUpdatedFlowEntries(net.onrc.onos.util.GraphDBConnection)}.
297 */
298 @Test
299 public final void testGetAllSwitchNotUpdatedFlowEntries() {
300 fail("Not yet implemented");
301 }
302
303 /**
Toshio Koide9d8856e2013-06-12 16:48:11 -0700304 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllSwitches(net.onrc.onos.util.GraphDBConnection)}.
305 */
306 @Test
307 public final void testGetAllSwitches() {
308 fail("Not yet implemented");
309 }
310
311 /**
312 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getInactiveSwitches(net.onrc.onos.util.GraphDBConnection)}.
313 */
314 @Test
315 public final void testGetInactiveSwitches() {
316 fail("Not yet implemented");
317 }
318
Toshio Koide9d8856e2013-06-12 16:48:11 -0700319}