Some interesting tidbits:
First, I am continuing to observe the Hackystat tradition of always including a reference to an Issue in the SVN commit message. In this case, the reference looks like:
http://code.google.com/p/hackystat-sensorbase-uh/issues/detail?id=3
Second, to my surprise, I am coding 100% in a TDD style, not out of any philosophical commitment or moral imperative, but simply out of the sense that this is just the most natural way to start to get some leverage on the SensorBase implementation. The REST API specification turns out to form a very nice specification of the target behavior, and so I just picked the first URI in the table (GET host/hackystat/sensordatatypes) which is supposed to return a list of sensordatatype resource references, and wrote a unit test which tries that call on a server. Of course, the test fails, because I haven't written the server yet.
Third, to my relief, the Restlet framework makes that test case wicked easy to write. In fact, here it is:
There's a couple of rough edges (I can't hard code the server URI, and my XPath is probably bogus), but the code runs and does the right thing (i.e. fails at the getStatus call with a connection not found error.)
@Test public void getSdtIndex () {
// Set up the call.
Method method = Method.GET;
Reference reference = new Reference("http://localhost:9090/hackystat/sensordatatypes");
Request request = new Request(method, reference);
// Make the call.
Client client = new Client(Protocol.HTTP);
Response response = client.handle(request);
// Test that the request was received and processed by the server OK.
assertTrue("Testing for successful status", response.getStatus().isSuccess());
// Now test that the response is OK.
XmlRepresentation data = response.getEntityAsSax();
assertEquals("Checking SDT", "SampleSDT", data.getText("SensorDataTypes/SensorDataType/@Name"));
}
I'm sure things won't be this easy forever, but it's nice to get off to a smooth start.
No comments:
Post a Comment