Examples of Wine


Examples of org.apache.directmemory.test.Wine

    @Test
    public void putAndGetAndDelete()
        throws Exception
    {
        Wine bordeaux = new Wine( "Bordeaux", "very great wine" );

        assertTrue( client.put( new DirectMemoryRequest<Wine>( "bordeaux", bordeaux ) ).isStored() );

        DirectMemoryResponse<Wine> response = client.retrieve( new DirectMemoryRequest( "bordeaux", Wine.class ) );

        assertTrue( response.isFound() );
        Wine wine = response.getResponse();
        assertEquals( "Bordeaux", wine.getName() );
        assertEquals( "very great wine", wine.getDescription() );

        // START SNIPPET: client-delete

        DirectMemoryResponse deleteResponse = client.delete( new DirectMemoryRequest<Wine>( "bordeaux" ) );
        assertTrue( deleteResponse.isDeleted() );
View Full Code Here

Examples of org.apache.directmemory.test.Wine

    public void putSmallExpiresAndGetNotFound()
        throws Exception
    {

        DirectMemoryResponse deleteResponse = client.delete( new DirectMemoryRequest<Wine>( "bordeaux" ) );
        Wine bordeaux = new Wine( "Bordeaux", "very great wine" );

        DirectMemoryResponse<Wine> response =
            client.put( new DirectMemoryRequest<Wine>( "bordeaux", bordeaux ).setExpiresIn( 1000 ) );

        assertTrue( response.isStored() );

        assertTrue( response.getStoredSize() > 0 );

        DirectMemoryRequest rq = new DirectMemoryRequest( "bordeaux", Wine.class );

        response = client.retrieve( rq );

        assertTrue( response.isFound() );
        Wine wine = response.getResponse();

        assertEquals( "Bordeaux", wine.getName() );
        assertEquals( "very great wine", wine.getDescription() );

        Thread.sleep( 10001 );

        rq = new DirectMemoryRequest( "bordeaux", Wine.class );
View Full Code Here

Examples of org.apache.directmemory.test.Wine

        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() );

    }
View Full Code Here

Examples of org.apache.directmemory.test.Wine

        throws Exception
    {

        Serializer serializer = SerializerFactory.createNewSerializer();

        Wine bordeaux = new Wine( "Bordeaux", "very great wine" );

        DirectMemoryRequest directMemoryRequest =
            new DirectMemoryRequest().setKey( "bordeaux" ).setCacheContent(
                serializer.serialize( bordeaux ) ).setExpiresIn( 3 );
View Full Code Here

Examples of org.apache.directmemory.test.Wine

        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() );

        // now delete the content

        MockHttpServletRequest deleteRq = new MockHttpServletRequest();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.