Package org.apache.directmemory.serialization

Examples of org.apache.directmemory.serialization.Serializer


    @Test
    public void storeObjectThenRemove()
        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
View Full Code Here


    public void simpleSerialization()
        throws Exception
    {
        Wine wine = getWineInstance();

        Serializer serializer = SerializerFactory.createNewSerializer( getSerializerClassName() );

        byte[] bytes = serializer.serialize( wine );

        Wine newWine = serializer.deserialize( bytes, Wine.class );

        assertEquals( wine.getName(), newWine.getName() );
        assertEquals( wine.getDescription(), newWine.getDescription() );

    }
View Full Code Here

TOP

Related Classes of org.apache.directmemory.serialization.Serializer

Copyright © 2018 www.massapicom. 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.