View Javadoc

1   /*****************************************************************
2    * Licensed to the Apache Software Foundation (ASF) under one   *
3    * or more contributor license agreements.  See the NOTICE file *
4    * distributed with this work for additional information        *
5    * regarding copyright ownership.  The ASF licenses this file   *
6    * to you under the Apache License, Version 2.0 (the            *
7    * "License"); you may not use this file except in compliance   *
8    * with the License.  You may obtain a copy of the License at   *
9    *                                                              *
10   *   http://www.apache.org/licenses/LICENSE-2.0                 *
11   *                                                              *
12   * Unless required by applicable law or agreed to in writing,   *
13   * software distributed under the License is distributed on an  *
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15   * KIND, either express or implied.  See the License for the    *
16   * specific language governing permissions and limitations      *
17   * under the License.                                           *
18   ****************************************************************/
19  
20  
21  package org.apache.james.test.mock.james;
22  
23  import org.apache.james.core.MailImpl;
24  import org.apache.james.services.MailRepository;
25  import org.apache.mailet.Mail;
26  
27  import javax.mail.MessagingException;
28  
29  import java.util.HashMap;
30  import java.util.Iterator;
31  import java.util.Collection;
32  
33  public class MockMailRepository implements MailRepository {
34      
35      private HashMap messages = new HashMap();
36  
37      public void store(Mail mc) throws MessagingException {
38          MailImpl m = new MailImpl(mc,mc.getName());
39          m.setState(mc.getState());
40          this.messages.put(mc.getName(),m);
41      }
42  
43      public Iterator list() throws MessagingException {
44          return messages.keySet().iterator();  // trivial implementation
45      }
46  
47      public Mail retrieve(String key) throws MessagingException {
48          Mail m2 = new MailImpl((Mail) messages.get(key),key);
49          m2.setState(((Mail) messages.get(key)).getState());
50          return m2;  // trivial implementation
51      }
52  
53      public void remove(Mail mail) throws MessagingException {
54          messages.remove(mail.getName());
55      }
56  
57      public void remove(Collection mails) throws MessagingException {
58          for (Iterator i = mails.iterator(); i.hasNext(); ) {
59              Mail m = (Mail) i.next();
60              messages.remove(m.getName());
61          }
62      }
63  
64      public void remove(String key) throws MessagingException {
65          messages.remove(key);
66      }
67  
68      public boolean lock(String key) throws MessagingException {
69          return false;  // trivial implementation
70      }
71  
72      public boolean unlock(String key) throws MessagingException {
73          return false;  // trivial implementation
74      }
75  }