001 /* 002 * Copyright 2007 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.NotificationChannel; 021 import org.kuali.rice.ken.bo.UserChannelSubscription; 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 UserChannelSubscription business object. 028 * 029 * @author Kuali Rice Team (rice.collab@kuali.org) 030 */ 031 public class UserChannelSubscriptionDaoTest extends BusinessObjectPersistenceTestCaseBase { 032 NotificationChannel channel1 = MockObjectsUtil.getTestChannel1(); 033 NotificationChannel channel2 = MockObjectsUtil.getTestChannel2(); 034 035 UserChannelSubscription subscription1 = new UserChannelSubscription(); 036 UserChannelSubscription subscription2 = new UserChannelSubscription(); 037 038 private String[] userIds = {"ag266", "jaf30"}; 039 private String[] updatedUserIds = {"bh79", "arh14"}; 040 041 /** 042 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#setup() 043 */ 044 @Override 045 protected void setup() { 046 businessObjectDao.save(channel1); 047 businessObjectDao.save(channel2); 048 } 049 050 /** 051 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#delete() 052 */ 053 @Override 054 protected boolean delete() { 055 try { 056 businessObjectDao.delete(subscription1); 057 businessObjectDao.delete(subscription2); 058 } catch(Exception e) { 059 return false; 060 } 061 return true; 062 } 063 064 /** 065 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#retrieve() 066 */ 067 @Override 068 protected boolean retrieve() { 069 subscription1 = null; 070 subscription2 = null; 071 072 HashMap criteria = new HashMap(); 073 074 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.CHANNEL_ID, channel1.getId()); 075 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.USER_ID, userIds[0]); 076 subscription1 = (UserChannelSubscription) businessObjectDao.findByUniqueKey(UserChannelSubscription.class, criteria); 077 078 criteria.clear(); 079 080 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.CHANNEL_ID, channel2.getId()); 081 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.USER_ID, userIds[1]); 082 subscription2 = (UserChannelSubscription) businessObjectDao.findByUniqueKey(UserChannelSubscription.class, criteria); 083 084 boolean success = true; 085 086 success &= subscription1 != null; 087 success &= subscription1.getId()>0; 088 success &= subscription1.getChannel().getId().equals(channel1.getId()); 089 090 success &= subscription2 != null; 091 success &= subscription2.getId()>0; 092 success &= subscription2.getChannel().getId().equals(channel2.getId()); 093 094 return success; 095 } 096 097 /** 098 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#insert() 099 */ 100 @Override 101 protected boolean insert() { 102 subscription1.setChannel(channel1); 103 subscription1.setUserId(userIds[0]); 104 105 subscription2.setChannel(channel2); 106 subscription2.setUserId(userIds[1]); 107 108 try { 109 businessObjectDao.save(subscription1); 110 businessObjectDao.save(subscription2); 111 } catch(Exception e) { 112 return false; 113 } 114 return true; 115 } 116 117 /** 118 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#update() 119 */ 120 @Override 121 protected boolean update() { 122 subscription1.setUserId(updatedUserIds[0]); 123 124 subscription2.setUserId(updatedUserIds[1]); 125 126 try { 127 businessObjectDao.save(subscription1); 128 businessObjectDao.save(subscription2); 129 } catch(Exception e) { 130 return false; 131 } 132 return true; 133 } 134 135 /** 136 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#validateChanges() 137 */ 138 @Override 139 protected boolean validateChanges() { 140 subscription1 = new UserChannelSubscription(); 141 subscription2 = new UserChannelSubscription(); 142 143 HashMap criteria = new HashMap(); 144 145 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.CHANNEL_ID, channel1.getId()); 146 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.USER_ID, updatedUserIds[0]); 147 subscription1 = (UserChannelSubscription) businessObjectDao.findByUniqueKey(UserChannelSubscription.class, criteria); 148 149 criteria.clear(); 150 151 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.CHANNEL_ID, channel2.getId()); 152 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.USER_ID, updatedUserIds[1]); 153 subscription2 = (UserChannelSubscription) businessObjectDao.findByUniqueKey(UserChannelSubscription.class, criteria); 154 155 boolean success = true; 156 157 success &= subscription1 != null; 158 success &= subscription1.getId()>0; 159 success &= subscription1.getChannel().getId().equals(channel1.getId()); 160 success &= subscription1.getUserId().equals(updatedUserIds[0]); 161 162 success &= subscription2 != null; 163 success &= subscription2.getId()>0; 164 success &= subscription2.getChannel().getId().equals(channel2.getId()); 165 success &= subscription2.getUserId().equals(updatedUserIds[1]); 166 167 return success; 168 } 169 }