1 package org.apache.ojb.broker.sequence; 2 3 import org.apache.commons.lang.builder.ToStringBuilder; 4 import org.apache.ojb.broker.Identity; 5 import org.apache.ojb.junit.PBTestCase; 6 7 13 public class AutoIncrementTest extends PBTestCase 14 { 15 public static void main(String [] args) 16 { 17 String [] arr = {AutoIncrementTest.class.getName()}; 18 junit.textui.TestRunner.main(arr); 19 } 20 21 public void testAutoIncrement() 22 { 23 IncrementObject obj_1 = new IncrementObject(); 24 IncrementObject obj_2 = new IncrementObject(); 25 broker.beginTransaction(); 26 broker.store(obj_1); 27 broker.store(obj_2); 28 broker.commitTransaction(); 29 assertTrue(obj_1.getIntId() < obj_2.getIntId()); 31 assertTrue(obj_1.getIntegerId().intValue() < obj_2.getIntegerId().intValue()); 32 assertTrue(!obj_1.getStr().equals(obj_2.getStr())); 33 assertTrue(obj_2.getIntId() > 0); 34 assertTrue(obj_2.getIntegerId().intValue() > 0); 35 assertTrue((new Integer (obj_2.getStr())).intValue() > 0); 36 37 Identity oid = new Identity(obj_2, broker); 38 IncrementObject newObj_2 = (IncrementObject) broker.getObjectByIdentity(oid); 39 broker.beginTransaction(); 40 broker.store(obj_1); 41 broker.store(obj_2); 42 broker.commitTransaction(); 43 assertEquals(obj_2.getIntId(), newObj_2.getIntId()); 44 assertEquals(obj_2.getIntegerId(), newObj_2.getIntegerId()); 45 assertEquals(obj_2.getStr(), newObj_2.getStr()); 46 } 47 48 public static class IncrementObject 49 { 50 int intId; 51 Integer integerId; 52 String str; 53 54 public IncrementObject() 55 { 56 } 57 58 public Integer getIntegerId() 59 { 60 return integerId; 61 } 62 63 public void setIntegerId(Integer integerId) 64 { 65 this.integerId = integerId; 66 } 67 68 public int getIntId() 69 { 70 return intId; 71 } 72 73 public void setIntId(int intId) 74 { 75 this.intId = intId; 76 } 77 78 public String getStr() 79 { 80 return str; 81 } 82 83 public void setStr(String str) 84 { 85 this.str = str; 86 } 87 88 public String toString() 89 { 90 return ToStringBuilder.reflectionToString(this); 91 } 92 } 93 } 94 | Popular Tags |