You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2021/12/02 03:53:22 UTC

[james-project] 03/04: JAMES-3675 : Introduce WebAdmin routes for vacation settings

This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 01d0060e929e49d743b8feeffb6931fc2af1fb97
Author: Karsten Otto <ka...@akquinet.de>
AuthorDate: Tue Nov 23 18:37:10 2021 +0100

    JAMES-3675 : Introduce WebAdmin routes for vacation settings
---
 .../org/apache/james/CassandraJamesServerMain.java |   2 +
 .../docs/modules/ROOT/pages/operate/webadmin.adoc  |  58 +++++
 .../james/CassandraRabbitMQJamesServerMain.java    |   2 +
 .../james/DistributedPOP3JamesServerMain.java      |   2 +
 .../org/apache/james/MemoryJamesServerMain.java    |   2 +
 .../james/modules/server/VacationRoutesModule.java |  34 +++
 .../org/apache/james/webadmin/dto/VacationDTO.java | 107 +++++++++
 .../james/webadmin/routes/VacationRoutes.java      | 148 ++++++++++++
 .../apache/james/webadmin/dto/VacationDTOTest.java |  68 ++++++
 .../james/webadmin/routes/VacationRoutesTest.java  | 257 +++++++++++++++++++++
 10 files changed, 680 insertions(+)

diff --git a/server/apps/cassandra-app/src/main/java/org/apache/james/CassandraJamesServerMain.java b/server/apps/cassandra-app/src/main/java/org/apache/james/CassandraJamesServerMain.java
index ec8c93b..7b1cc09 100644
--- a/server/apps/cassandra-app/src/main/java/org/apache/james/CassandraJamesServerMain.java
+++ b/server/apps/cassandra-app/src/main/java/org/apache/james/CassandraJamesServerMain.java
@@ -71,6 +71,7 @@ import org.apache.james.modules.server.MailboxesExportRoutesModule;
 import org.apache.james.modules.server.MessagesRoutesModule;
 import org.apache.james.modules.server.SieveRoutesModule;
 import org.apache.james.modules.server.TaskManagerModule;
+import org.apache.james.modules.server.VacationRoutesModule;
 import org.apache.james.modules.server.WebAdminMailOverWebModule;
 import org.apache.james.modules.server.WebAdminReIndexingTaskSerializationModule;
 import org.apache.james.modules.server.WebAdminServerModule;
