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.service.impl;
17  
18  import org.junit.Test;
19  import org.kuali.rice.kcb.bo.RecipientPreference;
20  import org.kuali.rice.kcb.deliverer.MessageDeliverer;
21  import org.kuali.rice.kcb.deliverer.impl.EmailMessageDeliverer;
22  import org.kuali.rice.kcb.exception.ErrorList;
23  import org.kuali.rice.kcb.service.MessageDelivererRegistryService;
24  import org.kuali.rice.kcb.service.RecipientPreferenceService;
25  import org.kuali.rice.kcb.test.KCBTestCase;
26  import org.kuali.rice.kcb.test.TestConstants;
27  import org.kuali.rice.test.BaselineTestCase.BaselineMode;
28  import org.kuali.rice.test.BaselineTestCase.Mode;
29  
30  import java.util.Collection;
31  import java.util.HashMap;
32  
33  import static org.junit.Assert.assertEquals;
34  
35  /**
36   * Tests {@link RecipientPreferenceService}
37   * 
38   * @author Kuali Rice Team (rice.collab@kuali.org)
39   */
40  @BaselineMode(Mode.ROLLBACK_CLEAR_DB)
41  public class RecipientPreferenceServiceTest extends KCBTestCase {
42      public static final String VALID_DELIVERER_NAME = EmailMessageDeliverer.NAME;
43      public static final String VALID_PROPERTY = EmailMessageDeliverer.NAME + "." + EmailMessageDeliverer.EMAIL_ADDR_PREF_KEY;
44      public static final String VALID_VALUE = TestConstants.EMAIL_DELIVERER_PROPERTY_VALUE;
45      public static final String VALID_USER_ID = "user1"; // any user will do as KCB has no referential integrity in this regard
46  
47      @Test
48      public void saveRecipientPreferences() throws ErrorList {
49          RecipientPreferenceService impl = services.getRecipientPreferenceService();
50          MessageDelivererRegistryService delivererService = services.getMessageDelivererRegistryService();
51          MessageDeliverer deliverer = delivererService.getDelivererByName(VALID_DELIVERER_NAME);
52          if (deliverer == null) {
53              throw new RuntimeException("Message deliverer could not be obtained");
54          }
55              
56          HashMap<String, String> userprefs = new HashMap<String, String>();
57          userprefs.put(VALID_PROPERTY, VALID_VALUE);
58          userprefs.put("Email.email_delivery_format", "text");
59  
60          impl.saveRecipientPreferences(VALID_USER_ID, userprefs, deliverer);
61          
62          RecipientPreference recipientPreference = new RecipientPreference();
63          recipientPreference.setRecipientId(VALID_USER_ID);
64          Collection<RecipientPreference> prefs = services.getKcbGenericDao().findMatchingByExample(recipientPreference);
65          assertEquals(2, prefs.size());
66      }
67  }