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.NotificationProducerBo;
20  import org.kuali.rice.ken.test.util.MockObjectsUtil;
21  import org.kuali.rice.ken.util.NotificationConstants;
22  
23  import java.util.HashMap;
24  
25  import static org.junit.Assert.assertEquals;
26  
27  
28  /**
29   * This class tests basic persistence for the NotificationProducer business object.
30   * 
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   */
33  public class NotificationProducerDaoTest extends BusinessObjectPersistenceTestCaseBase {
34      NotificationChannelBo mockChannel1 = MockObjectsUtil.getTestChannel1();
35      NotificationChannelBo mockChannel2 = MockObjectsUtil.getTestChannel2();
36      
37      NotificationProducerBo mockProducer1 = MockObjectsUtil.getTestProducer1();
38      
39      private String[] updatedDescriptions = {"Test 1 - updated description", "Test 2 - updated description"};
40      
41      /**
42       * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#setup()
43       */
44      @Override
45      protected void setup() {
46  	super.setup();
47  	businessObjectDao.save(mockChannel1);
48  	businessObjectDao.save(mockChannel2);
49      }
50      
51      /**
52       * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#delete()
53       */
54      @Override
55      protected boolean delete() {
56  	HashMap criteria = new HashMap();
57  	
58  	NotificationProducerBo producer4 = new NotificationProducerBo();
59  	criteria.put(NotificationConstants.BO_PROPERTY_NAMES.NAME, mockProducer1.getName());
60  	producer4 = (NotificationProducerBo) businessObjectDao.findByUniqueKey(NotificationProducerBo.class, criteria);
61  	
62  	assertEquals(1, producer4.getChannels().size());
63  	
64  	criteria.clear();
65  	NotificationProducerBo producer5 = new NotificationProducerBo();
66  	criteria.put(NotificationConstants.BO_PROPERTY_NAMES.NAME, mockProducer1.getName());
67  	producer5 = (NotificationProducerBo) businessObjectDao.findByUniqueKey(NotificationProducerBo.class, criteria);
68  		
69  	try {
70  	    businessObjectDao.delete(producer5);
71  	} catch(Exception e) {
72  	    return false;
73  	}
74  	return true;
75      }
76      
77      /**
78       * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#retrieve()
79       */
80      @Override
81      protected boolean retrieve() {
82  	NotificationProducerBo producer2 = new NotificationProducerBo();
83  	
84  	HashMap criteria = new HashMap();
85  	
86  	criteria.put(NotificationConstants.BO_PROPERTY_NAMES.NAME, mockProducer1.getName());
87  	producer2 = (NotificationProducerBo) businessObjectDao.findByUniqueKey(NotificationProducerBo.class, criteria);
88  	
89  	boolean success = true;
90  	
91  	success &= producer2 != null;
92  	success &= producer2.getDescription().equals(mockProducer1.getDescription());
93  	success &= producer2.getChannels().size()==2;
94  	
95  	return success;
96      }
97      
98      /**
99       * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#insert()
100      */
101     @Override
102     protected boolean insert() {
103 	NotificationProducerBo producer1 = MockObjectsUtil.getTestProducer1();
104 	
105 	//set up the channels
106 	producer1.getChannels().add(mockChannel1);
107 	producer1.getChannels().add(mockChannel2);
108 	
109 	try {
110 	    businessObjectDao.save(producer1);
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 	NotificationProducerBo producer2 = new NotificationProducerBo();
123 	
124 	HashMap criteria = new HashMap();
125 	
126 	criteria.put(NotificationConstants.BO_PROPERTY_NAMES.NAME, mockProducer1.getName());
127 	producer2 = (NotificationProducerBo) businessObjectDao.findByUniqueKey(NotificationProducerBo.class, criteria);
128 	
129 	producer2.setDescription(updatedDescriptions[0]);
130 	producer2.getChannels().remove(0);
131 	
132 	try {
133 	    businessObjectDao.save(producer2);
134 	} catch(Exception e) {
135 	    return false;
136 	}
137 	return true;
138     }
139     
140     /**
141      * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#validateChanges()
142      */
143     @Override
144     protected boolean validateChanges() {
145 	NotificationProducerBo producer2 = new NotificationProducerBo();
146 	
147 	HashMap criteria = new HashMap();
148 	
149 	criteria.put(NotificationConstants.BO_PROPERTY_NAMES.NAME, mockProducer1.getName());
150 	producer2 = (NotificationProducerBo) businessObjectDao.findByUniqueKey(NotificationProducerBo.class, criteria);
151 	
152 	boolean success = true;
153 	
154 	success &= producer2.getDescription().equals(updatedDescriptions[0]);
155 	success &= producer2.getChannels().size()==1;
156 	
157 	return success;
158     }
159 }