public void testPutOnContainerAndItemResource() {
WebClient wc = WebClient.create(Main.BASE_URI);
int createdResponse = Response.Status.CREATED.getStatusCode();
// Create a child resource for the container "quotes"
Container quotesContainer = new Container("quotes", Main.BASE_URI + "/quotes");
// PUT the container "quotes"
Response response = wc.path("containers/quotes").put(quotesContainer);
assertEquals(createdResponse, response.getStatus());
// PUT the items to be added to the "quotes" container
response = wc.path("1").type(MediaType.TEXT_PLAIN)
.put("Something is rotten in the state of Denmark");
assertEquals(createdResponse, response.getStatus());
response = wc.back(false).path("2").type(MediaType.TEXT_PLAIN).put("I could be bounded in a nutshell");
assertEquals(createdResponse, response.getStatus());
response = wc.back(false).path("3").type(MediaType.TEXT_PLAIN).put("catch the conscience of the king");
assertEquals(createdResponse, response.getStatus());
response = wc.back(false).path("4").type(MediaType.TEXT_PLAIN).put("Get thee to a nunnery");
assertEquals(createdResponse, response.getStatus());
// check that there are four items in the container "quotes"
wc.back(true).path("containers/quotes");
Container container = wc.accept(MediaType.APPLICATION_XML).get(Container.class);
int numberOfItems = container.getItem().size();
int expectedNumber = 4;
assertEquals("Expected: " + expectedNumber + " items, Seeing: " + numberOfItems,
expectedNumber, numberOfItems);
// search the container for all items containing the word "king"
wc.query("search", "king");
container = wc.accept(MediaType.APPLICATION_XML).get(Container.class);
numberOfItems = (container.getItem() == null) ? 0 : container.getItem().size();
expectedNumber = 1;
assertEquals("Expected: " + expectedNumber
+ " items which pass the search criterion, Seeing: " + numberOfItems,
expectedNumber, numberOfItems);
}