JAMES-2290 write a memory implementation of MailRepository
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/15a9f782 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/15a9f782 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/15a9f782 Branch: refs/heads/master Commit: 15a9f78212514e494aa5cef919dfc0bbe45eb199 Parents: 7fa6607 Author: Matthieu Baechler <[email protected]> Authored: Wed Jan 17 10:24:35 2018 +0100 Committer: benwa <[email protected]> Committed: Fri Jan 19 18:57:57 2018 +0700 ---------------------------------------------------------------------- .../mailrepository-memory/pom.xml | 82 ++++++++++++++++++++ .../memory/MemoryMailRepository.java | 76 ++++++++++++++++++ .../memory/MemoryMailRepositoryTest.java | 39 ++++++++++ server/pom.xml | 1 + 4 files changed, 198 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/15a9f782/server/mailrepository/mailrepository-memory/pom.xml ---------------------------------------------------------------------- diff --git a/server/mailrepository/mailrepository-memory/pom.xml b/server/mailrepository/mailrepository-memory/pom.xml new file mode 100644 index 0000000..4870dc5 --- /dev/null +++ b/server/mailrepository/mailrepository-memory/pom.xml @@ -0,0 +1,82 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.james</groupId> + <artifactId>james-server</artifactId> + <version>3.1.0-SNAPSHOT</version> + <relativePath>../../pom.xml</relativePath> + </parent> + + <artifactId>james-server-mailrepository-memory</artifactId> + <packaging>jar</packaging> + + <name>Apache James :: Server :: MailRepository :: Memory</name> + + <dependencies> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>james-server-core</artifactId> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>james-server-mailrepository-api</artifactId> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>james-server-mailrepository-api</artifactId> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>test-jar</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + </plugin> + </plugins> + </build> +</project> http://git-wip-us.apache.org/repos/asf/james-project/blob/15a9f782/server/mailrepository/mailrepository-memory/src/main/java/org/apache/james/mailrepository/memory/MemoryMailRepository.java ---------------------------------------------------------------------- diff --git a/server/mailrepository/mailrepository-memory/src/main/java/org/apache/james/mailrepository/memory/MemoryMailRepository.java b/server/mailrepository/mailrepository-memory/src/main/java/org/apache/james/mailrepository/memory/MemoryMailRepository.java new file mode 100644 index 0000000..e281d83 --- /dev/null +++ b/server/mailrepository/mailrepository-memory/src/main/java/org/apache/james/mailrepository/memory/MemoryMailRepository.java @@ -0,0 +1,76 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.mailrepository.memory; + +import java.util.Collection; +import java.util.Iterator; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.james.mailrepository.api.MailRepository; +import org.apache.mailet.Mail; + +public class MemoryMailRepository implements MailRepository { + + private final ConcurrentHashMap<String, Mail> mails; + + public MemoryMailRepository() { + mails = new ConcurrentHashMap<>(); + } + + @Override + public void store(Mail mail) { + mails.put(mail.getName(), mail); + } + + @Override + public Iterator<String> list() { + return mails.keySet().iterator(); + } + + @Override + public Mail retrieve(String key) { + return mails.get(key); + } + + @Override + public void remove(Mail mail) { + mails.remove(mail.getName()); + } + + @Override + public void remove(Collection<Mail> toRemove) { + toRemove.stream().map(Mail::getName).forEach(this::remove); + } + + @Override + public void remove(String key) { + mails.remove(key); + } + + @Override + public boolean lock(String key) { + return false; + } + + @Override + public boolean unlock(String key) { + return false; + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/15a9f782/server/mailrepository/mailrepository-memory/src/test/java/org/apache/james/mailrepository/memory/MemoryMailRepositoryTest.java ---------------------------------------------------------------------- diff --git a/server/mailrepository/mailrepository-memory/src/test/java/org/apache/james/mailrepository/memory/MemoryMailRepositoryTest.java b/server/mailrepository/mailrepository-memory/src/test/java/org/apache/james/mailrepository/memory/MemoryMailRepositoryTest.java new file mode 100644 index 0000000..420baf8 --- /dev/null +++ b/server/mailrepository/mailrepository-memory/src/test/java/org/apache/james/mailrepository/memory/MemoryMailRepositoryTest.java @@ -0,0 +1,39 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.mailrepository.memory; + +import org.apache.james.mailrepository.MailRepositoryContract; +import org.apache.james.mailrepository.api.MailRepository; +import org.junit.jupiter.api.BeforeEach; + +class MemoryMailRepositoryTest implements MailRepositoryContract { + + private MemoryMailRepository memoryMailRepository; + + @BeforeEach + void setup() { + memoryMailRepository = new MemoryMailRepository(); + } + + @Override + public MailRepository retrieveRepository() { + return memoryMailRepository; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/15a9f782/server/pom.xml ---------------------------------------------------------------------- diff --git a/server/pom.xml b/server/pom.xml index 5615df5..a1cc8ea 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -83,6 +83,7 @@ <module>mailet/mailets</module> <module>mailrepository/mailrepository-api</module> + <module>mailrepository/mailrepository-memory</module> <module>protocols/fetchmail</module> <module>protocols/jmap</module> --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
