1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ken.dao;
17
18 import org.kuali.rice.ken.bo.NotificationChannelBo;
19 import org.kuali.rice.ken.bo.NotificationProducerBo;
20 import org.kuali.rice.ken.test.util.MockObjectsUtil;
21 import org.kuali.rice.ken.util.NotificationConstants;
22
23 import java.util.HashMap;
24
25 import static org.junit.Assert.assertEquals;
26
27
28
29
30
31
32
33 public class NotificationProducerDaoTest extends BusinessObjectPersistenceTestCaseBase {
34 NotificationChannelBo mockChannel1 = MockObjectsUtil.getTestChannel1();
35 NotificationChannelBo mockChannel2 = MockObjectsUtil.getTestChannel2();
36
37 NotificationProducerBo mockProducer1 = MockObjectsUtil.getTestProducer1();
38
39 private String[] updatedDescriptions = {"Test 1 - updated description", "Test 2 - updated description"};
40
41
42
43
44 @Override
45 protected void setup() {
46 super.setup();
47 businessObjectDao.save(mockChannel1);
48 businessObjectDao.save(mockChannel2);
49 }
50
51
52
53
54 @Override
55 protected boolean delete() {
56 HashMap criteria = new HashMap();
57
58 NotificationProducerBo producer4 = new NotificationProducerBo();
59 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.NAME, mockProducer1.getName());
60 producer4 = (NotificationProducerBo) businessObjectDao.findByUniqueKey(NotificationProducerBo.class, criteria);
61
62 assertEquals(1, producer4.getChannels().size());
63
64 criteria.clear();
65 NotificationProducerBo producer5 = new NotificationProducerBo();
66 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.NAME, mockProducer1.getName());
67 producer5 = (NotificationProducerBo) businessObjectDao.findByUniqueKey(NotificationProducerBo.class, criteria);
68
69 try {
70 businessObjectDao.delete(producer5);
71 } catch(Exception e) {
72 return false;
73 }
74 return true;
75 }
76
77
78
79
80 @Override
81 protected boolean retrieve() {
82 NotificationProducerBo producer2 = new NotificationProducerBo();
83
84 HashMap criteria = new HashMap();
85
86 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.NAME, mockProducer1.getName());
87 producer2 = (NotificationProducerBo) businessObjectDao.findByUniqueKey(NotificationProducerBo.class, criteria);
88
89 boolean success = true;
90
91 success &= producer2 != null;
92 success &= producer2.getDescription().equals(mockProducer1.getDescription());
93 success &= producer2.getChannels().size()==2;
94
95 return success;
96 }
97
98
99
100
101 @Override
102 protected boolean insert() {
103 NotificationProducerBo producer1 = MockObjectsUtil.getTestProducer1();
104
105
106 producer1.getChannels().add(mockChannel1);
107 producer1.getChannels().add(mockChannel2);
108
109 try {
110 businessObjectDao.save(producer1);
111 } catch(Exception e) {
112 return false;
113 }
114 return true;
115 }
116
117
118
119
120 @Override
121 protected boolean update() {
122 NotificationProducerBo producer2 = new NotificationProducerBo();
123
124 HashMap criteria = new HashMap();
125
126 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.NAME, mockProducer1.getName());
127 producer2 = (NotificationProducerBo) businessObjectDao.findByUniqueKey(NotificationProducerBo.class, criteria);
128
129 producer2.setDescription(updatedDescriptions[0]);
130 producer2.getChannels().remove(0);
131
132 try {
133 businessObjectDao.save(producer2);
134 } catch(Exception e) {
135 return false;
136 }
137 return true;
138 }
139
140
141
142
143 @Override
144 protected boolean validateChanges() {
145 NotificationProducerBo producer2 = new NotificationProducerBo();
146
147 HashMap criteria = new HashMap();
148
149 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.NAME, mockProducer1.getName());
150 producer2 = (NotificationProducerBo) businessObjectDao.findByUniqueKey(NotificationProducerBo.class, criteria);
151
152 boolean success = true;
153
154 success &= producer2.getDescription().equals(updatedDescriptions[0]);
155 success &= producer2.getChannels().size()==1;
156
157 return success;
158 }
159 }