1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.useroptions;
18
19 import static org.junit.Assert.assertTrue;
20 import static org.junit.Assert.assertFalse;
21
22 import org.junit.Test;
23 import org.kuali.rice.kew.api.KewApiConstants;
24 import org.kuali.rice.kew.service.KEWServiceLocator;
25 import org.kuali.rice.kew.test.KEWTestCase;
26 import org.kuali.rice.kim.api.identity.principal.Principal;
27
28 import java.util.ArrayList;
29 import java.util.Collection;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33
34
35
36
37
38
39 public class UserOptionsServiceTest extends KEWTestCase {
40
41
42 private final static String REFRESH_RATE = "REFRESH_RATE";
43
44
45 private final static String ELEVEN = "11";
46
47
48
49
50
51 @Test
52 public void testUserOptionsSaveWithPrincipalIdOptionIdOptionVal() throws Exception {
53 final UserOptionsService userOptionsService = this.getUserOptionsService();
54 Principal principal = this.getPrincipalByPrincipalName("ewestfal");
55 Collection<UserOptions> userOptions = userOptionsService.findByWorkflowUser(principal.getPrincipalId());
56 assertTrue("UserOptions should by empty", userOptions.isEmpty());
57
58
59 userOptionsService.save(principal.getPrincipalId(), REFRESH_RATE, "11");
60
61
62 userOptions = userOptionsService.findByWorkflowUser(principal.getPrincipalId());
63 assertFalse("UserOptions should not by empty", userOptions.isEmpty());
64 UserOptions firstUsrOpt = new ArrayList<UserOptions>(userOptions).get(0);
65 assertTrue("UserOption option id should be " + REFRESH_RATE, REFRESH_RATE.equals(firstUsrOpt.getOptionId()));
66 assertTrue("UserOption option value should be 11", ELEVEN.equals(firstUsrOpt.getOptionVal()));
67 }
68
69
70
71
72
73 @Test
74 public void testUserOptionsSaveWithOptionMap() throws Exception {
75 final UserOptionsService userOptionsService = this.getUserOptionsService();
76 Principal principal = this.getPrincipalByPrincipalName("ewestfal");
77 Collection<UserOptions> userOptions = userOptionsService.findByWorkflowUser(principal.getPrincipalId());
78 assertTrue("UserOptions should by empty", userOptions.isEmpty());
79
80
81 Map<String, String> userOptMap = new HashMap<String, String>();
82 userOptMap.put("favoriteColor", "blue");
83 userOptMap.put("backgroundColor","white");
84 userOptMap.put(REFRESH_RATE, "30");
85 userOptionsService.save(principal.getPrincipalId(), userOptMap);
86
87 userOptions = userOptionsService.findByWorkflowUser(principal.getPrincipalId());
88 assertFalse("UserOptions should not be empty", userOptions.isEmpty());
89 assertTrue("UserOptions should contain three items", userOptions.size() == 3);
90 }
91
92
93
94
95
96 @Test
97 public void testFindByUserQualified() throws Exception {
98 final UserOptionsService userOptionsService = this.getUserOptionsService();
99 Principal principal = this.getPrincipalByPrincipalName("ewestfal");
100 Collection<UserOptions> userOptions = userOptionsService.findByWorkflowUser(principal.getPrincipalId());
101 assertTrue("UserOptions should by empty", userOptions.isEmpty());
102
103
104 Map<String, String> userOptMap = new HashMap<String, String>();
105 userOptMap.put("favoriteColor", "blue");
106 userOptMap.put("favoriteFood","pizza");
107 userOptMap.put("favoriteTimeOfYear", "summer");
108 userOptMap.put(REFRESH_RATE, "30");
109 userOptMap.put("lastSaveDate","now");
110 userOptionsService.save(principal.getPrincipalId(), userOptMap);
111
112 userOptions = userOptionsService.findByWorkflowUser(principal.getPrincipalId());
113 assertFalse("UserOptions should not be empty", userOptions.isEmpty());
114 assertTrue("UserOptions should contain five items", userOptions.size() == 5);
115
116 userOptions = userOptionsService.findByUserQualified(principal.getPrincipalId(), "favorite%");
117 assertFalse("UserOptions should not be empty", userOptions.isEmpty());
118 assertTrue("UserOptions should contain 3 items.", userOptions.size() == 3);
119 for (UserOptions opt: userOptions) {
120 assertTrue("UserOptionId (" + opt.getOptionId() + ") should start with favorite",
121 opt.getOptionId().startsWith("favorite"));
122 }
123 }
124
125
126
127
128
129 @Test
130 public void testRetrieveEmailPreferenceUserOptions() throws Exception {
131 final UserOptionsService userOptionsService = this.getUserOptionsService();
132 Principal principal = this.getPrincipalByPrincipalName("ewestfal");
133 Collection<UserOptions> userOptions = userOptionsService.findByWorkflowUser(principal.getPrincipalId());
134 assertTrue("UserOptions should by empty", userOptions.isEmpty());
135
136
137 Map<String, String> userOptMap1 = new HashMap<String, String>();
138 userOptMap1.put("favoriteColor", "blue");
139 userOptMap1.put("favoriteFood","pizza");
140 userOptMap1.put("favoriteTimeOfYear", "summer");
141 userOptMap1.put(REFRESH_RATE, "30");
142 List<UserOptions> optList = userOptionsService.retrieveEmailPreferenceUserOptions("testValue");
143 assertTrue("OptList should be empty.", optList.isEmpty());
144
145
146 Map<String, String> userOptMap2 = new HashMap<String, String>();
147 userOptMap2.put("favoriteColor", "blue");
148 userOptMap2.put("favoriteFood","pizza");
149 userOptMap2.put("favoriteTimeOfYear", "summer");
150 userOptMap2.put(REFRESH_RATE, "30");
151 userOptMap2.put(KewApiConstants.EMAIL_RMNDR_KEY, KewApiConstants.EMAIL_RMNDR_DAY_VAL);
152 userOptMap2.put("Error" + KewApiConstants.DOCUMENT_TYPE_NOTIFICATION_PREFERENCE_SUFFIX,
153 KewApiConstants.EMAIL_RMNDR_DAY_VAL);
154 userOptMap2.put("Warning" + KewApiConstants.DOCUMENT_TYPE_NOTIFICATION_PREFERENCE_SUFFIX,
155 KewApiConstants.EMAIL_RMNDR_DAY_VAL);
156 userOptionsService.save(principal.getPrincipalId(), userOptMap2);
157
158 optList = userOptionsService.retrieveEmailPreferenceUserOptions(KewApiConstants.EMAIL_RMNDR_DAY_VAL);
159 assertFalse("OptList should not be empty", optList.isEmpty());
160 assertTrue("OptList should contain 3 items, optList size is: " + optList.size(), optList.size() == 3);
161 }
162
163
164
165
166
167 private UserOptionsService getUserOptionsService() {
168 return KEWServiceLocator.getUserOptionsService();
169 }
170
171
172
173
174
175
176 private Principal getPrincipalByPrincipalName(String principleName) {
177 return KEWServiceLocator.getIdentityHelperService().getPrincipalByPrincipalName(principleName);
178 }
179 }