View Javadoc
1   /**
2    * Copyright 2005-2013 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.NotificationChannelBo;
19  import org.kuali.rice.ken.bo.NotificationChannelReviewerBo;
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 org.kuali.rice.ken.bo.NotificationChannelReviewerBo} business object.
28   *
29   * @author Kuali Rice Team (rice.collab@kuali.org)
30   */
31  public class NotificationChannelReviewerDaoTest extends BusinessObjectPersistenceTestCaseBase {
32      private NotificationChannelBo mockChannel1 = MockObjectsUtil.getTestChannel1();
33      private NotificationChannelReviewerBo 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          NotificationChannelReviewerBo
53                  reviewer = (NotificationChannelReviewerBo) businessObjectDao.findByUniqueKey(NotificationChannelReviewerBo.class, criteria);
54  
55          try {
56              businessObjectDao.delete(reviewer);
57          } catch(Exception e) {
58              return false;
59          }
60          return true;
61      }
62  
63  
64      /**
65       * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#insert()
66       */
67      @Override
68      protected boolean insert() {
69          mockReviewer.setChannel(mockChannel1);
70  
71          try {
72              businessObjectDao.save(mockReviewer);
73          } catch(Exception e) {
74              return false;
75          }
76          return true;
77      }
78  
79      /**
80       * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#retrieve()
81       */
82      @Override
83      protected boolean retrieve() {
84          HashMap criteria = new HashMap();
85  
86          criteria.put(NotificationConstants.BO_PROPERTY_NAMES.REVIEWER_ID, mockReviewer.getReviewerId());
87          NotificationChannelReviewerBo
88                  reviewer = (NotificationChannelReviewerBo) businessObjectDao.findByUniqueKey(NotificationChannelReviewerBo.class, criteria);
89  
90          boolean success = true;
91  
92          success &= reviewer != null;
93          success &= reviewer.getReviewerId().equals(mockReviewer.getReviewerId());
94          success &= reviewer.getReviewerType().equals(mockReviewer.getReviewerType());
95          success &= reviewer.getChannel() != null;
96          success &= reviewer.getChannel().getId().equals(mockChannel1.getId());
97  
98          return success;
99      }
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 }