1 24 package org.objectweb.jalisto.test.core.suite; 25 26 import junit.framework.Test; 27 import org.objectweb.jalisto.se.api.Extent; 28 import org.objectweb.jalisto.se.impl.LogicalOid; 29 import org.objectweb.jalisto.se.exception.TransactionException; 30 import org.objectweb.jalisto.se.test.data.Book; 31 import org.objectweb.jalisto.se.test.workbench.JalistoTestCase; 32 import org.objectweb.jalisto.se.test.workbench.JalistoTestSuite; 33 34 import java.util.ArrayList ; 35 36 public class ExtentTestCase extends JalistoTestCase { 37 38 private static final int number_of_book = 20; 39 40 public ExtentTestCase() { 41 } 42 43 public ExtentTestCase(String name) { 44 super(name); 45 } 46 47 public static Test suite() { 48 JalistoTestSuite suite = new JalistoTestSuite(); 49 ExtentTestCase tc = (ExtentTestCase) newTestCase(suite, new ExtentTestCase()); 50 51 tc.define(); 52 tc.cleanUp(); 53 tc.populate(number_of_book); 54 55 tc.testBasicExtent01(number_of_book); 56 tc.testBasicExtent02(number_of_book); 57 tc.testBasicExtent03(number_of_book); 58 59 tc.testCursorExtent01(number_of_book); 60 tc.testCursorExtent02(number_of_book); 61 tc.testCursorExtent03(number_of_book); 62 63 tc.testTransactionnalExtent01(number_of_book); 64 tc.testTransactionnalExtent02(number_of_book); 65 tc.testTransactionnalExtent03(number_of_book); 66 67 tc.finishTests(); 68 69 return suite; 70 } 71 72 public void testBasicExtent01(int nbr) { 73 try { 74 session.getExtent(Book.class); 75 assertTrue("must raise exception", false); 76 } catch (TransactionException jalistoTransactionExc) { 77 assertEquals("must be equal", "Transaction must be active during getExtent", jalistoTransactionExc.getMessage()); 78 } 79 } 80 81 public void testBasicExtent02(int nbr) { 82 tx.begin(); 83 Extent extent = session.getExtent(Book.class).readFully(); 84 assertEquals("must be equal", nbr, extent.size()); 85 tx.commit(); 86 } 87 88 public void testBasicExtent03(int nbr) { 89 tx.begin(); 90 Extent extent = session.getExtent(Book.class); 91 assertEquals("must be equal", 0, extent.size()); 92 tx.commit(); 93 try { 94 extent.readFully(); 95 assertTrue("must raise exception", false); 96 } catch (TransactionException jalistoTransactionExc) { 97 assertEquals("must be equal", "Transaction must be active during readFully", jalistoTransactionExc.getMessage()); 98 } 99 tx.begin(); 100 extent.readFully(); 101 tx.commit(); 102 assertEquals("must be equal", nbr, extent.size()); 103 } 104 105 public void testCursorExtent01(int nbr) { 106 if (session.getInternalSession().isRemoteSession()) { 107 System.out.println("can't execute this test with remote client"); 108 return; 109 } 110 111 tx.begin(); 112 Extent extent = session.getExtent(Book.class).readNextFloids(nbr/2); 113 assertEquals("must be equal", nbr/2, extent.size()); 114 tx.commit(); 115 116 ArrayList oids1 = new ArrayList (extent.collection()); 117 extent.cleanFloids(); 118 assertEquals("must be equal", 0, extent.size()); 119 120 tx.begin(); 121 extent.readNextFloids(10); 122 assertEquals("must be equal", nbr/2, extent.size()); 123 ArrayList oids2 = new ArrayList (extent.collection()); 124 tx.commit(); 125 126 int errors = 0; 127 for (int i = 0; i < oids1.size(); i++) { 128 if (oids2.contains(oids1.get(i))) { 129 errors++; 130 } 131 } 132 assertEquals("have errors", 0, errors); 133 } 134 135 public void testCursorExtent02(int nbr) { 136 if (session.getInternalSession().isRemoteSession()) { 137 System.out.println("can't execute this test with remote client"); 138 return; 139 } 140 141 tx.begin(); 142 Extent extent = session.getExtent(Book.class).readNextFloids(nbr/2); 143 assertEquals("must be equal", nbr/2, extent.size()); 144 tx.commit(); 145 146 try { 147 extent.readNextFloids(nbr/2); 148 assertTrue("must raise exception", false); 149 } catch (TransactionException jalistoTransactionExc) { 150 assertEquals("must be equal", "Transaction must be active during readNextFloids", jalistoTransactionExc.getMessage()); 151 } 152 153 tx.begin(); 154 extent.readNextFloids(10); 155 assertEquals("must be equal", nbr, extent.size()); 156 tx.commit(); 157 } 158 159 public void testCursorExtent03(int nbr) { 160 if (session.getInternalSession().isRemoteSession()) { 161 System.out.println("can't execute this test with remote client"); 162 return; 163 } 164 165 tx.begin(); 166 Extent extent = session.getExtent(Book.class).readNextFloids(nbr+5); 167 assertEquals("must be equal", nbr, extent.size()); 168 tx.commit(); 169 } 170 171 public void testTransactionnalExtent01(int nbr) { 172 tx.begin(); 173 ArrayList oids = new ArrayList (session.getExtent(Book.class).readFully().collection()); 174 tx.commit(); 175 176 assertEquals("must be equal", nbr, oids.size()); 177 LogicalOid oid = (LogicalOid) oids.get(0); 178 179 tx.begin(); 180 session.deleteObjectByOid(oid); 181 Extent extent = session.getExtent(Book.class).readFully(); 182 assertEquals("must be equal", nbr-1, extent.size()); 183 assertTrue("must not contains value", !extent.contains(oid)); 184 tx.commit(); 185 186 populate(1); 187 } 188 189 public void testTransactionnalExtent02(int nbr) { 190 tx.begin(); 191 ArrayList oids = new ArrayList (session.getExtent(Book.class).readFully().collection()); 192 tx.commit(); 193 194 assertEquals("must be equal", nbr, oids.size()); 195 196 tx.begin(); 197 LogicalOid oid01 = (LogicalOid) session.createObject(Book.newBook().toArray(), Book.class); 198 LogicalOid oid02 = (LogicalOid) session.createObject(Book.newBook().toArray(), Book.class); 199 Extent extent = session.getExtent(Book.class).readFully(); 200 assertEquals("must be equal", nbr+2, extent.size()); 201 assertTrue("must contains value", extent.contains(oid01)); 202 assertTrue("must contains value", extent.contains(oid02)); 203 tx.commit(); 207 208 tx.begin(); 209 session.deleteObjectByOid(oid01); 210 session.deleteObjectByOid(oid02); 211 tx.commit(); 212 } 213 214 public void testTransactionnalExtent03(int nbr) { 215 tx.begin(); 216 ArrayList oids = new ArrayList (session.getExtent(Book.class).readFully().collection()); 217 tx.commit(); 218 219 assertEquals("must be equal", nbr, oids.size()); 220 221 { 222 tx.begin(); 223 LogicalOid oid01 = (LogicalOid) session.makeNewFileOid(Book.class); 224 Extent extent = session.getExtent(Book.class).readFully(); 225 assertEquals("must be equal", nbr, extent.size()); 226 assertTrue("must not contains value", !extent.contains(oid01)); 227 tx.rollback(); 228 } 229 230 { 231 tx.begin(); 232 LogicalOid oid01 = (LogicalOid) session.makeNewFileOid(Book.class); 233 tx.commit(); 234 tx.begin(); 235 Extent extent = session.getExtent(Book.class).readFully(); 236 assertEquals("must be equal", nbr, extent.size()); 237 assertTrue("must not contains value", !extent.contains(oid01)); 238 tx.commit(); 239 tx.begin(); 240 session.deleteObjectByOid(oid01); 241 tx.commit(); 242 } 243 } 244 245 248 249 public void define() { 250 super.initSession(false); 251 super.define(Book.getMetaDescription()); 252 } 253 254 public void cleanUp() { 255 super.cleanUp(Book.class); 256 } 257 258 public void populate(int nbr) { 259 super.populate(nbr); 260 } 261 262 public void finishTests() { 263 super.finishTests(); 264 } 265 } 266 | Popular Tags |