1 25 26 package org.objectweb.jonas.jtests.clients.entity; 27 28 import java.util.Collection ; 29 import java.util.Iterator ; 30 import javax.ejb.FinderException ; 31 import junit.framework.Assert; 32 33 import org.objectweb.jonas.jtests.beans.etype.bytearray.ByteArray; 34 import org.objectweb.jonas.jtests.beans.etype.bytearray.ByteArrayHome; 35 import org.objectweb.jonas.jtests.util.JTestCase; 36 37 43 public abstract class A_EtypeByteArray extends JTestCase { 44 45 public A_EtypeByteArray(String name) { 46 super(name); 47 } 48 49 protected static boolean isInit = false; 50 51 protected void setUp() { 52 super.setUp(); 53 useBeans("bytearray", true); 54 if (!isInit) { 55 ByteArrayHome home = getHome(); 56 try { 58 home.findByPrimaryKey("pk1"); 59 } catch (Exception e) { 60 try { 62 home.create("pk1", new byte[] {1}); 63 home.create("pk2", new byte[] {2, 2}); 64 home.create("pk3", new byte[] {3, 3, 3}); 65 home.create("pk4", new byte[] {4, 4, 4, 4}); 66 home.create("pk5", new byte[] {5, 5, 5, 5, 5}); 67 home.create("pk5bis", new byte[] {5, 5, 5, 5, 5}); 68 home.create("pktoremove", new byte[] {100}); 69 } catch (Exception i) { 70 fail("InitialState creation problem: "+i); 71 } 72 } 73 isInit = true; 74 } 75 } 76 77 80 abstract public ByteArrayHome getHome(); 81 82 85 public void testByteArrayFindByPk() throws Exception { 86 String pk = "pk1"; 87 ByteArray bean = getHome().findByPrimaryKey(pk); 88 Assert.assertEquals("Pk", pk, bean.getPk()); 89 } 90 91 94 public void testByteArrayFindByF1() throws Exception { 95 byte[] f1 = new byte[] {5, 5, 5, 5, 5}; 96 Collection cBeans = getHome().findByF1(f1); 97 int nb = 0; 98 Iterator iBeans = cBeans.iterator(); 99 while (iBeans.hasNext()) { 100 ByteArray bean = (ByteArray) javax.rmi.PortableRemoteObject.narrow(iBeans.next(), 101 ByteArray.class); 102 Assert.assertEquals("F1", 5, bean.getF1().length); 103 nb++; 104 } 105 assertEquals("Beans number: ", 2, nb); 106 } 107 108 111 public void testByteArrayGetF1() throws Exception { 112 String pk = "pk2"; 113 ByteArray bean = getHome().findByPrimaryKey(pk); 114 byte[] f1 = bean.getF1(); 115 Assert.assertEquals("Pk", pk, bean.getPk()); 116 Assert.assertEquals("F1", 2, f1.length); 117 } 118 119 122 public void testByteArraySetF1() throws Exception { 123 String pk = "pk3"; 124 ByteArray bean = getHome().findByPrimaryKey(pk); 125 int nb = 30; 126 byte[] f1 = new byte[nb]; 127 for (int i=0; i<nb; i++) { 128 f1[i] = 3; 129 } 130 bean.setF1(f1); 131 Assert.assertEquals("Pk", pk, bean.getPk()); 132 Assert.assertEquals("F1", nb, bean.getF1().length); 133 } 134 135 138 public void testByteArrayCreate() throws Exception { 139 String pk = "pkcreated"; 140 byte[] f1 = new byte[] {9, 9, 9, 9, 9, 9, 9, 9, 9}; 141 ByteArray bean = getHome().create(pk, f1); 142 Assert.assertEquals("Pk", pk, bean.getPk()); 143 Assert.assertEquals("F1", 9, bean.getF1().length); 144 bean = getHome().findByPrimaryKey(pk); 145 bean.remove(); 147 } 148 149 152 public void testByteArrayRemove() throws Exception { 153 String pk = "pktoremove"; 154 ByteArray bean = getHome().findByPrimaryKey(pk); 155 byte[] f1 = bean.getF1(); 156 bean.remove(); 157 try { 158 getHome().findByPrimaryKey(pk); 159 fail("not removed"); 160 } catch (FinderException e) { 161 } 163 getHome().create(pk, f1); 165 } 166 167 } 168 | Popular Tags |