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.sql.Timestamp; 019 import java.util.ArrayList; 020 import java.util.Calendar; 021 import java.util.HashMap; 022 import java.util.List; 023 024 import org.kuali.rice.ken.bo.NotificationBo; 025 import org.kuali.rice.ken.bo.NotificationChannelBo; 026 import org.kuali.rice.ken.bo.NotificationContentTypeBo; 027 import org.kuali.rice.ken.bo.NotificationPriorityBo; 028 import org.kuali.rice.ken.bo.NotificationProducerBo; 029 import org.kuali.rice.ken.bo.NotificationRecipientBo; 030 import org.kuali.rice.ken.bo.NotificationSenderBo; 031 import org.kuali.rice.ken.test.util.MockObjectsUtil; 032 import org.kuali.rice.ken.util.NotificationConstants; 033 034 /** 035 * This class test basic persistence for the Notification business object. In addition, 036 * it also tests basic persistence for the NotificationSender and NotificationRecipient bos 037 * since those bos are mostly persisted and retrieved through the parent Notification 038 * instance. 039 * 040 * @author Kuali Rice Team (rice.collab@kuali.org) 041 */ 042 public class NotificationDaoTest extends BusinessObjectPersistenceTestCaseBase { 043 Long id = new Long(-1); 044 NotificationPriorityBo mockPriority = MockObjectsUtil.getTestPriority1(); 045 NotificationContentTypeBo mockContentType = MockObjectsUtil.getTestContentType1(); 046 NotificationChannelBo mockChannel = MockObjectsUtil.getTestChannel1(); 047 NotificationProducerBo mockProducer = MockObjectsUtil.getTestProducer1(); 048 049 NotificationBo notification = new NotificationBo(); 050 051 private String deliveryType = NotificationConstants.DELIVERY_TYPES.ACK; 052 private Timestamp sendDateTime = new Timestamp(Calendar.getInstance().getTimeInMillis()); 053 private Timestamp autoRemoveDateTime = null; 054 private String content = "Notification Content!"; 055 056 /** 057 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#setup() 058 */ 059 @Override 060 protected void setup() { 061 super.setup(); 062 businessObjectDao.save(mockPriority); 063 businessObjectDao.save(mockContentType); 064 businessObjectDao.save(mockChannel); 065 businessObjectDao.save(mockProducer); 066 } 067 068 /** 069 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#delete() 070 */ 071 @Override 072 protected boolean delete() { 073 try { 074 businessObjectDao.delete(notification); 075 } catch(Exception e) { 076 return false; 077 } 078 return true; 079 } 080 081 /** 082 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#retrieve() 083 */ 084 @Override 085 protected boolean retrieve() { 086 notification = new NotificationBo(); 087 088 HashMap criteria = new HashMap(); 089 090 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.ID, id); 091 notification = (NotificationBo) businessObjectDao.findByPrimaryKey(NotificationBo.class, criteria); 092 093 boolean success = true; 094 095 success &= notification != null; 096 success &= notification.getContentType().getName().equals(MockObjectsUtil.getTestContentType1().getName()); 097 success &= notification.getRecipients().size()==2; 098 success &= notification.getSenders().size()==2; 099 success &= notification.getCreationDateTime()!=null; 100 success &= notification.getAutoRemoveDateTime()==null; 101 success &= notification.getDeliveryType().equals(NotificationConstants.DELIVERY_TYPES.ACK); 102 success &= notification.getProcessingFlag().equals(NotificationConstants.PROCESSING_FLAGS.UNRESOLVED); 103 104 return success; 105 } 106 107 /** 108 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#insert() 109 */ 110 @Override 111 protected boolean insert() { 112 List<NotificationRecipientBo> recipients = new ArrayList(); 113 recipients.add(MockObjectsUtil.getTestRecipient1()); 114 recipients.add(MockObjectsUtil.getTestRecipient2()); 115 116 List<NotificationSenderBo> senders = new ArrayList(); 117 senders.add(MockObjectsUtil.getTestSender1()); 118 senders.add(MockObjectsUtil.getTestSender2()); 119 120 notification = MockObjectsUtil.buildTestNotification(deliveryType, sendDateTime, autoRemoveDateTime, mockContentType, 121 content, mockPriority, mockProducer, mockChannel, recipients, senders); 122 try { 123 businessObjectDao.save(notification); 124 id = new Long(notification.getId()); 125 } catch(Exception e) { 126 LOG.error("Error saving notification", e); 127 return false; 128 } 129 return true; 130 } 131 132 /** 133 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#update() 134 */ 135 @Override 136 protected boolean update() { 137 notification.setDeliveryType(NotificationConstants.DELIVERY_TYPES.FYI); 138 139 try { 140 businessObjectDao.save(notification); 141 } catch(Exception e) { 142 return false; 143 } 144 return true; 145 } 146 147 /** 148 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#validateChanges() 149 */ 150 @Override 151 protected boolean validateChanges() { 152 retrieve(); //retrieve fresh again 153 154 boolean success = true; 155 156 success &= notification.getDeliveryType().equals(NotificationConstants.DELIVERY_TYPES.FYI); 157 158 return success; 159 } 160 }