james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [15/20] james-project git commit: JAMES-2151 Update REST API endpoints for Sieve quota
Date Tue, 26 Jun 2018 09:13:11 GMT
JAMES-2151 Update REST API endpoints for Sieve quota


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/81db3c28
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/81db3c28
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/81db3c28

Branch: refs/heads/master
Commit: 81db3c28c71d4e4522390f9016739aca7b79d14a
Parents: 280c6f7
Author: benwa <btellier@linagora.com>
Authored: Tue Jun 26 09:57:32 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Tue Jun 26 16:09:51 2018 +0700

----------------------------------------------------------------------
 .../james/webadmin/routes/SieveQuotaRoutes.java | 25 +++++---------
 .../webadmin/routes/SieveQuotaRoutesTest.java   | 36 ++++++++++----------
 src/site/markdown/server/manage-webadmin.md     |  4 +--
 3 files changed, 28 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/81db3c28/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/SieveQuotaRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/SieveQuotaRoutes.java
b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/SieveQuotaRoutes.java
index 1b99b72..26f5a0c 100644
--- a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/SieveQuotaRoutes.java
+++ b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/SieveQuotaRoutes.java
@@ -19,6 +19,7 @@
 
 package org.apache.james.webadmin.routes;
 
+import static org.apache.james.webadmin.Constants.EMPTY_BODY;
 import static org.apache.james.webadmin.Constants.SEPARATOR;
 
 import javax.inject.Inject;
@@ -91,7 +92,7 @@ public class SieveQuotaRoutes implements Routes {
     @ApiOperation(value = "Reading global sieve quota size")
     @ApiResponses(value = {
             @ApiResponse(code = 200, message = "OK", response = Long.class),
-            @ApiResponse(code = 404, message = "Global sieve quota not set."),
+            @ApiResponse(code = 204, message = "Global sieve quota not set."),
             @ApiResponse(code = 500, message = "Internal server error - Something went bad
on the server side.")
     })
     public void defineGetGlobalSieveQuota(Service service) {
@@ -101,12 +102,8 @@ public class SieveQuotaRoutes implements Routes {
                 response.status(HttpStatus.OK_200);
                 return sieveQuota.asLong();
             } catch (QuotaNotFoundException e) {
-                LOGGER.info("Global sieve quota not set", e);
-                throw ErrorResponder.builder()
-                    .type(ErrorResponder.ErrorType.NOT_FOUND)
-                    .statusCode(HttpStatus.NOT_FOUND_404)
-                    .message("Global sieve quota not set")
-                    .haltError();
+                response.status(HttpStatus.NO_CONTENT_204);
+                return EMPTY_BODY;
             }
         }, jsonTransformer);
     }
