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 org.kuali.rice.ken.bo.NotificationChannel;
19  import org.kuali.rice.ken.bo.NotificationChannelReviewer;
20  import org.kuali.rice.ken.test.util.MockObjectsUtil;
21  import org.kuali.rice.ken.util.NotificationConstants;
22  import org.kuali.rice.kim.api.KimConstants.KimGroupMemberTypes;
23  
24  import java.util.HashMap;
25  
26  /**
27   * This class tests basic persistence for the {@link NotificationChannelReviewer} business object.
28   *
29   * @author Kuali Rice Team (rice.collab@kuali.org)
30   */
31  public class NotificationChannelReviewerDaoTest extends BusinessObjectPersistenceTestCaseBase {
32      private NotificationChannel mockChannel1 = MockObjectsUtil.getTestChannel1();
33      private NotificationChannelReviewer mockReviewer = MockObjectsUtil.buildTestNotificationChannelReviewer(KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE, "aReviewer");
34  
35      /**
36       * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#setup()
37       */
38      @Override
39      protected void setup() {
40          super.setup();
41          businessObjectDao.save(mockChannel1);
42      }
43  
44      /**
45       * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#delete()
46       */
47      @Override
48      protected boolean delete() {
49          HashMap criteria = new HashMap();
50  
51          criteria.put(NotificationConstants.BO_PROPERTY_NAMES.REVIEWER_ID, mockReviewer.getReviewerId());
52          NotificationChannelReviewer reviewer = (NotificationChannelReviewer) businessObjectDao.findByUniqueKey(NotificationChannelReviewer.class, criteria);
53  
54          try {
55              businessObjectDao.delete(reviewer);
56          } catch(Exception e) {
57              return false;
58          }
59          return true;
60      }
61  
62  
63      /**
64       * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#insert()
65       */
66      @Override
67      protected boolean insert() {
68          mockReviewer.setChannel(mockChannel1);
69  
70          try {
71              businessObjectDao.save(mockReviewer);
72          } catch(Exception e) {
73              return false;
74          }
75          return true;
76      }
77  
78      /**
79       * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#retrieve()
80       */
81      @Override
82      protected boolean retrieve() {
83          HashMap criteria = new HashMap();
84  
85          criteria.put(NotificationConstants.BO_PROPERTY_NAMES.REVIEWER_ID, mockReviewer.getReviewerId());
86          NotificationChannelReviewer reviewer = (NotificationChannelReviewer) businessObjectDao.findByUniqueKey(NotificationChannelReviewer.class, criteria);
87  
88          boolean success = true;
89  
90          success &= reviewer != null;
91          success &= reviewer.getReviewerId().equals(mockReviewer.getReviewerId());
92          success &= reviewer.getReviewerType().equals(mockReviewer.getReviewerType());
93          success &= reviewer.getChannel() != null;
94          success &= reviewer.getChannel().getId().equals(mockChannel1.getId());
95  
96          return success;
97      }
98  
99      /**
100      * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#update()
101      */
102     @Override
103     protected boolean update() {
104         HashMap criteria = new HashMap();
105 
106         criteria.put(NotificationConstants.BO_PROPERTY_NAMES.REVIEWER_ID, mockReviewer.getReviewerId());
107         NotificationChannelReviewer reviewer = (NotificationChannelReviewer) businessObjectDao.findByUniqueKey(NotificationChannelReviewer.class, criteria);
108 
109         reviewer.setReviewerId("updatedReviewerId");
110         reviewer.setReviewerType(KimGroupMemberTypes.GROUP_MEMBER_TYPE.getCode());
111 
112         try {
113             businessObjectDao.save(reviewer);
114         } catch(Exception e) {
115             return false;
116         }
117         return true;
118     }
119 
120     /**
121      * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#validateChanges()
122      */
123     @Override
124     protected boolean validateChanges() {
125         NotificationChannelReviewer reviewer = (NotificationChannelReviewer) businessObjectDao.findById(NotificationChannelReviewer.class, mockReviewer.getId());
126 
127         boolean success = reviewer != null;
128         success &= reviewer.getReviewerId().equals("updatedReviewerId");
129         success &= reviewer.getReviewerType().equals(KimGroupMemberTypes.GROUP_MEMBER_TYPE.getCode());
130 
131         return success;
132     }
133 }