You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/02/25 10:26:33 UTC
[james-project] 05/08: MAILBOX-381 Add a naive memory
implementation for the vault to exercise the contract
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 62cadef946c5bac5866c2477bfc883aa09fbe84b
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Feb 22 12:03:26 2019 +0700
MAILBOX-381 Add a naive memory implementation for the vault to exercise the contract
---
.../vault/memory/MemoryDeletedMessagesVault.java | 68 ++++++++++++++++++++++
.../memory/MemoryDeletedMessagesVaultTest.java | 39 +++++++++++++
2 files changed, 107 insertions(+)
diff --git a/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/memory/MemoryDeletedMessagesVault.java b/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/memory/MemoryDeletedMessagesVault.java
new file mode 100644
index 0000000..d35f43b
--- /dev/null
+++ b/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/memory/MemoryDeletedMessagesVault.java
@@ -0,0 +1,68 @@
+/****************************************************************
+ * 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.vault.memory;
+
+import org.apache.james.core.User;
+import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.vault.DeletedMessage;
+import org.apache.james.vault.DeletedMessageVault;
+import org.apache.james.vault.Query;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.Table;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+public class MemoryDeletedMessagesVault implements DeletedMessageVault {
+ private final Table<User, MessageId, DeletedMessage> table;
+
+ MemoryDeletedMessagesVault() {
+ table = HashBasedTable.create();
+ }
+
+ @Override
+ public Mono<Void> append(User user, DeletedMessage deletedMessage) {
+ Preconditions.checkNotNull(user);
+ Preconditions.checkNotNull(deletedMessage);
+
+ table.put(user, deletedMessage.getMessageId(), deletedMessage);
+ return Mono.empty();
+ }
+
+ @Override
+ public Mono<Void> delete(User user, MessageId messageId) {
+ Preconditions.checkNotNull(user);
+ Preconditions.checkNotNull(messageId);
+
+ table.remove(user, messageId);
+ return Mono.empty();
+ }
+
+ @Override
+ public Flux<DeletedMessage> search(User user, Query query) {
+ Preconditions.checkNotNull(user);
+ Preconditions.checkNotNull(query);
+ Preconditions.checkArgument(query.getCriteria().isEmpty(), "Search is not supported yet...");
+
+ return Flux.fromIterable(table.row(user).values());
+ }
+}
diff --git a/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/memory/MemoryDeletedMessagesVaultTest.java b/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/memory/MemoryDeletedMessagesVaultTest.java
new file mode 100644
index 0000000..2598d62
--- /dev/null
+++ b/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/memory/MemoryDeletedMessagesVaultTest.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.vault.memory;
+
+import org.apache.james.vault.DeletedMessageVault;
+import org.apache.james.vault.DeletedMessageVaultContract;
+import org.junit.jupiter.api.BeforeEach;
+
+public class MemoryDeletedMessagesVaultTest implements DeletedMessageVaultContract {
+
+ private MemoryDeletedMessagesVault memoryDeletedMessagesVault;
+
+ @BeforeEach
+ void setUp() {
+ memoryDeletedMessagesVault = new MemoryDeletedMessagesVault();
+ }
+
+ @Override
+ public DeletedMessageVault getVault() {
+ return memoryDeletedMessagesVault;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org