Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.core.internal; |
| 2 | |
| 3 | import static org.easymock.EasyMock.*; |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 4 | import net.onrc.onos.graph.GraphDBConnection; |
| 5 | import net.onrc.onos.graph.GraphDBOperation; |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 6 | import net.onrc.onos.ofcontroller.core.ISwitchStorage; |
| 7 | import net.onrc.onos.ofcontroller.core.ISwitchStorage.SwitchState; |
| 8 | import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl; |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 9 | import net.onrc.onos.ofcontroller.core.INetMapStorage.DM_OPERATION; |
| 10 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject; |
| 11 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject; |
Jonathan Hart | fb69851 | 2013-11-19 17:11:29 -0800 | [diff] [blame] | 12 | |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 13 | import org.easymock.EasyMock; |
| 14 | import org.junit.After; |
| 15 | import org.junit.Before; |
Jonathan Hart | fb69851 | 2013-11-19 17:11:29 -0800 | [diff] [blame] | 16 | import org.junit.Ignore; |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 17 | import org.junit.Test; |
| 18 | import org.junit.runner.RunWith; |
| 19 | import org.openflow.protocol.OFPhysicalPort; |
| 20 | import org.openflow.protocol.OFPhysicalPort.OFPortState; |
| 21 | import org.powermock.api.easymock.PowerMock; |
| 22 | import org.powermock.core.classloader.annotations.PrepareForTest; |
| 23 | import org.powermock.modules.junit4.PowerMockRunner; |
| 24 | import org.slf4j.LoggerFactory; |
| 25 | |
| 26 | import com.thinkaurelius.titan.core.TitanFactory; |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 27 | |
| 28 | //Add Powermock preparation |
Jonathan Hart | fb69851 | 2013-11-19 17:11:29 -0800 | [diff] [blame] | 29 | @Ignore //TODO broken 11/19/13, should fix |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 30 | @RunWith(PowerMockRunner.class) |
| 31 | @PrepareForTest({TitanFactory.class, GraphDBConnection.class, GraphDBOperation.class, SwitchStorageImpl.class}) |
| 32 | public class SwitchStorageImplTest { |
| 33 | |
| 34 | protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class); |
| 35 | |
| 36 | String conf; |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 37 | String dbStore; |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 38 | private GraphDBConnection mockConn = null; |
| 39 | private GraphDBOperation mockOpe = null; |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 40 | ISwitchStorage swSt = null; |
| 41 | |
| 42 | @Before |
| 43 | public void setUp() throws Exception { |
| 44 | |
| 45 | swSt = new SwitchStorageImpl(); |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 46 | dbStore = "dummyStore"; |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 47 | conf = "/dummy/path/to/db"; |
| 48 | |
| 49 | // Make mock cassandra DB |
| 50 | // Replace TitanFactory.open() to return mock DB |
| 51 | |
| 52 | PowerMock.mockStatic(GraphDBConnection.class); |
| 53 | mockConn = createMock(GraphDBConnection.class); |
| 54 | PowerMock.suppress(PowerMock.constructor(GraphDBConnection.class)); |
| 55 | EasyMock.expect(GraphDBConnection.getInstance((String)EasyMock.anyObject())).andReturn(mockConn); |
| 56 | PowerMock.replay(GraphDBConnection.class); |
| 57 | |
| 58 | PowerMock.mockStatic(GraphDBOperation.class); |
| 59 | mockOpe = PowerMock.createStrictMock(GraphDBOperation.class); |
| 60 | PowerMock.expectNew(GraphDBOperation.class, mockConn).andReturn(mockOpe); |
| 61 | PowerMock.replay(GraphDBOperation.class); |
| 62 | // Replace the conf to dummy conf |
| 63 | // String conf = "/tmp/cassandra.titan"; |
| 64 | |
| 65 | |
| 66 | } |
| 67 | |
| 68 | @After |
| 69 | public void tearDown() throws Exception { |
| 70 | swSt.close(); |
| 71 | swSt = null; |
| 72 | |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Desc: |
| 77 | * Test method for addSwitch method. |
| 78 | * Condition: |
| 79 | * Normal |
| 80 | * Expect: |
| 81 | * Call SwitchStorageImpl.addSwitch func with proper properties. |
| 82 | */ |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 83 | @Test |
| 84 | public void testAddSwitch() { |
| 85 | String dpid = "00:00:00:00:00:00:0a:07"; |
| 86 | String state = "ACTIVE"; |
| 87 | |
| 88 | //Mock Switch |
| 89 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
| 90 | mockISw.setState(state); |
| 91 | replay(mockISw); |
| 92 | |
| 93 | //Expectation of mock operation. |
| 94 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 95 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 96 | mockOpe.commit(); |
| 97 | mockOpe.close(); |
| 98 | replay(mockOpe); |
| 99 | |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 100 | swSt.init(dbStore, conf); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 101 | swSt.addSwitch(dpid); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Desc: |
| 106 | * Test method for addSwitch method. |
| 107 | * Condition: |
| 108 | * The switch is already existing. |
| 109 | * Expect: |
| 110 | * Call SwitchStorageImpl.addSwitch func with proper properties. |
| 111 | */ |
| 112 | //@Ignore |
| 113 | @Test |
| 114 | public void testAddSwitchExisting() { |
| 115 | String dpid = "00:00:00:00:00:00:0a:07"; |
| 116 | String state = "ACTIVE"; |
| 117 | |
| 118 | //Mock Switch |
| 119 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
| 120 | mockISw.setState(state); |
| 121 | mockISw.setState(state); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 122 | expect(mockISw.getDPID()).andReturn(dpid).anyTimes(); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 123 | replay(mockISw); |
| 124 | |
| 125 | //Expectation of mock operation. |
| 126 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 127 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 128 | mockOpe.commit(); |
| 129 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
| 130 | mockOpe.commit(); |
| 131 | mockOpe.close(); |
| 132 | replay(mockOpe); |
| 133 | |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 134 | swSt.init(dbStore, conf); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 135 | swSt.addSwitch(dpid); |
| 136 | swSt.addSwitch(dpid); |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Desc: |
| 141 | * Test method for addSwitch method. |
| 142 | * Condition: |
| 143 | * The switch construction is fail and return null |
| 144 | * Expect: |
| 145 | * Write the status as info log. |
| 146 | */ |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 147 | @Test |
| 148 | public void testAddSwitchAbnormal() { |
| 149 | String dpid = "00:00:00:00:00:00:0a:07"; |
| 150 | |
| 151 | //Expectation of mock operation. |
| 152 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 153 | expect(mockOpe.newSwitch(dpid)).andReturn(null); |
HIGUCHI Yuta | fabb003 | 2013-06-28 11:31:33 -0700 | [diff] [blame] | 154 | mockOpe.rollback(); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 155 | mockOpe.close(); |
| 156 | replay(mockOpe); |
| 157 | |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 158 | swSt.init(dbStore, conf); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 159 | swSt.addSwitch(dpid); |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Desc: |
| 164 | * Test method for addSwitch method. |
| 165 | * Condition: |
HIGUCHI Yuta | fabb003 | 2013-06-28 11:31:33 -0700 | [diff] [blame] | 166 | * Throw runtimeException. |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 167 | * Expect: |
| 168 | * The rollback method is called. |
| 169 | */ |
| 170 | //@Ignore |
| 171 | @Test |
| 172 | public void testAddSwitchException() { |
| 173 | String dpid = "00:00:00:00:00:00:0a:07"; |
| 174 | String state = "ACTIVE"; |
| 175 | |
| 176 | //Mock Switch |
| 177 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
| 178 | mockISw.setState(state); |
| 179 | replay(mockISw); |
| 180 | |
| 181 | //Expectation of mock operation. |
| 182 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 183 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 184 | mockOpe.commit(); |
| 185 | expectLastCall().andThrow(new RuntimeException()); |
| 186 | mockOpe.rollback(); |
| 187 | mockOpe.close(); |
| 188 | replay(mockOpe); |
| 189 | |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 190 | swSt.init(dbStore, conf); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 191 | swSt.addSwitch(dpid); |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Desc: |
| 196 | * Test method for updateSwitch method. |
| 197 | * Condition: |
| 198 | * SwitchState : INACTIVE |
| 199 | * DMOPERATION : UPDATE |
| 200 | * Expect: |
| 201 | * Should call addSwitch function and commit. |
| 202 | */ |
| 203 | //@Ignore |
| 204 | @Test |
| 205 | public void testUpdateUPDATE() { |
| 206 | String dpid = "00:00:00:00:00:00:0a:07"; |
| 207 | SwitchState stateINACTIVE = SwitchState.INACTIVE; |
| 208 | DM_OPERATION opUPDATE = DM_OPERATION.UPDATE; |
| 209 | |
| 210 | //Mock Switch |
| 211 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 212 | mockISw.setState(stateINACTIVE.toString()); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 213 | expect(mockISw.getDPID()).andReturn(dpid).anyTimes(); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 214 | replay(mockISw); |
| 215 | |
| 216 | //Expectation of mock operation. |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 217 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
| 218 | mockOpe.commit(); |
| 219 | mockOpe.close(); |
| 220 | replay(mockOpe); |
| 221 | |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 222 | swSt.init(dbStore, conf); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 223 | swSt.updateSwitch(dpid, stateINACTIVE, opUPDATE); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Desc: |
| 228 | * Test method for updateSwitch method. |
| 229 | * Condition: |
| 230 | * SwitchState : INACTIVE |
| 231 | * DMOPERATION : CREATE |
| 232 | * Expect: |
| 233 | * Should call addSwitch function and commit. |
| 234 | */ |
| 235 | //@Ignore |
| 236 | @Test |
| 237 | public void testUpdateCREATE() { |
| 238 | String dpid = "00:00:00:00:00:00:0a:07"; |
| 239 | SwitchState stateINACTIVE = SwitchState.INACTIVE; |
| 240 | DM_OPERATION opCREATE = DM_OPERATION.CREATE; |
| 241 | |
| 242 | //Mock Switch |
| 243 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
| 244 | mockISw.setState("ACTIVE"); |
| 245 | mockISw.setState(stateINACTIVE.toString()); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 246 | expect(mockISw.getDPID()).andReturn(dpid).anyTimes(); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 247 | replay(mockISw); |
| 248 | |
| 249 | //Expectation of mock operation. |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 250 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 251 | mockOpe.commit(); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 252 | mockOpe.close(); |
| 253 | replay(mockOpe); |
| 254 | |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 255 | swSt.init(dbStore, conf); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 256 | swSt.updateSwitch(dpid, stateINACTIVE, opCREATE); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | /** |
| 260 | * Desc: |
| 261 | * Test method for updateSwitch method. |
| 262 | * Condition: |
| 263 | * SwitchState : INACTIVE |
| 264 | * DMOPERATION : INSERT |
| 265 | * Expect: |
| 266 | * Should call addSwitch function and commit. |
| 267 | */ |
| 268 | //@Ignore |
| 269 | @Test |
| 270 | public void testUpdateINSERT() { |
| 271 | String dpid = "00:00:00:00:00:00:0a:07"; |
| 272 | SwitchState stateINACTIVE = SwitchState.INACTIVE; |
| 273 | DM_OPERATION opINSERT = DM_OPERATION.INSERT; |
| 274 | |
| 275 | //Mock Switch |
| 276 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
| 277 | mockISw.setState("ACTIVE"); |
| 278 | mockISw.setState(stateINACTIVE.toString()); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 279 | expect(mockISw.getDPID()).andReturn(dpid).anyTimes(); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 280 | replay(mockISw); |
| 281 | |
| 282 | //Expectation of mock operation. |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 283 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 284 | mockOpe.commit(); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 285 | mockOpe.close(); |
| 286 | replay(mockOpe); |
| 287 | |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 288 | swSt.init(dbStore, conf); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 289 | swSt.updateSwitch(dpid, stateINACTIVE, opINSERT); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | /** |
| 293 | * Desc: |
| 294 | * Test method for updateSwitch method. |
| 295 | * Condition: |
| 296 | * SwitchState : ACTIVE |
| 297 | * DMOPERATION : DELETE |
| 298 | * Expect: |
| 299 | * Should call removeSwitch function and commit. |
| 300 | */ |
| 301 | //@Ignore |
| 302 | @Test |
| 303 | public void testUpdateDELETE() { |
| 304 | String dpid = "00:00:00:00:00:00:0a:07"; |
| 305 | SwitchState stateACTIVE = SwitchState.ACTIVE; |
| 306 | DM_OPERATION opDELETE = DM_OPERATION.DELETE; |
| 307 | |
| 308 | //Mock Switch |
| 309 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
| 310 | mockISw.setState(stateACTIVE.toString()); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 311 | expect(mockISw.getDPID()).andReturn(dpid).anyTimes(); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 312 | replay(mockISw); |
| 313 | |
| 314 | //Expectation of mock operation. |
| 315 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 316 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 317 | mockOpe.commit(); |
| 318 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
| 319 | mockOpe.removeSwitch(mockISw); |
| 320 | mockOpe.commit(); |
| 321 | mockOpe.close(); |
| 322 | replay(mockOpe); |
| 323 | |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 324 | swSt.init(dbStore, conf); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 325 | swSt.addSwitch(dpid); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 326 | swSt.updateSwitch(dpid, stateACTIVE, opDELETE); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /** |
| 330 | * Desc: |
| 331 | * Test method for deleteSwitch method. |
| 332 | * Condition: |
| 333 | * The switch is existing. |
| 334 | * Expect: |
| 335 | * Should call removeSwitch function and commit. |
| 336 | */ |
| 337 | //@Ignore |
| 338 | @Test |
| 339 | public void testDeleteSwitch() { |
| 340 | String dpid = "00:00:00:00:00:00:0a:07"; |
| 341 | String state = "ACTIVE"; |
| 342 | |
| 343 | //Mock Switch |
| 344 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
| 345 | mockISw.setState(state); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 346 | expect(mockISw.getDPID()).andReturn(dpid).anyTimes(); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 347 | replay(mockISw); |
| 348 | |
| 349 | //Expectation of mock operation. |
| 350 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 351 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 352 | mockOpe.commit(); |
| 353 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
| 354 | mockOpe.removeSwitch(mockISw); |
| 355 | mockOpe.commit(); |
| 356 | mockOpe.close(); |
| 357 | replay(mockOpe); |
| 358 | |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 359 | swSt.init(dbStore, conf); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 360 | swSt.addSwitch(dpid); |
| 361 | swSt.deleteSwitch(dpid); |
| 362 | |
| 363 | //Iterator<Vertex> it = titanGraph.getVertices("dpid", dpid).iterator(); |
| 364 | //assertFalse(it.hasNext()); |
| 365 | } |
| 366 | |
| 367 | /** |
| 368 | * Desc: |
| 369 | * Test method for deleteSwitch method. |
| 370 | * Condition: |
| 371 | * The commit func throw exception. |
| 372 | * Expect: |
| 373 | * Should call rollback. |
| 374 | */ |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 375 | @Test |
| 376 | public void testDeleteSwitchException() { |
| 377 | String dpid = "00:00:00:00:00:00:0a:07"; |
| 378 | String state = "ACTIVE"; |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 379 | |
| 380 | //Mock Switch |
| 381 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
| 382 | mockISw.setState(state); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 383 | expect(mockISw.getDPID()).andReturn(dpid).anyTimes(); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 384 | replay(mockISw); |
| 385 | |
| 386 | //Expectation of mock operation. |
| 387 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 388 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 389 | mockOpe.commit(); |
| 390 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
Yuta HIGUCHI | b63f94f | 2013-10-14 10:01:45 -0700 | [diff] [blame] | 391 | mockOpe.removeSwitch(mockISw); |
| 392 | mockOpe.commit(); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 393 | expectLastCall().andThrow(new RuntimeException()); |
| 394 | mockOpe.rollback(); |
| 395 | mockOpe.close(); |
| 396 | replay(mockOpe); |
| 397 | |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 398 | swSt.init(dbStore, conf); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 399 | swSt.addSwitch(dpid); |
| 400 | swSt.deleteSwitch(dpid); |
| 401 | } |
| 402 | |
| 403 | /** |
| 404 | * Desc: |
| 405 | * Test method for addPort method. |
| 406 | * Condition: |
| 407 | * port is existing. |
| 408 | * Expect: |
| 409 | * Should call addPort and commit. |
| 410 | */ |
| 411 | //@Ignore |
| 412 | @Test |
| 413 | public void testAddPort() { |
| 414 | String dpid = "00:00:00:00:00:00:0a:01"; |
| 415 | short portNumber = 5; |
| 416 | String state = "ACTIVE"; |
| 417 | String name = "port 5 at SEA switch"; |
| 418 | |
| 419 | OFPhysicalPort portToAdd = new OFPhysicalPort(); |
| 420 | portToAdd.setName(name); |
| 421 | portToAdd.setCurrentFeatures(OFPhysicalPort.OFPortFeatures.OFPPF_100MB_FD.getValue()); |
| 422 | portToAdd.setPortNumber(portNumber); |
| 423 | portToAdd.setState(OFPortState.OFPPS_STP_FORWARD.getValue()); |
| 424 | |
| 425 | //Expectation of mock Port |
| 426 | IPortObject mockIPort = createMock(IPortObject.class); |
| 427 | mockIPort.setState(state); |
| 428 | mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue()); |
| 429 | mockIPort.setDesc(name); |
| 430 | replay(mockIPort); |
| 431 | |
| 432 | //Expectation of mock Switch |
| 433 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
| 434 | mockISw.setState(state); |
| 435 | mockISw.addPort(mockIPort); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 436 | expect(mockISw.getPort(anyShort())).andReturn(null); |
| 437 | expect(mockISw.getDPID()).andReturn(dpid).anyTimes(); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 438 | replay(mockISw); |
| 439 | |
| 440 | //Expectation of mock operation. |
| 441 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 442 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 443 | mockOpe.commit(); |
| 444 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 445 | // expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null); |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 446 | expect(mockOpe.newPort(dpid, portNumber)).andReturn(mockIPort); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 447 | mockOpe.commit(); |
| 448 | mockOpe.close(); |
| 449 | replay(mockOpe); |
| 450 | |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 451 | swSt.init(dbStore, conf); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 452 | swSt.addSwitch(dpid); |
| 453 | swSt.addPort(dpid, portToAdd); |
| 454 | } |
| 455 | |
| 456 | /** |
| 457 | * Desc: |
| 458 | * Test method for addPort method. |
| 459 | * Condition: |
| 460 | * Port status is down. |
| 461 | * Expect: |
| 462 | * Should call removePort and commit. |
| 463 | */ |
| 464 | //@Ignore |
| 465 | @Test |
| 466 | public void testAddPortWithPortLinkDown() { |
| 467 | String dpid = "00:00:00:00:00:00:0a:01"; |
| 468 | short portNumber = 5; |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 469 | String swState = "ACTIVE"; |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 470 | // String portState = "INACTIVE"; |
| 471 | String portId = "5"; |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 472 | String name = "port 5 at SEA switch"; |
| 473 | |
| 474 | OFPhysicalPort portToAdd = new OFPhysicalPort(); |
| 475 | portToAdd.setName(name); |
| 476 | portToAdd.setCurrentFeatures(OFPhysicalPort.OFPortFeatures.OFPPF_100MB_FD.getValue()); |
| 477 | portToAdd.setPortNumber(portNumber); |
| 478 | portToAdd.setState(OFPortState.OFPPS_LINK_DOWN.getValue()); |
| 479 | |
| 480 | //Expectation of mock Port |
| 481 | IPortObject mockIPort = createMock(IPortObject.class); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 482 | expect(mockIPort.getPortId()).andReturn(portId); |
| 483 | // mockIPort.setState(portState); |
| 484 | // mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue()); |
| 485 | // mockIPort.setDesc(name); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 486 | replay(mockIPort); |
| 487 | |
| 488 | //Expectation of mock Switch |
| 489 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 490 | mockISw.setState(swState); |
| 491 | // mockISw.removePort(mockIPort); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 492 | expect(mockISw.getPort(anyShort())).andReturn(mockIPort); |
| 493 | expect(mockISw.getDPID()).andReturn(dpid).anyTimes(); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 494 | replay(mockISw); |
| 495 | |
| 496 | //Expectation of mock operation. |
| 497 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 498 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 499 | mockOpe.commit(); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 500 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 501 | // expect(mockOpe.searchPort(dpid, portNumber)).andReturn(mockIPort); |
| 502 | mockOpe.removePort(mockIPort); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 503 | mockOpe.commit(); |
| 504 | mockOpe.close(); |
| 505 | replay(mockOpe); |
| 506 | |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 507 | swSt.init(dbStore, conf); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 508 | swSt.addSwitch(dpid); |
| 509 | swSt.addPort(dpid, portToAdd); |
| 510 | } |
| 511 | |
| 512 | /** |
| 513 | * Desc: |
| 514 | * Test method for addPort method. |
| 515 | * Condition: |
| 516 | * The switch is not existing. |
| 517 | * Expect: |
| 518 | * Nothing happens. |
| 519 | */ |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 520 | @Test |
| 521 | public void testAddPortAbnormalNoSwitch() { |
| 522 | String dpid = "00:00:00:00:00:00:0a:01"; |
| 523 | short portNumber = 5; |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 524 | String name = "port 5 at SEA switch"; |
| 525 | |
| 526 | OFPhysicalPort portToAdd = new OFPhysicalPort(); |
| 527 | portToAdd.setName(name); |
| 528 | portToAdd.setCurrentFeatures(OFPhysicalPort.OFPortFeatures.OFPPF_100MB_FD.getValue()); |
| 529 | portToAdd.setPortNumber(portNumber); |
| 530 | portToAdd.setState(OFPortState.OFPPS_STP_FORWARD.getValue()); |
| 531 | |
| 532 | //Expectation of mock Port |
| 533 | IPortObject mockIPort = createStrictMock(IPortObject.class); |
| 534 | replay(mockIPort); |
| 535 | |
| 536 | //Expectation of mock Switch |
| 537 | ISwitchObject mockISw = createStrictMock(ISwitchObject.class); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 538 | expect(mockISw.getDPID()).andReturn(dpid).anyTimes(); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 539 | replay(mockISw); |
| 540 | |
| 541 | //Expectation of mock operation. |
| 542 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 543 | mockOpe.close(); |
| 544 | replay(mockOpe); |
| 545 | |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 546 | swSt.init(dbStore, conf); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 547 | swSt.addPort(dpid, portToAdd); |
| 548 | } |
| 549 | |
| 550 | /** |
| 551 | * Desc: |
| 552 | * Test method for addPort method. |
| 553 | * Condition: |
| 554 | * port is not existing. |
| 555 | * Expect: |
| 556 | * Should call addPort and commit. |
| 557 | */ |
| 558 | //@Ignore |
| 559 | @Test |
| 560 | public void testAddPortAbnormalNoPort() { |
| 561 | String dpid = "00:00:00:00:00:00:0a:01"; |
| 562 | short portNumber = 5; |
| 563 | String state = "ACTIVE"; |
| 564 | String name = "port 5 at SEA switch"; |
| 565 | |
| 566 | OFPhysicalPort portToAdd = new OFPhysicalPort(); |
| 567 | portToAdd.setName(name); |
| 568 | portToAdd.setCurrentFeatures(OFPhysicalPort.OFPortFeatures.OFPPF_100MB_FD.getValue()); |
| 569 | portToAdd.setPortNumber(portNumber); |
| 570 | portToAdd.setState(OFPortState.OFPPS_STP_FORWARD.getValue()); |
| 571 | |
| 572 | //Expectation of mock Port |
| 573 | IPortObject mockIPort = createMock(IPortObject.class); |
| 574 | mockIPort.setState(state); |
| 575 | mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue()); |
| 576 | mockIPort.setDesc(name); |
| 577 | replay(mockIPort); |
| 578 | |
| 579 | //Expectation of mock Switch |
| 580 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
| 581 | mockISw.setState(state); |
| 582 | mockISw.addPort(mockIPort); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 583 | expect(mockISw.getPort(portNumber)).andReturn(null); |
| 584 | expect(mockISw.getDPID()).andReturn(dpid).anyTimes(); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 585 | replay(mockISw); |
| 586 | |
| 587 | //Expectation of mock operation. |
| 588 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 589 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 590 | mockOpe.commit(); |
| 591 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 592 | // expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null); |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 593 | expect(mockOpe.newPort(dpid, portNumber)).andReturn(null); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 594 | mockOpe.rollback(); |
| 595 | mockOpe.close(); |
| 596 | replay(mockOpe); |
| 597 | |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 598 | swSt.init(dbStore, conf); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 599 | swSt.addSwitch(dpid); |
| 600 | swSt.addPort(dpid, portToAdd); |
| 601 | } |
| 602 | |
| 603 | /** |
| 604 | * Desc: |
| 605 | * Test method for addPort method. |
| 606 | * Condition: |
| 607 | * commit throw the exception. |
| 608 | * Expect: |
| 609 | * Should call rollback. |
| 610 | */ |
| 611 | //@Ignore |
| 612 | @Test |
| 613 | public void testAddPortWithException() { |
| 614 | String dpid = "00:00:00:00:00:00:0a:01"; |
| 615 | short portNumber = 5; |
| 616 | String state = "ACTIVE"; |
| 617 | String name = "port 5 at SEA switch"; |
| 618 | |
| 619 | OFPhysicalPort portToAdd = new OFPhysicalPort(); |
| 620 | portToAdd.setName(name); |
| 621 | portToAdd.setCurrentFeatures(OFPhysicalPort.OFPortFeatures.OFPPF_100MB_FD.getValue()); |
| 622 | portToAdd.setPortNumber(portNumber); |
| 623 | portToAdd.setState(OFPortState.OFPPS_STP_FORWARD.getValue()); |
| 624 | |
| 625 | //Expectation of mock Port |
| 626 | IPortObject mockIPort = createMock(IPortObject.class); |
| 627 | mockIPort.setState(state); |
| 628 | mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue()); |
| 629 | mockIPort.setDesc(name); |
| 630 | replay(mockIPort); |
| 631 | |
| 632 | //Expectation of mock Switch |
| 633 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
| 634 | mockISw.setState(state); |
| 635 | mockISw.addPort(mockIPort); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 636 | expect(mockISw.getPort(portNumber)).andReturn(null); |
| 637 | expect(mockISw.getDPID()).andReturn(dpid).anyTimes(); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 638 | replay(mockISw); |
| 639 | |
| 640 | //Expectation of mock operation. |
| 641 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 642 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 643 | mockOpe.commit(); |
| 644 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 645 | // expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null); |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 646 | expect(mockOpe.newPort(dpid, portNumber)).andReturn(mockIPort); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 647 | mockOpe.commit(); |
| 648 | expectLastCall().andThrow(new RuntimeException()); |
| 649 | mockOpe.rollback(); |
| 650 | mockOpe.close(); |
| 651 | replay(mockOpe); |
| 652 | |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 653 | swSt.init(dbStore, conf); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 654 | swSt.addSwitch(dpid); |
| 655 | swSt.addPort(dpid, portToAdd); |
| 656 | } |
| 657 | |
| 658 | /** |
| 659 | * Desc: |
| 660 | * Test method for deletePort method. |
| 661 | * Condition: |
| 662 | * port is existing. |
| 663 | * Expect: |
| 664 | * Should call removePort and commit. |
| 665 | */ |
| 666 | //@Ignore |
| 667 | @Test |
| 668 | public void testDeletePort() { |
| 669 | String dpid = "00:00:00:00:00:00:0a:01"; |
| 670 | short portNumber = 5; |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 671 | String portState = "INACTIVE"; |
| 672 | String swState = "ACTIVE"; |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 673 | String portId = "5"; |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 674 | String name = "port 5 at SEA switch"; |
| 675 | |
| 676 | OFPhysicalPort portToAdd = new OFPhysicalPort(); |
| 677 | portToAdd.setName(name); |
| 678 | portToAdd.setCurrentFeatures(OFPhysicalPort.OFPortFeatures.OFPPF_100MB_FD.getValue()); |
| 679 | portToAdd.setPortNumber(portNumber); |
| 680 | portToAdd.setState(OFPortState.OFPPS_STP_FORWARD.getValue()); |
| 681 | |
| 682 | //Expectation of mock Port |
| 683 | IPortObject mockIPort = createMock(IPortObject.class); |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 684 | mockIPort.setState(swState); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 685 | // mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue()); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 686 | mockIPort.setDesc(name); |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 687 | mockIPort.setState(portState); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 688 | expect(mockIPort.getPortId()).andReturn(portId); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 689 | replay(mockIPort); |
| 690 | |
| 691 | //Expectation of mock Switch |
| 692 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 693 | mockISw.setState(swState); |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 694 | // mockISw.removePort(mockIPort); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 695 | expect(mockISw.getPort(portNumber)).andReturn(null); |
| 696 | mockISw.addPort(mockIPort); |
| 697 | expect(mockISw.getPort(portNumber)).andReturn(mockIPort); |
| 698 | expect(mockISw.getDPID()).andReturn(dpid).anyTimes(); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 699 | replay(mockISw); |
| 700 | |
| 701 | //Expectation of mock operation. |
| 702 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 703 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 704 | mockOpe.commit(); |
| 705 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 706 | // expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null); |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 707 | expect(mockOpe.newPort(dpid, portNumber)).andReturn(mockIPort); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 708 | mockOpe.commit(); |
| 709 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 710 | // expect(mockOpe.searchPort(dpid, portNumber)).andReturn(mockIPort); |
| 711 | mockOpe.removePort(mockIPort); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 712 | mockOpe.commit(); |
| 713 | mockOpe.close(); |
| 714 | replay(mockOpe); |
| 715 | |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 716 | swSt.init(dbStore, conf); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 717 | swSt.addSwitch(dpid); |
| 718 | swSt.addPort(dpid, portToAdd); |
| 719 | swSt.deletePort(dpid, portNumber); |
| 720 | } |
| 721 | |
| 722 | /** |
| 723 | * Desc: |
| 724 | * Test method for addPort method. |
| 725 | * Condition: |
| 726 | * commit throws the exception. |
| 727 | * Expect: |
| 728 | * Should call rollback. |
| 729 | */ |
| 730 | //@Ignore |
| 731 | @Test |
| 732 | public void testDeletePortException() { |
| 733 | String dpid = "00:00:00:00:00:00:0a:01"; |
| 734 | short portNumber = 5; |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 735 | String swState = "ACTIVE"; |
| 736 | String portState = "INACTIVE"; |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 737 | String portId = "5"; |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 738 | String name = "port 5 at SEA switch"; |
| 739 | |
| 740 | OFPhysicalPort portToAdd = new OFPhysicalPort(); |
| 741 | portToAdd.setName(name); |
| 742 | portToAdd.setCurrentFeatures(OFPhysicalPort.OFPortFeatures.OFPPF_100MB_FD.getValue()); |
| 743 | portToAdd.setPortNumber(portNumber); |
| 744 | portToAdd.setState(OFPortState.OFPPS_STP_FORWARD.getValue()); |
| 745 | |
| 746 | //Expectation of mock Port |
| 747 | IPortObject mockIPort = createMock(IPortObject.class); |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 748 | mockIPort.setState(swState); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 749 | mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue()); |
| 750 | mockIPort.setDesc(name); |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 751 | mockIPort.setState(portState); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 752 | expect(mockIPort.getPortId()).andReturn(portId); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 753 | replay(mockIPort); |
| 754 | |
| 755 | //Expectation of mock Switch |
| 756 | ISwitchObject mockISw = createMock(ISwitchObject.class); |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 757 | mockISw.setState(swState); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 758 | mockISw.addPort(mockIPort); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 759 | expect(mockISw.getPort(portNumber)).andReturn(null); |
| 760 | expect(mockISw.getPort(portNumber)).andReturn(mockIPort).anyTimes(); |
Pankaj Berde | ac54a4b | 2013-08-02 15:31:28 -0700 | [diff] [blame] | 761 | // mockISw.removePort(mockIPort); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 762 | |
| 763 | expect(mockISw.getDPID()).andReturn(dpid).anyTimes(); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 764 | replay(mockISw); |
| 765 | |
| 766 | //Expectation of mock operation. |
| 767 | expect(mockOpe.searchSwitch(dpid)).andReturn(null); |
| 768 | expect(mockOpe.newSwitch(dpid)).andReturn(mockISw); |
| 769 | mockOpe.commit(); |
| 770 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 771 | // expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null); |
Pankaj Berde | bbd3861 | 2013-06-22 05:59:12 -0700 | [diff] [blame] | 772 | expect(mockOpe.newPort(dpid, portNumber)).andReturn(mockIPort); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 773 | mockOpe.commit(); |
| 774 | expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw); |
Naoki Shiota | 987a572 | 2013-10-23 11:59:36 -0700 | [diff] [blame] | 775 | // expect(mockOpe.searchPort(dpid, portNumber)).andReturn(mockIPort); |
| 776 | // mockOpe.commit(); // Cannot generate exception..need to revisit this test |
| 777 | mockOpe.removePort(mockIPort); |
| 778 | expectLastCall().andThrow(new RuntimeException()); |
| 779 | mockOpe.rollback(); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 780 | mockOpe.close(); |
| 781 | replay(mockOpe); |
| 782 | |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 783 | swSt.init(dbStore, conf); |
Teru | ab4b01a | 2013-06-20 10:09:57 -0700 | [diff] [blame] | 784 | swSt.addSwitch(dpid); |
| 785 | swSt.addPort(dpid, portToAdd); |
| 786 | swSt.deletePort(dpid, portNumber); |
| 787 | } |
| 788 | } |