blob: 0f8f4db78e64469e2bc2d131c97eb1748b32fa86 [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
10import junit.framework.Assert;
11
Toshio Koide9d8856e2013-06-12 16:48:11 -070012import net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject;
13import net.floodlightcontroller.core.ISwitchStorage.SwitchState;
14import net.floodlightcontroller.core.internal.TestDatabaseManager;
15import net.onrc.onos.util.GraphDBConnection.Transaction;
16
17import org.easymock.EasyMock;
18import org.junit.After;
19import org.junit.AfterClass;
20import org.junit.Before;
21import org.junit.BeforeClass;
22import org.junit.Test;
23import org.junit.runner.RunWith;
24import org.powermock.api.easymock.PowerMock;
25import org.powermock.core.classloader.annotations.PrepareForTest;
26import org.powermock.modules.junit4.PowerMockRunner;
27
28import com.thinkaurelius.titan.core.TitanFactory;
29import com.thinkaurelius.titan.core.TitanGraph;
Toshio Koide3c460e12013-06-13 11:55:12 -070030import com.tinkerpop.blueprints.Vertex;
Toshio Koide9d8856e2013-06-12 16:48:11 -070031
32/**
33 * @author Toshio Koide
34 *
35 */
36@RunWith(PowerMockRunner.class)
37@PrepareForTest({TitanFactory.class})
38public class GraphDBOperationTest {
Toshio Koide3c460e12013-06-13 11:55:12 -070039 private static TitanGraph testdb;
Toshio Koide9d8856e2013-06-12 16:48:11 -070040 private static GraphDBConnection conn;
41 private static GraphDBOperation op;
42
43 /**
44 * @throws java.lang.Exception
45 */
46 @BeforeClass
47 public static void setUpBeforeClass() throws Exception {
48 }
49
50 /**
51 * @throws java.lang.Exception
52 */
53 @AfterClass
54 public static void tearDownAfterClass() throws Exception {
55 }
56
57 /**
58 * @throws java.lang.Exception
59 */
60 @Before
61 public void setUp() throws Exception {
62 TestDatabaseManager.deleteTestDatabase();
Toshio Koide3c460e12013-06-13 11:55:12 -070063 testdb = TestDatabaseManager.getTestDatabase();
Toshio Koide9d8856e2013-06-12 16:48:11 -070064// TestDatabaseManager.populateTestData(titanGraph);
65
66 // replace return value of TitanFactory.open() to dummy DB created above
67 PowerMock.mockStatic(TitanFactory.class);
Toshio Koide3c460e12013-06-13 11:55:12 -070068 EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(testdb);
Toshio Koide9d8856e2013-06-12 16:48:11 -070069 PowerMock.replay(TitanFactory.class);
70
71 conn = GraphDBConnection.getInstance("/dummy/to/conf");
72 op = new GraphDBOperation(conn);
73 }
74
75 /**
76 * @throws java.lang.Exception
77 */
78 @After
79 public void tearDown() throws Exception {
80 conn.close();
Toshio Koide3c460e12013-06-13 11:55:12 -070081 testdb.shutdown();
Toshio Koide9d8856e2013-06-12 16:48:11 -070082 }
83
Toshio Koide3c460e12013-06-13 11:55:12 -070084 private Iterator<Vertex> enumerateVertices(String vertexType) {
85 return testdb.getVertices("type", vertexType).iterator();
86 }
87
Toshio Koide9d8856e2013-06-12 16:48:11 -070088 /**
89 * Test method for {@link net.onrc.onos.util.GraphDBOperation#newSwitch(net.onrc.onos.util.GraphDBConnection)}.
90 */
91 @Test
92 public final void testNewSwitch() {
Toshio Koide3c460e12013-06-13 11:55:12 -070093 Iterator<Vertex> vertices;
94 assertFalse(enumerateVertices("switch").hasNext());
Toshio Koide9d8856e2013-06-12 16:48:11 -070095
Toshio Koide727acfc2013-06-12 18:32:47 -070096 ISwitchObject sw = op.newSwitch("123");
Toshio Koide3c460e12013-06-13 11:55:12 -070097
98 assertEquals("123", sw.getDPID());
Toshio Koidea9a03002013-06-13 13:10:48 -070099 op.commit();
Toshio Koide9d8856e2013-06-12 16:48:11 -0700100
Toshio Koide3c460e12013-06-13 11:55:12 -0700101 vertices = enumerateVertices("switch");
102 assertTrue(vertices.hasNext());
103 assertEquals(vertices.next().getProperty("dpid").toString(), "123");
Toshio Koide9d8856e2013-06-12 16:48:11 -0700104 }
105
106 /**
107 * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchSwitch(net.onrc.onos.util.GraphDBConnection, java.lang.String)}.
108 */
109 @Test
110 public final void testSearchSwitch() {
Toshio Koide3c460e12013-06-13 11:55:12 -0700111 ISwitchObject sw = op.newSwitch("123");
Toshio Koidea9a03002013-06-13 13:10:48 -0700112 op.commit();
113
Toshio Koide3c460e12013-06-13 11:55:12 -0700114 sw = op.searchSwitch("123");
115
116 assertNotNull(sw);
117 assertEquals("123", sw.getDPID());
118 }
119
120 /**
121 * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchActiveSwitch(net.onrc.onos.util.GraphDBConnection, java.lang.String)}.
122 */
123 @Test
124 public final void testSearchActiveSwitch() {
125 ISwitchObject sw = op.newSwitch("111");
126 sw.setState(SwitchState.ACTIVE.toString());
127 sw = op.newSwitch("222");
128 sw.setState(SwitchState.INACTIVE.toString());
Toshio Koidea9a03002013-06-13 13:10:48 -0700129 op.commit();
130
Toshio Koide3c460e12013-06-13 11:55:12 -0700131 sw = op.searchActiveSwitch("111");
132 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() {
144 ISwitchObject sw = op.newSwitch("111");
145 sw.setState(SwitchState.ACTIVE.toString());
146 sw = op.newSwitch("222");
147 sw.setState(SwitchState.INACTIVE.toString());
Toshio Koidea9a03002013-06-13 13:10:48 -0700148 op.commit();
Toshio Koide3c460e12013-06-13 11:55:12 -0700149
150 Iterator<ISwitchObject> i = op.getActiveSwitches().iterator();
151 assertTrue(i.hasNext());
152 assertEquals("111", i.next().getDPID());
153 assertFalse(i.hasNext());
154 }
155
156 /**
157 * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeSwitch(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject)}.
158 */
159 @Test
160 public final void testRemoveSwitch() {
161 ISwitchObject sw = op.newSwitch("123");
Toshio Koidea9a03002013-06-13 13:10:48 -0700162 op.commit();
Toshio Koide3c460e12013-06-13 11:55:12 -0700163 sw = op.searchSwitch("123");
164
165 op.removeSwitch(sw);
166
167 assertFalse(enumerateVertices("switch").hasNext());
Toshio Koide9d8856e2013-06-12 16:48:11 -0700168 }
169
170 /**
171 * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchDevice(net.onrc.onos.util.GraphDBConnection, java.lang.String)}.
172 */
173 @Test
174 public final void testSearchDevice() {
175 fail("Not yet implemented");
176 }
177
178 /**
179 * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchPort(net.onrc.onos.util.GraphDBConnection, java.lang.String, short)}.
180 */
181 @Test
182 public final void testSearchPort() {
183 fail("Not yet implemented");
184 }
185
186 /**
187 * Test method for {@link net.onrc.onos.util.GraphDBOperation#newPort(net.onrc.onos.util.GraphDBConnection)}.
188 */
189 @Test
190 public final void testNewPort() {
191 fail("Not yet implemented");
192 }
193
194 /**
195 * Test method for {@link net.onrc.onos.util.GraphDBOperation#newDevice(net.onrc.onos.util.GraphDBConnection)}.
196 */
197 @Test
198 public final void testNewDevice() {
199 fail("Not yet implemented");
200 }
201
202 /**
203 * Test method for {@link net.onrc.onos.util.GraphDBOperation#removePort(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IPortObject)}.
204 */
205 @Test
206 public final void testRemovePort() {
207 fail("Not yet implemented");
208 }
209
210 /**
211 * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeDevice(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IDeviceObject)}.
212 */
213 @Test
214 public final void testRemoveDevice() {
215 fail("Not yet implemented");
216 }
217
218 /**
219 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getDevices(net.onrc.onos.util.GraphDBConnection)}.
220 */
221 @Test
222 public final void testGetDevices() {
223 fail("Not yet implemented");
224 }
225
226 /**
227 * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchFlowPath(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.util.FlowId)}.
228 */
229 @Test
230 public final void testSearchFlowPath() {
231 fail("Not yet implemented");
232 }
233
234 /**
235 * Test method for {@link net.onrc.onos.util.GraphDBOperation#newFlowPath(net.onrc.onos.util.GraphDBConnection)}.
236 */
237 @Test
238 public final void testNewFlowPath() {
239 fail("Not yet implemented");
240 }
241
242 /**
243 * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeFlowPath(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowPath)}.
244 */
245 @Test
246 public final void testRemoveFlowPath() {
247 fail("Not yet implemented");
248 }
249
250 /**
251 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getFlowPathByFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry)}.
252 */
253 @Test
254 public final void testGetFlowPathByFlowEntry() {
255 fail("Not yet implemented");
256 }
257
258 /**
259 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllFlowPaths(net.onrc.onos.util.GraphDBConnection)}.
260 */
261 @Test
262 public final void testGetAllFlowPaths() {
263 fail("Not yet implemented");
264 }
265
266 /**
267 * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.util.FlowEntryId)}.
268 */
269 @Test
270 public final void testSearchFlowEntry() {
271 fail("Not yet implemented");
272 }
273
274 /**
275 * Test method for {@link net.onrc.onos.util.GraphDBOperation#newFlowEntry(net.onrc.onos.util.GraphDBConnection)}.
276 */
277 @Test
278 public final void testNewFlowEntry() {
279 fail("Not yet implemented");
280 }
281
282 /**
283 * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry)}.
284 */
285 @Test
286 public final void testRemoveFlowEntry() {
287 fail("Not yet implemented");
288 }
289
290 /**
291 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllFlowEntries(net.onrc.onos.util.GraphDBConnection)}.
292 */
293 @Test
294 public final void testGetAllFlowEntries() {
295 fail("Not yet implemented");
296 }
297
298 /**
299 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllSwitchNotUpdatedFlowEntries(net.onrc.onos.util.GraphDBConnection)}.
300 */
301 @Test
302 public final void testGetAllSwitchNotUpdatedFlowEntries() {
303 fail("Not yet implemented");
304 }
305
306 /**
Toshio Koide9d8856e2013-06-12 16:48:11 -0700307 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllSwitches(net.onrc.onos.util.GraphDBConnection)}.
308 */
309 @Test
310 public final void testGetAllSwitches() {
311 fail("Not yet implemented");
312 }
313
314 /**
315 * Test method for {@link net.onrc.onos.util.GraphDBOperation#getInactiveSwitches(net.onrc.onos.util.GraphDBConnection)}.
316 */
317 @Test
318 public final void testGetInactiveSwitches() {
319 fail("Not yet implemented");
320 }
321
Toshio Koide9d8856e2013-06-12 16:48:11 -0700322}