001 /** 002 * Copyright 2005-2013 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 org.kuali.rice.ken.bo.NotificationChannelBo; 019 import org.kuali.rice.ken.bo.NotificationChannelReviewerBo; 020 import org.kuali.rice.ken.test.util.MockObjectsUtil; 021 import org.kuali.rice.ken.util.NotificationConstants; 022 import org.kuali.rice.kim.api.KimConstants.KimGroupMemberTypes; 023 024 import java.util.HashMap; 025 026 /** 027 * This class tests basic persistence for the {@link org.kuali.rice.ken.bo.NotificationChannelReviewerBo} business object. 028 * 029 * @author Kuali Rice Team (rice.collab@kuali.org) 030 */ 031 public class NotificationChannelReviewerDaoTest extends BusinessObjectPersistenceTestCaseBase { 032 private NotificationChannelBo mockChannel1 = MockObjectsUtil.getTestChannel1(); 033 private NotificationChannelReviewerBo mockReviewer = MockObjectsUtil.buildTestNotificationChannelReviewer(KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE, "aReviewer"); 034 035 /** 036 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#setup() 037 */ 038 @Override 039 protected void setup() { 040 super.setup(); 041 businessObjectDao.save(mockChannel1); 042 } 043 044 /** 045 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#delete() 046 */ 047 @Override 048 protected boolean delete() { 049 HashMap criteria = new HashMap(); 050 051 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.REVIEWER_ID, mockReviewer.getReviewerId()); 052 NotificationChannelReviewerBo 053 reviewer = (NotificationChannelReviewerBo) businessObjectDao.findByUniqueKey(NotificationChannelReviewerBo.class, criteria); 054 055 try { 056 businessObjectDao.delete(reviewer); 057 } catch(Exception e) { 058 return false; 059 } 060 return true; 061 } 062 063 064 /** 065 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#insert() 066 */ 067 @Override 068 protected boolean insert() { 069 mockReviewer.setChannel(mockChannel1); 070 071 try { 072 businessObjectDao.save(mockReviewer); 073 } catch(Exception e) { 074 return false; 075 } 076 return true; 077 } 078 079 /** 080 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#retrieve() 081 */ 082 @Override 083 protected boolean retrieve() { 084 HashMap criteria = new HashMap(); 085 086 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.REVIEWER_ID, mockReviewer.getReviewerId()); 087 NotificationChannelReviewerBo 088 reviewer = (NotificationChannelReviewerBo) businessObjectDao.findByUniqueKey(NotificationChannelReviewerBo.class, criteria); 089 090 boolean success = true; 091 092 success &= reviewer != null; 093 success &= reviewer.getReviewerId().equals(mockReviewer.getReviewerId()); 094 success &= reviewer.getReviewerType().equals(mockReviewer.getReviewerType()); 095 success &= reviewer.getChannel() != null; 096 success &= reviewer.getChannel().getId().equals(mockChannel1.getId()); 097 098 return success; 099 } 100 101 /** 102 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#update() 103 */ 104 @Override 105 protected boolean update() { 106 HashMap criteria = new HashMap(); 107 108 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.REVIEWER_ID, mockReviewer.getReviewerId()); 109 NotificationChannelReviewerBo 110 reviewer = (NotificationChannelReviewerBo) businessObjectDao.findByUniqueKey(NotificationChannelReviewerBo.class, criteria); 111 112 reviewer.setReviewerId("updatedReviewerId"); 113 reviewer.setReviewerType(KimGroupMemberTypes.GROUP_MEMBER_TYPE.getCode()); 114 115 try { 116 businessObjectDao.save(reviewer); 117 } catch(Exception e) { 118 return false; 119 } 120 return true; 121 } 122 123 /** 124 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#validateChanges() 125 */ 126 @Override 127 protected boolean validateChanges() { 128 NotificationChannelReviewerBo 129 reviewer = (NotificationChannelReviewerBo) businessObjectDao.findById(NotificationChannelReviewerBo.class, mockReviewer.getId()); 130 131 boolean success = reviewer != null; 132 success &= reviewer.getReviewerId().equals("updatedReviewerId"); 133 success &= reviewer.getReviewerType().equals(KimGroupMemberTypes.GROUP_MEMBER_TYPE.getCode()); 134 135 return success; 136 } 137 }