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