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 3bad6c4850702aa50e5e4d0aeb115593af1a156f
Author: RĂ©mi Kowalski <rkowal...@linagora.com>
AuthorDate: Mon Sep 2 11:50:05 2019 +0200

    JAMES-2813 serialize SingleMessageReindexingTaskAdditionalInformationDTO
---
 ...sageReindexingTaskAdditionalInformationDTO.java | 61 ++++++++++++++++++++++
 ...ngleMessageReindexingTaskSerializationTest.java | 30 ++++++++---
 2 files changed, 85 insertions(+), 6 deletions(-)

diff --git 
a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMessageReindexingTaskAdditionalInformationDTO.java
 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMessageReindexingTaskAdditionalInformationDTO.java
new file mode 100644
index 0000000..b5f144b
--- /dev/null
+++ 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMessageReindexingTaskAdditionalInformationDTO.java
@@ -0,0 +1,61 @@
+/****************************************************************
+ * 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.mailbox.tools.indexer;
+
+import java.util.function.Function;
+
+import org.apache.james.json.DTOModule;
+import org.apache.james.mailbox.MessageUid;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.server.task.json.dto.AdditionalInformationDTO;
+import org.apache.james.server.task.json.dto.AdditionalInformationDTOModule;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class SingleMessageReindexingTaskAdditionalInformationDTO implements 
AdditionalInformationDTO {
+
+    static final Function<MailboxId.Factory, 
AdditionalInformationDTOModule<SingleMessageReindexingTask.AdditionalInformation,
 SingleMessageReindexingTaskAdditionalInformationDTO>> SERIALIZATION_MODULE =
+        factory ->
+            
DTOModule.forDomainObject(SingleMessageReindexingTask.AdditionalInformation.class)
+                
.convertToDTO(SingleMessageReindexingTaskAdditionalInformationDTO.class)
+                .toDomainObjectConverter(dto -> new 
SingleMessageReindexingTask.AdditionalInformation(factory.fromString(dto.mailboxId),
 MessageUid.of(dto.getUid())))
+                .toDTOConverter((details, type) -> new 
SingleMessageReindexingTaskAdditionalInformationDTO(details.getMailboxId(), 
details.getUid()))
+                
.typeName(SingleMessageReindexingTask.MESSAGE_RE_INDEXING.asString())
+                .withFactory(AdditionalInformationDTOModule::new);
+
+    private final String mailboxId;
+    private final long uid;
+
+    private 
SingleMessageReindexingTaskAdditionalInformationDTO(@JsonProperty("mailboxId") 
String mailboxId, @JsonProperty("uid") long uid) {
+        this.mailboxId = mailboxId;
+        this.uid = uid;
+    }
+
+    public String getMailboxId() {
+        return mailboxId;
+    }
+
+    public long getUid() {
+        return uid;
+    }
+
+    public static SingleMessageReindexingTaskAdditionalInformationDTO 
of(SingleMessageReindexingTask task) {
+        return new 
SingleMessageReindexingTaskAdditionalInformationDTO(task.getMailboxId().serialize(),
 task.getUid().asLong());
+    }
+}
diff --git 
a/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/SingleMessageReindexingTaskSerializationTest.java
 
b/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/SingleMessageReindexingTaskSerializationTest.java
index 56d5804..b3c7c58 100644
--- 
a/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/SingleMessageReindexingTaskSerializationTest.java
+++ 
b/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/SingleMessageReindexingTaskSerializationTest.java
@@ -26,6 +26,7 @@ import java.io.IOException;
 
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.model.TestId;
+import 
org.apache.james.server.task.json.JsonTaskAdditionalInformationsSerializer;
 import org.apache.james.server.task.json.JsonTaskSerializer;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -34,21 +35,27 @@ import com.fasterxml.jackson.core.JsonProcessingException;
 
 class SingleMessageReindexingTaskSerializationTest {
 
+    private final TestId.Factory mailboxIdFactory = new TestId.Factory();
     private ReIndexerPerformer reIndexerPerformer;
     private JsonTaskSerializer taskSerializer;
     private final String serializedMessageReindexingTask = "{\"type\": 
\"messageReIndexing\", \"mailboxId\": \"1\", \"uid\": 10}";
+    private final String SERIALIZED_ADDITIONAL_INFORMATION = "{\"mailboxId\": 
\"1\", \"uid\": 10}";
+    private final TestId mailboxId = TestId.of(1L);
+    private final MessageUid messageUid = MessageUid.of(10L);
+    private JsonTaskAdditionalInformationsSerializer 
jsonAdditionalInformationSerializer = new 
JsonTaskAdditionalInformationsSerializer(
+        SingleMessageReindexingTaskAdditionalInformationDTO
+            .SERIALIZATION_MODULE
+            .apply(mailboxIdFactory));
 
     @BeforeEach
     void setUp() {
         reIndexerPerformer = mock(ReIndexerPerformer.class);
-        SingleMessageReindexingTask.Factory factory = new 
SingleMessageReindexingTask.Factory(reIndexerPerformer, new TestId.Factory());
-        taskSerializer = new 
JsonTaskSerializer(SingleMessageReindexingTask.MODULE.apply(factory));
+        SingleMessageReindexingTask.Factory factory = new 
SingleMessageReindexingTask.Factory(reIndexerPerformer, mailboxIdFactory);
+        taskSerializer = new 
JsonTaskSerializer(SingleMessageReindexingTaskDTO.MODULE.apply(factory));
     }
 
     @Test
     void singleMessageReindexingShouldBeSerializable() throws 
JsonProcessingException {
-        TestId mailboxId = TestId.of(1L);
-        MessageUid messageUid = MessageUid.of(10L);
         SingleMessageReindexingTask task = new 
SingleMessageReindexingTask(reIndexerPerformer, mailboxId, messageUid);
 
         assertThatJson(taskSerializer.serialize(task))
@@ -57,12 +64,23 @@ class SingleMessageReindexingTaskSerializationTest {
 
     @Test
     void singleMessageReindexingShouldBeDeserializable() throws IOException {
-        TestId mailboxId = TestId.of(1L);
-        MessageUid messageUid = MessageUid.of(10L);
         SingleMessageReindexingTask task = new 
SingleMessageReindexingTask(reIndexerPerformer, mailboxId, messageUid);
 
         assertThat(taskSerializer.deserialize(serializedMessageReindexingTask))
             .isEqualToComparingOnlyGivenFields(task, "reIndexerPerformer", 
"mailboxId", "uid");
     }
+
+    @Test
+    void additionalInformationShouldBeSerializable() throws 
JsonProcessingException {
+        SingleMessageReindexingTask.AdditionalInformation details = new 
SingleMessageReindexingTask.AdditionalInformation(mailboxId, messageUid);
+        
assertThatJson(jsonAdditionalInformationSerializer.serialize(details)).isEqualTo(SERIALIZED_ADDITIONAL_INFORMATION);
+    }
+
+    @Test
+    void additonalInformationShouldBeDeserializable() throws IOException {
+        SingleMessageReindexingTask.AdditionalInformation details = new 
SingleMessageReindexingTask.AdditionalInformation(mailboxId, messageUid);
+        
assertThat(jsonAdditionalInformationSerializer.deserialize("messageReIndexing", 
SERIALIZED_ADDITIONAL_INFORMATION))
+            .isEqualToComparingFieldByField(details);
+    }
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to