1 25 26 package org.objectweb.jonas.jtests.clients.entity; 27 28 import java.util.Collection ; 29 import java.util.Date ; 30 import java.util.Iterator ; 31 import javax.ejb.FinderException ; 32 33 import org.objectweb.jonas.jtests.beans.etype.outildate.Outildate; 34 import org.objectweb.jonas.jtests.beans.etype.outildate.OutildateHome; 35 import org.objectweb.jonas.jtests.util.JTestCase; 36 37 43 public abstract class A_EtypeOutildate extends JTestCase { 44 45 private static final long ONE_HOUR = 60L * 60L * 1000L; 46 private static final long ONE_DAY = 24L * ONE_HOUR; 47 48 public A_EtypeOutildate(String name) { 49 super(name); 50 } 51 52 protected void setUp() { 53 super.setUp(); 54 useBeans("outildate", false); 55 } 56 57 60 abstract public OutildateHome getHome(); 61 62 65 public void testUtilDateFindByPk() throws Exception { 66 String pk = "pk1"; 67 Outildate bean = getHome().findByPrimaryKey(pk); 68 assertEquals("Pk", pk, bean.getPk()); 69 } 70 71 74 public void testUtilDateFindByF1() throws Exception { 75 Date d5 = new Date (5 * ONE_DAY); 76 Collection cBeans = getHome().findByF1(d5); 77 int nb = 0; 78 Iterator iBeans = cBeans.iterator(); 79 while (iBeans.hasNext()) { 80 Outildate bean = (Outildate) javax.rmi.PortableRemoteObject.narrow(iBeans.next(), 81 Outildate.class); 82 Date f1 = bean.getF1(); 83 if ((f1.getTime() - d5.getTime() > 2 * ONE_HOUR) 87 || (f1.getTime() - d5.getTime() < -2 * ONE_HOUR)) { 88 assertEquals("F1", d5, f1); 90 } 91 nb++; 92 } 93 assertEquals("Beans number: ", 2, nb); 94 } 95 96 99 public void testUtilDateGetF1() throws Exception { 100 String pk = "pk2"; 101 Outildate bean = getHome().findByPrimaryKey(pk); 102 Date d2 = new Date (2 * ONE_DAY); 103 Date f1 = bean.getF1(); 104 assertEquals("Pk", pk, bean.getPk()); 105 if ((f1.getTime() - d2.getTime() > 2 * ONE_HOUR) 109 || (f1.getTime() - d2.getTime() < -2 * ONE_HOUR)) { 110 assertEquals("F1", d2, f1); 112 } 113 } 114 115 118 public void testUtilDateGetF1Null() throws Exception { 119 String pk = "pknull"; 120 Outildate bean = getHome().findByPrimaryKey(pk); 121 Date f1 = bean.getF1(); 122 assertEquals("Pk", pk, bean.getPk()); 123 assertNull("F1 not null", f1); 124 } 125 126 129 public void testUtilDateSetF1() throws Exception { 130 String pk = "pk3"; 131 Outildate bean = getHome().findByPrimaryKey(pk); 132 Date f1 = new Date (30 * ONE_DAY); 133 bean.setF1(f1); 134 assertEquals("Pk", pk, bean.getPk()); 135 assertEquals("F1", f1, bean.getF1()); 136 bean.setF1(new Date (3 * ONE_DAY)); 138 } 139 140 143 public void testUtilDateSetF1Null() throws Exception { 144 String pk = "pkchangenull"; 145 Outildate bean = getHome().findByPrimaryKey(pk); 146 bean.setF1(null); 147 assertEquals("Pk", pk, bean.getPk()); 148 assertNull("F1", bean.getF1()); 149 } 150 151 154 public void testUtilDateCreate() throws Exception { 155 String pk = "pkcreated"; 156 Date f1 = new Date (1959 * ONE_DAY); 157 Outildate bean = getHome().create(pk, f1); 158 assertEquals("Pk", pk, bean.getPk()); 159 assertEquals("F1", f1, bean.getF1()); 160 bean = getHome().findByPrimaryKey(pk); 161 bean.remove(); 163 } 164 165 168 public void testUtilDateRemove() throws Exception { 169 String pk = "pktoremove"; 170 Outildate bean = getHome().findByPrimaryKey(pk); 171 Date f1 = bean.getF1(); 172 bean.remove(); 173 try { 174 getHome().findByPrimaryKey(pk); 175 fail("not removed"); 176 } catch (FinderException e) { 177 } 179 getHome().create(pk, f1); 181 } 182 185 public void testUtilDateLessThen() throws Exception { 186 Date d3 = new Date (3*ONE_DAY); 187 Collection cBeans = getHome().findByF1LessThen(d3); 188 Iterator iBeans = cBeans.iterator(); 189 int nb=0; 190 while(iBeans.hasNext()) { 191 Outildate bean = (Outildate) javax.rmi.PortableRemoteObject.narrow(iBeans.next(), 192 Outildate.class); 193 Date f = bean.getF1(); 194 assertTrue("Pk="+bean.getPk()+",f1="+f, f.compareTo(d3) < 0); 195 nb++; 196 } 197 assertEquals("Beans number: ", 2, nb); 198 } 199 200 203 public void testUtilDateLessOrEqualThen() throws Exception { 204 Date d3 = new Date (3*ONE_DAY); 205 Collection cBeans = getHome().findByF1LessOrEqualThen(d3); 206 Iterator iBeans = cBeans.iterator(); 207 int nb=0; 208 while(iBeans.hasNext()) { 209 Outildate bean = (Outildate) javax.rmi.PortableRemoteObject.narrow(iBeans.next(), 210 Outildate.class); 211 Date f = bean.getF1(); 212 assertTrue("Pk="+bean.getPk()+",f1="+f, f.compareTo(d3) <= 0); 213 nb++; 214 } 215 assertEquals("Beans number: ", 3, nb); 216 } 217 218 219 } 220 | Popular Tags |