1 25 26 package org.objectweb.jonas.jtests.clients.entity; 27 28 import org.objectweb.jonas.jtests.beans.annuaire.Personne; 29 import org.objectweb.jonas.jtests.beans.annuaire.PersonneHome; 30 import org.objectweb.jonas.jtests.util.JTestCase; 31 32 37 public abstract class A_Timer extends JTestCase { 38 39 String mynum = "638"; 40 String myname = "Philippe Durieux"; 41 42 public A_Timer(String name) { 43 super(name); 44 } 45 46 protected void setUp() { 47 super.setUp(); 48 useBeans("annuaire", true); 49 } 50 51 54 abstract public PersonneHome getHome(); 55 56 59 public void testTimer1() throws Exception { 60 int duration = 5; 61 Personne p = getHome().findByPrimaryKey(myname); 62 int oldval = p.getTimerCount(); 63 int id = p.setTimer(duration, 0); 64 assertEquals("timer expired too quickly", oldval, p.getTimerCount()); 65 sleep(1000 * (duration + 1)); 66 assertEquals("timer did not expired", oldval + 1, p.getTimerCount()); 67 } 68 69 72 public void testTimeRemaining() throws Exception { 73 int duration1 = 5000; 74 int duration2 = 2000; 75 Personne p = getHome().findByPrimaryKey(myname); 76 int id1 = p.setTimer(duration1, 0); 77 int id2 = p.setTimer(duration2, 0); 78 long t1 = p.getTimeRemaining(id1) / 1000; 79 long t2 = p.getTimeRemaining(id2) / 1000; 80 sleep(1000); 81 assertTrue(t1 < duration1); 82 assertTrue(t2 < duration2); 83 assertTrue(t1 > duration1 - 2); 84 assertTrue(t2 > duration2 - 2); 85 } 86 87 90 public void testCancel1() throws Exception { 91 int duration = 2; 92 Personne p = getHome().findByPrimaryKey(myname); 93 int oldval = p.getTimerCount(); 94 int id = p.setTimer(duration, 0); 95 assertEquals("timer expired too quickly", oldval, p.getTimerCount()); 96 p.cancelTimer(id); 97 sleep(1000 * (duration + 1)); 98 assertEquals("timer did expired", oldval, p.getTimerCount()); 99 } 100 101 } 102 | Popular Tags |