1 25 26 package org.objectweb.jonas.jtests.clients.entity; 27 28 import java.util.Collection ; 29 import java.util.Iterator ; 30 31 import javax.naming.NamingException ; 32 import javax.rmi.PortableRemoteObject ; 33 34 import junit.framework.Test; 35 import junit.framework.TestSuite; 36 37 import org.objectweb.jonas.jtests.beans.ebasic.E4Query; 38 import org.objectweb.jonas.jtests.beans.ebasic.E4QueryHome; 39 import org.objectweb.jonas.jtests.util.JTestCase; 40 41 42 46 47 public class F_BasicEjbqlEC2 extends JTestCase { 48 49 private static String BEAN_HOME_E4QUERY = "ebasicE4QueryEC2Home"; 50 protected static E4QueryHome home = null; 51 52 53 public F_BasicEjbqlEC2(String name) { 54 super(name); 55 } 56 57 protected void setUp() { 58 if (home == null) { 59 useBeans("ebasic", true); 61 try { 62 home = (E4QueryHome) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_E4QUERY), 63 E4QueryHome.class); 64 } catch (NamingException e) { 65 fail("Cannot get bean home: " + e.getMessage()); 66 } 67 try { 69 home.findByPrimaryKey("id1"); 70 } catch (Exception e) { 71 try { 72 home.create("idnull", null, 0, 0.0); 73 home.create("id1","helene", 1959, 1959.0); 74 home.create("id2","ahelene", -1959, 1959.0); 75 home.create("id3","helene-bis", 1959*1959, 1959.0*1959.0); 76 home.create("id4","eric", 1957, 1957.0); 77 home.create("id4e","ric", 1957, 1957.0); 78 } catch (Exception i) { 79 fail("InitialState creation problem:: "+i); 80 } 81 } 82 } 83 } 84 85 88 public void testLength() throws Exception { 89 int l = "helene".length(); 90 Collection cBeans = home.findByLengthString(l); 91 Iterator iBeans = cBeans.iterator(); 92 int nb=0; 93 while(iBeans.hasNext()) { 94 E4Query bean = (E4Query) javax.rmi.PortableRemoteObject.narrow(iBeans.next(), 95 E4Query.class); 96 assertEquals("Id="+bean.getId(), l, bean.getFstring().length()); 97 nb++; 98 } 99 assertEquals("Beans number: ", 1, nb); 100 101 } 102 103 106 public void testLocate() throws Exception { 107 String l = "helene"; 108 Collection cBeans = home.findByLocateString(l); 109 Iterator iBeans = cBeans.iterator(); 110 int nb=0; 111 while(iBeans.hasNext()) { 112 E4Query bean = (E4Query) javax.rmi.PortableRemoteObject.narrow(iBeans.next(), 113 E4Query.class); 114 String f = bean.getFstring(); 115 assertTrue("Id="+bean.getId(), f.indexOf(l)>-1); 116 nb++; 117 } 118 assertEquals("Beans number: ", 3, nb); 119 120 } 121 122 126 public void testLocateAt() throws Exception { 127 String l = "helene"; 128 Collection cBeans = home.findByLocateStringAt(l, 2); 129 Iterator iBeans = cBeans.iterator(); 130 int nb=0; 131 while(iBeans.hasNext()) { 132 E4Query bean = (E4Query) javax.rmi.PortableRemoteObject.narrow(iBeans.next(), 133 E4Query.class); 134 String f = bean.getFstring(); 135 assertTrue("Id=" + bean.getId() + ",f=" + f, f.indexOf(l, 1)>-1); 136 nb++; 137 } 138 assertEquals("Beans number: ", 1, nb); 139 140 } 141 142 145 public void testSubstring() throws Exception { 146 String s = "el"; 147 int is = 2; 148 int il = "el".length(); 149 Collection cBeans = home.findBySubstring(s, is, il); 150 Iterator iBeans = cBeans.iterator(); 151 int nb=0; 152 int ib = is - 1; 153 int ie = is - 1 + il; 154 while(iBeans.hasNext()) { 155 E4Query bean = (E4Query) javax.rmi.PortableRemoteObject.narrow(iBeans.next(), 156 E4Query.class); 157 String f = bean.getFstring(); 158 assertTrue("id="+bean.getId(), s.equals(f.substring(ib, ie))); 159 nb++; 160 } 161 assertEquals("Beans number: ", 2, nb); 162 163 } 164 165 168 public void testConcat() throws Exception { 169 String s = "id4"+"eric"; 170 Collection cBeans = home.findByConcatString(s); 171 Iterator iBeans = cBeans.iterator(); 172 int nb=0; 173 while(iBeans.hasNext()) { 174 E4Query bean = (E4Query) javax.rmi.PortableRemoteObject.narrow(iBeans.next(), 175 E4Query.class); 176 String f = bean.getFstring(); 177 assertTrue("Id="+bean.getId(), s.equals(bean.getId().concat(bean.getFstring()))); 178 nb++; 179 } 180 assertEquals("Beans number: ", 2, nb); 181 182 } 183 184 187 public void testAbsInt() throws Exception { 188 int i = 1959; 189 Collection cBeans = home.findByAbsInt(i); 190 Iterator iBeans = cBeans.iterator(); 191 int nb=0; 192 while(iBeans.hasNext()) { 193 E4Query bean = (E4Query) javax.rmi.PortableRemoteObject.narrow(iBeans.next(), 194 E4Query.class); 195 int f = bean.getFint(); 196 assertTrue("Id="+bean.getId(), (f==-i) || (f==i)); 197 nb++; 198 } 199 assertEquals("Beans number: ", 2, nb); 200 201 } 202 203 206 public void testSqrt() throws Exception { 207 int i = 1959; 208 Collection cBeans = home.findBySqrtDouble(1959.0); 209 Iterator iBeans = cBeans.iterator(); 210 int nb=0; 211 while(iBeans.hasNext()) { 212 E4Query bean = (E4Query) javax.rmi.PortableRemoteObject.narrow(iBeans.next(), 213 E4Query.class); 214 int f = bean.getFint(); 215 assertTrue("Id="+bean.getId(), f==i*i); 216 nb++; 217 } 218 assertEquals("Beans number: ", 1, nb); 219 220 } 221 222 225 public void testIsNull() throws Exception { 226 Collection cBeans = home.findByIsNull(); 227 Iterator iBeans = cBeans.iterator(); 228 int nb=0; 229 while(iBeans.hasNext()) { 230 E4Query bean = (E4Query) javax.rmi.PortableRemoteObject.narrow(iBeans.next(), 231 E4Query.class); 232 assertNull("Id="+bean.getId(), bean.getFstring()); 233 nb++; 234 } 235 assertEquals("Beans number: ", 1, nb); 236 237 } 238 239 242 public void testIsNull1Param() throws Exception { 243 Collection cBeans = home.findByIsNullParam(null); 244 Iterator iBeans = cBeans.iterator(); 245 int nb=0; 246 while(iBeans.hasNext()) { 247 E4Query bean = (E4Query) javax.rmi.PortableRemoteObject.narrow(iBeans.next(), 248 E4Query.class); 249 nb++; 250 } 251 assertEquals("Beans number: ", 6, nb); 252 } 253 254 257 public void testIsNull2Param() throws Exception { 258 Collection cBeans = home.findByIsNullParam("hello"); 259 Iterator iBeans = cBeans.iterator(); 260 int nb=0; 261 while(iBeans.hasNext()) { 262 E4Query bean = (E4Query) javax.rmi.PortableRemoteObject.narrow(iBeans.next(), 263 E4Query.class); 264 nb++; 265 } 266 assertEquals("Beans number: ", 0, nb); 267 } 268 269 272 public void testInStrings() throws Exception { 273 Collection cBeans = home.findByInStrings(); 274 Iterator iBeans = cBeans.iterator(); 275 int nb=0; 276 while(iBeans.hasNext()) { 277 E4Query bean = (E4Query) javax.rmi.PortableRemoteObject.narrow(iBeans.next(), 278 E4Query.class); 279 boolean ok = "helene".equals(bean.getFstring()) || "eric".equals(bean.getFstring()); 280 assertTrue("Id="+bean.getId(), ok); 281 nb++; 282 } 283 assertEquals("Beans number: ", 2, nb); 284 285 } 286 287 290 public void testLessThanMinus100() throws Exception { 291 Collection cBeans = home.findByLessThanMinus100(); 292 Iterator iBeans = cBeans.iterator(); 293 int nb=0; 294 while(iBeans.hasNext()) { 295 E4Query bean = (E4Query) javax.rmi.PortableRemoteObject.narrow(iBeans.next(), 296 E4Query.class); 297 int f = bean.getFint(); 298 assertTrue("Id="+bean.getId(), f < -100); 299 nb++; 300 } 301 assertEquals("Beans number: ", 1, nb); 302 303 } 304 305 308 public void testIntEqualExpr() throws Exception { 309 Collection cBeans = home.findByIntEqualExpr(1959, 255, 255); 310 Iterator iBeans = cBeans.iterator(); 311 int nb=0; 312 while(iBeans.hasNext()) { 313 E4Query bean = (E4Query) javax.rmi.PortableRemoteObject.narrow(iBeans.next(), 314 E4Query.class); 315 int f = bean.getFint(); 316 assertEquals("Id="+bean.getId(), 1959, f); 317 nb++; 318 } 319 assertEquals("Beans number: ", 1, nb); 320 321 } 322 323 326 public void testStringGreaterThenExpr() throws Exception { 327 Collection cBeans = home.findByStringGreaterThenExpr("helene"); 328 Iterator iBeans = cBeans.iterator(); 329 int nb=0; 330 while(iBeans.hasNext()) { 331 E4Query bean = (E4Query) javax.rmi.PortableRemoteObject.narrow(iBeans.next(), 332 E4Query.class); 333 String f = bean.getFstring(); 334 assertTrue("Id="+bean.getId()+",fString="+f, f.compareTo("helene") > 0); 335 nb++; 336 } 337 assertEquals("Beans number: ", 2, nb); 338 } 339 340 343 public void testStringGreaterOrEqualThenExpr() throws Exception { 344 Collection cBeans = home.findByStringGreaterOrEqualThenExpr("helene"); 345 Iterator iBeans = cBeans.iterator(); 346 int nb=0; 347 while(iBeans.hasNext()) { 348 E4Query bean = (E4Query) javax.rmi.PortableRemoteObject.narrow(iBeans.next(), 349 E4Query.class); 350 String f = bean.getFstring(); 351 assertTrue("Id="+bean.getId()+",fString="+f, f.compareTo("helene") >= 0); 352 nb++; 353 } 354 assertEquals("Beans number: ", 3, nb); 355 } 356 357 360 public void testMod() throws Exception { 361 int op2 = 1959; 362 Collection cBeans = home.findByIntModXIsZero(op2); 363 Iterator iBeans = cBeans.iterator(); 364 int nb=0; 365 while(iBeans.hasNext()) { 366 E4Query bean = (E4Query) javax.rmi.PortableRemoteObject.narrow(iBeans.next(), 367 E4Query.class); 368 int f = bean.getFint(); 369 assertTrue("Id="+bean.getId()+",fInt="+f, (f % op2) == 0); 371 nb++; 372 } 373 assertEquals("Beans number: ", 4, nb); 374 } 375 376 377 public static Test suite() { 378 return new TestSuite(F_BasicEjbqlEC2.class); 379 } 380 381 public static void main(String args[]) { 382 String testtorun = null; 383 for (int argn = 0; argn < args.length; argn++) { 385 String s_arg = args[argn]; 386 Integer i_arg; 387 if (s_arg.equals("-n")) { 388 testtorun = args[++argn]; 389 } 390 } 391 if (testtorun == null) { 392 junit.textui.TestRunner.run(suite()); 393 } else { 394 junit.textui.TestRunner.run(new F_BasicEjbqlEC2(testtorun)); 395 } 396 } 397 398 } 399 | Popular Tags |