You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-dev@jakarta.apache.org by as...@apache.org on 2009/06/11 16:17:12 UTC

svn commit: r783781 - /jakarta/jcs/trunk/src/test/org/apache/jcs/utils/serialization/SerializationConversionUtilUnitTest.java

Author: asmuts
Date: Thu Jun 11 14:17:11 2009
New Revision: 783781

URL: http://svn.apache.org/viewvc?rev=783781&view=rev
Log:
adding more tests for the serialization util

Modified:
    jakarta/jcs/trunk/src/test/org/apache/jcs/utils/serialization/SerializationConversionUtilUnitTest.java

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/utils/serialization/SerializationConversionUtilUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/utils/serialization/SerializationConversionUtilUnitTest.java?rev=783781&r1=783780&r2=783781&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/utils/serialization/SerializationConversionUtilUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/utils/serialization/SerializationConversionUtilUnitTest.java Thu Jun 11 14:17:11 2009
@@ -32,15 +32,54 @@
 
 /**
  * Tests the serialization conversion util.
- *<p>
+ * <p>
  * @author Aaron Smuts
  */
 public class SerializationConversionUtilUnitTest
     extends TestCase
 {
     /**
+     * Verify null for null.
+     * <p>
+     * @throws IOException
+     */
+    public void testgGetSerializedCacheElement_null()
+        throws IOException
+    {
+        // SETUP
+        IElementSerializer elementSerializer = new StandardSerializer();
+        ICacheElement before = null;
+
+        // DO WORK
+        ICacheElementSerialized result = SerializationConversionUtil.getSerializedCacheElement( before,
+                                                                                                elementSerializer );
+
+        // VERIFY
+        assertNull( "Should get null for null", result );
+    }
+
+    /**
+     * Verify null for null.
+     * <p>
+     * @throws Exception
+     */
+    public void testgGetDeSerializedCacheElement_null()
+        throws Exception
+    {
+        // SETUP
+        IElementSerializer elementSerializer = new StandardSerializer();
+        ICacheElementSerialized before = null;
+
+        // DO WORK
+        ICacheElement result = SerializationConversionUtil.getDeSerializedCacheElement( before, elementSerializer );
+
+        // VERIFY
+        assertNull( "Should get null for null", result );
+    }
+
+    /**
      * Verify that we can go back and forth with the simplest of objects.
-     *<p>
+     * <p>
      * @throws Exception
      */
     public void testSimpleConversion()
@@ -80,6 +119,49 @@
     }
 
     /**
+     * Verify that we can go back and forth with the simplest of objects.
+     *<p>
+     * @throws Exception
+     */
+    public void testAccidentalDoubleConversion()
+        throws Exception
+    {
+        // SETUP
+        String cacheName = "testName";
+        String key = "key";
+        String value = "value fdsadf dsafdsa fdsaf dsafdsaf dsafdsaf dsaf dsaf dsaf dsafa dsaf dsaf dsafdsaf";
+
+        IElementSerializer elementSerializer = new StandardSerializer();
+
+        IElementAttributes attr = new ElementAttributes();
+        attr.setMaxLifeSeconds( 34 );
+
+        ICacheElement before = new CacheElement( cacheName, key, value );
+        before.setElementAttributes( attr );
+
+        // DO WORK
+        ICacheElementSerialized alreadySerialized = SerializationConversionUtil
+            .getSerializedCacheElement( before, elementSerializer );
+        ICacheElementSerialized serialized = SerializationConversionUtil.getSerializedCacheElement( alreadySerialized,
+                                                                                                    elementSerializer );
+
+        // VERIFY
+        assertNotNull( "Should have a serialized object.", serialized );
+        System.out.println( "testSimpleConversion, " + serialized );
+
+        // DO WORK
+        ICacheElement after = SerializationConversionUtil.getDeSerializedCacheElement( serialized, elementSerializer );
+
+        // VERIFY
+        assertNotNull( "Should have a deserialized object.", after );
+        assertEquals( "Values should be the same.", before.getVal(), after.getVal() );
+        assertEquals( "Attributes should be the same.", before.getElementAttributes().getMaxLifeSeconds(), after
+            .getElementAttributes().getMaxLifeSeconds() );
+        assertEquals( "Keys should be the same.", before.getKey(), after.getKey() );
+        assertEquals( "Cache name should be the same.", before.getCacheName(), after.getCacheName() );
+    }
+
+    /**
      * Verify that we get an IOException for a null serializer.
      */
     public void testNullSerializerConversion()



---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-dev-help@jakarta.apache.org