throws Exception
{
File dir = TestConfig.getTestDir("test.app.feed.basics");
dir.delete();
TestConfig config = new TestConfig("test.app.feed.basics","localhost","localhost",8080);
// Make sure we start clean
System.out.println("Using database directory: "+config.getDatabaseDirectory());
config.startServer();
Client client = new Client(new Context(),config.getServerLocation().getSchemeProtocol()) {
public void handle(Request request,Response response) {
request.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,"admin","admin"));
super.handle(request,response);
}
};
Reference rootFeed = new Reference(config.getServerLocation()+"R/");
Response response;
Form headers;
String entryLocation;
Reference entryRef;
response = client.handle(makeHead(rootFeed));
System.out.println("Status: "+response.getStatus());
switch (response.getStatus().getCode()) {
case 404:
{
System.out.println("Creating feed.");
response = client.handle(makePost(rootFeed,new StringRepresentation("<feed xmlns='http://www.w3.org/2005/Atom'><title>Root</title></feed>",MediaType.APPLICATION_ATOM)));
System.out.println("Status: "+response.getStatus());
response.getEntity().release();
assertTrue(response.getStatus().isSuccess());
break;
}
default:
assertTrue(response.getStatus().isSuccess());
}
response = client.handle(makePost(rootFeed,new StringRepresentation("<entry xmlns='http://www.w3.org/2005/Atom'><title>Entry 1</title></entry>",MediaType.APPLICATION_ATOM)));
System.out.println("Status: "+response.getStatus());
assertTrue(response.getStatus().isSuccess());
headers = (Form)response.getAttributes().get("org.restlet.http.headers");
entryLocation = headers.getValues("Location");
System.out.println("Entry: "+entryLocation);
//System.out.println("Entry: "+response.getEntity().getText());
response.getEntity().release();
entryRef = new Reference(entryLocation);
response = client.handle(makeGet(entryRef));
System.out.println("Status: "+response.getStatus());
response.getEntity().release();
assertTrue(response.getStatus().isSuccess());
response = client.handle(makePost(rootFeed,new StringRepresentation("<entry xmlns='http://www.w3.org/2005/Atom'><title>Entry 2</title></entry>",MediaType.APPLICATION_ATOM)));
System.out.println("Status: "+response.getStatus());
response.getEntity().release();
assertTrue(response.getStatus().isSuccess());
entryLocation = headers.getValues("Location");
System.out.println("Entry: "+entryLocation);
response.getEntity().release();
entryRef = new Reference(entryLocation);
response = client.handle(makeGet(entryRef));
System.out.println("Status: "+response.getStatus());
assertTrue(response.getStatus().isSuccess());
response.getEntity().release();
response = client.handle(makePut(rootFeed,new StringRepresentation("<feed xmlns='http://www.w3.org/2005/Atom'><title>Root</title><category term='test'/><category term='bingo'/></feed>",MediaType.APPLICATION_ATOM)));
System.out.println("Status: "+response.getStatus());
assertTrue(response.getStatus().isSuccess());
response.getEntity().release();
config.stopServer();
}