1 5 package org.apache.ojb.broker; 6 7 import org.apache.ojb.broker.query.Criteria; 8 import org.apache.ojb.broker.query.Query; 9 import org.apache.ojb.broker.query.QueryFactory; 10 import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor; 11 import org.apache.ojb.junit.PBTestCase; 12 13 import java.sql.Timestamp ; 14 import java.util.Iterator ; 15 16 19 public class ContractVersionEffectivenessTest extends PBTestCase 20 { 21 private int COUNT = 10; 22 public static void main(String [] args) 23 { 24 String [] arr = {ContractVersionEffectivenessTest.class.getName()}; 25 junit.textui.TestRunner.main(arr); 26 } 27 28 32 public ContractVersionEffectivenessTest(String name) 33 34 { 35 super(name); 36 } 37 38 42 public void setUp() throws Exception 43 { 44 super.setUp(); 45 } 46 47 51 public void tearDown() throws Exception 52 { 53 super.tearDown(); 54 } 55 56 private void createTestData() 57 { 58 broker.beginTransaction(); 59 for (int i = 0; i < COUNT; i++) 60 { 61 Contract contract = new Contract(); 62 contract.setPk("C"+System.currentTimeMillis()); 63 contract.setContractValue1("contractvalue1"); 64 contract.setContractValue2(1); 65 contract.setContractValue3("contractvalue3"); 66 contract.setContractValue4(new Timestamp (System.currentTimeMillis())); 67 broker.store(contract); 68 69 Version version = new Version(); 70 version.setPk("V"+System.currentTimeMillis()); 71 version.setVersionValue1("versionvalue1"); 72 version.setVersionValue2(1); 73 version.setVersionValue3(new Timestamp (System.currentTimeMillis())); 74 version.setContract(contract); 75 broker.store(version); 76 77 Effectiveness eff = new Effectiveness(); 78 eff.setPk("E"+System.currentTimeMillis()); 79 eff.setEffValue1("effvalue1"); 80 eff.setEffValue2(1); 81 eff.setEffValue3(new Timestamp (System.currentTimeMillis())); 82 eff.setVersion(version); 83 broker.store(eff); 84 } 85 broker.commitTransaction(); 86 } 87 88 public void testCreateContractVersionEffectiveness() 89 { 90 createTestData(); 91 } 92 93 public void testAutoRetrieveFalse() 94 { 95 ojbChangeReferenceSetting(Contract.class, "relatedToContract", false, 96 ObjectReferenceDescriptor.CASCADE_OBJECT, ObjectReferenceDescriptor.CASCADE_OBJECT, false); 97 String name = "testAutoRetrieveFalse_" + System.currentTimeMillis(); 98 Contract contract = new Contract(); 99 contract.setPk("C"+System.currentTimeMillis()); 100 contract.setContractValue1(name + "_Contract"); 101 contract.setContractValue2(1); 102 contract.setContractValue3("contractvalue3"); 103 contract.setContractValue4(new Timestamp (System.currentTimeMillis())); 104 105 RelatedToContract rc = new RelatedToContract(); 106 rc.setPk("R_" + System.currentTimeMillis()); 107 rc.setRelatedValue1(name + "_RelatedToContract"); 108 109 contract.setRelatedToContract(rc); 110 broker.beginTransaction(); 111 broker.store(contract); 113 broker.commitTransaction(); 114 115 broker.clearCache(); 116 Identity oid = broker.serviceIdentity().buildIdentity(contract); 117 Contract newC = (Contract) broker.getObjectByIdentity(oid); 118 assertNotNull(newC); 119 assertNull(newC.getRelatedToContract()); 121 broker.retrieveAllReferences(newC); 122 assertNotNull(newC.getRelatedToContract()); 124 } 125 126 public void testUpdateContractVersionEffectiveness() 127 { 128 createTestData(); 129 130 Criteria crit = new Criteria(); 131 Query q; 132 Iterator iter; 133 136 q = QueryFactory.newQuery(Effectiveness.class, crit); 137 iter = broker.getIteratorByQuery(q); 138 Effectiveness eff = null; 139 broker.beginTransaction(); 140 while (iter.hasNext()) 141 { 142 eff = (Effectiveness)iter.next(); 143 eff.setEffValue1("effValueUpdated"); 144 broker.store(eff); 145 } 146 broker.commitTransaction(); 147 150 Version version = null; 151 q = QueryFactory.newQuery(Version.class, crit); 152 iter = broker.getIteratorByQuery(q); 153 broker.beginTransaction(); 154 while (iter.hasNext()) 155 { 156 version = (Version) iter.next(); 157 version.setVersionValue1("verValueUpdated"); 158 broker.store(version); 159 } 160 broker.commitTransaction(); 161 164 Contract contract = null; 165 q = QueryFactory.newQuery(Contract.class, crit); 166 iter = broker.getIteratorByQuery(q); 167 broker.beginTransaction(); 168 while (iter.hasNext()) 169 { 170 contract = (Contract) iter.next(); 171 contract.setContractValue1("contractValueUpdated"); 172 broker.store(contract); 173 } 174 broker.commitTransaction(); 175 } 176 public void testDeleteContractVersionEffectiveness() 177 { 178 createTestData(); 179 180 Criteria crit = new Criteria(); 181 Query q; 182 Iterator iter; 183 186 q = QueryFactory.newQuery(Effectiveness.class, crit); 187 iter = broker.getIteratorByQuery(q); 188 broker.beginTransaction(); 189 while (iter.hasNext()) 190 { 191 broker.delete(iter.next()); 192 } 193 broker.commitTransaction(); 194 197 q = QueryFactory.newQuery(Version.class, crit); 198 iter = broker.getIteratorByQuery(q); 199 broker.beginTransaction(); 200 while (iter.hasNext()) 201 { 202 broker.delete(iter.next()); 203 } 204 broker.commitTransaction(); 205 208 q = QueryFactory.newQuery(Contract.class, crit); 209 iter = broker.getIteratorByQuery(q); 210 broker.beginTransaction(); 211 while (iter.hasNext()) 212 { 213 broker.delete(iter.next()); 214 } 215 broker.commitTransaction(); 216 } 217 218 } 219 | Popular Tags |