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.kcb.bo.RecipientPreference;
20 import org.kuali.rice.kcb.deliverer.MessageDeliverer;
21 import org.kuali.rice.kcb.deliverer.impl.EmailMessageDeliverer;
22 import org.kuali.rice.kcb.exception.ErrorList;
23 import org.kuali.rice.kcb.service.MessageDelivererRegistryService;
24 import org.kuali.rice.kcb.service.RecipientPreferenceService;
25 import org.kuali.rice.kcb.test.KCBTestCase;
26 import org.kuali.rice.kcb.test.TestConstants;
27 import org.kuali.rice.test.BaselineTestCase.BaselineMode;
28 import org.kuali.rice.test.BaselineTestCase.Mode;
29
30 import java.util.Collection;
31 import java.util.HashMap;
32
33 import static org.junit.Assert.assertEquals;
34
35
36
37
38
39
40 @BaselineMode(Mode.ROLLBACK_CLEAR_DB)
41 public class RecipientPreferenceServiceTest extends KCBTestCase {
42 public static final String VALID_DELIVERER_NAME = EmailMessageDeliverer.NAME;
43 public static final String VALID_PROPERTY = EmailMessageDeliverer.NAME + "." + EmailMessageDeliverer.EMAIL_ADDR_PREF_KEY;
44 public static final String VALID_VALUE = TestConstants.EMAIL_DELIVERER_PROPERTY_VALUE;
45 public static final String VALID_USER_ID = "user1";
46
47 @Test
48 public void saveRecipientPreferences() throws ErrorList {
49 RecipientPreferenceService impl = services.getRecipientPreferenceService();
50 MessageDelivererRegistryService delivererService = services.getMessageDelivererRegistryService();
51 MessageDeliverer deliverer = delivererService.getDelivererByName(VALID_DELIVERER_NAME);
52 if (deliverer == null) {
53 throw new RuntimeException("Message deliverer could not be obtained");
54 }
55
56 HashMap<String, String> userprefs = new HashMap<String, String>();
57 userprefs.put(VALID_PROPERTY, VALID_VALUE);
58 userprefs.put("Email.email_delivery_format", "text");
59
60 impl.saveRecipientPreferences(VALID_USER_ID, userprefs, deliverer);
61
62 RecipientPreference recipientPreference = new RecipientPreference();
63 recipientPreference.setRecipientId(VALID_USER_ID);
64 Collection<RecipientPreference> prefs = services.getKcbGenericDao().findMatchingByExample(recipientPreference);
65 assertEquals(2, prefs.size());
66 }
67 }