Reference Guide

Table Of Contents
Figure 54 REST API CURL Execution Example
RESTful Web Services Unit Test
Even though at this point the implementation uses fake data, a unit test is shown to illustrate the
utility classes provided by the HP VAN SDN Controller SDK; creating good test cases is
application dependent and it is out of the scope of this document.
The following listing shows the unit test for SwitchResource using the infrastructure class
ClientResourceTest provided by the HP VAN SDN Controller SDK. SwitchResourceTest should be
located under hm-rs/src/test/java/com/hp/hm/rs directory. New dependencies needed at
runtime must be declared in order to properly run the resource test. Open the hm-rs/pom.xml file
and add the XML extract from the Resource Test Dependencies listing to the <dependencies>
node; after updating the POM file update the Eclipse project dependencies (see Updating Project
Dependencies on page 146).
SwitchResourceTest.java:
package com.hp.hm.rs;
import com.hp.sdn.rs.misc.ControllerResourceTest;
import com.hp.util.rs.ResourceTest;
...
public class SwitchResourceTest extends ControllerResourceTest {
private static final String BASE_PATH = "switches";
public SwitchResourceTest() {
super("com.hp.hm.rs");
}
@Override
@Before
public void setUp() throws Exception {
super.setUp();
// If a specific test case expects a different format, such
// format will have to be set calling this method.
178