@Test
public void storeObject()
throws Exception
{
Serializer serializer = SerializerFactory.createNewSerializer();
Wine bordeaux = new Wine( "Bordeaux", "very great wine" );
DirectMemoryRequest directMemoryRequest =
new DirectMemoryRequest().setKey( "bordeaux" ).setCacheContent( serializer.serialize( bordeaux ) );
String rq = writer.generateJsonRequest( directMemoryRequest );
MockHttpServletRequest putRequest = new MockHttpServletRequest();
putRequest.setContentType( MediaType.APPLICATION_JSON );
putRequest.setServletPath( "cache" );
putRequest.setPathInfo( "/bordeaux" );
putRequest.setContent( rq.getBytes() );
MockHttpServletResponse putResponse = new MockHttpServletResponse();
directMemoryServlet.doPut( putRequest, putResponse );
assertEquals( HttpServletResponse.SC_OK, putResponse.getStatus() );
// now retrieve the content
MockHttpServletRequest getRequest = new MockHttpServletRequest();
getRequest.addHeader( "Accept", MediaType.APPLICATION_JSON );
getRequest.setPathInfo( "/bordeaux" );
MockHttpServletResponse getResponse = new MockHttpServletResponse();
directMemoryServlet.doGet( getRequest, getResponse );
assertEquals( HttpServletResponse.SC_OK, getResponse.getStatus() );
assertEquals( MediaType.APPLICATION_JSON, getResponse.getContentType() );
DirectMemoryResponse response =
parser.buildResponse( new ByteArrayInputStream( getResponse.getContentAsByteArray() ) );
Wine wineFromCache = serializer.deserialize( response.getCacheContent(), Wine.class );
assertEquals( bordeaux.getName(), wineFromCache.getName() );
assertEquals( bordeaux.getDescription(), wineFromCache.getDescription() );
}