001 /**
002 * Copyright 2005-2011 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.ken.dao;
017
018 import java.util.HashMap;
019
020 import org.kuali.rice.ken.bo.NotificationChannelBo;
021 import org.kuali.rice.ken.bo.NotificationRecipientListBo;
022 import org.kuali.rice.ken.test.util.MockObjectsUtil;
023 import org.kuali.rice.ken.util.NotificationConstants;
024
025
026 /**
027 * This class test basic persistence for the NotificationRecipientList business object.
028 *
029 * @author Kuali Rice Team (rice.collab@kuali.org)
030 */
031 public class NotificationRecipientListDaoTest extends BusinessObjectPersistenceTestCaseBase {
032 NotificationChannelBo channel1 = MockObjectsUtil.getTestChannel1();
033 NotificationChannelBo channel2 = MockObjectsUtil.getTestChannel2();
034
035 NotificationRecipientListBo recipientList1 = new NotificationRecipientListBo();
036 NotificationRecipientListBo recipientList2 = new NotificationRecipientListBo();
037
038 private String[] recipientTypes = {"Type 1", "Type 2"};
039 private String[] recipientIds = {"ag266", "jaf30"};
040 private String[] updatedRecipientIds = {"bh79", "arh14"};
041
042 /**
043 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#setup()
044 */
045 @Override
046 protected void setup() {
047 businessObjectDao.save(channel1);
048 businessObjectDao.save(channel2);
049 }
050
051 /**
052 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#delete()
053 */
054 @Override
055 protected boolean delete() {
056 try {
057 businessObjectDao.delete(recipientList1);
058 businessObjectDao.delete(recipientList2);
059 } catch(Exception e) {
060 return false;
061 }
062 return true;
063 }
064
065 /**
066 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#retrieve()
067 */
068 @Override
069 protected boolean retrieve() {
070 recipientList1 = new NotificationRecipientListBo();
071 recipientList2 = new NotificationRecipientListBo();
072
073 HashMap criteria = new HashMap();
074
075 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.CHANNEL_ID, channel1.getId());
076 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.RECIPIENT_TYPE, recipientTypes[0]);
077 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.RECIPIENT_ID, recipientIds[0]);
078 recipientList1 = (NotificationRecipientListBo) (businessObjectDao.findMatching(NotificationRecipientListBo.class, criteria)).iterator().next();
079
080 criteria.clear();
081
082 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.CHANNEL_ID, channel2.getId());
083 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.RECIPIENT_TYPE, recipientTypes[1]);
084 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.RECIPIENT_ID, recipientIds[1]);
085 recipientList2 = (NotificationRecipientListBo) (businessObjectDao.findMatching(NotificationRecipientListBo.class, criteria)).iterator().next();
086
087 boolean success = true;
088
089 success &= recipientList1 != null;
090 success &= recipientList1.getRecipientId().equals(recipientIds[0]);
091
092 success &= recipientList2 != null;
093 success &= recipientList2.getRecipientId().equals(recipientIds[1]);
094
095 return success;
096 }
097
098 /**
099 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#insert()
100 */
101 @Override
102 protected boolean insert() {
103 recipientList1.setChannel(channel1);
104 recipientList1.setRecipientType(recipientTypes[0]);
105 recipientList1.setRecipientId(recipientIds[0]);
106
107 recipientList2.setChannel(channel2);
108 recipientList2.setRecipientType(recipientTypes[1]);
109 recipientList2.setRecipientId(recipientIds[1]);
110
111 try {
112 businessObjectDao.save(recipientList1);
113 businessObjectDao.save(recipientList2);
114 } catch(Exception e) {
115 LOG.error("Error saving recipients", e);
116 return false;
117 }
118 return true;
119 }
120
121 /**
122 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#update()
123 */
124 @Override
125 protected boolean update() {
126 recipientList1.setRecipientId(updatedRecipientIds[0]);
127
128 recipientList2.setRecipientId(updatedRecipientIds[1]);
129
130 try {
131 businessObjectDao.save(recipientList1);
132 businessObjectDao.save(recipientList2);
133 } catch(Exception e) {
134 return false;
135 }
136 return true;
137 }
138
139 /**
140 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#validateChanges()
141 */
142 @Override
143 protected boolean validateChanges() {
144 recipientList1 = new NotificationRecipientListBo();
145 recipientList2 = new NotificationRecipientListBo();
146
147 HashMap criteria = new HashMap();
148
149 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.CHANNEL_ID, channel1.getId());
150 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.RECIPIENT_TYPE, recipientTypes[0]);
151 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.RECIPIENT_ID, updatedRecipientIds[0]);
152 recipientList1 = (NotificationRecipientListBo) (businessObjectDao.findMatching(NotificationRecipientListBo.class, criteria)).iterator().next();
153
154 criteria.clear();
155
156 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.CHANNEL_ID, channel2.getId());
157 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.RECIPIENT_TYPE, recipientTypes[1]);
158 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.RECIPIENT_ID, updatedRecipientIds[1]);
159 recipientList2 = (NotificationRecipientListBo) (businessObjectDao.findMatching(NotificationRecipientListBo.class, criteria)).iterator().next();
160
161 boolean success = true;
162
163 success &= recipientList1.getRecipientId().equals(updatedRecipientIds[0]);
164 success &= recipientList2.getRecipientId().equals(updatedRecipientIds[1]);
165
166 return success;
167 }
168 }