View Javadoc
1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.ken.dao;
17  
18  import java.util.HashMap;
19  
20  import org.kuali.rice.ken.bo.NotificationPriorityBo;
21  import org.kuali.rice.ken.test.util.MockObjectsUtil;
22  import org.kuali.rice.ken.util.NotificationConstants;
23  
24  
25  /**
26   * This class test basic persistence for the NotificationPriority business object.
27   * 
28   * @author Kuali Rice Team (rice.collab@kuali.org)
29   */
30  public class NotificationPriorityDaoTest extends BusinessObjectPersistenceTestCaseBase {
31      NotificationPriorityBo mockPriority1 = MockObjectsUtil.getTestPriority1();
32      NotificationPriorityBo priority1 = MockObjectsUtil.getTestPriority1();
33      
34      private String[] updatedDescriptions = {"Test 1 - updated description", "Test 2 - updated description"};
35      
36      /**
37       * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#delete()
38       */
39      @Override
40      protected boolean delete() {
41  	try {
42  	    businessObjectDao.delete(priority1);
43  	} catch(Exception e) {
44  	    return false;
45  	}
46  	return true;
47      }
48      
49      /**
50       * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#retrieve()
51       */
52      @Override
53      protected boolean retrieve() {
54  	priority1 = new NotificationPriorityBo();
55  	
56  	HashMap criteria = new HashMap();
57  	
58  	criteria.put(NotificationConstants.BO_PROPERTY_NAMES.NAME, mockPriority1.getName());
59  	priority1 = (NotificationPriorityBo) (businessObjectDao.findMatching(NotificationPriorityBo.class, criteria)).iterator().next();
60  	
61  	boolean success = true;
62  	
63  	success &= priority1 != null;
64  	success &= priority1.getDescription().equals(mockPriority1.getDescription());
65  	
66  	return success;
67      }
68      
69      /**
70       * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#insert()
71       */
72      @Override
73      protected boolean insert() {
74  	try {
75  	    businessObjectDao.save(priority1);
76  	} catch(Exception e) {
77  	    return false;
78  	}
79  	return true;
80      }
81      
82      /**
83       * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#update()
84       */
85      @Override
86      protected boolean update() {
87  	priority1.setDescription(updatedDescriptions[0]);
88  	
89  	try {
90  	    businessObjectDao.save(priority1);
91  	} catch(Exception e) {
92  	    return false;
93  	}
94  	return true;
95      }
96      
97      /**
98       * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#validateChanges()
99       */
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 }