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 b2c71571422639efd2ec1f9aba2b2d8b15c4d7ca Author: Gautier DI FOLCO <gdifo...@linagora.com> AuthorDate: Wed Sep 4 13:26:03 2019 +0200 JAMES-2813 Add MailboxPathV2MigrationTask serialization --- .../migration/MailboxPathV2MigrationTaskDTO.java | 60 ++++++++++++++++++++++ ...ailboxPathV2MigrationTaskSerializationTest.java | 52 +++++++++++++++++++ 2 files changed, 112 insertions(+) diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/migration/MailboxPathV2MigrationTaskDTO.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/migration/MailboxPathV2MigrationTaskDTO.java new file mode 100644 index 0000000..5a7460a --- /dev/null +++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/migration/MailboxPathV2MigrationTaskDTO.java @@ -0,0 +1,60 @@ +/** + * ************************************************************* + * 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.migration; + +import java.util.function.Function; + +import org.apache.james.json.DTOModule; +import org.apache.james.server.task.json.dto.TaskDTO; +import org.apache.james.server.task.json.dto.TaskDTOModule; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class MailboxPathV2MigrationTaskDTO implements TaskDTO { + + private static MailboxPathV2MigrationTaskDTO fromDomainObject(MailboxPathV2Migration.MailboxPathV2MigrationTask task, String type) { + return new MailboxPathV2MigrationTaskDTO(type); + } + + public static final Function<MailboxPathV2Migration, TaskDTOModule<MailboxPathV2Migration.MailboxPathV2MigrationTask, MailboxPathV2MigrationTaskDTO>> MODULE = (migration) -> + DTOModule + .forDomainObject(MailboxPathV2Migration.MailboxPathV2MigrationTask.class) + .convertToDTO(MailboxPathV2MigrationTaskDTO.class) + .toDomainObjectConverter(dto -> dto.toDomainObject(migration)) + .toDTOConverter(MailboxPathV2MigrationTaskDTO::fromDomainObject) + .typeName(MailboxPathV2Migration.TYPE.asString()) + .withFactory(TaskDTOModule::new); + + private final String type; + + public MailboxPathV2MigrationTaskDTO(@JsonProperty("type") String type) { + this.type = type; + } + + @Override + public String getType() { + return type; + } + + private MailboxPathV2Migration.MailboxPathV2MigrationTask toDomainObject(MailboxPathV2Migration migration) { + return new MailboxPathV2Migration.MailboxPathV2MigrationTask(migration); + } +} diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/MailboxPathV2MigrationTaskSerializationTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/MailboxPathV2MigrationTaskSerializationTest.java new file mode 100644 index 0000000..34a8070 --- /dev/null +++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/MailboxPathV2MigrationTaskSerializationTest.java @@ -0,0 +1,52 @@ +/** + * ************************************************************* + * 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.migration; + +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.server.task.json.JsonTaskSerializer; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.junit.jupiter.api.Test; + +class MailboxPathV2MigrationTaskSerializationTest { + private static final MailboxPathV2Migration MIGRATION = mock(MailboxPathV2Migration.class); + private static final MailboxPathV2Migration.MailboxPathV2MigrationTask TASK = new MailboxPathV2Migration.MailboxPathV2MigrationTask(MIGRATION); + private static final String SERIALIZED_TASK = "{\"type\": \"Cassandra_mailboxPathV2Migration\"}"; + + private static final JsonTaskSerializer TASK_SERIALIZER = new JsonTaskSerializer(MailboxPathV2MigrationTaskDTO.MODULE.apply(MIGRATION)); + + @Test + void taskShouldBeSerializable() throws JsonProcessingException { + assertThatJson(TASK_SERIALIZER.serialize(TASK)) + .isEqualTo(SERIALIZED_TASK); + } + + @Test + void taskShouldBeDeserializable() throws IOException { + assertThat(TASK_SERIALIZER.deserialize(SERIALIZED_TASK)) + .isEqualToComparingFieldByField(TASK); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org