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 bedbd4fa1317058196fa12f85388e2d63ccb93a3
Author: Gautier DI FOLCO <gdifo...@linagora.com>
AuthorDate: Wed Sep 4 11:39:42 2019 +0200

    JAMES-2813 MailboxMergingTaskDTO.Details serialize
---
 ...MailboxMergingTaskAdditionalInformationDTO.java | 98 ++++++++++++++++++++++
 .../mail/task/MailboxMergingTaskTest.java          | 16 ++++
 2 files changed, 114 insertions(+)

diff --git 
a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskAdditionalInformationDTO.java
 
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskAdditionalInformationDTO.java
new file mode 100644
index 0000000..16a898e
--- /dev/null
+++ 
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskAdditionalInformationDTO.java
@@ -0,0 +1,98 @@
+/**
+ * *************************************************************
+ * 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.cassandra.mail.task;
+
+import org.apache.james.json.DTOModule;
+import org.apache.james.mailbox.cassandra.ids.CassandraId;
+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 MailboxMergingTaskAdditionalInformationDTO implements 
AdditionalInformationDTO {
+    private static CassandraId.Factory ID_FACTORY = new CassandraId.Factory();
+
+    private static MailboxMergingTaskAdditionalInformationDTO 
fromDomainObject(MailboxMergingTask.Details details, String type) {
+        return new MailboxMergingTaskAdditionalInformationDTO(
+            details.getOldMailboxId(),
+            details.getNewMailboxId(),
+            details.getTotalMessageCount(),
+            details.getMessageMovedCount(),
+            details.getMessageFailedCount()
+        );
+    }
+
+    static final AdditionalInformationDTOModule<MailboxMergingTask.Details, 
MailboxMergingTaskAdditionalInformationDTO> SERIALIZATION_MODULE =
+        DTOModule.forDomainObject(MailboxMergingTask.Details.class)
+            .convertToDTO(MailboxMergingTaskAdditionalInformationDTO.class)
+            
.toDomainObjectConverter(MailboxMergingTaskAdditionalInformationDTO::toDomainObject)
+            
.toDTOConverter(MailboxMergingTaskAdditionalInformationDTO::fromDomainObject)
+            .typeName(MailboxMergingTask.MAILBOX_MERGING.asString())
+            .withFactory(AdditionalInformationDTOModule::new);
+
+    private final String oldMailboxId;
+    private final String newMailboxId;
+    private final long totalMessageCount;
+    private final long messageMovedCount;
+    private final long messageFailedCount;
+
+    public 
MailboxMergingTaskAdditionalInformationDTO(@JsonProperty("oldMailboxId") String 
oldMailboxId,
+                                                      
@JsonProperty("newMailboxId") String newMailboxId,
+                                                      
@JsonProperty("totalMessageCount") long totalMessageCount,
+                                                      
@JsonProperty("messageMovedCount") long messageMovedCount,
+                                                      
@JsonProperty("messageFailedCount") long messageFailedCount) {
+        this.oldMailboxId = oldMailboxId;
+        this.newMailboxId = newMailboxId;
+        this.totalMessageCount = totalMessageCount;
+        this.messageMovedCount = messageMovedCount;
+        this.messageFailedCount = messageFailedCount;
+    }
+
+    public String getOldMailboxId() {
+        return oldMailboxId;
+    }
+
+    public String getNewMailboxId() {
+        return newMailboxId;
+    }
+
+    public long getTotalMessageCount() {
+        return totalMessageCount;
+    }
+
+    public long getMessageMovedCount() {
+        return messageMovedCount;
+    }
+
+    public long getMessageFailedCount() {
+        return messageFailedCount;
+    }
+
+    private MailboxMergingTask.Details toDomainObject() {
+        return new MailboxMergingTask.Details(
+            ID_FACTORY.fromString(oldMailboxId),
+            ID_FACTORY.fromString(newMailboxId),
+            totalMessageCount,
+            messageMovedCount,
+            messageFailedCount
+        );
+    }
+}
diff --git 
a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskTest.java
 
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskTest.java
index 32bf837..59fa8b9 100644
--- 
a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskTest.java
+++ 
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskTest.java
@@ -19,12 +19,14 @@
 
 package org.apache.james.mailbox.cassandra.mail.task;
 
+import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 
 import java.io.IOException;
 
 import org.apache.james.mailbox.cassandra.ids.CassandraId;
+import 
org.apache.james.server.task.json.JsonTaskAdditionalInformationsSerializer;
 import org.apache.james.server.task.json.JsonTaskSerializer;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
@@ -34,8 +36,11 @@ import org.junit.jupiter.api.Test;
 class MailboxMergingTaskTest {
     private static final CassandraId.Factory CASSANDRA_ID_FACTORY = new 
CassandraId.Factory();
     private static final String SERIALIZED = 
"{\"type\":\"mailboxMerging\",\"totalMessageCount\":0,\"oldMailboxId\":\"3b8e5f90-b94f-20f8-ce7b-3c4aad93b90c\",\"newMailboxId\":\"2c7f4081-aa30-11e9-bf6c-2d3b9e84aafd\"}";
+    private static final String SERIALIZED_ADDITIONAL_INFORMATION = 
"{\"oldMailboxId\":\"3b8e5f90-b94f-20f8-ce7b-3c4aad93b90c\",\"newMailboxId\":\"2c7f4081-aa30-11e9-bf6c-2d3b9e84aafd\",\"totalMessageCount\":10,\"messageMovedCount\":15,\"messageFailedCount\":20}";
     private static final MailboxMergingTaskRunner TASK_RUNNER = 
mock(MailboxMergingTaskRunner.class);
     private static final MailboxMergingTask TASK = new 
MailboxMergingTask(TASK_RUNNER, 0L, 
CASSANDRA_ID_FACTORY.fromString("3b8e5f90-b94f-20f8-ce7b-3c4aad93b90c"), 
CASSANDRA_ID_FACTORY.fromString("2c7f4081-aa30-11e9-bf6c-2d3b9e84aafd"));
+    private static final MailboxMergingTask.Details DETAILS = new 
MailboxMergingTask.Details(CASSANDRA_ID_FACTORY.fromString("3b8e5f90-b94f-20f8-ce7b-3c4aad93b90c"),
 CASSANDRA_ID_FACTORY.fromString("2c7f4081-aa30-11e9-bf6c-2d3b9e84aafd"), 10, 
15, 20);
+    private static final JsonTaskAdditionalInformationsSerializer 
JSON_TASK_ADDITIONAL_INFORMATIONS_SERIALIZER = new 
JsonTaskAdditionalInformationsSerializer(MailboxMergingTaskAdditionalInformationDTO.SERIALIZATION_MODULE);
     private static final JsonTaskSerializer TESTEE = new 
JsonTaskSerializer(MailboxMergingTaskDTO.MODULE.apply(TASK_RUNNER));
 
     @Test
@@ -49,4 +54,15 @@ class MailboxMergingTaskTest {
         assertThat(TESTEE.deserialize(SERIALIZED))
             .isEqualToComparingFieldByFieldRecursively(TASK);
     }
+
+    @Test
+    void additionalInformationShouldBeSerializable() throws 
JsonProcessingException {
+        
assertThatJson(JSON_TASK_ADDITIONAL_INFORMATIONS_SERIALIZER.serialize(DETAILS)).isEqualTo(SERIALIZED_ADDITIONAL_INFORMATION);
+    }
+
+    @Test
+    void additonalInformationShouldBeDeserializable() throws IOException {
+        
assertThat(JSON_TASK_ADDITIONAL_INFORMATIONS_SERIALIZER.deserialize("mailboxMerging",
 SERIALIZED_ADDITIONAL_INFORMATION))
+            .isEqualToComparingFieldByField(DETAILS);
+    }
 }
\ No newline at end of file


---------------------------------------------------------------------
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