[jboss-cvs] JBossAS SVN: r107040 - projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jul 22 18:06:36 EDT 2010


Author: pferraro
Date: 2010-07-22 18:06:35 -0400 (Thu, 22 Jul 2010)
New Revision: 107040

Added:
   projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerTest.java
Log:
Unit test for SessionAttributeMarshallerImpl

Added: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerTest.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerTest.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerTest.java	2010-07-22 22:06:35 UTC (rev 107040)
@@ -0,0 +1,128 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.web.tomcat.service.session.distributedcache.impl;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Date;
+
+import org.easymock.EasyMock;
+import org.jboss.ha.framework.server.MarshalledValueObjectStreamSource;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class SessionAttributeMarshallerTest
+{
+   private final LocalDistributableSessionManager manager = EasyMock.createStrictMock(LocalDistributableSessionManager.class);
+   
+   private final SessionAttributeMarshaller marshaller = new SessionAttributeMarshallerImpl(this.manager, new MarshalledValueObjectStreamSource());
+   @Test
+   public void test() throws IOException, ClassNotFoundException
+   {
+      this.test(null, true);
+      this.test("test", true);
+      this.test(Boolean.TRUE, true);
+      this.test(Byte.valueOf(Byte.MAX_VALUE), true);
+      this.test(Character.valueOf(Character.MAX_VALUE), true);
+      this.test(Double.valueOf(Double.MAX_VALUE), true);
+      this.test(Float.valueOf(Float.MAX_VALUE), true);
+      this.test(Integer.valueOf(Integer.MAX_VALUE), true);
+      this.test(Long.valueOf(Long.MAX_VALUE), true);
+      this.test(Short.valueOf(Short.MAX_VALUE), true);
+      this.test(new String[] { "test" }, true);
+      this.test(new boolean[] { Boolean.TRUE }, true);
+      this.test(new byte[] { Byte.MAX_VALUE }, true);
+      this.test(new char[] { Character.MAX_VALUE }, true);
+      this.test(new double[] { Double.MAX_VALUE }, true);
+      this.test(new float[] { Float.MAX_VALUE }, true);
+      this.test(new int[] { Integer.MAX_VALUE }, true);
+      this.test(new long[] { Long.MAX_VALUE }, true);
+      this.test(new short[] { Short.MAX_VALUE }, true);
+      this.test(new Boolean[] { Boolean.TRUE }, true);
+      this.test(new Byte[] { Byte.valueOf(Byte.MAX_VALUE) }, true);
+      this.test(new Character[] { Character.valueOf(Character.MAX_VALUE) }, true);
+      this.test(new Double[] { Double.valueOf(Double.MAX_VALUE) }, true);
+      this.test(new Float[] { Float.valueOf(Float.MAX_VALUE) }, true);
+      this.test(new Integer[] { Integer.valueOf(Integer.MAX_VALUE) }, true);
+      this.test(new Long[] { Long.valueOf(Long.MAX_VALUE) }, true);
+      this.test(new Short[] { Short.valueOf(Short.MAX_VALUE) }, true);
+      this.test(this.getClass(), false);
+      this.test(new Date(System.currentTimeMillis()), false);
+      this.test(new Object(), false);
+   }
+   
+   private void test(Object original, boolean same) throws IOException, ClassNotFoundException
+   {
+      EasyMock.replay(this.manager);
+      
+      try
+      {
+         Object marshalled = this.marshaller.marshal(original);
+         
+         if (same)
+         {
+            Assert.assertSame(original, marshalled);
+         }
+         else
+         {
+            Assert.assertTrue(marshalled instanceof Serializable);
+            Assert.assertNotSame(original, marshalled);
+         }
+         
+         EasyMock.verify(this.manager);
+         EasyMock.reset(this.manager);
+         
+         if (!same)
+         {
+            EasyMock.expect(this.manager.getApplicationClassLoader()).andReturn(Thread.currentThread().getContextClassLoader());
+         }
+         
+         EasyMock.replay(this.manager);
+         
+         Object unmarshalled = this.marshaller.unmarshal(marshalled);
+         
+         if (same)
+         {
+            Assert.assertSame(marshalled, unmarshalled);
+         }
+         else
+         {
+            Assert.assertTrue(marshalled instanceof Serializable);
+            Assert.assertNotSame(marshalled, unmarshalled);
+            Assert.assertEquals(original, unmarshalled);
+         }
+      }
+      catch (IllegalArgumentException e)
+      {
+         Assert.assertFalse(same);
+         Assert.assertFalse(original instanceof Serializable);
+      }
+      
+      EasyMock.verify(this.manager);
+      EasyMock.reset(this.manager);
+   }
+}



More information about the jboss-cvs-commits mailing list