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 4445be6ba5c792792f15525e937733f2a92cdd0f
Author: Benoit Tellier <btell...@linagora.com>
AuthorDate: Tue Feb 19 14:28:02 2019 +0700

    JAMES-2661 WebAdmin for EventDeadLetter: List groups
---
 server/protocols/webadmin/webadmin-mailbox/pom.xml |   5 +
 .../webadmin/routes/EventDeadLettersRoutes.java    |  63 +++++++++
 .../routes/EventDeadLettersRoutesTest.java         | 145 +++++++++++++++++++++
 3 files changed, 213 insertions(+)

diff --git a/server/protocols/webadmin/webadmin-mailbox/pom.xml 
b/server/protocols/webadmin/webadmin-mailbox/pom.xml
index b9d293e..c8d7b72 100644
--- a/server/protocols/webadmin/webadmin-mailbox/pom.xml
+++ b/server/protocols/webadmin/webadmin-mailbox/pom.xml
@@ -50,6 +50,11 @@
         </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
+            <artifactId>apache-james-mailbox-event-memory</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
             <artifactId>apache-james-mailbox-memory</artifactId>
             <scope>test</scope>
         </dependency>
diff --git 
a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/EventDeadLettersRoutes.java
 
b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/EventDeadLettersRoutes.java
new file mode 100644
index 0000000..2121312
--- /dev/null
+++ 
b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/EventDeadLettersRoutes.java
@@ -0,0 +1,63 @@
+/****************************************************************
+ * 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 javax.inject.Inject;
+
+import org.apache.james.mailbox.events.EventDeadLetters;
+import org.apache.james.mailbox.events.Group;
+import org.apache.james.webadmin.Routes;
+import org.apache.james.webadmin.utils.JsonTransformer;
+
+import com.github.steveash.guavate.Guavate;
+
+import spark.Request;
+import spark.Response;
+import spark.Service;
+
+public class EventDeadLettersRoutes implements Routes {
+    private static final String BASE_PATH = "/events/deadLetter";
+
+    private final EventDeadLetters deadLetters;
+    private final JsonTransformer jsonTransformer;
+
+    @Inject
+    EventDeadLettersRoutes(EventDeadLetters deadLetters, JsonTransformer 
jsonTransformer) {
+        this.deadLetters = deadLetters;
+        this.jsonTransformer = jsonTransformer;
+    }
+
+    @Override
+    public String getBasePath() {
+        return BASE_PATH;
+    }
+
+    @Override
+    public void define(Service service) {
+        service.get(BASE_PATH + "/groups", this::listGroups, jsonTransformer);
+    }
+
+    private Iterable<String> listGroups(Request request, Response response) {
+        return deadLetters.groupsWithFailedEvents()
+            .map(Group::asString)
+            .collect(Guavate.toImmutableList())
+            .block();
+    }
+}
diff --git 
a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/EventDeadLettersRoutesTest.java
 
b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/EventDeadLettersRoutesTest.java
new file mode 100644
index 0000000..d05c1bb
--- /dev/null
+++ 
b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/EventDeadLettersRoutesTest.java
@@ -0,0 +1,145 @@
+/****************************************************************
+ * 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 io.restassured.RestAssured.when;
+import static org.apache.james.webadmin.WebAdminServer.NO_CONFIGURATION;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.hasSize;
+
+import org.apache.james.core.User;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.events.Event;
+import org.apache.james.mailbox.events.EventBusTestFixture;
+import org.apache.james.mailbox.events.EventDeadLetters;
+import org.apache.james.mailbox.events.MailboxListener;
+import org.apache.james.mailbox.events.MemoryEventDeadLetters;
+import org.apache.james.mailbox.inmemory.InMemoryId;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.store.event.EventFactory;
+import org.apache.james.metrics.logger.DefaultMetricFactory;
+import org.apache.james.webadmin.WebAdminServer;
+import org.apache.james.webadmin.WebAdminUtils;
+import org.apache.james.webadmin.utils.JsonTransformer;
+import org.eclipse.jetty.http.HttpStatus;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+
+class EventDeadLettersRoutesTest {
+    private static final String BOB = "b...@apache.org";
+    private static final String UUID_1 = 
"6e0dd59d-660e-4d9b-b22f-0354479f47b4";
+    private static final String UUID_2 = 
"6e0dd59d-660e-4d9b-b22f-0354479f47b5";
+    private static final MailboxListener.MailboxAdded EVENT_1 = 
EventFactory.mailboxAdded()
+        .eventId(Event.EventId.of(UUID_1))
+        .user(User.fromUsername(BOB))
+        .sessionId(MailboxSession.SessionId.of(452))
+        .mailboxId(InMemoryId.of(453))
+        .mailboxPath(MailboxPath.forUser(BOB, "Important-mailbox"))
+        .build();
+    private static final MailboxListener.MailboxAdded EVENT_2 = 
EventFactory.mailboxAdded()
+        .eventId(Event.EventId.of(UUID_2))
+        .user(User.fromUsername(BOB))
+        .sessionId(MailboxSession.SessionId.of(455))
+        .mailboxId(InMemoryId.of(456))
+        .mailboxPath(MailboxPath.forUser(BOB, "project-3"))
+        .build();
+
+    private WebAdminServer webAdminServer;
+    private EventDeadLetters deadLetters;
+
+    @BeforeEach
+    void beforeEach() throws Exception {
+        deadLetters = new MemoryEventDeadLetters();
+        JsonTransformer jsonTransformer = new JsonTransformer();
+
+        webAdminServer = WebAdminUtils.createWebAdminServer(
+            new DefaultMetricFactory(),
+            new EventDeadLettersRoutes(
+                deadLetters,
+                jsonTransformer));
+        webAdminServer.configure(NO_CONFIGURATION);
+        webAdminServer.await();
+
+        RestAssured.requestSpecification = 
WebAdminUtils.buildRequestSpecification(webAdminServer).build();
+        RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
+    }
+
+    @AfterEach
+    void tearDown() {
+        webAdminServer.destroy();
+    }
+
+    @Nested
+    class ListGroups {
+        @Test
+        void getGroupsShouldReturnEmptyWhenNone() {
+            when()
+                .get("/events/deadLetter/groups")
+            .then()
+                .statusCode(HttpStatus.OK_200)
+                .contentType(ContentType.JSON)
+                .body(".", hasSize(0));
+        }
+
+        @Test
+        void getGroupsShouldReturnGroupsOfContainedEvents() {
+            deadLetters.store(new EventBusTestFixture.GroupA(), 
EVENT_1).block();
+
+            when()
+                .get("/events/deadLetter/groups")
+            .then()
+                .statusCode(HttpStatus.OK_200)
+                .contentType(ContentType.JSON)
+                .body(".", 
contains(EventBusTestFixture.GroupA.class.getName()));
+        }
+
+        @Test
+        void getGroupsShouldReturnGroupsOfContainedEventsWithoutDuplicates() {
+            deadLetters.store(new EventBusTestFixture.GroupA(), 
EVENT_1).block();
+            deadLetters.store(new EventBusTestFixture.GroupA(), 
EVENT_2).block();
+
+            when()
+                .get("/events/deadLetter/groups")
+            .then()
+                .statusCode(HttpStatus.OK_200)
+                .contentType(ContentType.JSON)
+                .body(".", 
contains(EventBusTestFixture.GroupA.class.getName()));
+        }
+
+        @Test
+        void getGroupsShouldReturnGroupsOfAllContainedEvents() {
+            deadLetters.store(new EventBusTestFixture.GroupA(), 
EVENT_1).block();
+            deadLetters.store(new EventBusTestFixture.GroupB(), 
EVENT_2).block();
+
+            when()
+                .get("/events/deadLetter/groups")
+            .then()
+                .statusCode(HttpStatus.OK_200)
+                .contentType(ContentType.JSON)
+                .body(".", 
containsInAnyOrder(EventBusTestFixture.GroupA.class.getName(), 
EventBusTestFixture.GroupB.class.getName()));
+        }
+    }
+}
\ 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