1 24 package org.objectweb.jalisto.test.core.suite; 25 26 import junit.framework.Test; 27 import org.objectweb.jalisto.se.test.data.Book; 28 import org.objectweb.jalisto.se.test.workbench.JalistoTestCase; 29 import org.objectweb.jalisto.se.test.workbench.JalistoTestSuite; 30 import org.objectweb.jalisto.se.api.Extent; 31 import org.objectweb.jalisto.se.api.Session; 32 import org.objectweb.jalisto.se.api.Transaction; 33 import org.objectweb.jalisto.se.JalistoFactory; 34 35 public class ReadOnlyTestCase extends JalistoTestCase { 36 37 private final static int number_of_books = 50; 38 39 public ReadOnlyTestCase() { 40 } 41 42 public ReadOnlyTestCase(String name) { 43 super(name); 44 } 45 46 protected void tearDownOnce() throws Exception { 47 super.tearDownOnce(); 48 System.out.println("tearDownOnce for ReadOnly test"); 49 if ((roTx != null) && (roTx.isActive())) { 50 roTx.rollback(); 51 } 52 if ((roSession != null) && (roSession.isOpen())) { 53 roSession.closeSession(); 54 } 55 } 56 57 public static Test suite() { 58 JalistoTestSuite suite = new JalistoTestSuite(); 59 ReadOnlyTestCase tc = (ReadOnlyTestCase) newTestCase(suite, new ReadOnlyTestCase()); 60 61 tc.initSession(); 62 63 tc.populate(number_of_books); 64 65 tc.initRoSession(); 66 tc.extentTest(number_of_books); 67 68 tc.finishTests(); 69 70 return suite; 71 } 72 73 public void initRoSession() { 74 endTransaction(); 75 closeSession(); 76 JalistoFactory.getInternalFactory().cleanFactory(); 77 roSession = JalistoFactory.getSession("jalisto-ro.properties"); 78 roSession.openSession(); 79 roTx = roSession.currentTransaction(); 80 } 81 82 public void extentTest(int number) { 83 roTx.begin(); 84 Extent extent = roSession.getExtent(Book.class).readFully(); 85 assertEquals("must be equal", number, extent.size()); 86 roTx.commit(); 87 } 88 89 private Transaction roTx; 90 private Session roSession; 91 92 93 94 public void initSession() { 95 super.initSession(true); 96 define(Book.getMetaDescription()); 97 } 98 99 public void cleanUp(Class aClass) { 100 super.cleanUp(aClass); 101 } 102 103 public void finishTests() { 104 super.finishTests(); 105 } 106 107 public void populate(int i) { 108 super.populate(i); 109 } 110 } 111 | Popular Tags |