Reference Guide
Table Of Contents
- 1 Introduction
- 2 Establishing Your Test and Development Environments
- 3 Developing Applications
- Introduction
- Authentication
- REST API
- Audit Logging
- Alert Logging
- Configuration
- High Availability
- OpenFlow
- Metrics Framework
- GUI
- SKI Framework - Overview
- SKI Framework - Navigation Tree
- SKI Framework - Hash Navigation
- SKI Framework - View Life-Cycle
- SKI Framework - Live Reference Application
- UI Extension
- Introduction
- Controller Teaming
- Distributed Coordination Service
- Persistence
- Backup and Restore
- Device Driver Framework
- 4 Application Security
- 5 Including Debian Packages with Applications
- 6 Sample Application
- Application Description
- Creating Application Development Workspace
- Application Generator (Automatic Workspace Creation)
- Creating Eclipse Projects
- Updating Project Dependencies
- Building the Application
- Installing the Application
- Application Code
- 7 Testing Applications
- 8 Built-In Applications
- Appendix A
- Appendix B
- Bibliography
import com.hp.hm.api.SwitchService;
...
@Path("switches")
public class SwitchResource extends ControllerResource {
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response list() {
SwitchService service = get(SwitchService.class);
List<Switch> switches = service. getAll();
String result = "{switches:{}}"; // TODO: Encode switches
return ok(result).build();
}
...
}
The following SwitchResourceTest.java Mocking Domain Services listing shows an extract of a
modified SwitchResourceTest (from RESTful Web Services Unit Test on page 178) that uses
EasyMock [37] to mock SwitchService. Note how SwitchResourceTest registers the service mock
before the test and unregisters it after.
SwitchResourceTest.java Mocking Domain Services:
package com.hp.hm.rs;
import org.easymock.EasyMock;
import com.hp.hm.api.SwitchService;
...
public class SwitchResourceTest extends ControllerResourceTest {
private static final String BASE_PATH = "switches";
private SwitchService switchServiceMock;
public SwitchResourceTest() {
super("com.hp.hm.rs");
}
@Override
@Before
public void setUp() throws Exception {
super.setUp();
ResourceTest.setDefaultMediaType(MediaType.APPLICATION_JSON);
switchServiceMock = EasyMock.createMock(SwitchService.class);
sl.register(SwitchService.class, switchServiceMock,
Collections.<String, Object> emptyMap());
}
182