SDN Controller Programming Guide

156
import com.hp.sdn.json.JsonService;
...
public class SwitchResourceTest extends ControllerResourceTest {
private static final String BASE_PATH = "switches";
private SwitchService switchServiceMock;
private JsonService jsonServiceMock;
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());
jsonServiceMock = EasyMock.createMock(JsonService.class);
sl.register(JsonService.class, jsonServiceMock,
Collections.<String, Object> emptyMap());
}
@Override
@After
public void tearDown() throws Exception {
super.tearDown();
sl.unregister(SwitchService.class, switchServiceMock);
sl.unregister(JsonService.class, jsonServiceMock);
}
@Test
public void testList() {
// Create mocks and define test case data
// Note that the expected switches can be anything
// (it doesn't matter) since the SwitchService has been mocked.
List<Switch> switches = Collections.emptyList();
// Note that the returned JSON does not matter since
// the JSON codec has been mocked.