@@ -144,7 +141,6 @@ public class SieveQuotaRoutes implements Routes {
     @ApiOperation(value = "Removes global sieve quota")
     @ApiResponses(value = {
             @ApiResponse(code = 204, message = "Global sieve quota removed."),
-            @ApiResponse(code = 404, message = "Global sieve quota not set."),
             @ApiResponse(code = 500, message = "Internal server error - Something went bad
on the server side.")
     })
     public void defineRemoveGlobalSieveQuota(Service service) {
@@ -166,7 +162,7 @@ public class SieveQuotaRoutes implements Routes {
     })
     @ApiResponses(value = {
             @ApiResponse(code = 200, message = "OK", response = Long.class),
-            @ApiResponse(code = 404, message = "User sieve quota not set."),
+            @ApiResponse(code = 204, message = "User sieve quota not set."),
             @ApiResponse(code = 500, message = "Internal server error - Something went bad
on the server side.")
     })
     public void defineGetPerUserSieveQuota(Service service) {
@@ -177,12 +173,8 @@ public class SieveQuotaRoutes implements Routes {
                 response.status(HttpStatus.OK_200);
                 return userQuota.asLong();
             } catch (QuotaNotFoundException e) {
-                LOGGER.info("User sieve quota not set", e);
-                throw ErrorResponder.builder()
-                    .type(ErrorResponder.ErrorType.NOT_FOUND)
-                    .statusCode(HttpStatus.NOT_FOUND_404)
-                    .message("User sieve quota not set")
-                    .haltError();
+                response.status(HttpStatus.NO_CONTENT_204);
+                return EMPTY_BODY;
             }
         }, jsonTransformer);
     }
@@ -194,7 +186,7 @@ public class SieveQuotaRoutes implements Routes {
             @ApiImplicitParam(required = true, dataType = "long", name = REQUESTED_SIZE,
paramType = "body")
     })
     @ApiResponses(value = {
-            @ApiResponse(code = 200, message = "OK", response = Long.class),
+            @ApiResponse(code = 204, message = "OK", response = Long.class),
             @ApiResponse(code = 400, message = "The body is not a positive integer."),
             @ApiResponse(code = 500, message = "Internal server error - Something went bad
on the server side.")
     })
@@ -225,7 +217,6 @@ public class SieveQuotaRoutes implements Routes {
     })
     @ApiResponses(value = {
             @ApiResponse(code = 204, message = "User sieve quota removed."),
-            @ApiResponse(code = 404, message = "User sieve quota not set."),
             @ApiResponse(code = 500, message = "Internal server error - Something went bad
on the server side.")
     })
     public void defineRemovePerUserSieveQuota(Service service) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/81db3c28/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/SieveQuotaRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/SieveQuotaRoutesTest.java
b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/SieveQuotaRoutesTest.java
index 80b3891..a5ebd5a 100644
--- a/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/SieveQuotaRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-data/src/test/java/org/apache/james/webadmin/routes/SieveQuotaRoutesTest.java
@@ -47,7 +47,7 @@ public class SieveQuotaRoutesTest {
     private SieveQuotaRepository sieveRepository;
 
     @BeforeEach
-    public void setUp() throws Exception {
+    void setUp() throws Exception {
         sieveRepository = new InMemorySieveQuotaRepository();
         webAdminServer = WebAdminUtils.createWebAdminServer(
                 new DefaultMetricFactory(),
@@ -60,20 +60,20 @@ public class SieveQuotaRoutesTest {
     }
 
     @AfterEach
-    public void tearDown() {
+    void tearDown() {
         webAdminServer.destroy();
     }
 
     @Test
-    public void getGlobalSieveQuotaShouldReturn404WhenNoQuotaSet() {
+    void getGlobalSieveQuotaShouldReturn204WhenNoQuotaSet() {
         given()
             .get("/sieve/quota/default")
         .then()
-            .statusCode(404);
+            .statusCode(204);
     }
 
     @Test
-    public void getGlobalSieveQuotaShouldReturnStoredValue() throws Exception {
+    void getGlobalSieveQuotaShouldReturnStoredValue() throws Exception {
         QuotaSize value = QuotaSize.size(1000L);
         sieveRepository.setDefaultQuota(value);
 
@@ -90,7 +90,7 @@ public class SieveQuotaRoutesTest {
     }
 
     @Test
-    public void updateGlobalSieveQuotaShouldUpdateStoredValue() throws Exception {
+    void updateGlobalSieveQuotaShouldUpdateStoredValue() throws Exception {
         sieveRepository.setDefaultQuota(QuotaSize.size(500L));
         long requiredSize = 1024L;
 
@@ -104,7 +104,7 @@ public class SieveQuotaRoutesTest {
     }
 
     @Test
-    public void updateGlobalSieveQuotaShouldReturn400WhenMalformedJSON() {
+    void updateGlobalSieveQuotaShouldReturn400WhenMalformedJSON() {
         given()
             .body("invalid")
             .put("/sieve/quota/default")
@@ -113,7 +113,7 @@ public class SieveQuotaRoutesTest {
     }
 
     @Test
-    public void updateGlobalSieveQuotaShouldReturn400WhenRequestedSizeNotPositiveInteger()
{
+    void updateGlobalSieveQuotaShouldReturn400WhenRequestedSizeNotPositiveInteger() {
         given()
             .body(-100L)
             .put("/sieve/quota/default")
@@ -122,7 +122,7 @@ public class SieveQuotaRoutesTest {
     }
 
     @Test
-    public void removeGlobalSieveQuotaShouldReturn404WhenNoQuotaSet() {
+    void removeGlobalSieveQuotaShouldReturn204WhenNoQuotaSet() {
         given()
             .delete("/sieve/quota/default")
         .then()
@@ -130,7 +130,7 @@ public class SieveQuotaRoutesTest {
     }
 
     @Test
-    public void removeGlobalSieveQuotaShouldRemoveGlobalSieveQuota() throws Exception {
+    void removeGlobalSieveQuotaShouldRemoveGlobalSieveQuota() throws Exception {
         sieveRepository.setDefaultQuota(QuotaSize.size(1024L));
 
         given()
@@ -140,15 +140,15 @@ public class SieveQuotaRoutesTest {
     }
 
     @Test
-    public void getPerUserQuotaShouldReturn404WhenNoQuotaSetForUser() {
+    void getPerUserQuotaShouldReturn204WhenNoQuotaSetForUser() {
         given()
             .get("/sieve/quota/users/" + USER_A.asString())
         .then()
-            .statusCode(HttpStatus.NOT_FOUND_404);
+            .statusCode(HttpStatus.NO_CONTENT_204);
     }
 
     @Test
-    public void getPerUserSieveQuotaShouldReturnedStoredValue() throws Exception {
+    void getPerUserSieveQuotaShouldReturnStoredValue() throws Exception {
         QuotaSize value = QuotaSize.size(1024L);
         sieveRepository.setQuota(USER_A, value);
 
@@ -165,7 +165,7 @@ public class SieveQuotaRoutesTest {
     }
 
     @Test
-    public void updatePerUserSieveQuotaShouldUpdateStoredValue() throws Exception {
+    void updatePerUserSieveQuotaShouldUpdateStoredValue() throws Exception {
         sieveRepository.setQuota(USER_A, QuotaSize.size(500L));
         long requiredSize = 1024L;
 
@@ -179,7 +179,7 @@ public class SieveQuotaRoutesTest {
     }
 
     @Test
-    public void updatePerUserSieveQuotaShouldReturn400WhenMalformedJSON() {
+    void updatePerUserSieveQuotaShouldReturn400WhenMalformedJSON() {
         given()
             .body("invalid")
             .put("/sieve/quota/users/" + USER_A.asString())
@@ -188,7 +188,7 @@ public class SieveQuotaRoutesTest {
     }
 
     @Test
-    public void updatePerUserSieveQuotaShouldReturn400WhenRequestedSizeNotPositiveInteger()
{
+    void updatePerUserSieveQuotaShouldReturn400WhenRequestedSizeNotPositiveInteger() {
         given()
             .body(-100L)
             .put("/sieve/quota/users/" + USER_A.asString())
@@ -197,7 +197,7 @@ public class SieveQuotaRoutesTest {
     }
 
     @Test
-    public void removePerUserSieveQuotaShouldReturn404WhenNoQuotaSetForUser() {
+    void removePerUserSieveQuotaShouldReturn204WhenNoQuotaSetForUser() {
         given()
             .delete("/sieve/quota/users/" + USER_A.asString())
         .then()
@@ -205,7 +205,7 @@ public class SieveQuotaRoutesTest {
     }
 
     @Test
-    public void removePerUserSieveQuotaShouldRemoveQuotaForUser() throws Exception {
+    void removePerUserSieveQuotaShouldRemoveQuotaForUser() throws Exception {
         sieveRepository.setQuota(USER_A, QuotaSize.size(1024));
 
         given()

http://git-wip-us.apache.org/repos/asf/james-project/blob/81db3c28/src/site/markdown/server/manage-webadmin.md
----------------------------------------------------------------------
diff --git a/src/site/markdown/server/manage-webadmin.md b/src/site/markdown/server/manage-webadmin.md
index 637fb98..6708a26 100644
--- a/src/site/markdown/server/manage-webadmin.md
+++ b/src/site/markdown/server/manage-webadmin.md
@@ -1895,7 +1895,7 @@ Will return the bytes count allowed by user per default on this server.
 
 Response codes:
  - 200: Request is a success and the value is returned
- - 404: No quota is being configured
+ - 204: No default quota is being configured
 
 ### Updating global sieve quota
 
@@ -1942,7 +1942,7 @@ Will return the bytes count allowed for this user.
 
 Response codes:
  - 200: Request is a success and the value is returned
- - 404: No quota is being configured for this user
+ - 204: No quota is being configured for this user
 
 ### Updating user sieve quota
 


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


Mime
View raw message