001 /* 002 * Copyright 2006-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.service.impl; 017 018 import org.junit.Test; 019 import org.kuali.rice.kcb.bo.RecipientPreference; 020 import org.kuali.rice.kcb.deliverer.MessageDeliverer; 021 import org.kuali.rice.kcb.deliverer.impl.EmailMessageDeliverer; 022 import org.kuali.rice.kcb.exception.ErrorList; 023 import org.kuali.rice.kcb.service.MessageDelivererRegistryService; 024 import org.kuali.rice.kcb.service.RecipientPreferenceService; 025 import org.kuali.rice.kcb.test.KCBTestCase; 026 import org.kuali.rice.kcb.test.TestConstants; 027 import org.kuali.rice.test.BaselineTestCase.BaselineMode; 028 import org.kuali.rice.test.BaselineTestCase.Mode; 029 030 import java.util.Collection; 031 import java.util.HashMap; 032 033 import static org.junit.Assert.assertEquals; 034 035 /** 036 * Tests {@link RecipientPreferenceService} 037 * 038 * @author Kuali Rice Team (rice.collab@kuali.org) 039 */ 040 @BaselineMode(Mode.ROLLBACK_CLEAR_DB) 041 public class RecipientPreferenceServiceTest extends KCBTestCase { 042 public static final String VALID_DELIVERER_NAME = EmailMessageDeliverer.NAME; 043 public static final String VALID_PROPERTY = EmailMessageDeliverer.NAME + "." + EmailMessageDeliverer.EMAIL_ADDR_PREF_KEY; 044 public static final String VALID_VALUE = TestConstants.EMAIL_DELIVERER_PROPERTY_VALUE; 045 public static final String VALID_USER_ID = "user1"; // any user will do as KCB has no referential integrity in this regard 046 047 @Test 048 public void saveRecipientPreferences() throws ErrorList { 049 RecipientPreferenceService impl = services.getRecipientPreferenceService(); 050 MessageDelivererRegistryService delivererService = services.getMessageDelivererRegistryService(); 051 MessageDeliverer deliverer = delivererService.getDelivererByName(VALID_DELIVERER_NAME); 052 if (deliverer == null) { 053 throw new RuntimeException("Message deliverer could not be obtained"); 054 } 055 056 HashMap<String, String> userprefs = new HashMap<String, String>(); 057 userprefs.put(VALID_PROPERTY, VALID_VALUE); 058 userprefs.put("Email.email_delivery_format", "text"); 059 060 impl.saveRecipientPreferences(VALID_USER_ID, userprefs, deliverer); 061 062 RecipientPreference recipientPreference = new RecipientPreference(); 063 recipientPreference.setRecipientId(VALID_USER_ID); 064 Collection<RecipientPreference> prefs = services.getKcbGenericDao().findMatchingByExample(recipientPreference); 065 assertEquals(2, prefs.size()); 066 } 067 }