Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | */ |
| 4 | package net.onrc.onos.util; |
| 5 | |
| 6 | import static org.junit.Assert.*; |
| 7 | |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 8 | import java.util.Iterator; |
| 9 | |
| 10 | import junit.framework.Assert; |
| 11 | |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 12 | import net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject; |
| 13 | import net.floodlightcontroller.core.ISwitchStorage.SwitchState; |
| 14 | import net.floodlightcontroller.core.internal.TestDatabaseManager; |
| 15 | import net.onrc.onos.util.GraphDBConnection.Transaction; |
| 16 | |
| 17 | import org.easymock.EasyMock; |
| 18 | import org.junit.After; |
| 19 | import org.junit.AfterClass; |
| 20 | import org.junit.Before; |
| 21 | import org.junit.BeforeClass; |
| 22 | import org.junit.Test; |
| 23 | import org.junit.runner.RunWith; |
| 24 | import org.powermock.api.easymock.PowerMock; |
| 25 | import org.powermock.core.classloader.annotations.PrepareForTest; |
| 26 | import org.powermock.modules.junit4.PowerMockRunner; |
| 27 | |
| 28 | import com.thinkaurelius.titan.core.TitanFactory; |
| 29 | import com.thinkaurelius.titan.core.TitanGraph; |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 30 | import com.tinkerpop.blueprints.Vertex; |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * @author Toshio Koide |
| 34 | * |
| 35 | */ |
| 36 | @RunWith(PowerMockRunner.class) |
| 37 | @PrepareForTest({TitanFactory.class}) |
| 38 | public class GraphDBOperationTest { |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 39 | private static TitanGraph testdb; |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 40 | 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 Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 63 | testdb = TestDatabaseManager.getTestDatabase(); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 64 | // TestDatabaseManager.populateTestData(titanGraph); |
| 65 | |
| 66 | // replace return value of TitanFactory.open() to dummy DB created above |
| 67 | PowerMock.mockStatic(TitanFactory.class); |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 68 | EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(testdb); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 69 | 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 Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 81 | testdb.shutdown(); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 84 | private Iterator<Vertex> enumerateVertices(String vertexType) { |
| 85 | return testdb.getVertices("type", vertexType).iterator(); |
| 86 | } |
| 87 | |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 88 | /** |
| 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 Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 93 | Iterator<Vertex> vertices; |
| 94 | assertFalse(enumerateVertices("switch").hasNext()); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 95 | |
Toshio Koide | 727acfc | 2013-06-12 18:32:47 -0700 | [diff] [blame] | 96 | ISwitchObject sw = op.newSwitch("123"); |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 97 | |
| 98 | assertEquals("123", sw.getDPID()); |
Toshio Koide | a9a0300 | 2013-06-13 13:10:48 -0700 | [diff] [blame^] | 99 | op.commit(); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 100 | |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 101 | vertices = enumerateVertices("switch"); |
| 102 | assertTrue(vertices.hasNext()); |
| 103 | assertEquals(vertices.next().getProperty("dpid").toString(), "123"); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 104 | } |
| 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 Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 111 | ISwitchObject sw = op.newSwitch("123"); |
Toshio Koide | a9a0300 | 2013-06-13 13:10:48 -0700 | [diff] [blame^] | 112 | op.commit(); |
| 113 | |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 114 | 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 Koide | a9a0300 | 2013-06-13 13:10:48 -0700 | [diff] [blame^] | 129 | op.commit(); |
| 130 | |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 131 | 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 Koide | a9a0300 | 2013-06-13 13:10:48 -0700 | [diff] [blame^] | 148 | op.commit(); |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 149 | |
| 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 Koide | a9a0300 | 2013-06-13 13:10:48 -0700 | [diff] [blame^] | 162 | op.commit(); |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 163 | sw = op.searchSwitch("123"); |
| 164 | |
| 165 | op.removeSwitch(sw); |
| 166 | |
| 167 | assertFalse(enumerateVertices("switch").hasNext()); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 168 | } |
| 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 307 | * 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 322 | } |