01: /****************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one *
03: * or more contributor license agreements. See the NOTICE file *
04: * distributed with this work for additional information *
05: * regarding copyright ownership. The ASF licenses this file *
06: * to you under the Apache License, Version 2.0 (the *
07: * "License"); you may not use this file except in compliance *
08: * with the License. You may obtain a copy of the License at *
09: * *
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: ****************************************************************/package org.apache.james.test.mock.james;
19:
20: import org.apache.james.core.MailImpl;
21: import org.apache.james.services.MailRepository;
22: import org.apache.mailet.Mail;
23:
24: import javax.mail.MessagingException;
25:
26: import java.util.HashMap;
27: import java.util.Iterator;
28: import java.util.Collection;
29:
30: public class MockMailRepository implements MailRepository {
31:
32: private HashMap messages = new HashMap();
33:
34: public void store(Mail mc) throws MessagingException {
35: MailImpl m = new MailImpl(mc, mc.getName());
36: m.setState(mc.getState());
37: this .messages.put(mc.getName(), m);
38: }
39:
40: public Iterator list() throws MessagingException {
41: return messages.keySet().iterator(); // trivial implementation
42: }
43:
44: public Mail retrieve(String key) throws MessagingException {
45: Mail m2 = new MailImpl((Mail) messages.get(key), key);
46: m2.setState(((Mail) messages.get(key)).getState());
47: return m2; // trivial implementation
48: }
49:
50: public void remove(Mail mail) throws MessagingException {
51: messages.remove(mail.getName());
52: }
53:
54: public void remove(Collection mails) throws MessagingException {
55: for (Iterator i = mails.iterator(); i.hasNext();) {
56: Mail m = (Mail) i.next();
57: messages.remove(m.getName());
58: }
59: }
60:
61: public void remove(String key) throws MessagingException {
62: messages.remove(key);
63: }
64:
65: public boolean lock(String key) throws MessagingException {
66: return false; // trivial implementation
67: }
68:
69: public boolean unlock(String key) throws MessagingException {
70: return false; // trivial implementation
71: }
72: }
|