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 java.util.HashMap;
19  
20  import org.kuali.rice.ken.bo.NotificationChannelBo;
21  import org.kuali.rice.ken.bo.UserChannelSubscriptionBo;
22  import org.kuali.rice.ken.test.util.MockObjectsUtil;
23  import org.kuali.rice.ken.util.NotificationConstants;
24  
25  
26  /**
27   * This class test basic persistence for the UserChannelSubscription business object.
28   * 
29   * @author Kuali Rice Team (rice.collab@kuali.org)
30   */
31  public class UserChannelSubscriptionDaoTest extends BusinessObjectPersistenceTestCaseBase {
32      NotificationChannelBo channel1 = MockObjectsUtil.getTestChannel1();
33      NotificationChannelBo channel2 = MockObjectsUtil.getTestChannel2();
34      
35      UserChannelSubscriptionBo subscription1 = new UserChannelSubscriptionBo();
36      UserChannelSubscriptionBo subscription2 = new UserChannelSubscriptionBo();
37      
38      private String[] userIds = {"ag266", "jaf30"};
39      private String[] updatedUserIds = {"bh79", "arh14"};
40      
41      /**
42       * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#setup()
43       */
44      @Override
45      protected void setup() {
46  	businessObjectDao.save(channel1);
47  	businessObjectDao.save(channel2);
48      }
49      
50      /**
51       * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#delete()
52       */
53      @Override
54      protected boolean delete() {
55  	try {
56  	    businessObjectDao.delete(subscription1);
57  	    businessObjectDao.delete(subscription2);
58  	} catch(Exception e) {
59  	    return false;
60  	}
61  	return true;
62      }
63      
64      /**
65       * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#retrieve()
66       */
67      @Override
68      protected boolean retrieve() {
69  	subscription1 = null;
70  	subscription2 = null;
71  	
72  	HashMap criteria = new HashMap();
73  	
74  	criteria.put(NotificationConstants.BO_PROPERTY_NAMES.CHANNEL_ID, channel1.getId());
75  	criteria.put(NotificationConstants.BO_PROPERTY_NAMES.USER_ID, userIds[0]);
76  	subscription1 = (UserChannelSubscriptionBo) businessObjectDao.findByUniqueKey(UserChannelSubscriptionBo.class, criteria);
77  	
78  	criteria.clear();
79  	
80  	criteria.put(NotificationConstants.BO_PROPERTY_NAMES.CHANNEL_ID, channel2.getId());
81  	criteria.put(NotificationConstants.BO_PROPERTY_NAMES.USER_ID, userIds[1]);
82  	subscription2 = (UserChannelSubscriptionBo) businessObjectDao.findByUniqueKey(UserChannelSubscriptionBo.class, criteria);
83  	
84  	boolean success = true;
85  	
86  	success &= subscription1 != null;
87  	success &= subscription1.getId()>0;
88  	success &= subscription1.getChannel().getId().equals(channel1.getId());
89  	
90  	success &= subscription2 != null;
91  	success &= subscription2.getId()>0;
92  	success &= subscription2.getChannel().getId().equals(channel2.getId());
93  	
94  	return success;
95      }
96      
97      /**
98       * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#insert()
99       */
100     @Override
101     protected boolean insert() {
102 	subscription1.setChannel(channel1);
103 	subscription1.setUserId(userIds[0]);
104 	
105 	subscription2.setChannel(channel2);
106 	subscription2.setUserId(userIds[1]);
107 	
108 	try {
109 	    businessObjectDao.save(subscription1);
110 	    businessObjectDao.save(subscription2);
111 	} catch(Exception e) {
112 	    return false;
113 	}
114 	return true;
115     }
116     
117     /**
118      * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#update()
119      */
120     @Override
121     protected boolean update() {
122 	subscription1.setUserId(updatedUserIds[0]);
123 	
124 	subscription2.setUserId(updatedUserIds[1]);
125 	
126 	try {
127 	    businessObjectDao.save(subscription1);
128 	    businessObjectDao.save(subscription2);
129 	} catch(Exception e) {
130 	    return false;
131 	}
132 	return true;
133     }
134     
135     /**
136      * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#validateChanges()
137      */
138     @Override
139     protected boolean validateChanges() {
140 	subscription1 = new UserChannelSubscriptionBo();
141 	subscription2 = new UserChannelSubscriptionBo();
142 	
143 	HashMap criteria = new HashMap();
144 	
145 	criteria.put(NotificationConstants.BO_PROPERTY_NAMES.CHANNEL_ID, channel1.getId());
146 	criteria.put(NotificationConstants.BO_PROPERTY_NAMES.USER_ID, updatedUserIds[0]);
147 	subscription1 = (UserChannelSubscriptionBo) businessObjectDao.findByUniqueKey(UserChannelSubscriptionBo.class, criteria);
148 	
149 	criteria.clear();
150 	
151 	criteria.put(NotificationConstants.BO_PROPERTY_NAMES.CHANNEL_ID, channel2.getId());
152 	criteria.put(NotificationConstants.BO_PROPERTY_NAMES.USER_ID, updatedUserIds[1]);
153 	subscription2 = (UserChannelSubscriptionBo) businessObjectDao.findByUniqueKey(UserChannelSubscriptionBo.class, criteria);
154 	
155 	boolean success = true;
156 	
157 	success &= subscription1 != null;
158 	success &= subscription1.getId()>0;
159 	success &= subscription1.getChannel().getId().equals(channel1.getId());
160 	success &= subscription1.getUserId().equals(updatedUserIds[0]);
161 	
162 	success &= subscription2 != null;
163 	success &= subscription2.getId()>0;
164 	success &= subscription2.getChannel().getId().equals(channel2.getId());
165 	success &= subscription2.getUserId().equals(updatedUserIds[1]);
166 	
167 	return success;
168     }
169 }