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 java.util.HashMap;
019
020 import org.kuali.rice.ken.bo.NotificationPriorityBo;
021 import org.kuali.rice.ken.test.util.MockObjectsUtil;
022 import org.kuali.rice.ken.util.NotificationConstants;
023
024
025 /**
026 * This class test basic persistence for the NotificationPriority business object.
027 *
028 * @author Kuali Rice Team (rice.collab@kuali.org)
029 */
030 public class NotificationPriorityDaoTest extends BusinessObjectPersistenceTestCaseBase {
031 NotificationPriorityBo mockPriority1 = MockObjectsUtil.getTestPriority1();
032 NotificationPriorityBo priority1 = MockObjectsUtil.getTestPriority1();
033
034 private String[] updatedDescriptions = {"Test 1 - updated description", "Test 2 - updated description"};
035
036 /**
037 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#delete()
038 */
039 @Override
040 protected boolean delete() {
041 try {
042 businessObjectDao.delete(priority1);
043 } catch(Exception e) {
044 return false;
045 }
046 return true;
047 }
048
049 /**
050 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#retrieve()
051 */
052 @Override
053 protected boolean retrieve() {
054 priority1 = new NotificationPriorityBo();
055
056 HashMap criteria = new HashMap();
057
058 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.NAME, mockPriority1.getName());
059 priority1 = (NotificationPriorityBo) (businessObjectDao.findMatching(NotificationPriorityBo.class, criteria)).iterator().next();
060
061 boolean success = true;
062
063 success &= priority1 != null;
064 success &= priority1.getDescription().equals(mockPriority1.getDescription());
065
066 return success;
067 }
068
069 /**
070 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#insert()
071 */
072 @Override
073 protected boolean insert() {
074 try {
075 businessObjectDao.save(priority1);
076 } catch(Exception e) {
077 return false;
078 }
079 return true;
080 }
081
082 /**
083 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#update()
084 */
085 @Override
086 protected boolean update() {
087 priority1.setDescription(updatedDescriptions[0]);
088
089 try {
090 businessObjectDao.save(priority1);
091 } catch(Exception e) {
092 return false;
093 }
094 return true;
095 }
096
097 /**
098 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#validateChanges()
099 */
100 @Override
101 protected boolean validateChanges() {
102 retrieve(); //retrieve fresh again
103
104 boolean success = true;
105
106 success &= priority1.getDescription().equals(updatedDescriptions[0]);
107
108 return success;
109 }
110 }