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.kcb.dao;
17  
18  import org.junit.Ignore;
19  import org.junit.Test;
20  import org.kuali.rice.kcb.bo.RecipientPreference;
21  import org.kuali.rice.kcb.test.BusinessObjectTestCase;
22  
23  import java.util.HashMap;
24  
25  import static org.junit.Assert.assertEquals;
26  import static org.junit.Assert.assertNotNull;
27  
28  /**
29   * This class test basic persistence for the RecipientPreference business object.
30   * 
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   */
33  public class RecipientPreferenceDaoTest extends BusinessObjectTestCase {
34      RecipientPreference pref1 = new RecipientPreference();
35      RecipientPreference pref2 = new RecipientPreference();
36      
37      private String[] recipientTypes = {"Type 1", "Type 2"};
38      private String[] recipientIds = {"unit_test_recip1", "unit_test_recip2"};
39      private String[] propertys = {"Property A", "Property B"};
40      private String[] values = {"Value A", "Value B"};
41      private String[] updatedValues = {"Value C", "Value D"};
42      
43      /**
44       * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#delete()
45       */
46      @Test
47      @Override
48      public void testDelete() {
49          testCreate();
50          businessObjectDao.delete(pref1);
51          businessObjectDao.delete(pref2);
52      }
53      
54      /**
55       * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#retrieve()
56       */
57      @Test
58      @Override
59      public void testReadByQuery() {
60          testCreate();
61          
62          HashMap criteria = new HashMap();
63          
64          criteria.put(RecipientPreference.RECIPIENT_FIELD, recipientIds[0]);
65          criteria.put(RecipientPreference.PROPERTY_FIELD, propertys[0]);
66          pref1 = (RecipientPreference) businessObjectDao.findByUniqueKey(RecipientPreference.class, criteria);
67          
68          criteria.clear();
69          
70          criteria.put(RecipientPreference.RECIPIENT_FIELD, recipientIds[1]);
71          criteria.put(RecipientPreference.PROPERTY_FIELD, propertys[1]);
72          pref2 = (RecipientPreference) businessObjectDao.findByUniqueKey(RecipientPreference.class, criteria);
73          
74          assertNotNull(pref1);
75          assertEquals(recipientIds[0], pref1.getRecipientId());
76          
77          assertNotNull(pref2);
78          assertEquals(recipientIds[1], pref2.getRecipientId());
79      
80      }
81      
82      /**
83       * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#insert()
84       */
85      @Test
86      @Override
87      public void testCreate() {
88          pref1.setRecipientId(recipientIds[0]);
89          pref1.setProperty(propertys[0]);
90          pref1.setValue(values[0]);
91          
92          pref2.setRecipientId(recipientIds[1]);
93          pref2.setProperty(propertys[1]);
94          pref2.setValue(values[1]);
95          
96          businessObjectDao.save(pref1);
97          businessObjectDao.save(pref2);
98      }
99      
100     /**
101      * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#update()
102      */
103     @Test
104     @Ignore // until I fix how this test uses test data
105     @Override
106     public void testUpdate() {
107         testCreate();
108         pref1.setValue(updatedValues[0]);
109         
110         pref2.setValue(updatedValues[1]);
111     
112         businessObjectDao.save(pref1);
113         businessObjectDao.save(pref2);
114         
115         testReadByQuery();
116         
117         assertEquals(updatedValues[0], pref1.getValue());
118         assertEquals(updatedValues[1], pref2.getValue());
119     }
120 }