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