1 package org.apache.ojb.broker; 2 3 import org.apache.ojb.broker.util.ObjectModification; 4 import org.apache.ojb.junit.PBTestCase; 5 6 10 public class KeyConstraintViolationTest extends PBTestCase 11 { 12 public static void main(String [] args) 13 { 14 String [] arr = {KeyConstraintViolationTest.class.getName()}; 15 junit.textui.TestRunner.main(arr); 16 } 17 18 public KeyConstraintViolationTest(String name) 19 { 20 super(name); 21 } 22 23 27 public void testKeyViolation() throws Exception 28 { 29 broker.beginTransaction(); 30 Article obj = new Article(); 31 obj.setProductGroupId(new Integer (1)); 32 obj.articleName = "repeated Article"; 33 broker.store(obj, ObjectModification.INSERT); 35 broker.commitTransaction(); 36 37 broker.clearCache(); 38 try 39 { 40 broker.beginTransaction(); 41 Article obj2 = new Article(); 42 obj2.articleId = obj.getArticleId(); 43 obj2.setProductGroupId(new Integer (1)); 44 obj2.articleName = "repeated Article"; 45 46 broker.store(obj2, ObjectModification.INSERT); 48 broker.commitTransaction(); 49 50 fail("Should have thrown a KeyConstraintViolatedException"); 51 } 52 catch (KeyConstraintViolatedException t) 53 { 54 broker.abortTransaction(); 56 } 57 } 58 } 59 | Popular Tags |