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(); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#newSwitch(net.onrc.onos.util.GraphDBConnection)}. |
| 80 | */ |
| 81 | @Test |
| 82 | public final void testNewSwitch() { |
| 83 | Iterable<ISwitchObject> switches; |
| 84 | |
| 85 | switches = op.getAllSwitches(); |
| 86 | assertFalse(switches.iterator().hasNext()); |
| 87 | |
| 88 | ISwitchObject sw = op.newSwitch(); |
| 89 | sw.setType("switch"); |
| 90 | sw.setDPID("123"); |
| 91 | sw.setState(SwitchState.ACTIVE.toString()); |
| 92 | conn.endTx(Transaction.COMMIT); |
| 93 | |
| 94 | switches = op.getAllSwitches(); |
| 95 | assertTrue(switches.iterator().hasNext()); |
| 96 | |
| 97 | ISwitchObject obtained_sw = switches.iterator().next(); |
| 98 | String obtained_dpid = obtained_sw.getDPID(); |
| 99 | assertEquals("123", obtained_dpid); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeSwitch(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.ISwitchObject)}. |
| 104 | */ |
| 105 | @Test |
| 106 | public final void testRemoveSwitch() { |
| 107 | Iterable<ISwitchObject> switches; |
| 108 | |
| 109 | // make sure there is no switch |
| 110 | switches = op.getAllSwitches(); |
| 111 | assertFalse(switches.iterator().hasNext()); |
| 112 | |
| 113 | |
| 114 | ISwitchObject sw = op.newSwitch(); |
| 115 | sw.setType("switch"); |
| 116 | sw.setDPID("123"); |
| 117 | sw.setState(SwitchState.ACTIVE.toString()); |
| 118 | conn.endTx(Transaction.COMMIT); |
| 119 | |
| 120 | switches = op.getAllSwitches(); |
| 121 | assertTrue(switches.iterator().hasNext()); |
| 122 | |
| 123 | ISwitchObject obtained_sw = switches.iterator().next(); |
| 124 | String obtained_dpid = obtained_sw.getDPID(); |
| 125 | assertEquals("123", obtained_dpid); |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchSwitch(net.onrc.onos.util.GraphDBConnection, java.lang.String)}. |
| 130 | */ |
| 131 | @Test |
| 132 | public final void testSearchSwitch() { |
| 133 | fail("Not yet implemented"); |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchDevice(net.onrc.onos.util.GraphDBConnection, java.lang.String)}. |
| 138 | */ |
| 139 | @Test |
| 140 | public final void testSearchDevice() { |
| 141 | fail("Not yet implemented"); |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchPort(net.onrc.onos.util.GraphDBConnection, java.lang.String, short)}. |
| 146 | */ |
| 147 | @Test |
| 148 | public final void testSearchPort() { |
| 149 | fail("Not yet implemented"); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#newPort(net.onrc.onos.util.GraphDBConnection)}. |
| 154 | */ |
| 155 | @Test |
| 156 | public final void testNewPort() { |
| 157 | fail("Not yet implemented"); |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#newDevice(net.onrc.onos.util.GraphDBConnection)}. |
| 162 | */ |
| 163 | @Test |
| 164 | public final void testNewDevice() { |
| 165 | fail("Not yet implemented"); |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#removePort(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IPortObject)}. |
| 170 | */ |
| 171 | @Test |
| 172 | public final void testRemovePort() { |
| 173 | fail("Not yet implemented"); |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeDevice(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IDeviceObject)}. |
| 178 | */ |
| 179 | @Test |
| 180 | public final void testRemoveDevice() { |
| 181 | fail("Not yet implemented"); |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#getDevices(net.onrc.onos.util.GraphDBConnection)}. |
| 186 | */ |
| 187 | @Test |
| 188 | public final void testGetDevices() { |
| 189 | fail("Not yet implemented"); |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchFlowPath(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.util.FlowId)}. |
| 194 | */ |
| 195 | @Test |
| 196 | public final void testSearchFlowPath() { |
| 197 | fail("Not yet implemented"); |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#newFlowPath(net.onrc.onos.util.GraphDBConnection)}. |
| 202 | */ |
| 203 | @Test |
| 204 | public final void testNewFlowPath() { |
| 205 | fail("Not yet implemented"); |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeFlowPath(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowPath)}. |
| 210 | */ |
| 211 | @Test |
| 212 | public final void testRemoveFlowPath() { |
| 213 | fail("Not yet implemented"); |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#getFlowPathByFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry)}. |
| 218 | */ |
| 219 | @Test |
| 220 | public final void testGetFlowPathByFlowEntry() { |
| 221 | fail("Not yet implemented"); |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllFlowPaths(net.onrc.onos.util.GraphDBConnection)}. |
| 226 | */ |
| 227 | @Test |
| 228 | public final void testGetAllFlowPaths() { |
| 229 | fail("Not yet implemented"); |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.util.FlowEntryId)}. |
| 234 | */ |
| 235 | @Test |
| 236 | public final void testSearchFlowEntry() { |
| 237 | fail("Not yet implemented"); |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#newFlowEntry(net.onrc.onos.util.GraphDBConnection)}. |
| 242 | */ |
| 243 | @Test |
| 244 | public final void testNewFlowEntry() { |
| 245 | fail("Not yet implemented"); |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#removeFlowEntry(net.onrc.onos.util.GraphDBConnection, net.floodlightcontroller.core.INetMapTopologyObjects.IFlowEntry)}. |
| 250 | */ |
| 251 | @Test |
| 252 | public final void testRemoveFlowEntry() { |
| 253 | fail("Not yet implemented"); |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllFlowEntries(net.onrc.onos.util.GraphDBConnection)}. |
| 258 | */ |
| 259 | @Test |
| 260 | public final void testGetAllFlowEntries() { |
| 261 | fail("Not yet implemented"); |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllSwitchNotUpdatedFlowEntries(net.onrc.onos.util.GraphDBConnection)}. |
| 266 | */ |
| 267 | @Test |
| 268 | public final void testGetAllSwitchNotUpdatedFlowEntries() { |
| 269 | fail("Not yet implemented"); |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#getActiveSwitches(net.onrc.onos.util.GraphDBConnection)}. |
| 274 | */ |
| 275 | @Test |
| 276 | public final void testGetActiveSwitches() { |
| 277 | fail("Not yet implemented"); |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#getAllSwitches(net.onrc.onos.util.GraphDBConnection)}. |
| 282 | */ |
| 283 | @Test |
| 284 | public final void testGetAllSwitches() { |
| 285 | fail("Not yet implemented"); |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#getInactiveSwitches(net.onrc.onos.util.GraphDBConnection)}. |
| 290 | */ |
| 291 | @Test |
| 292 | public final void testGetInactiveSwitches() { |
| 293 | fail("Not yet implemented"); |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * Test method for {@link net.onrc.onos.util.GraphDBOperation#searchActiveSwitch(net.onrc.onos.util.GraphDBConnection, java.lang.String)}. |
| 298 | */ |
| 299 | @Test |
| 300 | public final void testSearchActiveSwitch() { |
| 301 | fail("Not yet implemented"); |
| 302 | } |
| 303 | |
| 304 | } |