blob: aef7262d9cff06fe059305ed2a0b7d1ab13da408 [file] [log] [blame]
Ray Milkey0fe43852014-06-05 14:41:46 -07001package net.onrc.onos.api.rest;
2
3import net.floodlightcontroller.core.module.FloodlightModuleContext;
4import net.floodlightcontroller.core.module.FloodlightModuleException;
5import net.onrc.onos.core.intent.runtime.IntentTestMocks;
6import net.onrc.onos.core.intent.runtime.PathCalcRuntimeModule;
Ray Milkey0fe43852014-06-05 14:41:46 -07007import net.onrc.onos.core.topology.ITopologyService;
8import net.onrc.onos.core.topology.web.TopologyWebRoutable;
Ray Milkey0fe43852014-06-05 14:41:46 -07009
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 */
15public 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 Milkey0fe43852014-06-05 14:41:46 -070071}