1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.krad.data.jpa;
18
19 import org.eclipse.persistence.exceptions.DatabaseException;
20 import org.junit.Test;
21 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
22 import org.kuali.rice.krad.service.KRADServiceLocator;
23 import org.kuali.rice.krad.test.KRADTestCase;
24 import org.kuali.rice.test.BaselineTestCase;
25
26 import javax.persistence.Column;
27 import javax.persistence.Entity;
28 import javax.persistence.Id;
29 import javax.persistence.Table;
30
31 import static org.junit.Assert.*;
32
33
34
35
36
37
38 @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.CLEAR_DB)
39 public class DisableVersioningTest extends KRADTestCase {
40
41 private DisableVersion createDisableVersion(String rndId, String propertyVal) {
42 return new DisableVersion(rndId, propertyVal, new Long(0));
43 }
44
45 private DisableNoVersion createDisableNoVersion(String rndId, String propertyVal) {
46 return new DisableNoVersion(rndId, propertyVal);
47 }
48
49 private DisableNoVersionRemoveMapping createDisableNoVersionRemoveMapping(String rndId, String propertyVal) {
50 return new DisableNoVersionRemoveMapping(rndId, propertyVal);
51 }
52
53 private String getRandomId() {
54 String time = String.valueOf(System.currentTimeMillis());
55 return (time.substring(time.length() - 9));
56 }
57
58 @Test
59 public void testDisableVersioning() {
60
61 String rndId = getRandomId();
62 String property = "testPropertyValue";
63
64
65 KRADServiceLocator.getDataObjectService().save(createDisableVersion(rndId, property));
66
67 DisableVersion resultDV = KRADServiceLocator.getDataObjectService().find(DisableVersion.class, rndId);
68
69 assertNotNull("DisableVersion is null", resultDV);
70 assertEquals("DisableVersion id does not match given value", rndId, resultDV.getId());
71 assertEquals("DisableVersion property does not match given value", property, resultDV.getProperty());
72 assertEquals(new Long(0), resultDV.getVersionNumber());
73
74 resultDV.setVersionNumber(new Long(50));
75 resultDV = KRADServiceLocator.getDataObjectService().save(resultDV);
76 assertEquals(new Long(50), resultDV.getVersionNumber());
77
78
79
80 try {
81 KRADServiceLocator.getDataObjectService().save(createDisableNoVersion(rndId, property));
82 fail("Database exception should have been thrown when saving with no version number column");
83 } catch (DatabaseException e) {}
84
85
86
87 KRADServiceLocator.getDataObjectService().save(createDisableNoVersionRemoveMapping(rndId, property));
88
89 DisableNoVersionRemoveMapping resultDNV = KRADServiceLocator.getDataObjectService().find(DisableNoVersionRemoveMapping.class, rndId);
90
91 assertNotNull("DisableNoVersionRemoveMapping is null", resultDNV);
92 assertEquals("DisableNoVersionRemoveMapping id does not match given value", rndId, resultDNV.getId());
93 assertEquals("DisableNoVersionRemoveMapping property does not match given value", property, resultDNV.getProperty());
94
95 }
96
97 @Entity
98 @Table(name="KRTST_TEST_DISABLE_VER_T")
99 @DisableVersioning
100 public static class DisableVersion extends PersistableBusinessObjectBase {
101
102 @Id
103 @Column(name="ID")
104 private String id;
105
106 @Column(name="STR_PROP")
107 private String property;
108
109 public DisableVersion() { }
110
111 public DisableVersion(String id, String property, Long versionNumber) {
112 this.id = id;
113 this.property = property;
114 setVersionNumber(versionNumber);
115 }
116
117 public String getId() {
118 return id;
119 }
120
121 public void setId(String id) {
122 this.id = id;
123 }
124
125 public String getProperty() {
126 return property;
127 }
128
129 public void setProperty(String property) {
130 this.property = property;
131 }
132 }
133
134 @Entity
135 @Table(name="KRTST_TEST_DISABLE_NO_VER_T")
136 @DisableVersioning
137 public static class DisableNoVersion extends PersistableBusinessObjectBase {
138
139 @Id
140 @Column(name="ID")
141 private String id;
142
143 @Column(name="STR_PROP")
144 private String property;
145
146 public DisableNoVersion() { }
147
148 public DisableNoVersion(String id, String property) {
149 this.id = id;
150 this.property = property;
151 }
152
153 public String getId() {
154 return id;
155 }
156
157 public void setId(String id) {
158 this.id = id;
159 }
160
161 public String getProperty() {
162 return property;
163 }
164
165 public void setProperty(String property) {
166 this.property = property;
167 }
168 }
169
170 @Entity
171 @Table(name="KRTST_TEST_DISABLE_NO_VER_T")
172 @DisableVersioning
173 @RemoveMapping(name = "versionNumber")
174 public static class DisableNoVersionRemoveMapping extends PersistableBusinessObjectBase {
175
176 @Id
177 @Column(name="ID")
178 private String id;
179
180 @Column(name="STR_PROP")
181 private String property;
182
183 public DisableNoVersionRemoveMapping() { }
184
185 public DisableNoVersionRemoveMapping(String id, String property) {
186 this.id = id;
187 this.property = property;
188 }
189
190 public String getId() {
191 return id;
192 }
193
194 public void setId(String id) {
195 this.id = id;
196 }
197
198 public String getProperty() {
199 return property;
200 }
201
202 public void setProperty(String property) {
203 this.property = property;
204 }
205 }
206 }