1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kcb.service.impl;
17
18 import org.junit.Test;
19 import org.kuali.rice.core.api.criteria.QueryByCriteria;
20 import org.kuali.rice.kcb.bo.RecipientPreference;
21 import org.kuali.rice.kcb.deliverer.MessageDeliverer;
22 import org.kuali.rice.kcb.deliverer.impl.EmailMessageDeliverer;
23 import org.kuali.rice.kcb.exception.ErrorList;
24 import org.kuali.rice.kcb.service.MessageDelivererRegistryService;
25 import org.kuali.rice.kcb.service.RecipientPreferenceService;
26 import org.kuali.rice.kcb.test.KCBTestCase;
27 import org.kuali.rice.kcb.test.TestConstants;
28 import org.kuali.rice.krad.service.KRADServiceLocator;
29 import org.kuali.rice.test.BaselineTestCase.BaselineMode;
30 import org.kuali.rice.test.BaselineTestCase.Mode;
31
32 import java.util.HashMap;
33 import java.util.List;
34
35 import static org.junit.Assert.assertEquals;
36
37 import static org.kuali.rice.core.api.criteria.PredicateFactory.equal;
38
39
40
41
42
43
44 @BaselineMode(Mode.ROLLBACK_CLEAR_DB)
45 public class RecipientPreferenceServiceTest extends KCBTestCase {
46
47 public static final String VALID_DELIVERER_NAME = EmailMessageDeliverer.NAME;
48 public static final String VALID_PROPERTY = EmailMessageDeliverer.NAME + "." + EmailMessageDeliverer.EMAIL_ADDR_PREF_KEY;
49 public static final String VALID_VALUE = TestConstants.EMAIL_DELIVERER_PROPERTY_VALUE;
50 public static final String VALID_USER_ID = "user1";
51
52 @Test
53 public void saveRecipientPreferences() throws ErrorList {
54 RecipientPreferenceService impl = services.getRecipientPreferenceService();
55 MessageDelivererRegistryService delivererService = services.getMessageDelivererRegistryService();
56 MessageDeliverer deliverer = delivererService.getDelivererByName(VALID_DELIVERER_NAME);
57 if (deliverer == null) {
58 throw new RuntimeException("Message deliverer could not be obtained");
59 }
60
61 HashMap<String, String> userprefs = new HashMap<String, String>();
62 userprefs.put(VALID_PROPERTY, VALID_VALUE);
63 userprefs.put("Email.email_delivery_format", "text");
64
65 impl.saveRecipientPreferences(VALID_USER_ID, userprefs, deliverer);
66
67 QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
68 criteria.setPredicates(equal("recipientId", VALID_USER_ID));
69 List<RecipientPreference> prefs =
70 KRADServiceLocator.getDataObjectService().findMatching(RecipientPreference.class, criteria.build()).getResults();
71 assertEquals(2, prefs.size());
72 }
73 }