Ray Milkey | 0fe4385 | 2014-06-05 14:41:46 -0700 | [diff] [blame] | 1 | package net.onrc.onos.api.rest; |
| 2 | |
| 3 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 4 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 5 | import net.onrc.onos.core.intent.runtime.IntentTestMocks; |
| 6 | import net.onrc.onos.core.intent.runtime.PathCalcRuntimeModule; |
Ray Milkey | 0fe4385 | 2014-06-05 14:41:46 -0700 | [diff] [blame] | 7 | import net.onrc.onos.core.topology.ITopologyService; |
| 8 | import net.onrc.onos.core.topology.web.TopologyWebRoutable; |
Ray Milkey | 0fe4385 | 2014-06-05 14:41:46 -0700 | [diff] [blame] | 9 | |
| 10 | /** |
| 11 | * Test harness for Topology based REST API tests. This class maintains the |
| 12 | * web server and mocks required for testing topology APIs. REST API tests |
| 13 | * for topology should inherit from this class. |
| 14 | */ |
| 15 | public class TestRestTopology extends TestRest { |
| 16 | |
| 17 | private IntentTestMocks mocks; |
| 18 | |
| 19 | /** |
| 20 | * Fetch the Intent mocking object. |
| 21 | * |
| 22 | * @return intent mocking object |
| 23 | */ |
| 24 | IntentTestMocks getMocks() { |
| 25 | return mocks; |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Create the web server and mocks required for the topology tests. |
| 30 | */ |
| 31 | @Override |
| 32 | public void setUp() { |
| 33 | mocks = new IntentTestMocks(); |
| 34 | mocks.setUpIntentMocks(); |
| 35 | |
| 36 | addRestlet(new TopologyWebRoutable()); |
| 37 | super.setUp(); |
| 38 | |
| 39 | final PathCalcRuntimeModule runtime = new PathCalcRuntimeModule(); |
| 40 | final FloodlightModuleContext moduleContext = getMocks().getModuleContext(); |
| 41 | try { |
| 42 | runtime.init(moduleContext); |
| 43 | } catch (FloodlightModuleException floodlightEx) { |
| 44 | throw new IllegalArgumentException(floodlightEx); |
| 45 | } |
| 46 | runtime.startUp(moduleContext); |
| 47 | |
| 48 | getRestApiServer().addAttribute(ITopologyService.class.getCanonicalName(), |
| 49 | mocks.getTopologyService()); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Remove anything that will interfere with the next test running correctly. |
| 54 | * Shuts down the test REST web server and removes the mocks. |
| 55 | */ |
| 56 | @Override |
| 57 | public void tearDown() { |
| 58 | getMocks().tearDownIntentMocks(); |
| 59 | super.tearDown(); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Fetch the base URL for Topology REST APIs. |
| 64 | * |
| 65 | * @return base URL |
| 66 | */ |
| 67 | String getBaseRestTopologyUrl() { |
| 68 | return getBaseRestUrl() + "/topology"; |
| 69 | } |
| 70 | |
Ray Milkey | 0fe4385 | 2014-06-05 14:41:46 -0700 | [diff] [blame] | 71 | } |