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 | |
| 8 | import net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject; |
| 9 | import net.floodlightcontroller.core.ISwitchStorage.SwitchState; |
| 10 | import net.floodlightcontroller.core.internal.TestDatabaseManager; |
| 11 | import net.onrc.onos.util.GraphDBConnection.Transaction; |
| 12 | |
| 13 | import org.easymock.EasyMock; |
| 14 | import org.junit.After; |
| 15 | import org.junit.AfterClass; |
| 16 | import org.junit.Before; |
| 17 | import org.junit.BeforeClass; |
| 18 | import org.junit.Test; |
| 19 | import org.junit.runner.RunWith; |
| 20 | import org.powermock.api.easymock.PowerMock; |
| 21 | import org.powermock.core.classloader.annotations.PrepareForTest; |
| 22 | import org.powermock.modules.junit4.PowerMockRunner; |
| 23 | |
| 24 | import com.thinkaurelius.titan.core.TitanFactory; |
| 25 | import com.thinkaurelius.titan.core.TitanGraph; |
| 26 | |
| 27 | /** |
| 28 | * @author Toshio Koide |
| 29 | * |
| 30 | */ |
| 31 | @RunWith(PowerMockRunner.class) |
| 32 | @PrepareForTest({TitanFactory.class}) |
| 33 | public class GraphDBOperationTest { |
| 34 | private static TitanGraph titanGraph; |
| 35 | private static GraphDBConnection conn; |
| 36 | private static GraphDBOperation op; |
| 37 | |
| 38 | /** |
| 39 | * @throws java.lang.Exception |
| 40 | */ |
| 41 | @BeforeClass |
| 42 | public static void setUpBeforeClass() throws Exception { |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @throws java.lang.Exception |
| 47 | */ |
| 48 | @AfterClass |
| 49 | public static void tearDownAfterClass() throws Exception { |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @throws java.lang.Exception |
| 54 | */ |
| 55 | @Before |
| 56 | public void setUp() throws Exception { |
| 57 | TestDatabaseManager.deleteTestDatabase(); |
| 58 | titanGraph = TestDatabaseManager.getTestDatabase(); |
| 59 | // TestDatabaseManager.populateTestData(titanGraph); |
| 60 | |
| 61 | // replace return value of TitanFactory.open() to dummy DB created above |
| 62 | PowerMock.mockStatic(TitanFactory.class); |
| 63 | EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(titanGraph); |
| 64 | PowerMock.replay(TitanFactory.class); |
| 65 | |
| 66 | conn = GraphDBConnection.getInstance("/dummy/to/conf"); |
| 67 | op = new GraphDBOperation(conn); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @throws java.lang.Exception |
| 72 | */ |
| 73 | @After |
| 74 | public void tearDown() throws Exception { |
| 75 | conn.close(); |
Toshio Koide | d7b7e10 | 2013-06-12 17:13:25 -0700 | [diff] [blame] | 76 | titanGraph.shutdown(); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#newSwitch(net.onrc.onos.util.GraphDBConnection)}. |
| 81 | */ |
| 82 | @Test |
| 83 | public final void testNewSwitch() { |
| 84 | Iterable<ISwitchObject> switches; |
| 85 | |
| 86 | switches = op.getAllSwitches(); |
| 87 | assertFalse(switches.iterator().hasNext()); |
| 88 | |
Toshio Koide | 727acfc | 2013-06-12 18:32:47 -0700 | [diff] [blame] | 89 | ISwitchObject sw = op.newSwitch("123"); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 90 | sw.setState(SwitchState.ACTIVE.toString()); |
| 91 | conn.endTx(Transaction.COMMIT); |
| 92 | |
| 93 | switches = op.getAllSwitches(); |
| 94 | assertTrue(switches.iterator().hasNext()); |
| 95 | |
| 96 | ISwitchObject obtained_sw = switches.iterator().next(); |
| 97 | String obtained_dpid = obtained_sw.getDPID(); |
| 98 | assertEquals("123", obtained_dpid); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeSwitch(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject)}. |
| 103 | */ |
| 104 | @Test |
| 105 | public final void testRemoveSwitch() { |
| 106 | Iterable<ISwitchObject> switches; |
| 107 | |
| 108 | // make sure there is no switch |
| 109 | switches = op.getAllSwitches(); |
| 110 | assertFalse(switches.iterator().hasNext()); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 111 | |
Toshio Koide | 727acfc | 2013-06-12 18:32:47 -0700 | [diff] [blame] | 112 | ISwitchObject sw = op.newSwitch("123"); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 113 | sw.setState(SwitchState.ACTIVE.toString()); |
| 114 | conn.endTx(Transaction.COMMIT); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 115 | |
Toshio Koide | d7b7e10 | 2013-06-12 17:13:25 -0700 | [diff] [blame] | 116 | sw = op.searchSwitch("123"); |
| 117 | op.removeSwitch(sw); |
| 118 | |
| 119 | assertNull(op.searchSwitch("123")); |
Toshio Koide | 9d8856e | 2013-06-12 16:48:11 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchSwitch(net.onrc.onos.util.GraphDBConnection, java.lang.String)}. |
| 124 | */ |
| 125 | @Test |
| 126 | public final void testSearchSwitch() { |
| 127 | fail("Not yet implemented"); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchDevice(net.onrc.onos.util.GraphDBConnection, java.lang.String)}. |
| 132 | */ |
| 133 | @Test |
| 134 | public final void testSearchDevice() { |
| 135 | fail("Not yet implemented"); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchPort(net.onrc.onos.util.GraphDBConnection, java.lang.String, short)}. |
| 140 | */ |
| 141 | @Test |
| 142 | public final void testSearchPort() { |
| 143 | fail("Not yet implemented"); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#newPort(net.onrc.onos.util.GraphDBConnection)}. |
| 148 | */ |
| 149 | @Test |
| 150 | public final void testNewPort() { |
| 151 | fail("Not yet implemented"); |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#newDevice(net.onrc.onos.util.GraphDBConnection)}. |
| 156 | */ |
| 157 | @Test |
| 158 | public final void testNewDevice() { |
| 159 | fail("Not yet implemented"); |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#removePort(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IPortObject)}. |
| 164 | */ |
| 165 | @Test |
| 166 | public final void testRemovePort() { |
| 167 | fail("Not yet implemented"); |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeDevice(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IDeviceObject)}. |
| 172 | */ |
| 173 | @Test |
| 174 | public final void testRemoveDevice() { |
| 175 | fail("Not yet implemented"); |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#getDevices(net.onrc.onos.util.GraphDBConnection)}. |
| 180 | */ |
| 181 | @Test |
| 182 | public final void testGetDevices() { |
| 183 | fail("Not yet implemented"); |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchFlowPath(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.util.FlowId)}. |
| 188 | */ |
| 189 | @Test |
| 190 | public final void testSearchFlowPath() { |
| 191 | fail("Not yet implemented"); |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#newFlowPath(net.onrc.onos.util.GraphDBConnection)}. |
| 196 | */ |
| 197 | @Test |
| 198 | public final void testNewFlowPath() { |
| 199 | fail("Not yet implemented"); |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeFlowPath(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowPath)}. |
| 204 | */ |
| 205 | @Test |
| 206 | public final void testRemoveFlowPath() { |
| 207 | fail("Not yet implemented"); |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#getFlowPathByFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry)}. |
| 212 | */ |
| 213 | @Test |
| 214 | public final void testGetFlowPathByFlowEntry() { |
| 215 | fail("Not yet implemented"); |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllFlowPaths(net.onrc.onos.util.GraphDBConnection)}. |
| 220 | */ |
| 221 | @Test |
| 222 | public final void testGetAllFlowPaths() { |
| 223 | fail("Not yet implemented"); |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.util.FlowEntryId)}. |
| 228 | */ |
| 229 | @Test |
| 230 | public final void testSearchFlowEntry() { |
| 231 | fail("Not yet implemented"); |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#newFlowEntry(net.onrc.onos.util.GraphDBConnection)}. |
| 236 | */ |
| 237 | @Test |
| 238 | public final void testNewFlowEntry() { |
| 239 | fail("Not yet implemented"); |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry)}. |
| 244 | */ |
| 245 | @Test |
| 246 | public final void testRemoveFlowEntry() { |
| 247 | fail("Not yet implemented"); |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllFlowEntries(net.onrc.onos.util.GraphDBConnection)}. |
| 252 | */ |
| 253 | @Test |
| 254 | public final void testGetAllFlowEntries() { |
| 255 | fail("Not yet implemented"); |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllSwitchNotUpdatedFlowEntries(net.onrc.onos.util.GraphDBConnection)}. |
| 260 | */ |
| 261 | @Test |
| 262 | public final void testGetAllSwitchNotUpdatedFlowEntries() { |
| 263 | fail("Not yet implemented"); |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#getActiveSwitches(net.onrc.onos.util.GraphDBConnection)}. |
| 268 | */ |
| 269 | @Test |
| 270 | public final void testGetActiveSwitches() { |
| 271 | fail("Not yet implemented"); |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllSwitches(net.onrc.onos.util.GraphDBConnection)}. |
| 276 | */ |
| 277 | @Test |
| 278 | public final void testGetAllSwitches() { |
| 279 | fail("Not yet implemented"); |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#getInactiveSwitches(net.onrc.onos.util.GraphDBConnection)}. |
| 284 | */ |
| 285 | @Test |
| 286 | public final void testGetInactiveSwitches() { |
| 287 | fail("Not yet implemented"); |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchActiveSwitch(net.onrc.onos.util.GraphDBConnection, java.lang.String)}. |
| 292 | */ |
| 293 | @Test |
| 294 | public final void testSearchActiveSwitch() { |
| 295 | fail("Not yet implemented"); |
| 296 | } |
| 297 | |
| 298 | } |