@@ -90,6 +91,7 @@ public class CassandraJamesServerMain implements JamesServerMain {
     public static final Module WEBADMIN = Modules.combine(
         new CassandraRoutesModule(),
         new DataRoutesModules(),
+        new VacationRoutesModule(),
         new DeletedMessageVaultRoutesModule(),
         new DLPRoutesModule(),
         new InconsistencyQuotasSolvingRoutesModule(),
diff --git a/server/apps/distributed-app/docs/modules/ROOT/pages/operate/webadmin.adoc b/server/apps/distributed-app/docs/modules/ROOT/pages/operate/webadmin.adoc
index b3a75f5..8ea74ea 100644
--- a/server/apps/distributed-app/docs/modules/ROOT/pages/operate/webadmin.adoc
+++ b/server/apps/distributed-app/docs/modules/ROOT/pages/operate/webadmin.adoc
@@ -551,6 +551,64 @@ Response codes:
 * 400: The user is invalid
 * 404: The user is unknown
 
+== Administrating vacation settings
+
+=== Get vacation settings
+
+....
+curl -XGET http://ip:port/vacation/usernameToBeUsed
+....
+
+Resource name usernameToBeUsed representing valid users, hence it should
+match the criteria at xref:configure/usersrepository.adoc[User Repositories documentation]
+
+The response will look like this:
+
+....
+{
+  "enabled": true,
+  "fromDate": "2021-09-20T10:00:00Z",
+  "toDate": "2021-09-27T18:00:00Z",
+  "subject": "Out of office",
+  "textBody": "I am on vacation, will be back soon.",
+  "htmlBody": "<p>I am on vacation, will be back soon.</p>"
+}
+....
+
+Response codes:
+
+* 200: The vacation settings were successfully retrieved
+* 404: The user name is unknown
+
+=== Update vacation settings
+
+....
+curl -XPOST http://ip:port/vacation/usernameToBeUsed
+....
+
+Request body must be a JSON structure as described above.
+
+If any field is not set in the request, the corresponding field in the existing vacation message is left unchanged.
+
+Response codes:
+
+* 204: The vacation settings were successfully updated
+* 404: The user name is unknown
+* 400: The payload is invalid
+
+=== Delete vacation settings
+
+....
+curl -XDELETE http://ip:port/vacation/usernameToBeUsed
+....
+
+For convenience, this disables and clears the existing vacation settings of the user.
+
+Response codes:
+
+* 204: The vacation settings were successfully disabled
+* 404: The user name is unknown
+
 == Administrating mailboxes
 
 === All mailboxes
diff --git a/server/apps/distributed-app/src/main/java/org/apache/james/CassandraRabbitMQJamesServerMain.java b/server/apps/distributed-app/src/main/java/org/apache/james/CassandraRabbitMQJamesServerMain.java
index 77a11dd..51ce86b 100644
--- a/server/apps/distributed-app/src/main/java/org/apache/james/CassandraRabbitMQJamesServerMain.java
+++ b/server/apps/distributed-app/src/main/java/org/apache/james/CassandraRabbitMQJamesServerMain.java
@@ -75,6 +75,7 @@ import org.apache.james.modules.server.MailboxesExportRoutesModule;
 import org.apache.james.modules.server.MessagesRoutesModule;
 import org.apache.james.modules.server.RabbitMailQueueRoutesModule;
 import org.apache.james.modules.server.SieveRoutesModule;
+import org.apache.james.modules.server.VacationRoutesModule;
 import org.apache.james.modules.server.WebAdminMailOverWebModule;
 import org.apache.james.modules.server.WebAdminReIndexingTaskSerializationModule;
 import org.apache.james.modules.server.WebAdminServerModule;
@@ -93,6 +94,7 @@ public class CassandraRabbitMQJamesServerMain implements JamesServerMain {
     public static final Module WEBADMIN = Modules.combine(
         new CassandraRoutesModule(),
         new DataRoutesModules(),
+        new VacationRoutesModule(),
         new DeletedMessageVaultRoutesModule(),
         new DLPRoutesModule(),
         new InconsistencyQuotasSolvingRoutesModule(),
diff --git a/server/apps/distributed-pop3-app/src/main/java/org/apache/james/DistributedPOP3JamesServerMain.java b/server/apps/distributed-pop3-app/src/main/java/org/apache/james/DistributedPOP3JamesServerMain.java
index be01d56..7ef4de3 100644
--- a/server/apps/distributed-pop3-app/src/main/java/org/apache/james/DistributedPOP3JamesServerMain.java
+++ b/server/apps/distributed-pop3-app/src/main/java/org/apache/james/DistributedPOP3JamesServerMain.java
@@ -78,6 +78,7 @@ import org.apache.james.modules.server.MailboxRoutesModule;
 import org.apache.james.modules.server.MailboxesExportRoutesModule;
 import org.apache.james.modules.server.MessagesRoutesModule;
 import org.apache.james.modules.server.RabbitMailQueueRoutesModule;
+import org.apache.james.modules.server.VacationRoutesModule;
 import org.apache.james.modules.server.WebAdminMailOverWebModule;
 import org.apache.james.modules.server.WebAdminReIndexingTaskSerializationModule;
 import org.apache.james.modules.server.WebAdminServerModule;
@@ -96,6 +97,7 @@ public class DistributedPOP3JamesServerMain implements JamesServerMain {
     public static final Module WEBADMIN = Modules.combine(
         new CassandraRoutesModule(),
         new DataRoutesModules(),
+        new VacationRoutesModule(),
         new DeletedMessageVaultRoutesModule(),
         new InconsistencyQuotasSolvingRoutesModule(),
         new InconsistencySolvingRoutesModule(),
diff --git a/server/apps/memory-app/src/main/java/org/apache/james/MemoryJamesServerMain.java b/server/apps/memory-app/src/main/java/org/apache/james/MemoryJamesServerMain.java
index 6a43833..b59790d 100644
--- a/server/apps/memory-app/src/main/java/org/apache/james/MemoryJamesServerMain.java
+++ b/server/apps/memory-app/src/main/java/org/apache/james/MemoryJamesServerMain.java
@@ -53,6 +53,7 @@ import org.apache.james.modules.server.NoJwtModule;
 import org.apache.james.modules.server.RawPostDequeueDecoratorModule;
 import org.apache.james.modules.server.SieveRoutesModule;
 import org.apache.james.modules.server.TaskManagerModule;
+import org.apache.james.modules.server.VacationRoutesModule;
 import org.apache.james.modules.server.WebAdminServerModule;
 import org.apache.james.modules.spamassassin.SpamAssassinListenerModule;
 import org.apache.james.modules.vault.DeletedMessageVaultModule;
@@ -71,6 +72,7 @@ public class MemoryJamesServerMain implements JamesServerMain {
     public static final Module WEBADMIN = Modules.combine(
         new WebAdminServerModule(),
         new DataRoutesModules(),
+        new VacationRoutesModule(),
         new DeletedMessageVaultRoutesModule(),
         new DLPRoutesModule(),
         new MailboxesExportRoutesModule(),
diff --git a/server/container/guice/protocols/webadmin-data/src/main/java/org/apache/james/modules/server/VacationRoutesModule.java b/server/container/guice/protocols/webadmin-data/src/main/java/org/apache/james/modules/server/VacationRoutesModule.java
new file mode 100644
index 0000000..2fc26d7
--- /dev/null
+++ b/server/container/guice/protocols/webadmin-data/src/main/java/org/apache/james/modules/server/VacationRoutesModule.java
@@ -0,0 +1,34 @@
+/****************************************************************
+ * 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.modules.server;
+
+import org.apache.james.webadmin.Routes;
+import org.apache.james.webadmin.routes.VacationRoutes;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.multibindings.Multibinder;
+
+public class VacationRoutesModule extends AbstractModule {
+    @Override
+    protected void configure() {
+        Multibinder.newSetBinder(binder(), Routes.class).addBinding()
+            .to(VacationRoutes.class);
+    }
+}
diff --git a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/dto/VacationDTO.java b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/dto/VacationDTO.java
new file mode 100755
index 0000000..dc57e13
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/dto/VacationDTO.java
@@ -0,0 +1,107 @@
+/****************************************************************
+ * 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.webadmin.dto;
+
+import java.time.ZonedDateTime;
+import java.util.Objects;
+import java.util.Optional;
+
+import org.apache.james.vacation.api.Vacation;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+
+public class VacationDTO {
+
+    public static VacationDTO from(Vacation vacation) {
+        Preconditions.checkNotNull(vacation);
+        return new VacationDTO(
+            Optional.of(vacation.isEnabled()),
+            vacation.getFromDate(),
+            vacation.getToDate(),
+            vacation.getSubject(),
+            vacation.getTextBody(),
+            vacation.getHtmlBody());
+    }
+
+    private final Optional<Boolean> enabled;
+    private final Optional<ZonedDateTime> fromDate;
+    private final Optional<ZonedDateTime> toDate;
+    private final Optional<String> subject;
+    private final Optional<String> textBody;
+    private final Optional<String> htmlBody;
+
+    @JsonCreator
+    private VacationDTO(@JsonProperty("enabled") Optional<Boolean> enabled,
+                        @JsonProperty("fromDate") Optional<ZonedDateTime> fromDate,
+                        @JsonProperty("toDate") Optional<ZonedDateTime> toDate,
+                        @JsonProperty("subject") Optional<String> subject,
+                        @JsonProperty("textBody") Optional<String> textBody,
+                        @JsonProperty("htmlBody") Optional<String> htmlBody) {
+        this.enabled = enabled;
+        this.fromDate = fromDate;
+        this.toDate = toDate;
+        this.textBody = textBody;
+        this.subject = subject;
+        this.htmlBody = htmlBody;
+    }
+
+    public Optional<Boolean> getEnabled() {
+        return enabled;
+    }
+
+    public Optional<ZonedDateTime> getFromDate() {
+        return fromDate;
+    }
+
+    public Optional<ZonedDateTime> getToDate() {
+        return toDate;
+    }
+
+    public Optional<String> getTextBody() {
+        return textBody;
+    }
+
+    public Optional<String> getSubject() {
+        return subject;
+    }
+
+    public Optional<String> getHtmlBody() {
+        return htmlBody;
+    }
+
+    @Override
+    public final boolean equals(Object o) {
+        if (o instanceof VacationDTO) {
+            VacationDTO that = (VacationDTO) o;
+
+            return Objects.equals(this.enabled, that.enabled) && Objects.equals(this.fromDate, that.fromDate)
+                && Objects.equals(this.toDate, that.toDate) && Objects.equals(this.subject, that.subject)
+                && Objects.equals(this.textBody, that.textBody) && Objects.equals(this.htmlBody, that.htmlBody);
+        }
+        return false;
+    }
+
+    @Override
+    public final int hashCode() {
+        return Objects.hash(enabled, fromDate, toDate, subject, textBody, htmlBody);
+    }
+}
diff --git a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/VacationRoutes.java b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/VacationRoutes.java
new file mode 100644
index 0000000..c4a8d0f
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/VacationRoutes.java
@@ -0,0 +1,148 @@
+/****************************************************************
+ * 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.webadmin.routes;
+
+import static org.apache.james.webadmin.Constants.SEPARATOR;
+
+import java.util.Optional;
+
+import javax.inject.Inject;
+
+import org.apache.james.core.Username;
+import org.apache.james.user.api.UsersRepository;
+import org.apache.james.user.api.UsersRepositoryException;
+import org.apache.james.util.ValuePatch;
+import org.apache.james.vacation.api.AccountId;
+import org.apache.james.vacation.api.NotificationRegistry;
+import org.apache.james.vacation.api.Vacation;
+import org.apache.james.vacation.api.VacationPatch;
+import org.apache.james.vacation.api.VacationRepository;
+import org.apache.james.webadmin.Routes;
+import org.apache.james.webadmin.dto.VacationDTO;
+import org.apache.james.webadmin.utils.ErrorResponder;
+import org.apache.james.webadmin.utils.JsonExtractException;
+import org.apache.james.webadmin.utils.JsonExtractor;
+import org.apache.james.webadmin.utils.JsonTransformer;
+import org.apache.james.webadmin.utils.Responses;
+import org.eclipse.jetty.http.HttpStatus;
+
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+
+import spark.Request;
+import spark.Response;
+import spark.Service;
+
+public class VacationRoutes implements Routes {
+
+    public static final String VACATION = "/vacation";
+    private static final String USER_NAME = ":userName";
+
+    private final JsonTransformer jsonTransformer;
+    private final JsonExtractor<VacationDTO> jsonExtractor;
+
+    private final VacationRepository vacationRepository;
+    private final NotificationRegistry notificationRegistry;
+    private final UsersRepository usersRepository;
+
+    @Inject
+    public VacationRoutes(VacationRepository vacationRepository, NotificationRegistry notificationRegistry,
+                          UsersRepository usersRepository, JsonTransformer jsonTransformer) {
+        this.vacationRepository = vacationRepository;
+        this.notificationRegistry = notificationRegistry;
+        this.usersRepository = usersRepository;
+        this.jsonTransformer = jsonTransformer;
+        this.jsonExtractor = new JsonExtractor<>(VacationDTO.class, new JavaTimeModule());
+    }
+
+    @Override
+    public String getBasePath() {
+        return VACATION;
+    }
+
+    @Override
+    public void define(Service service) {
+        service.get(VACATION + SEPARATOR + USER_NAME, this::getVacation, jsonTransformer);
+        service.post(VACATION + SEPARATOR + USER_NAME, this::updateVacation);
+        service.delete(VACATION + SEPARATOR + USER_NAME, this::deleteVacation);
+    }
+
+    public VacationDTO getVacation(Request request, Response response) {
+        testUserExists(request);
+        AccountId accountId = AccountId.fromString(request.params(USER_NAME));
+        Vacation vacation = vacationRepository.retrieveVacation(accountId).block();
+        return VacationDTO.from(vacation);
+    }
+
+    public String updateVacation(Request request, Response response) throws JsonExtractException {
+        testUserExists(request);
+        AccountId accountId = AccountId.fromString(request.params(USER_NAME));
+        VacationDTO vacationDto = jsonExtractor.parse(request.body());
+        VacationPatch vacationPatch = VacationPatch.builder()
+            .subject(updateOrKeep(vacationDto.getSubject()))
+            .textBody(updateOrKeep(vacationDto.getTextBody()))
+            .htmlBody(updateOrKeep(vacationDto.getHtmlBody()))
+            .fromDate(updateOrKeep(vacationDto.getFromDate()))
+            .toDate(updateOrKeep(vacationDto.getToDate()))
+            .isEnabled(updateOrKeep(vacationDto.getEnabled()))
+            .build();
+        vacationRepository.modifyVacation(accountId, vacationPatch)
+            .then(notificationRegistry.flush(accountId)).block();
+        return Responses.returnNoContent(response);
+    }
+
+    public String deleteVacation(Request request, Response response) {
+        testUserExists(request);
+        AccountId accountId = AccountId.fromString(request.params(USER_NAME));
+        VacationPatch vacationPatch = VacationPatch.builder()
+            .isEnabled(false)
+            .subject(ValuePatch.remove())
+            .textBody(ValuePatch.remove())
+            .htmlBody(ValuePatch.remove())
+            .fromDate(ValuePatch.remove())
+            .toDate(ValuePatch.remove())
+            .build();
+        vacationRepository.modifyVacation(accountId, vacationPatch)
+            .then(notificationRegistry.flush(accountId)).block();
+        return Responses.returnNoContent(response);
+    }
+
+    private void testUserExists(Request request) {
+        Username username = Username.of(request.params(USER_NAME));
+        if (!isExistingUser(username)) {
+            throw ErrorResponder.builder()
+                .statusCode(HttpStatus.NOT_FOUND_404)
+                .type(ErrorResponder.ErrorType.NOT_FOUND)
+                .message("The user '" + username.asString() + "' does not exist")
+                .haltError();
+        }
+    }
+
+    private boolean isExistingUser(Username username) {
+        try {
+            return usersRepository.contains(username);
+        } catch (UsersRepositoryException e) {
+            return false;
+        }
+    }
+
+    private static <T> ValuePatch<T> updateOrKeep(Optional<T> opt) {
+        return opt.map(ValuePatch::modifyTo).orElse(ValuePatch.keep());
+    }
+}
diff --git a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/dto/VacationDTOTest.java b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/dto/VacationDTOTest.java
new file mode 100644
index 0000000..2286b7e
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/dto/VacationDTOTest.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.webadmin.dto;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+import org.apache.james.vacation.api.Vacation;
+import org.assertj.core.api.SoftAssertions;
+import org.junit.jupiter.api.Test;
+
+import java.time.ZonedDateTime;
+import java.util.Optional;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class VacationDTOTest {
+
+    @Test
+    public void shouldMatchBeanContract() {
+        EqualsVerifier.forClass(VacationDTO.class).verify();
+    }
+
+    @Test
+    public void fromShouldThrowOnNull() {
+        assertThatThrownBy(() -> VacationDTO.from(null))
+            .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    public void fromShouldSetAllFields() {
+        Vacation vacation = Vacation.builder()
+            .enabled(false)
+            .fromDate(Optional.of(ZonedDateTime.parse("2021-09-13T10:00:00Z")))
+            .toDate(Optional.of(ZonedDateTime.parse("2021-09-20T19:00:00Z")))
+            .subject(Optional.of("I am on vacation"))
+            .textBody(Optional.of("I am on vacation, will be back soon."))
+            .htmlBody(Optional.of("<p>I am on vacation, will be back soon.</p>"))
+            .build();
+
+        VacationDTO dto = VacationDTO.from(vacation);
+
+        SoftAssertions.assertSoftly(softly -> {
+            softly.assertThat(dto.getEnabled()).isNotEmpty();
+            softly.assertThat(dto.getEnabled().get()).isEqualTo(vacation.isEnabled());
+            softly.assertThat(dto.getFromDate()).isEqualTo(vacation.getFromDate());
+            softly.assertThat(dto.getToDate()).isEqualTo(vacation.getToDate());
+            softly.assertThat(dto.getSubject()).isEqualTo(vacation.getSubject());
+            softly.assertThat(dto.getTextBody()).isEqualTo(vacation.getTextBody());
+            softly.assertThat(dto.getHtmlBody()).isEqualTo(vacation.getHtmlBody());
+        });
+    }
+}
diff --git a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/VacationRoutesTest.java b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/VacationRoutesTest.java
new file mode 100755
index 0000000..e790367
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/VacationRoutesTest.java
@@ -0,0 +1,257 @@
+/****************************************************************
+ * 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.webadmin.routes;
+
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.apache.james.core.Domain;
+import org.apache.james.core.MailAddress;
+import org.apache.james.core.Username;
+import org.apache.james.domainlist.api.mock.SimpleDomainList;
+import org.apache.james.user.memory.MemoryUsersRepository;
+import org.apache.james.util.date.DefaultZonedDateTimeProvider;
+import org.apache.james.vacation.api.AccountId;
+import org.apache.james.vacation.api.RecipientId;
+import org.apache.james.vacation.api.Vacation;
+import org.apache.james.vacation.api.VacationPatch;
+import org.apache.james.vacation.memory.MemoryNotificationRegistry;
+import org.apache.james.vacation.memory.MemoryVacationRepository;
+import org.apache.james.webadmin.WebAdminServer;
+import org.apache.james.webadmin.WebAdminUtils;
+import org.apache.james.webadmin.utils.ErrorResponder;
+import org.apache.james.webadmin.utils.JsonTransformer;
+import org.assertj.core.api.SoftAssertions;
+import org.eclipse.jetty.http.HttpStatus;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.Optional;
+
+import static io.restassured.RestAssured.given;
+import static io.restassured.RestAssured.when;
+import static org.apache.james.webadmin.Constants.SEPARATOR;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+
+public class VacationRoutesTest {
+
+    private static final String BOB = "bob@example.org";
+    private static final String ALICE = "alice@example.org";
+    private static final String CAROL = "carol@example.org";
+
+    private static final Domain DOMAIN = Domain.of("example.org");
+
+    private static final Vacation VACATION = Vacation.builder()
+        .enabled(false)
+        .fromDate(Optional.of(ZonedDateTime.parse("2021-09-13T10:00:00Z")))
+        .toDate(Optional.of(ZonedDateTime.parse("2021-09-20T19:00:00Z")))
+        .subject(Optional.of("I am on vacation"))
+        .textBody(Optional.of("I am on vacation, will be back soon."))
+        .htmlBody(Optional.of("<p>I am on vacation, will be back soon.</p>"))
+        .build();
+
+    private static String isoString(ZonedDateTime date) {
+        return date.format(DateTimeFormatter.ISO_DATE_TIME);
+    }
+
+    private WebAdminServer webAdminServer;
+    private MemoryVacationRepository vacationRepository;
+    private MemoryNotificationRegistry notificationRegistry;
+
+    @BeforeEach
+    public void setUp() throws Exception {
+        vacationRepository = new MemoryVacationRepository();
+        notificationRegistry = new MemoryNotificationRegistry(new DefaultZonedDateTimeProvider());
+
+        SimpleDomainList domainList = new SimpleDomainList();
+        domainList.addDomain(DOMAIN);
+        MemoryUsersRepository usersRepository = MemoryUsersRepository.withVirtualHosting(domainList);
+
+        VacationRoutes vacationRoutes = new VacationRoutes(
+            vacationRepository, notificationRegistry, usersRepository, new JsonTransformer());
+        this.webAdminServer = WebAdminUtils.createWebAdminServer(vacationRoutes).start();
+
+        RestAssured.requestSpecification = WebAdminUtils.buildRequestSpecification(webAdminServer).build();
+        RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
+
+        usersRepository.addUser(Username.of(BOB), "secret");
+    }
+
+    @AfterEach
+    void tearDown() {
+        webAdminServer.destroy();
+    }
+
+    @Test
+    void getVacation() {
+        vacationRepository.modifyVacation(AccountId.fromString(BOB), VacationPatch.builderFrom(VACATION).build()).block();
+
+        when()
+            .get(VacationRoutes.VACATION + SEPARATOR + BOB)
+        .then()
+            .statusCode(HttpStatus.OK_200)
+            .contentType(ContentType.JSON)
+            .body("enabled", equalTo(VACATION.isEnabled()))
+            .body("fromDate", equalTo(isoString(VACATION.getFromDate().get())))
+            .body("toDate", equalTo(isoString(VACATION.getToDate().get())))
+            .body("subject", equalTo(VACATION.getSubject().get()))
+            .body("textBody", equalTo(VACATION.getTextBody().get()))
+            .body("htmlBody", equalTo(VACATION.getHtmlBody().get()));
+    }
+
+    @Test
+    void getVacationFails() {
+        when()
+            .get(VacationRoutes.VACATION + SEPARATOR + CAROL)
+        .then()
+            .statusCode(HttpStatus.NOT_FOUND_404)
+            .body("statusCode", is(HttpStatus.NOT_FOUND_404))
+            .body("type", is(ErrorResponder.ErrorType.NOT_FOUND.getType()))
+            .body("message", is("The user 'carol@example.org' does not exist"));
+    }
+
+    @Test
+    void postVacationCreates() throws Exception {
+        AccountId bob = AccountId.fromString(BOB);
+        RecipientId alice = RecipientId.fromMailAddress(new MailAddress(ALICE));
+
+        vacationRepository.modifyVacation(bob, VacationPatch.builderFrom(VACATION).build())
+                .then(notificationRegistry.register(bob, alice, Optional.empty())).block();
+
+        given()
+            .body("{\"enabled\":true,\"fromDate\":\"2021-09-20T10:00:00Z\",\"toDate\":\"2021-09-27T18:00:00Z\"," +
+                "\"subject\":\"On vacation again\",\"textBody\":\"Need more vacation!\",\"htmlBody\":\"<p>Need more vacation!</p>\"}")
+        .when()
+            .post(VacationRoutes.VACATION + SEPARATOR + BOB)
+        .then()
+            .statusCode(HttpStatus.NO_CONTENT_204);
+
+        Vacation vacation = vacationRepository.retrieveVacation(bob).block();
+        SoftAssertions.assertSoftly(softly -> {
+            softly.assertThat(vacation).isNotNull();
+            softly.assertThat(vacation.isEnabled()).isTrue();
+            softly.assertThat(vacation.getFromDate()).isEqualTo(Optional.of(ZonedDateTime.parse("2021-09-20T10:00:00Z[UTC]")));
+            softly.assertThat(vacation.getToDate()).isEqualTo(Optional.of(ZonedDateTime.parse("2021-09-27T18:00:00Z[UTC]")));
+            softly.assertThat(vacation.getSubject()).isEqualTo(Optional.of("On vacation again"));
+            softly.assertThat(vacation.getTextBody()).isEqualTo(Optional.of("Need more vacation!"));
+            softly.assertThat(vacation.getHtmlBody()).isEqualTo(Optional.of("<p>Need more vacation!</p>"));
+        });
+
+        Boolean registered = notificationRegistry.isRegistered(bob, alice).block();
+        assertThat(registered).isFalse();
+    }
+
+    @Test
+    void postVacationUpdates() throws Exception {
+        AccountId bob = AccountId.fromString(BOB);
+        RecipientId alice = RecipientId.fromMailAddress(new MailAddress(ALICE));
+
+        vacationRepository.modifyVacation(bob, VacationPatch.builderFrom(VACATION).build())
+            .then(notificationRegistry.register(bob, alice, Optional.empty())).block();
+
+        given()
+            .body("{\"enabled\":true,\"subject\":\"More vacation\"}")
+        .when()
+            .post(VacationRoutes.VACATION + SEPARATOR + BOB)
+        .then()
+            .statusCode(HttpStatus.NO_CONTENT_204);
+
+        Vacation vacation = vacationRepository.retrieveVacation(bob).block();
+        SoftAssertions.assertSoftly(softly -> {
+            softly.assertThat(vacation).isNotNull();
+            softly.assertThat(vacation.isEnabled()).isTrue();
+            softly.assertThat(vacation.getFromDate()).isEqualTo(VACATION.getFromDate());
+            softly.assertThat(vacation.getToDate()).isEqualTo(VACATION.getToDate());
+            softly.assertThat(vacation.getSubject()).isEqualTo(Optional.of("More vacation"));
+            softly.assertThat(vacation.getTextBody()).isEqualTo(VACATION.getTextBody());
+            softly.assertThat(vacation.getHtmlBody()).isEqualTo(VACATION.getHtmlBody());
+        });
+
+        Boolean registered = notificationRegistry.isRegistered(bob, alice).block();
+        assertThat(registered).isFalse();
+    }
+
+    @Test
+    void postVacationFails() {
+        given()
+            .body("{\"enabled\":true,\"subject\":\"On vacation again\"}")
+        .when()
+            .post(VacationRoutes.VACATION + SEPARATOR + CAROL)
+        .then()
+            .statusCode(HttpStatus.NOT_FOUND_404)
+            .body("statusCode", is(HttpStatus.NOT_FOUND_404))
+            .body("type", is(ErrorResponder.ErrorType.NOT_FOUND.getType()))
+            .body("message", is("The user 'carol@example.org' does not exist"));
+    }
+
+    @Test
+    void postVacationHandlesBadJson() {
+        given()
+            .body("{not really a JSON object}")
+        .when()
+            .post(VacationRoutes.VACATION + SEPARATOR + BOB)
+        .then()
+            .statusCode(HttpStatus.BAD_REQUEST_400)
+            .body("statusCode", is(HttpStatus.BAD_REQUEST_400));
+    }
+
+    @Test
+    void deleteVacation() throws Exception {
+        AccountId bob = AccountId.fromString(BOB);
+        RecipientId alice = RecipientId.fromMailAddress(new MailAddress(ALICE));
+
+        vacationRepository.modifyVacation(bob, VacationPatch.builderFrom(VACATION).build())
+            .then(notificationRegistry.register(bob, alice, Optional.empty())).block();
+
+        when()
+            .delete(VacationRoutes.VACATION + SEPARATOR + BOB)
+        .then()
+            .statusCode(HttpStatus.NO_CONTENT_204);
+
+        Vacation vacation = vacationRepository.retrieveVacation(bob).block();
+        SoftAssertions.assertSoftly(softly -> {
+            softly.assertThat(vacation).isNotNull();
+            softly.assertThat(vacation.isEnabled()).isFalse();
+            softly.assertThat(vacation.getFromDate()).isEmpty();
+            softly.assertThat(vacation.getToDate()).isEmpty();
+            softly.assertThat(vacation.getSubject()).isEmpty();
+            softly.assertThat(vacation.getTextBody()).isEmpty();
+            softly.assertThat(vacation.getHtmlBody()).isEmpty();
+        });
+
+        Boolean registered = notificationRegistry.isRegistered(bob, alice).block();
+        assertThat(registered).isFalse();
+    }
+
+    @Test
+    void deleteVacationFails() {
+        when()
+            .delete(VacationRoutes.VACATION + SEPARATOR + CAROL)
+        .then()
+            .statusCode(HttpStatus.NOT_FOUND_404)
+            .body("statusCode", is(HttpStatus.NOT_FOUND_404))
+            .body("type", is(ErrorResponder.ErrorType.NOT_FOUND.getType()))
+            .body("message", is("The user 'carol@example.org' does not exist"));
+    }
+}

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org