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.exception.RiceRuntimeException;
20 import org.kuali.rice.kcb.bo.RecipientDelivererConfig;
21 import org.kuali.rice.kcb.service.GlobalKCBServiceLocator;
22 import org.kuali.rice.kcb.service.RecipientPreferenceService;
23 import org.kuali.rice.kcb.test.KCBTestCase;
24 import org.kuali.rice.krad.service.KRADServiceLocator;
25 import org.kuali.rice.test.BaselineTestCase.BaselineMode;
26 import org.kuali.rice.test.BaselineTestCase.Mode;
27 import org.springframework.dao.DataAccessException;
28
29 import java.util.Collection;
30
31 import static org.junit.Assert.assertEquals;
32
33
34
35
36
37
38 @BaselineMode(Mode.ROLLBACK_CLEAR_DB)
39 public class RecipientDelivererConfigTest extends KCBTestCase {
40
41
42 private RecipientPreferenceService prefsvc;
43
44 @Override
45 public void setUp() throws Exception {
46 super.setUp();
47
48 prefsvc = GlobalKCBServiceLocator.getInstance().getRecipientPreferenceService();
49
50
51
52
53
54
55 prefsvc.saveRecipientDelivererConfig("user1", "mock", new String[] { "channel1" });
56 }
57
58 @Test
59 public void testCreate() throws Exception {
60 prefsvc.saveRecipientDelivererConfig("user1", "mock", new String[] { "channel2" });
61
62 Collection<RecipientDelivererConfig> deliverers = prefsvc.getDeliverersForRecipient("user1");
63 assertEquals(2, deliverers.size());
64 }
65
66 @Test
67 public void testDelete() throws Exception {
68 prefsvc.removeRecipientDelivererConfigs("user1");
69
70 assertEquals(0, prefsvc.getDeliverersForRecipient("user1").size());
71 }
72
73 @Test(expected = RiceRuntimeException.class)
74 public void testDuplicateCreate() throws Exception {
75
76 prefsvc.saveRecipientDelivererConfig("user1", "mock", new String[] { "channel1" });
77 }
78
79 @Test(expected = DataAccessException.class)
80 public void testInvalidUpdate() throws Exception {
81
82 prefsvc.saveRecipientDelivererConfig("user1", null, new String[] { "channel2" });
83 KRADServiceLocator.getDataObjectService().flush(RecipientDelivererConfig.class);
84 }
85
86 @Test
87 public void testGetDeliverersForRecipientAndChannel() {
88 Collection<RecipientDelivererConfig> cfgs = prefsvc.getDeliverersForRecipientAndChannel("user1", "channel1");
89 assertEquals(1, cfgs.size());
90 assertEquals("mock", cfgs.iterator().next().getDelivererName());
91 }
92 }