001 /** 002 * Copyright 2005-2011 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.kcb.dao; 017 018 import org.junit.Ignore; 019 import org.junit.Test; 020 import org.kuali.rice.kcb.bo.RecipientPreference; 021 import org.kuali.rice.kcb.test.BusinessObjectTestCase; 022 023 import java.util.HashMap; 024 025 import static org.junit.Assert.assertEquals; 026 import static org.junit.Assert.assertNotNull; 027 028 /** 029 * This class test basic persistence for the RecipientPreference business object. 030 * 031 * @author Kuali Rice Team (rice.collab@kuali.org) 032 */ 033 public class RecipientPreferenceDaoTest extends BusinessObjectTestCase { 034 RecipientPreference pref1 = new RecipientPreference(); 035 RecipientPreference pref2 = new RecipientPreference(); 036 037 private String[] recipientTypes = {"Type 1", "Type 2"}; 038 private String[] recipientIds = {"unit_test_recip1", "unit_test_recip2"}; 039 private String[] propertys = {"Property A", "Property B"}; 040 private String[] values = {"Value A", "Value B"}; 041 private String[] updatedValues = {"Value C", "Value D"}; 042 043 /** 044 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#delete() 045 */ 046 @Test 047 @Override 048 public void testDelete() { 049 testCreate(); 050 businessObjectDao.delete(pref1); 051 businessObjectDao.delete(pref2); 052 } 053 054 /** 055 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#retrieve() 056 */ 057 @Test 058 @Override 059 public void testReadByQuery() { 060 testCreate(); 061 062 HashMap criteria = new HashMap(); 063 064 criteria.put(RecipientPreference.RECIPIENT_FIELD, recipientIds[0]); 065 criteria.put(RecipientPreference.PROPERTY_FIELD, propertys[0]); 066 pref1 = (RecipientPreference) businessObjectDao.findByUniqueKey(RecipientPreference.class, criteria); 067 068 criteria.clear(); 069 070 criteria.put(RecipientPreference.RECIPIENT_FIELD, recipientIds[1]); 071 criteria.put(RecipientPreference.PROPERTY_FIELD, propertys[1]); 072 pref2 = (RecipientPreference) businessObjectDao.findByUniqueKey(RecipientPreference.class, criteria); 073 074 assertNotNull(pref1); 075 assertEquals(recipientIds[0], pref1.getRecipientId()); 076 077 assertNotNull(pref2); 078 assertEquals(recipientIds[1], pref2.getRecipientId()); 079 080 } 081 082 /** 083 * @see org.kuali.rice.ken.dao.BusinessObjectPersistenceTestCaseBase#insert() 084 */ 085 @Test 086 @Override 087 public void testCreate() { 088 pref1.setRecipientId(recipientIds[0]); 089 pref1.setProperty(propertys[0]); 090 pref1.setValue(values[0]); 091 092 pref2.setRecipientId(recipientIds[1]); 093 pref2.setProperty(propertys[1]); 094 pref2.setValue(values[1]); 095 096 businessObjectDao.save(pref1); 097 businessObjectDao.save(pref2); 098 } 099 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 }