1 19 package org.fjank.jcache; 20 21 import java.text.ParseException ; 22 import java.text.SimpleDateFormat ; 23 import java.util.Date ; 24 import javax.util.jcache.Attributes; 25 import javax.util.jcache.CacheAccessFactory; 26 import javax.util.jcache.CacheObjectInfo; 27 import junit.framework.TestCase; 28 29 34 public class CacheObjectInfoImplTest extends TestCase { 35 private CacheObject testObj; 36 private CacheObjectInfoImpl impl; 37 private static final long TTL = 5; 38 39 protected void setUp() throws Exception { 40 testObj = new CacheObject("key", "value", new CacheGroup("group"), new CacheRegion("name", new AttributesImpl()), null); 41 Attributes att = CacheAccessFactory.getInstance().getDefaultAttributes(); 42 att.setTimeToLive(TTL); 43 testObj.setAttributes(att); 44 impl = new CacheObjectInfoImpl(testObj); 45 46 } 47 48 public final void testGetRegion() { 49 impl.getRegion(); 50 } 51 52 public final void testGetName() { 53 impl.getName(); 54 } 55 56 public final void testGetType() { 57 impl.getType(); 58 } 59 60 public final void testGetGroup() { 61 impl.getGroup(); 62 } 63 64 public final void testGetRefCount() { 65 impl.getRefCount(); 66 } 67 68 public final void testGetAccesses() { 69 impl.getAccesses(); 70 } 71 72 public final void testGetExpire() throws ParseException { 73 SimpleDateFormat form = new SimpleDateFormat ("EEE MMM dd HH:mm:ss zzz yyyy"); 74 75 Attributes att = testObj.getAttributes(); 76 long ttl = att.getTimeToLive(); 78 long createTime = att.getCreateTime(); 80 long expire = form.parse(impl.getExpire()).getTime(); 82 long expectedExpiry = form.parse(form.format(new Date ((ttl*1000)+createTime))).getTime(); 83 assertEquals(expectedExpiry, expire); 84 CacheObject obj = new CacheObject("key", "value", null, null, null); 86 Attributes att1 = CacheAccessFactory.getInstance().getDefaultAttributes(); 87 obj.setAttributes(att1); 88 CacheObjectInfoImpl imp = new CacheObjectInfoImpl(obj); 89 assertEquals(CacheObjectInfo.NEVER_EXPIRES, imp.getExpire()); 90 91 } 92 } 93 | Popular Tags |