1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.data.provider;
17
18 import org.eclipse.persistence.exceptions.ValidationException;
19 import org.junit.Test;
20 import org.kuali.rice.krad.data.DataObjectService;
21 import org.kuali.rice.krad.data.KradDataServiceLocator;
22 import org.kuali.rice.krad.data.PersistenceOption;
23 import org.kuali.rice.krad.test.KRADTestCase;
24 import org.kuali.rice.krad.test.document.bo.AccountType;
25 import org.kuali.rice.test.data.PerSuiteUnitTestData;
26 import org.kuali.rice.test.data.UnitTestData;
27 import org.kuali.rice.test.data.UnitTestFile;
28 import org.springframework.orm.jpa.JpaSystemException;
29
30 import javax.persistence.PersistenceException;
31
32 import static org.junit.Assert.*;
33
34
35
36
37
38
39 @PerSuiteUnitTestData( {
40 @UnitTestData(
41 sqlFiles = {
42 @UnitTestFile(filename = "classpath:testAccountType.sql", delimiter = ";")
43 })
44 })
45 public class RollbackExceptionErrorReportingTest extends KRADTestCase {
46
47 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RollbackExceptionErrorReportingTest.class);
48
49 protected DataObjectService getDataObjectService() {
50 return KradDataServiceLocator.getDataObjectService();
51 }
52
53
54
55
56 @Test
57 public void changePrimaryKeyValue_Exception() {
58 AccountType acctType = getDataObjectService().find(AccountType.class, "CAT");
59 assertNotNull( "Error retrieving CAT account type from data object service", acctType );
60
61 acctType.setAccountTypeCode("CLR");
62
63
64 try {
65 getDataObjectService().save(acctType, PersistenceOption.FLUSH);
66 fail( "The save method should have failed." );
67 } catch (JpaSystemException ex) {
68
69
70 LOG.info(ex, ex);
71 assertNotNull("The thrown rollback exception should have had a cause", ex.getCause());
72 assertTrue("Embedded error should have been a javax.persistence.PersistenceException. But was: " + ex.getCause(), ex.getCause() instanceof PersistenceException);
73 assertNotNull("The embedded rollback exception should have had a cause", ex.getCause().getCause());
74 assertTrue("The embedded rollback exception should have been a validation exception, but was: " + ex.getCause().getCause(), ex.getCause().getCause() instanceof ValidationException);
75 } catch (Exception ex) {
76 fail("It should have failed with JpaSystemException");
77 }
78 }
79
80 }