1 4 package com.terracotta.session; 5 6 import com.terracotta.session.util.MockContextMgr; 7 import com.terracotta.session.util.MockLifecycleEventMgr; 8 9 import java.util.Arrays ; 10 11 import junit.framework.TestCase; 12 13 public class SessionDataTest extends TestCase { 14 15 public final void testConstructor() { 16 final int maxIdleSeconds = 123; 17 SessionData sd = new SessionData(maxIdleSeconds); 18 assertEquals(maxIdleSeconds, sd.getMaxInactiveMillis() / 1000); 19 } 20 21 public final void testCollection() { 22 final int maxIdleSeconds = 123; 23 SessionData sd = new SessionData(maxIdleSeconds); 24 sd.associate(new MockSessionId(), new MockLifecycleEventMgr(), new MockContextMgr()); 25 final String [] attributes = new String [] { "one", "two", "three", "four", "five" }; 26 for (int i = 0; i < attributes.length; i++) { 27 String a = attributes[i]; 28 29 sd.setAttribute(a, a); 31 String v = (String ) sd.getAttribute(a); 32 assertSame(a, v); 33 34 String [] namesOut = sd.getValueNames(); 36 Arrays.sort(namesOut); 37 assertEquals(i + 1, namesOut.length); 38 for (int j = 0; j < i; j++) 39 assertTrue(Arrays.binarySearch(namesOut, attributes[j]) >= 0); 40 41 final String newVal = new String ("SomeNewString"); 43 final String oldVal = (String ) sd.setAttributeReturnOld(a, newVal); 44 assertSame(a, oldVal); 45 assertSame(newVal, sd.getAttribute(a)); 46 47 final String removedVal = (String ) sd.removeAttributeReturnOld(a); 49 assertSame(newVal, removedVal); 50 assertNull(sd.removeAttributeReturnOld(a)); 51 52 sd.setAttribute(a, a); 54 } 55 } 56 } 57 | Popular Tags |