You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2018/01/25 05:02:22 UTC
[11/16] james-project git commit: JAMES-2292 Add GET /mailQueues
WebAdmin endpoint
JAMES-2292 Add GET /mailQueues WebAdmin endpoint
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/0e1719da
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/0e1719da
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/0e1719da
Branch: refs/heads/master
Commit: 0e1719da47fb67828633cd05c69cd38153a0ffef
Parents: bef10ee
Author: Antoine Duprat <ad...@linagora.com>
Authored: Mon Jan 22 14:59:52 2018 +0100
Committer: benwa <bt...@linagora.com>
Committed: Thu Jan 25 11:44:44 2018 +0700
----------------------------------------------------------------------
.../webadmin/webadmin-mailqueue/pom.xml | 33 +++++
.../james/webadmin/routes/MailQueueRoutes.java | 75 ++++++++++
.../webadmin/routes/MailQueueRoutesTest.java | 139 +++++++++++++++++++
3 files changed, 247 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/0e1719da/server/protocols/webadmin/webadmin-mailqueue/pom.xml
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailqueue/pom.xml b/server/protocols/webadmin/webadmin-mailqueue/pom.xml
index 3507c7f..4bcd366 100644
--- a/server/protocols/webadmin/webadmin-mailqueue/pom.xml
+++ b/server/protocols/webadmin/webadmin-mailqueue/pom.xml
@@ -33,6 +33,39 @@
<name>Apache James :: Server :: Web Admin :: MailQueue</name>
<dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>james-server-queue-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>james-server-queue-memory</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>james-server-webadmin-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>james-server-webadmin-core</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.jayway.restassured</groupId>
+ <artifactId>rest-assured</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
http://git-wip-us.apache.org/repos/asf/james-project/blob/0e1719da/server/protocols/webadmin/webadmin-mailqueue/src/main/java/org/apache/james/webadmin/routes/MailQueueRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailqueue/src/main/java/org/apache/james/webadmin/routes/MailQueueRoutes.java b/server/protocols/webadmin/webadmin-mailqueue/src/main/java/org/apache/james/webadmin/routes/MailQueueRoutes.java
new file mode 100644
index 0000000..b2ef8f6
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-mailqueue/src/main/java/org/apache/james/webadmin/routes/MailQueueRoutes.java
@@ -0,0 +1,75 @@
+/****************************************************************
+ * 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 java.util.List;
+
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+
+import org.apache.james.queue.api.MailQueueFactory;
+import org.apache.james.queue.api.ManageableMailQueue;
+import org.apache.james.webadmin.Routes;
+import org.apache.james.webadmin.utils.JsonTransformer;
+import org.eclipse.jetty.http.HttpStatus;
+
+import com.github.steveash.guavate.Guavate;
+import com.google.common.annotations.VisibleForTesting;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import spark.Service;
+
+public class MailQueueRoutes implements Routes {
+
+ @VisibleForTesting static final String BASE_URL = "/mailQueues";
+ private final MailQueueFactory<ManageableMailQueue> mailQueueFactory;
+ private final JsonTransformer jsonTransformer;
+
+ @Inject
+ @VisibleForTesting MailQueueRoutes(MailQueueFactory<ManageableMailQueue> mailQueueFactory, JsonTransformer jsonTransformer) {
+ this.mailQueueFactory = mailQueueFactory;
+ this.jsonTransformer = jsonTransformer;
+ }
+
+ @Override
+ public void define(Service service) {
+ defineListQueues(service);
+ }
+
+ @GET
+ @ApiOperation(
+ value = "Listing existing MailQueues"
+ )
+ @ApiResponses(value = {
+ @ApiResponse(code = HttpStatus.OK_200, message = "OK", response = List.class),
+ @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.")
+ })
+ public void defineListQueues(Service service) {
+ service.get(BASE_URL,
+ (request, response) ->
+ mailQueueFactory
+ .listCreatedMailQueues()
+ .stream()
+ .map(ManageableMailQueue::getName)
+ .collect(Guavate.toImmutableList()),
+ jsonTransformer);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/0e1719da/server/protocols/webadmin/webadmin-mailqueue/src/test/java/org/apache/james/webadmin/routes/MailQueueRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailqueue/src/test/java/org/apache/james/webadmin/routes/MailQueueRoutesTest.java b/server/protocols/webadmin/webadmin-mailqueue/src/test/java/org/apache/james/webadmin/routes/MailQueueRoutesTest.java
new file mode 100644
index 0000000..73a24a7
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-mailqueue/src/test/java/org/apache/james/webadmin/routes/MailQueueRoutesTest.java
@@ -0,0 +1,139 @@
+/****************************************************************
+ * 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 com.jayway.restassured.config.EncoderConfig.encoderConfig;
+import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
+import static org.apache.james.webadmin.WebAdminServer.NO_CONFIGURATION;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+import org.apache.james.metrics.api.NoopMetricFactory;
+import org.apache.james.queue.api.RawMailQueueItemDecoratorFactory;
+import org.apache.james.queue.memory.MemoryMailQueueFactory;
+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.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.jayway.restassured.RestAssured;
+import com.jayway.restassured.builder.RequestSpecBuilder;
+import com.jayway.restassured.http.ContentType;
+import com.jayway.restassured.specification.RequestSpecification;
+
+public class MailQueueRoutesTest {
+
+ static final String FIRST_QUEUE = "first one";
+ static final String SECOND_QUEUE = "second one";
+ static final String THIRD_QUEUE = "third one";
+ static final String FOURTH_QUEUE = "fourth one";
+ WebAdminServer webAdminServer;
+ MemoryMailQueueFactory mailQueueFactory;
+
+
+ WebAdminServer createServer(MemoryMailQueueFactory mailQueueFactory) throws Exception {
+ WebAdminServer server = WebAdminUtils.createWebAdminServer(
+ new NoopMetricFactory(),
+ new MailQueueRoutes(mailQueueFactory, new JsonTransformer()));
+ server.configure(NO_CONFIGURATION);
+ server.await();
+ return server;
+ }
+
+ RequestSpecification buildRequestSpecification(WebAdminServer server) {
+ return new RequestSpecBuilder()
+ .setContentType(ContentType.JSON)
+ .setAccept(ContentType.JSON)
+ .setBasePath(MailQueueRoutes.BASE_URL)
+ .setPort(server.getPort().get().getValue())
+ .setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(StandardCharsets.UTF_8)))
+ .build();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ mailQueueFactory = new MemoryMailQueueFactory(new RawMailQueueItemDecoratorFactory());
+ webAdminServer = createServer(mailQueueFactory);
+ RestAssured.requestSpecification = buildRequestSpecification(webAdminServer);
+ }
+
+ @After
+ public void tearDown() {
+ webAdminServer.destroy();
+ }
+
+ @Test
+ public void listAllMailQueuesShouldReturnEmptyWhenNone() {
+ List<String> actual = RestAssured.when()
+ .get()
+ .then()
+ .statusCode(HttpStatus.OK_200)
+ .contentType(ContentType.JSON)
+ .extract()
+ .body()
+ .jsonPath()
+ .getList(".");
+
+ assertThat(actual).isEmpty();
+ }
+
+ @Test
+ public void listAllMailQueuesShouldReturnSingleElementListWhenOnlyOneMailQueue() {
+ mailQueueFactory.createQueue(FIRST_QUEUE);
+
+ List<String> actual = RestAssured.when()
+ .get()
+ .then()
+ .statusCode(HttpStatus.OK_200)
+ .contentType(ContentType.JSON)
+ .extract()
+ .body()
+ .jsonPath()
+ .getList(".");
+
+ assertThat(actual).containsOnly(FIRST_QUEUE);
+ }
+
+ @Test
+ public void listAllMailQueuesShouldReturnListWhenSeveralMailQueues() {
+ mailQueueFactory.createQueue(FIRST_QUEUE);
+ mailQueueFactory.createQueue(SECOND_QUEUE);
+ mailQueueFactory.createQueue(THIRD_QUEUE);
+ mailQueueFactory.createQueue(FOURTH_QUEUE);
+
+ List<String> actual = RestAssured.when()
+ .get()
+ .then()
+ .statusCode(HttpStatus.OK_200)
+ .contentType(ContentType.JSON)
+ .extract()
+ .body()
+ .jsonPath()
+ .getList(".");
+
+ assertThat(actual).containsOnly(FIRST_QUEUE, SECOND_QUEUE, THIRD_QUEUE, FOURTH_QUEUE);
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org