1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.service;
17
18 import org.junit.Test;
19 import org.kuali.rice.krad.test.document.bo.Account;
20 import org.kuali.rice.krad.test.document.bo.AccountManager;
21 import org.kuali.rice.krad.test.KRADTestCase;
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import static org.junit.Assert.*;
27
28
29
30
31
32
33
34
35 public class BusinessObjectServiceTest extends KRADTestCase {
36
37 public BusinessObjectServiceTest() {}
38
39
40
41
42
43
44 @Test
45 public void testSave() throws Exception {
46 BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
47
48 AccountManager am = new AccountManager();
49 am.setUserName("bhutchin");
50 List<Account> accounts = new ArrayList<Account>();
51 Account account1 = new Account();
52 account1.setNumber("1");
53 account1.setName("account 1");
54 account1.setAccountManager(am);
55 accounts.add(account1);
56
57 Account account2 = new Account();
58 account2.setNumber("2");
59 account2.setName("account 2");
60 account2.setAccountManager(am);
61
62 accounts.add(account2);
63 am.setAccounts(accounts);
64
65 businessObjectService.save(am);
66 }
67
68
69
70
71 @Test
72 public void testRetrieve() {
73 BusinessObjectService businessObjectService = KRADServiceLocator.getBusinessObjectService();
74
75 AccountManager manager = new AccountManager();
76 manager.setUserName("mgorilla");
77 List<Account> accounts = new ArrayList<Account>();
78 Account account1 = new Account();
79 account1.setNumber("MG1");
80 account1.setName("Manilla Gorilla Account");
81 account1.setAccountManager(manager);
82 accounts.add(account1);
83 manager.setAccounts(accounts);
84
85 manager = (AccountManager)businessObjectService.save(manager);
86
87 AccountManager manager2 = (AccountManager)businessObjectService.retrieve(manager);
88 assertNotNull("manager2 should not be null", manager2);
89 assertEquals("manager2 should have the same user name as manager", manager.getUserName(), manager2.getUserName());
90
91 AccountManager manager3 = new AccountManager();
92 manager3.setAmId(manager.getAmId());
93 manager2 = (AccountManager)businessObjectService.retrieve(manager3);
94 assertNotNull("manager2 should not be null", manager2);
95 assertEquals("manager2 should have the same user name as manager", manager.getUserName(), manager2.getUserName());
96
97 manager3.setAmId(-99L);
98 manager2 = (AccountManager)businessObjectService.retrieve(manager3);
99 assertNull("manager2 should be null", manager2);
100
101 AccountManager manager4 = new AccountManager();
102 manager4.setAmId(manager.getAmId());
103 manager2 = (AccountManager)businessObjectService.findBySinglePrimaryKey(AccountManager.class, manager4.getAmId());
104 assertNotNull("manager2 should not be null", manager2);
105 assertEquals("manager2 should have the same user name as manager", manager.getUserName(), manager2.getUserName());
106
107 }
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132 }