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 | |
Toshio Koide | b29b9b3 | 2013-06-13 14:37:46 -0700 | [diff] [blame] | 10 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject; |
| 11 | import net.onrc.onos.ofcontroller.core.ISwitchStorage.SwitchState; |
HIGUCHI Yuta | 0813793 | 2013-06-17 14:11:50 -0700 | [diff] [blame^] | 12 | import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager; |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 13 | |
| 14 | import org.easymock.EasyMock; |
| 15 | import org.junit.After; |
| 16 | import org.junit.AfterClass; |
| 17 | import org.junit.Before; |
| 18 | import org.junit.BeforeClass; |
| 19 | import org.junit.Test; |
| 20 | import org.junit.runner.RunWith; |
| 21 | import org.powermock.api.easymock.PowerMock; |
| 22 | import org.powermock.core.classloader.annotations.PrepareForTest; |
| 23 | import org.powermock.modules.junit4.PowerMockRunner; |
| 24 | |
| 25 | import com.thinkaurelius.titan.core.TitanFactory; |
| 26 | import com.thinkaurelius.titan.core.TitanGraph; |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 27 | import com.tinkerpop.blueprints.Vertex; |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * @author Toshio Koide |
| 31 | * |
| 32 | */ |
| 33 | @RunWith(PowerMockRunner.class) |
| 34 | @PrepareForTest({TitanFactory.class}) |
| 35 | public class GraphDBOperationTest { |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 36 | private static TitanGraph testdb; |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 37 | 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 Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 60 | testdb = TestDatabaseManager.getTestDatabase(); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 61 | // TestDatabaseManager.populateTestData(titanGraph); |
| 62 | |
| 63 | // replace return value of TitanFactory.open() to dummy DB created above |
| 64 | PowerMock.mockStatic(TitanFactory.class); |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 65 | EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(testdb); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 66 | 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 Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 78 | testdb.shutdown(); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 81 | private Iterator<Vertex> enumerateVertices(String vertexType) { |
| 82 | return testdb.getVertices("type", vertexType).iterator(); |
| 83 | } |
| 84 | |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 85 | /** |
| 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 Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 90 | Iterator<Vertex> vertices; |
| 91 | assertFalse(enumerateVertices("switch").hasNext()); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 92 | |
Toshio Koide | 727acfc | 2013-06-12 18:32:47 -0700 | [diff] [blame] | 93 | ISwitchObject sw = op.newSwitch("123"); |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 94 | |
| 95 | assertEquals("123", sw.getDPID()); |
Toshio Koide | a9a0300 | 2013-06-13 13:10:48 -0700 | [diff] [blame] | 96 | op.commit(); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 97 | |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 98 | vertices = enumerateVertices("switch"); |
| 99 | assertTrue(vertices.hasNext()); |
| 100 | assertEquals(vertices.next().getProperty("dpid").toString(), "123"); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 101 | } |
| 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 Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 108 | ISwitchObject sw = op.newSwitch("123"); |
Toshio Koide | a9a0300 | 2013-06-13 13:10:48 -0700 | [diff] [blame] | 109 | op.commit(); |
| 110 | |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 111 | 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 Koide | a9a0300 | 2013-06-13 13:10:48 -0700 | [diff] [blame] | 126 | op.commit(); |
| 127 | |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 128 | 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 Koide | a9a0300 | 2013-06-13 13:10:48 -0700 | [diff] [blame] | 145 | op.commit(); |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 146 | |
| 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 Koide | a9a0300 | 2013-06-13 13:10:48 -0700 | [diff] [blame] | 159 | op.commit(); |
Toshio Koide | 3c460e1 | 2013-06-13 11:55:12 -0700 | [diff] [blame] | 160 | sw = op.searchSwitch("123"); |
| 161 | |
| 162 | op.removeSwitch(sw); |
| 163 | |
| 164 | assertFalse(enumerateVertices("switch").hasNext()); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 165 | } |
| 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 304 | * 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 Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 319 | } |