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.test.service.impl;
17  
18  import java.util.ArrayList;
19  import java.util.HashMap;
20  import java.util.List;
21  import java.util.Map;
22  
23  import org.apache.log4j.Logger;
24  import org.kuali.rice.kcb.service.impl.EmailServiceImpl;
25  import org.kuali.rice.kcb.test.service.MockEmailService;
26  
27  /**
28   * Mock EmailService implementation that does not actually send any mail
29   * @author Kuali Rice Team (rice.collab@kuali.org)
30   */
31  public class MockEmailServiceImpl extends EmailServiceImpl implements MockEmailService {
32      private static final Logger LOG = Logger.getLogger(MockEmailServiceImpl.class);
33  
34      public final Map<String, List<Map<String, String>>> MAILBOXES = new HashMap<String, List<Map<String, String>>>();
35  
36  	/**
37       * @see org.kuali.rice.kcb.test.service.MockEmailService#getMailBoxes()
38       */
39      public Map<String, List<Map<String, String>>> getMailBoxes() {
40          return MAILBOXES;
41      }
42  
43      /**
44       * @see org.kuali.rice.kcb.service.impl.EmailServiceImpl#sendEmail(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
45       */
46      //@Override
47      protected void sendEmail(String message, String subject, String from, String sendTo, String format) {
48          LOG.info("Storing mail for user: " + sendTo + ": " + subject);
49          Map<String, String> mail = new HashMap<String, String>();
50          mail.put("message", message);
51          mail.put("subject", subject);
52          mail.put("from", from);
53          mail.put("sendTo", sendTo);
54          mail.put("format", format);
55  
56          synchronized (MAILBOXES) {
57              List<Map<String, String>> mailbox = MAILBOXES.get(sendTo);
58              if (mailbox == null) {
59                  mailbox = new ArrayList<Map<String, String>>();
60                  MAILBOXES.put(sendTo, mailbox);
61              }
62              mailbox.add(mail);
63          }
64      }
65  }