1 package org.kuali.rice.krad.data.provider;
2
3 import org.apache.commons.lang.RandomStringUtils;
4 import org.kuali.rice.krad.service.KRADServiceLocator;
5 import org.kuali.rice.krad.test.document.bo.AccountExtension;
6 import org.kuali.rice.krad.test.document.bo.AccountType;
7 import org.kuali.rice.krad.test.document.bo.SimpleAccount;
8
9 import static org.junit.Assert.assertEquals;
10
11
12
13
14 public abstract class PersistenceProviderAccountTestBase extends PersistenceProviderTestBase<SimpleAccount> {
15
16 @Override
17 protected SimpleAccount createTopLevelObject() {
18 SimpleAccount a = new SimpleAccount();
19
20
21 String name = RandomStringUtils.randomAlphanumeric(10);
22
23
24 a.setName(name);
25 return a;
26 }
27
28 @Override
29 protected void addLinkedReferences(SimpleAccount a) {
30 addUnlinkedReferences(a);
31
32 AccountExtension e = (AccountExtension) a.getExtension();
33 e.setAccountTypeCode(e.getAccountType().getAccountTypeCode());
34 e.setNumber(a.getNumber());
35 }
36
37 @Override
38 protected void addUnlinkedReferences(SimpleAccount a) {
39
40
41
42 AccountExtension extension = new AccountExtension();
43
44 AccountType at = new AccountType();
45 at.setName(RandomStringUtils.randomAlphanumeric(10));
46 at.setAccountTypeCode(RandomStringUtils.randomAlphanumeric(2));
47 extension.setAccountType(at);
48 a.setExtension(extension);
49 }
50
51 @Override
52 protected String[] getPropertiesForQuery() {
53 return new String[] { "number", "name" };
54 }
55
56 @Override
57 protected Object getIdForLookup(SimpleAccount a) {
58 return a.getNumber();
59 }
60
61 @Override
62 protected Object getNextTestObjectId() {
63 return KRADServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber("trvl_id_seq").toString();
64 }
65
66 @Override
67 protected void setTestObjectPK(SimpleAccount a, Object key) {
68 a.setNumber((String) key);
69 }
70
71 @Override
72 protected void assertTestObjectIdentityEquals(SimpleAccount expected, SimpleAccount actual) {
73 assertTestObjectEquals(expected, actual);
74 assertEquals(expected.getNumber(), actual.getNumber());
75 }
76
77 @Override
78 protected void assertTestObjectEquals(SimpleAccount expected, SimpleAccount actual) {
79 assertEquals(expected.getAmId(), actual.getAmId());
80 assertEquals(expected.getName(), actual.getName());
81 if (expected.getExtension() != null) {
82 AccountExtension e1 = (AccountExtension) expected.getExtension();
83 AccountExtension e2 = (AccountExtension) actual.getExtension();
84 assertEquals(e1.getNumber(), e2.getNumber());
85 assertEquals(e1.getAccountTypeCode(), e2.getAccountTypeCode());
86
87 if (e1.getAccountType() != null) {
88 AccountType at1 = e1.getAccountType();
89 AccountType at2 = e2.getAccountType();
90 assertEquals(at1.getName(), at2.getName());
91 assertEquals(at1.getAccountTypeCode(), at2.getAccountTypeCode());
92 }
93 }
94
95 }
96 }