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.test.service.impl;
017    
018    import java.util.ArrayList;
019    import java.util.HashMap;
020    import java.util.List;
021    import java.util.Map;
022    
023    import org.apache.log4j.Logger;
024    import org.kuali.rice.kcb.service.impl.EmailServiceImpl;
025    import org.kuali.rice.kcb.test.service.MockEmailService;
026    
027    /**
028     * Mock EmailService implementation that does not actually send any mail
029     * @author Kuali Rice Team (rice.collab@kuali.org)
030     */
031    public class MockEmailServiceImpl extends EmailServiceImpl implements MockEmailService {
032        private static final Logger LOG = Logger.getLogger(MockEmailServiceImpl.class);
033    
034        public final Map<String, List<Map<String, String>>> MAILBOXES = new HashMap<String, List<Map<String, String>>>();
035    
036            /**
037         * @see org.kuali.rice.kcb.test.service.MockEmailService#getMailBoxes()
038         */
039        public Map<String, List<Map<String, String>>> getMailBoxes() {
040            return MAILBOXES;
041        }
042    
043        /**
044         * @see org.kuali.rice.kcb.service.impl.EmailServiceImpl#sendEmail(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
045         */
046        //@Override
047        protected void sendEmail(String message, String subject, String from, String sendTo, String format) {
048            LOG.info("Storing mail for user: " + sendTo + ": " + subject);
049            Map<String, String> mail = new HashMap<String, String>();
050            mail.put("message", message);
051            mail.put("subject", subject);
052            mail.put("from", from);
053            mail.put("sendTo", sendTo);
054            mail.put("format", format);
055    
056            synchronized (MAILBOXES) {
057                List<Map<String, String>> mailbox = MAILBOXES.get(sendTo);
058                if (mailbox == null) {
059                    mailbox = new ArrayList<Map<String, String>>();
060                    MAILBOXES.put(sendTo, mailbox);
061                }
062                mailbox.add(mail);
063            }
064        }
065    }