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 ff5f4538b413d9d479f05dafb2407ebf998fd377 Author: tran tien duc <[email protected]> AuthorDate: Tue Feb 19 13:00:33 2019 +0700 MAILBOX-379 Introduce PreDeletionHook API --- .../james/mailbox/extension/PreDeletionHook.java | 106 +++++++++++++++++++++ .../mailbox/extension/PreDeletionHookTest.java | 47 +++++++++ mailbox/store/pom.xml | 20 +++- 3 files changed, 168 insertions(+), 5 deletions(-) diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/extension/PreDeletionHook.java b/mailbox/api/src/main/java/org/apache/james/mailbox/extension/PreDeletionHook.java new file mode 100644 index 0000000..41df20d --- /dev/null +++ b/mailbox/api/src/main/java/org/apache/james/mailbox/extension/PreDeletionHook.java @@ -0,0 +1,106 @@ +/**************************************************************** + * 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.mailbox.extension; + +import java.util.List; +import java.util.Objects; +import java.util.UUID; + +import org.apache.james.mailbox.MetadataWithMailboxId; +import org.reactivestreams.Publisher; + +public interface PreDeletionHook { + + class DeletionId { + + public static DeletionId random() { + return new DeletionId(UUID.randomUUID()); + } + + public static DeletionId of(UUID uuid) { + return new DeletionId(uuid); + } + + private final UUID id; + + private DeletionId(UUID id) { + this.id = id; + } + + public String asString() { + return id.toString(); + } + + @Override + public final boolean equals(Object o) { + if (o instanceof DeletionId) { + DeletionId that = (DeletionId) o; + return Objects.equals(this.id, that.id); + } + return false; + } + + @Override + public final int hashCode() { + return Objects.hash(id); + } + } + + class DeleteOperation { + + public static DeleteOperation from(List<MetadataWithMailboxId> deletionMetadataList) { + return new DeleteOperation(DeletionId.random(), deletionMetadataList); + } + + private final DeletionId deletionId; + private final List<MetadataWithMailboxId> deletionMetadataList; + + private DeleteOperation(DeletionId deletionId, List<MetadataWithMailboxId> deletionMetadataList) { + this.deletionId = deletionId; + this.deletionMetadataList = deletionMetadataList; + } + + public DeletionId getDeletionId() { + return deletionId; + } + + public List<MetadataWithMailboxId> getDeletionMetadataList() { + return deletionMetadataList; + } + + @Override + public final boolean equals(Object o) { + if (o instanceof DeleteOperation) { + DeleteOperation that = (DeleteOperation) o; + + return Objects.equals(this.deletionId, that.deletionId) + && Objects.equals(this.deletionMetadataList, that.deletionMetadataList); + } + return false; + } + + @Override + public final int hashCode() { + return Objects.hash(deletionId, deletionMetadataList); + } + } + + Publisher<Void> notifyDelete(DeleteOperation deleteOperation); +} diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/extension/PreDeletionHookTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/extension/PreDeletionHookTest.java new file mode 100644 index 0000000..2b19ce1 --- /dev/null +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/extension/PreDeletionHookTest.java @@ -0,0 +1,47 @@ +/**************************************************************** + * 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.mailbox.extension; + +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import nl.jqno.equalsverifier.EqualsVerifier; + +class PreDeletionHookTest { + + @Nested + class DeletionIdTest { + + @Test + void shouldMatchBeanContract() { + EqualsVerifier.forClass(PreDeletionHook.DeletionId.class) + .verify(); + } + } + + @Nested + class DeleteOperationTest { + + @Test + void shouldMatchBeanContract() { + EqualsVerifier.forClass(PreDeletionHook.DeleteOperation.class) + .verify(); + } + } +} \ No newline at end of file diff --git a/mailbox/store/pom.xml b/mailbox/store/pom.xml index 572fd84..dbca17c 100644 --- a/mailbox/store/pom.xml +++ b/mailbox/store/pom.xml @@ -109,11 +109,6 @@ <artifactId>javax.inject</artifactId> </dependency> <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> <groupId>net.javacrumbs.json-unit</groupId> <artifactId>json-unit-assertj</artifactId> <scope>test</scope> @@ -138,6 +133,21 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.platform</groupId> + <artifactId>junit-platform-launcher</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.vintage</groupId> + <artifactId>junit-vintage-engine</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> <scope>test</scope> --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
