[jboss-cvs] JBossAS SVN: r106968 - 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
Tue Jul 20 23:49:59 EDT 2010


Author: pferraro
Date: 2010-07-20 23:49:58 -0400 (Tue, 20 Jul 2010)
New Revision: 106968

Added:
   projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/CoarseSessionAttributeStorageTest.java
   projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/FineSessionAttributeStorageTest.java
Log:
Unit tests for session attribute storage impls

Added: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/CoarseSessionAttributeStorageTest.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/CoarseSessionAttributeStorageTest.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/CoarseSessionAttributeStorageTest.java	2010-07-21 03:49:58 UTC (rev 106968)
@@ -0,0 +1,101 @@
+/*
+ * 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.util.Collections;
+import java.util.Map;
+
+import org.easymock.EasyMock;
+import org.infinispan.atomic.AtomicMap;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingSessionGranularitySessionData;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class CoarseSessionAttributeStorageTest
+{
+   private SessionAttributeMarshaller marshaller = EasyMock.createStrictMock(SessionAttributeMarshaller.class);
+   private SessionAttributeStorage<OutgoingSessionGranularitySessionData> storage = new CoarseSessionAttributeStorage(this.marshaller);
+   
+   @Test
+   public void store()
+   {
+      @SuppressWarnings("unchecked")
+      AtomicMap<Object, Object> map = EasyMock.createStrictMock(AtomicMap.class);
+      OutgoingSessionGranularitySessionData data = EasyMock.createStrictMock(OutgoingSessionGranularitySessionData.class);
+      Map<String, Object> attributes = Collections.emptyMap();
+      Object marshalledAttributes = new Object();
+      
+      EasyMock.expect(data.getSessionAttributes()).andReturn(attributes);
+      EasyMock.expect(this.marshaller.marshal(attributes)).andReturn(marshalledAttributes);
+      EasyMock.expect(map.put(EasyMock.eq((byte) AtomicMapEntry.ATTRIBUTES.ordinal()), EasyMock.same(marshalledAttributes))).andReturn(null);
+      
+      EasyMock.replay(this.marshaller, map, data);
+      
+      this.storage.store(map, data);
+      
+      EasyMock.verify(this.marshaller, map, data);
+      EasyMock.reset(this.marshaller, map, data);
+   }
+   
+   @Test
+   public void storeNull()
+   {
+      @SuppressWarnings("unchecked")
+      AtomicMap<Object, Object> map = EasyMock.createStrictMock(AtomicMap.class);
+      OutgoingSessionGranularitySessionData data = EasyMock.createStrictMock(OutgoingSessionGranularitySessionData.class);
+      
+      EasyMock.expect(data.getSessionAttributes()).andReturn(null);
+      
+      EasyMock.replay(this.marshaller, map, data);
+      
+      this.storage.store(map, data);
+      
+      EasyMock.verify(this.marshaller, map, data);
+      EasyMock.reset(this.marshaller, map, data);
+   }
+   
+   @Test
+   public void load() throws Exception
+   {
+      @SuppressWarnings("unchecked")
+      AtomicMap<Object, Object> map = EasyMock.createStrictMock(AtomicMap.class);
+      Object marshalledAttributes = new Object();
+      Map<String, Object> attributes = Collections.emptyMap();
+      
+      EasyMock.expect(map.get(Byte.valueOf((byte) AtomicMapEntry.ATTRIBUTES.ordinal()))).andReturn(marshalledAttributes);
+      EasyMock.expect(this.marshaller.unmarshal(EasyMock.same(marshalledAttributes))).andReturn(attributes);
+      
+      EasyMock.replay(this.marshaller, map);
+      
+      Map<String, Object> result = this.storage.load(map);
+      
+      EasyMock.verify(this.marshaller, map);
+      
+      Assert.assertSame(attributes, result);
+      
+      EasyMock.reset(this.marshaller, map);
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/FineSessionAttributeStorageTest.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/FineSessionAttributeStorageTest.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/FineSessionAttributeStorageTest.java	2010-07-21 03:49:58 UTC (rev 106968)
@@ -0,0 +1,118 @@
+/*
+ * 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.util.AbstractMap;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.easymock.EasyMock;
+import org.infinispan.atomic.AtomicMap;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingAttributeGranularitySessionData;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class FineSessionAttributeStorageTest
+{
+   private SessionAttributeMarshaller marshaller = EasyMock.createStrictMock(SessionAttributeMarshaller.class);
+   private SessionAttributeStorage<OutgoingAttributeGranularitySessionData> storage = new FineSessionAttributeStorage(this.marshaller);
+   
+   @Test
+   public void store()
+   {
+      @SuppressWarnings("unchecked")
+      AtomicMap<Object, Object> map = EasyMock.createStrictMock(AtomicMap.class);
+      OutgoingAttributeGranularitySessionData data = EasyMock.createStrictMock(OutgoingAttributeGranularitySessionData.class);
+      Map<String, Object> modifiedAttributes = Collections.singletonMap("key", (Object) "value");
+      Set<String> removedAttributes = Collections.singleton("removed");
+      Object marshalledAttribute = new Object();
+      
+      EasyMock.expect(data.getModifiedSessionAttributes()).andReturn(modifiedAttributes);
+      EasyMock.expect(this.marshaller.marshal("value")).andReturn(marshalledAttribute);
+      EasyMock.expect(map.put(EasyMock.eq("key"), EasyMock.same(marshalledAttribute))).andReturn(null);
+      EasyMock.expect(data.getRemovedSessionAttributes()).andReturn(removedAttributes);
+      EasyMock.expect(map.remove("removed")).andReturn(null);
+      
+      EasyMock.replay(this.marshaller, map, data);
+      
+      this.storage.store(map, data);
+      
+      EasyMock.verify(this.marshaller, map, data);
+      EasyMock.reset(this.marshaller, map, data);
+   }
+   
+   @Test
+   public void storeNull()
+   {
+      @SuppressWarnings("unchecked")
+      AtomicMap<Object, Object> map = EasyMock.createStrictMock(AtomicMap.class);
+      OutgoingAttributeGranularitySessionData data = EasyMock.createStrictMock(OutgoingAttributeGranularitySessionData.class);
+      
+      EasyMock.expect(data.getModifiedSessionAttributes()).andReturn(null);
+      EasyMock.expect(data.getRemovedSessionAttributes()).andReturn(null);
+      
+      EasyMock.replay(this.marshaller, map, data);
+      
+      this.storage.store(map, data);
+      
+      EasyMock.verify(this.marshaller, map, data);
+      EasyMock.reset(this.marshaller, map, data);
+   }
+   
+   @Test
+   public void load() throws Exception
+   {
+      @SuppressWarnings("unchecked")
+      AtomicMap<Object, Object> map = EasyMock.createStrictMock(AtomicMap.class);
+      Object marshalledAttribute = new Object();
+
+      Map.Entry<Object, Object> nonAttributeEntry = new AbstractMap.SimpleImmutableEntry<Object, Object>(new Object(), new Object());
+      Map.Entry<Object, Object> attributeEntry = new AbstractMap.SimpleImmutableEntry<Object, Object>((Object) "key", marshalledAttribute);
+      @SuppressWarnings("unchecked")
+      List<Map.Entry<Object, Object>> entries = Arrays.asList(nonAttributeEntry, attributeEntry);
+      
+      EasyMock.expect(map.entrySet()).andReturn(new HashSet<Map.Entry<Object, Object>>(entries));
+      EasyMock.expect(this.marshaller.unmarshal(EasyMock.same(marshalledAttribute))).andReturn("value");
+      
+      EasyMock.replay(this.marshaller, map);
+      
+      Map<String, Object> result = this.storage.load(map);
+      
+      EasyMock.verify(this.marshaller, map);
+      
+      Assert.assertNotNull(result);
+      Assert.assertEquals(1, result.size());
+      Assert.assertTrue(result.toString(), result.containsKey("key"));
+      Assert.assertEquals("value", result.get("key"));
+      
+      EasyMock.reset(this.marshaller, map);
+   }
+
+}



More information about the jboss-cvs-commits mailing list