JAMES-2468 Handle quota update on mailbox deletion

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

Branch: refs/heads/master
Commit: a4214bdfcf359a6e8510c31c93bc0503fecbd163
Parents: 3a1a896
Author: benwa <[email protected]>
Authored: Thu Aug 2 09:51:59 2018 +0700
Committer: Benoit Tellier <[email protected]>
Committed: Fri Aug 3 07:56:28 2018 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/MailboxListener.java   | 21 ++++-
 .../james/mailbox/MailboxManagerTest.java       | 17 ++++
 .../resources/META-INF/spring/event-system.xml  |  4 -
 mailbox/store/pom.xml                           |  4 +
 .../mailbox/store/StoreMailboxManager.java      | 27 ++++--
 .../james/mailbox/store/event/EventFactory.java | 12 ++-
 .../store/event/MailboxEventDispatcher.java     |  4 +-
 .../store/json/JacksonEventSerializer.java      | 94 +++++++++++++++++++-
 .../store/json/event/EventConverter.java        | 37 ++++++--
 .../json/event/EventNotValidException.java      | 26 ++++++
 .../json/event/dto/EventDataTransferObject.java | 53 ++++++++++-
 .../quota/ListeningCurrentQuotaUpdater.java     |  9 ++
 .../DefaultDelegatingMailboxListenerTest.java   | 15 +++-
 .../event/MailboxAnnotationListenerTest.java    |  9 +-
 .../BroadcastDelegatingMailboxListenerTest.java | 10 ++-
 ...RegisteredDelegatingMailboxListenerTest.java | 10 ++-
 .../mailbox/store/json/EventSerializerTest.java | 14 ++-
 .../quota/ListeningCurrentQuotaUpdaterTest.java | 13 +++
 .../registrations/GlobalRegistrationTest.java   |  8 +-
 19 files changed, 353 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/a4214bdf/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
----------------------------------------------------------------------
diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
index 5329b87..3112378 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
@@ -170,8 +170,27 @@ public interface MailboxListener {
          */
         private static final long serialVersionUID = 1L;
 
-        public MailboxDeletion(MailboxSession session, MailboxPath path) {
+        private final QuotaRoot quotaRoot;
+        private final QuotaCount deletedMessageCOunt;
+        private final QuotaSize totalDeletedSize;
+
+        public MailboxDeletion(MailboxSession session, MailboxPath path, 
QuotaRoot quotaRoot, QuotaCount deletedMessageCOunt, QuotaSize 
totalDeletedSize) {
             super(session, path);
+            this.quotaRoot = quotaRoot;
+            this.deletedMessageCOunt = deletedMessageCOunt;
+            this.totalDeletedSize = totalDeletedSize;
+        }
+
+        public QuotaRoot getQuotaRoot() {
+            return quotaRoot;
+        }
+
+        public QuotaCount getDeletedMessageCount() {
+            return deletedMessageCOunt;
+        }
+
+        public QuotaSize getTotalDeletedSize() {
+            return totalDeletedSize;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4214bdf/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java 
b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
index 796d80e..a89a602 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
@@ -933,6 +933,23 @@ public abstract class MailboxManagerTest {
     }
 
     @Test
+    public void deleteMailboxShouldFireMailboxDeletionEvent() throws Exception 
{
+        
Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.Quota));
+        session = mailboxManager.createSystemSession(USER_1);
+
+        EventCollector listener = new EventCollector();
+        mailboxManager.addGlobalListener(listener, session);
+
+        MailboxPath inbox = MailboxPath.inbox(session);
+        mailboxManager.createMailbox(inbox, session);
+        mailboxManager.deleteMailbox(inbox, session);
+
+        assertThat(listener.getEvents())
+            .filteredOn(event -> event instanceof 
MailboxListener.MailboxDeletion)
+            .isNotEmpty();
+    }
+
+    @Test
     public void 
moveMessagesShouldNotThrowWhenMovingAllMessagesOfAnEmptyMailbox() throws 
Exception {
         session = mailboxManager.createSystemSession(USER_1);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4214bdf/mailbox/spring/src/main/resources/META-INF/spring/event-system.xml
----------------------------------------------------------------------
diff --git a/mailbox/spring/src/main/resources/META-INF/spring/event-system.xml 
b/mailbox/spring/src/main/resources/META-INF/spring/event-system.xml
index 2647d0c..b168c72 100644
--- a/mailbox/spring/src/main/resources/META-INF/spring/event-system.xml
+++ b/mailbox/spring/src/main/resources/META-INF/spring/event-system.xml
@@ -54,10 +54,6 @@
         <constructor-arg index="0" ref="mailbox-converter"/>
     </bean>
 
-    <bean id="message-pack-event-serializer" 
class="org.apache.james.mailbox.store.json.MessagePackEventSerializer" 
lazy-init="true">
-        <constructor-arg index="0" ref="event-converter"/>
-    </bean>
-
     <bean id="event-converter" 
class="org.apache.james.mailbox.store.json.event.EventConverter" 
lazy-init="true">
         <constructor-arg index="0" ref="mailbox-converter"/>
     </bean>

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4214bdf/mailbox/store/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/store/pom.xml b/mailbox/store/pom.xml
index 1913e89..ae0fabb 100644
--- a/mailbox/store/pom.xml
+++ b/mailbox/store/pom.xml
@@ -81,6 +81,10 @@
             <artifactId>jackson-databind</artifactId>
         </dependency>
         <dependency>
+            <groupId>com.fasterxml.jackson.datatype</groupId>
+            <artifactId>jackson-datatype-jdk8</artifactId>
+        </dependency>
+        <dependency>
             <groupId>com.github.steveash.guavate</groupId>
             <artifactId>guavate</artifactId>
         </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4214bdf/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
index 31307fa..f5d7a54 100644
--- 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
+++ 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
@@ -30,6 +30,8 @@ import java.util.stream.Stream;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 
+import org.apache.james.core.quota.QuotaCount;
+import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.MailboxAnnotationManager;
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MailboxManager;
@@ -60,6 +62,7 @@ import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.MessageId.Factory;
 import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.MultimailboxesSearchQuery;
+import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.model.search.MailboxNameExpression;
 import org.apache.james.mailbox.model.search.MailboxQuery;
 import org.apache.james.mailbox.quota.QuotaManager;
@@ -69,7 +72,9 @@ import 
org.apache.james.mailbox.store.event.MailboxAnnotationListener;
 import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
 import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
+import org.apache.james.mailbox.store.mail.MessageMapper;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.Message;
 import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
 import org.apache.james.mailbox.store.quota.DefaultUserQuotaRootResolver;
@@ -79,6 +84,7 @@ import 
org.apache.james.mailbox.store.search.ListeningMessageSearchIndex;
 import org.apache.james.mailbox.store.search.MessageSearchIndex;
 import org.apache.james.mailbox.store.search.SimpleMessageSearchIndex;
 import org.apache.james.mailbox.store.transaction.Mapper;
+import org.apache.james.util.streams.Iterators;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -529,22 +535,29 @@ public class StoreMailboxManager implements 
MailboxManager {
     public void deleteMailbox(final MailboxPath mailboxPath, final 
MailboxSession session) throws MailboxException {
         LOGGER.info("deleteMailbox {}", mailboxPath);
         assertIsOwner(session, mailboxPath);
-        final MailboxMapper mapper = 
mailboxSessionMapperFactory.getMailboxMapper(session);
+        MailboxMapper mailboxMapper = 
mailboxSessionMapperFactory.getMailboxMapper(session);
+        MessageMapper messageMapper = 
mailboxSessionMapperFactory.getMessageMapper(session);
 
-        Mailbox mailbox = mapper.execute((Mapper.Transaction<Mailbox>) () -> {
-            final Mailbox mailbox1 = mapper.findMailboxByPath(mailboxPath);
-            if (mailbox1 == null) {
+        mailboxMapper.execute((Mapper.Transaction<Mailbox>) () -> {
+            Mailbox mailbox = mailboxMapper.findMailboxByPath(mailboxPath);
+            if (mailbox == null) {
                 throw new MailboxNotFoundException(mailboxPath);
             }
 
+            QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(mailboxPath);
+            long messageCount = messageMapper.countMessagesInMailbox(mailbox);
+            long totalSize = 
Iterators.toStream(messageMapper.findInMailbox(mailbox, MessageRange.all(), 
MessageMapper.FetchType.Metadata, -1))
+                .mapToLong(Message::getFullContentOctets)
+                .sum();
+
             // We need to create a copy of the mailbox as maybe we can not 
refer to the real
             // mailbox once we remove it
-            SimpleMailbox m = new SimpleMailbox(mailbox1);
-            mapper.delete(mailbox1);
+            SimpleMailbox m = new SimpleMailbox(mailbox);
+            mailboxMapper.delete(mailbox);
+            dispatcher.mailboxDeleted(session, mailbox, quotaRoot, 
QuotaCount.count(messageCount), QuotaSize.size(totalSize));
             return m;
         });
 
-        dispatcher.mailboxDeleted(session, mailbox);
 
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4214bdf/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
index aa38509..4ee78b6 100644
--- 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
+++ 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventFactory.java
@@ -23,6 +23,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.SortedMap;
 
+import org.apache.james.core.quota.QuotaCount;
+import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageUid;
@@ -30,6 +32,7 @@ import org.apache.james.mailbox.acl.ACLDiff;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageMetaData;
 import org.apache.james.mailbox.model.MessageMoves;
+import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.store.StoreMailboxPath;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
@@ -136,8 +139,8 @@ public class EventFactory {
     public final class MailboxDeletionImpl extends 
MailboxListener.MailboxDeletion implements MailboxAware {
         private final Mailbox mailbox;
 
-        public MailboxDeletionImpl(MailboxSession session, Mailbox mailbox) {
-            super(session, new StoreMailboxPath(mailbox));
+        public MailboxDeletionImpl(MailboxSession session, Mailbox mailbox, 
QuotaRoot quotaRoot, QuotaCount deletedMessageCount, QuotaSize 
totalDeletedSize) {
+            super(session, new StoreMailboxPath(mailbox), quotaRoot, 
deletedMessageCount, totalDeletedSize);
             this.mailbox = mailbox;
         }
 
@@ -204,8 +207,9 @@ public class EventFactory {
         return new MailboxRenamedEventImpl(session, from, to);
     }
 
-    public MailboxListener.MailboxDeletion mailboxDeleted(MailboxSession 
session, Mailbox mailbox) {
-        return new MailboxDeletionImpl(session, mailbox);
+    public MailboxListener.MailboxDeletion mailboxDeleted(MailboxSession 
session, Mailbox mailbox, QuotaRoot quotaRoot,
+                                                          QuotaCount 
deletedMessageCount, QuotaSize totalDeletedSize) {
+        return new MailboxDeletionImpl(session, mailbox, quotaRoot, 
deletedMessageCount, totalDeletedSize);
     }
 
     public MailboxListener.MailboxAdded mailboxAdded(MailboxSession session, 
Mailbox mailbox) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4214bdf/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
index c897ac9..da0f503 100644
--- 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
+++ 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxEventDispatcher.java
@@ -145,8 +145,8 @@ public class MailboxEventDispatcher {
      * Should get called when a Mailbox was deleted. All registered
      * MailboxListener will get triggered then
      */
-    public void mailboxDeleted(MailboxSession session, Mailbox mailbox) {
-        listener.event(eventFactory.mailboxDeleted(session, mailbox));
+    public void mailboxDeleted(MailboxSession session, Mailbox mailbox, 
QuotaRoot quotaRoot, QuotaCount deletedMessageCount, QuotaSize 
totalDeletedSize) {
+        listener.event(eventFactory.mailboxDeleted(session, mailbox, 
quotaRoot, deletedMessageCount, totalDeletedSize));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4214bdf/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/JacksonEventSerializer.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/JacksonEventSerializer.java
 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/JacksonEventSerializer.java
index 82fc394..6710b58 100644
--- 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/JacksonEventSerializer.java
+++ 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/JacksonEventSerializer.java
@@ -20,18 +20,26 @@
 package org.apache.james.mailbox.store.json;
 
 import java.io.IOException;
+import java.util.Optional;
 
+import org.apache.james.core.Domain;
+import org.apache.james.core.quota.QuotaCount;
+import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.MessageId.Factory;
+import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.store.event.EventSerializer;
 import org.apache.james.mailbox.store.json.event.EventConverter;
 import org.apache.james.mailbox.store.json.event.dto.EventDataTransferObject;
 
 import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParseException;
 import com.fasterxml.jackson.core.JsonParser;
 import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.ObjectCodec;
+import com.fasterxml.jackson.core.TreeNode;
 import com.fasterxml.jackson.databind.DeserializationContext;
 import com.fasterxml.jackson.databind.JsonDeserializer;
 import com.fasterxml.jackson.databind.JsonSerializer;
@@ -39,6 +47,9 @@ import com.fasterxml.jackson.databind.KeyDeserializer;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.SerializerProvider;
 import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.fasterxml.jackson.databind.node.TextNode;
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+import com.github.fge.lambdas.Throwing;
 
 public class JacksonEventSerializer implements EventSerializer {
 
@@ -69,7 +80,13 @@ public class JacksonEventSerializer implements 
EventSerializer {
         module.addKeySerializer(MessageUid.class, new 
MessageUidKeySerializer());
         module.addSerializer(MessageId.class, new MessageIdSerializer());
         module.addDeserializer(MessageId.class, new 
MessageIdDeserializer(messageIdFactory));
-        objectMapper.registerModule(module);
+        module.addSerializer(QuotaRoot.class, new QuotaRootSerializer());
+        module.addDeserializer(QuotaRoot.class, new QuotaRootDeserializer());
+        module.addSerializer(QuotaCount.class, new QuotaCountSerializer());
+        module.addDeserializer(QuotaCount.class, new QuotaCountDeserializer());
+        module.addSerializer(QuotaSize.class, new QuotaSizeSerializer());
+        module.addDeserializer(QuotaSize.class, new QuotaSizeDeserializer());
+        objectMapper.registerModules(module, new Jdk8Module());
         return objectMapper;
     }
 
@@ -132,4 +149,79 @@ public class JacksonEventSerializer implements 
EventSerializer {
         
     }
 
+    private static final String QUOTA_ROOT_VALUE_FIELD = "value";
+    private static final String QUOTA_ROOT_DOMAIN_FIELD = "domain";
+
+    public static class QuotaRootSerializer extends JsonSerializer<QuotaRoot> {
+
+        @Override
+        public void serialize(QuotaRoot value, JsonGenerator generator, 
SerializerProvider serializers) throws IOException, JsonProcessingException {
+            generator.writeStartObject();
+            generator.writeStringField(QUOTA_ROOT_VALUE_FIELD, 
value.getValue());
+            value.getDomain()
+                .ifPresent(Throwing.consumer(domain -> 
generator.writeStringField(QUOTA_ROOT_DOMAIN_FIELD, domain.asString())));
+            generator.writeEndObject();
+        }
+        
+    }
+
+    public static class QuotaRootDeserializer extends 
JsonDeserializer<QuotaRoot> {
+
+        @Override
+        public QuotaRoot deserialize(JsonParser parser, DeserializationContext 
context) throws IOException, JsonProcessingException {
+            ObjectCodec codec = parser.getCodec();
+            TreeNode node = codec.readTree(parser);
+            return QuotaRoot.quotaRoot(value(node), domain(node));
+        }
+
+        private String value(TreeNode node) throws IOException, 
JsonParseException {
+            TextNode value = (TextNode) node.get(QUOTA_ROOT_VALUE_FIELD);
+            return value.asText();
+        }
+
+        private Optional<Domain> domain(TreeNode node) throws IOException, 
JsonParseException {
+            TreeNode value = node.get(QUOTA_ROOT_DOMAIN_FIELD);
+            if (value == null || value.isMissingNode()) {
+                return Optional.empty();
+            }
+            return 
Optional.ofNullable(node.asToken().asString()).map(Domain::of);
+        }
+        
+    }
+
+    public static class QuotaCountSerializer extends 
JsonSerializer<QuotaCount> {
+
+        @Override
+        public void serialize(QuotaCount value, JsonGenerator generator, 
SerializerProvider serializers) throws IOException, JsonProcessingException {
+            generator.writeNumber(value.asLong());
+        }
+        
+    }
+
+    public static class QuotaCountDeserializer extends 
JsonDeserializer<QuotaCount> {
+
+        @Override
+        public QuotaCount deserialize(JsonParser parser, 
DeserializationContext context) throws IOException, JsonProcessingException {
+            return QuotaCount.count(parser.getLongValue());
+        }
+        
+    }
+
+    public static class QuotaSizeSerializer extends JsonSerializer<QuotaSize> {
+
+        @Override
+        public void serialize(QuotaSize value, JsonGenerator generator, 
SerializerProvider serializers) throws IOException, JsonProcessingException {
+            generator.writeNumber(value.asLong());
+        }
+        
+    }
+
+    public static class QuotaSizeDeserializer extends 
JsonDeserializer<QuotaSize> {
+
+        @Override
+        public QuotaSize deserialize(JsonParser parser, DeserializationContext 
context) throws IOException, JsonProcessingException {
+            return QuotaSize.size(parser.getLongValue());
+        }
+        
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4214bdf/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventConverter.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventConverter.java
 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventConverter.java
index 12c54e8..d92d077 100644
--- 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventConverter.java
+++ 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventConverter.java
@@ -22,15 +22,19 @@ package org.apache.james.mailbox.store.json.event;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Set;
 import java.util.SortedMap;
 import java.util.TreeMap;
 
+import org.apache.james.core.quota.QuotaCount;
+import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageMetaData;
+import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.store.event.EventFactory;
 import org.apache.james.mailbox.store.json.event.dto.EventDataTransferObject;
@@ -83,11 +87,15 @@ public class EventConverter {
                 mailboxDataTransferObject,
                 event.getMailboxPath());
         } else if (event instanceof MailboxListener.MailboxDeletion) {
-            return constructMailboxEventProxy(EventType.MAILBOX_DELETED,
+            MailboxListener.MailboxDeletion deletionEvent = 
(MailboxListener.MailboxDeletion) event;
+            return constructMailboxDeletionProxy(EventType.MAILBOX_DELETED,
                 event.getSession(),
-                mailboxDataTransferObject);
+                mailboxDataTransferObject,
+                deletionEvent.getQuotaRoot(),
+                deletionEvent.getDeletedMessageCount(),
+                deletionEvent.getTotalDeletedSize());
         } else if (event instanceof MailboxListener.MailboxAdded) {
-            return constructMailboxEventProxy(EventType.MAILBOX_ADDED,
+            return constructMailboxAddedProxy(EventType.MAILBOX_ADDED,
                 event.getSession(),
                 mailboxDataTransferObject);
         } else {
@@ -115,7 +123,10 @@ public class EventConverter {
             case MAILBOX_ADDED:
                 return 
eventFactory.mailboxAdded(eventDataTransferObject.getSession().getMailboxSession(),
 mailbox);
             case MAILBOX_DELETED:
-                return 
eventFactory.mailboxDeleted(eventDataTransferObject.getSession().getMailboxSession(),
 mailbox);
+                return 
eventFactory.mailboxDeleted(eventDataTransferObject.getSession().getMailboxSession(),
 mailbox, 
+                    eventDataTransferObject.getQuotaRoot().orElseThrow(() -> 
new EventNotValidException("Not a Deletion event, missing quotaRoot")),
+                    
eventDataTransferObject.getDeletedMessageCount().orElseThrow(() -> new 
EventNotValidException("Not a Deletion event, missing quotaCount")),
+                    
eventDataTransferObject.getTotalDeletedSize().orElseThrow(() -> new 
EventNotValidException("Not a Deletion event, missing quotaSize")));
             case MAILBOX_RENAMED:
                 return 
eventFactory.mailboxRenamed(eventDataTransferObject.getSession().getMailboxSession(),
                     eventDataTransferObject.getFrom().getPath(),
@@ -125,7 +136,7 @@ public class EventConverter {
         }
     }
 
-    private EventDataTransferObject constructMailboxEventProxy(EventType 
eventType,
+    private EventDataTransferObject constructMailboxAddedProxy(EventType 
eventType,
                                                                MailboxSession 
mailboxSession,
                                                                
MailboxDataTransferObject mailboxIntermediate) {
         return EventDataTransferObject.builder()
@@ -135,6 +146,22 @@ public class EventConverter {
             .build();
     }
 
+    private EventDataTransferObject constructMailboxDeletionProxy(EventType 
eventType,
+                                                               MailboxSession 
mailboxSession,
+                                                               
MailboxDataTransferObject mailboxIntermediate, 
+                                                               QuotaRoot 
quotaRoot, 
+                                                               QuotaCount 
deletedMessageCount,
+                                                               QuotaSize 
totalDeletedSize) {
+        return EventDataTransferObject.builder()
+            .type(eventType)
+            .session(new MailboxSessionDataTransferObject(mailboxSession))
+            .mailbox(mailboxIntermediate)
+            .quotaRoot(Optional.of(quotaRoot))
+            .deletedMessageCount(Optional.of(deletedMessageCount))
+            .totalDeletedSize(Optional.of(totalDeletedSize))
+            .build();
+    }
+
     private EventDataTransferObject 
constructMailboxRenamedProxy(MailboxSession mailboxSession,
                                                                  
MailboxDataTransferObject mailboxIntermediate,
                                                                  MailboxPath 
from) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4214bdf/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventNotValidException.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventNotValidException.java
 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventNotValidException.java
new file mode 100644
index 0000000..f4536be
--- /dev/null
+++ 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventNotValidException.java
@@ -0,0 +1,26 @@
+/****************************************************************
+ * 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.store.json.event;
+
+public class EventNotValidException extends Exception {
+
+    public EventNotValidException(String message) {
+        super(message);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4214bdf/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/EventDataTransferObject.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/EventDataTransferObject.java
 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/EventDataTransferObject.java
index e007f9d..0041a21 100644
--- 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/EventDataTransferObject.java
+++ 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/EventDataTransferObject.java
@@ -21,8 +21,12 @@ package org.apache.james.mailbox.store.json.event.dto;
 
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 
+import org.apache.james.core.quota.QuotaCount;
+import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.MessageUid;
+import org.apache.james.mailbox.model.QuotaRoot;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonProperty;
@@ -38,6 +42,9 @@ public class EventDataTransferObject {
         private Map<MessageUid, MessageMetaDataDataTransferObject> metaData;
         private List<UpdatedFlagsDataTransferObject> updatedFlags;
         private MailboxPathDataTransferObject from;
+        private Optional<QuotaRoot> quotaRoot;
+        private Optional<QuotaCount> deletedMessageCount;
+        private Optional<QuotaSize> totalDeletedSize;
 
         public Builder type(EventType type) {
             this.type = type;
@@ -74,8 +81,23 @@ public class EventDataTransferObject {
             return this;
         }
 
+        public Builder quotaRoot(Optional<QuotaRoot> quotaRoot) {
+            this.quotaRoot = quotaRoot;
+            return this;
+        }
+
+        public Builder deletedMessageCount(Optional<QuotaCount> 
deletedMessageCount) {
+            this.deletedMessageCount = deletedMessageCount;
+            return this;
+        }
+
+        public Builder totalDeletedSize(Optional<QuotaSize> totalDeletedSize) {
+            this.totalDeletedSize = totalDeletedSize;
+            return this;
+        }
+
         public EventDataTransferObject build() {
-            return new EventDataTransferObject(type, mailbox, session, uids, 
metaData, updatedFlags, from);
+            return new EventDataTransferObject(type, mailbox, session, uids, 
metaData, updatedFlags, from, quotaRoot, deletedMessageCount, totalDeletedSize);
         }
 
     }
@@ -98,6 +120,12 @@ public class EventDataTransferObject {
     private List<UpdatedFlagsDataTransferObject> updatedFlags;
     @JsonProperty()
     private MailboxPathDataTransferObject from;
+    @JsonProperty()
+    private Optional<QuotaRoot> quotaRoot;
+    @JsonProperty()
+    private Optional<QuotaCount> deletedMessageCount;
+    @JsonProperty()
+    private Optional<QuotaSize> totalDeletedSize;
 
     public EventDataTransferObject() {}
 
@@ -107,7 +135,10 @@ public class EventDataTransferObject {
                                    List<MessageUid> uids,
                                    Map<MessageUid, 
MessageMetaDataDataTransferObject> metaData,
                                    List<UpdatedFlagsDataTransferObject> 
updatedFlags,
-                                   MailboxPathDataTransferObject from) {
+                                   MailboxPathDataTransferObject from, 
+                                   Optional<QuotaRoot> quotaRoot, 
+                                   Optional<QuotaCount> deletedMessageCount,
+                                   Optional<QuotaSize> totalDeletedSize) {
         this.type = type;
         this.mailbox = mailbox;
         this.session = session;
@@ -115,6 +146,9 @@ public class EventDataTransferObject {
         this.metaData = metaData;
         this.updatedFlags = updatedFlags;
         this.from = from;
+        this.quotaRoot = quotaRoot;
+        this.deletedMessageCount = deletedMessageCount;
+        this.totalDeletedSize = totalDeletedSize;
     }
 
     @JsonIgnore
@@ -151,4 +185,19 @@ public class EventDataTransferObject {
     public MailboxPathDataTransferObject getFrom() {
         return from;
     }
+
+    @JsonIgnore
+    public Optional<QuotaRoot> getQuotaRoot() {
+        return quotaRoot;
+    }
+
+    @JsonIgnore
+    public Optional<QuotaCount> getDeletedMessageCount() {
+        return deletedMessageCount;
+    }
+
+    @JsonIgnore
+    public Optional<QuotaSize> getTotalDeletedSize() {
+        return totalDeletedSize;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4214bdf/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
index 4ffbf4a..a6c8308 100644
--- 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
+++ 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdater.java
@@ -66,6 +66,9 @@ public class ListeningCurrentQuotaUpdater implements 
MailboxListener, QuotaUpdat
                 Expunged expungedEvent = (Expunged) event;
                 QuotaRoot quotaRoot = 
quotaRootResolver.getQuotaRoot(expungedEvent.getMailboxPath());
                 handleExpungedEvent(expungedEvent, quotaRoot);
+            } else if (event instanceof MailboxDeletion) {
+                MailboxDeletion mailboxDeletionEvent = (MailboxDeletion) event;
+                handleMailboxDeletionEvent(mailboxDeletionEvent);
             }
         } catch (MailboxException e) {
             LOGGER.error("Error while updating quotas", e);
@@ -107,4 +110,10 @@ public class ListeningCurrentQuotaUpdater implements 
MailboxListener, QuotaUpdat
             quotaManager.getStorageQuota(quotaRoot));
     }
 
+    private void handleMailboxDeletionEvent(MailboxDeletion 
mailboxDeletionEvent) throws MailboxException {
+        currentQuotaManager.decrease(mailboxDeletionEvent.getQuotaRoot(),
+                mailboxDeletionEvent.getDeletedMessageCount().asLong(),
+                mailboxDeletionEvent.getTotalDeletedSize().asLong());
+    }
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4214bdf/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java
 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java
index 1e5d36d..fe509ec 100644
--- 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java
+++ 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java
@@ -24,11 +24,16 @@ import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+import java.util.Optional;
+
+import org.apache.james.core.quota.QuotaCount;
+import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.util.EventCollector;
 import org.junit.Before;
 import org.junit.Test;
@@ -124,7 +129,10 @@ public class DefaultDelegatingMailboxListenerTest {
 
     @Test
     public void mailboxDeletionShouldUnregisterMAILBOXListeners() throws 
Exception {
-        MailboxListener.MailboxDeletion event = new 
MailboxListener.MailboxDeletion(null, MAILBOX_PATH) {};
+        QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty());
+        QuotaCount deletedMessageCount = QuotaCount.count(123);
+        QuotaSize totalDeletedSize = QuotaSize.size(456);
+        MailboxListener.MailboxDeletion event = new 
MailboxListener.MailboxDeletion(null, MAILBOX_PATH, quotaRoot, 
deletedMessageCount, totalDeletedSize) {};
         defaultDelegatingMailboxListener.event(event);
         MailboxListener.MailboxEvent secondEvent = new 
MailboxListener.MailboxEvent(null, MAILBOX_PATH) {};
         defaultDelegatingMailboxListener.event(secondEvent);
@@ -135,7 +143,10 @@ public class DefaultDelegatingMailboxListenerTest {
 
     @Test
     public void mailboxDeletionShouldNotRegisterMAILBOXListenerToOtherPaths() 
throws Exception {
-        MailboxListener.MailboxDeletion event = new 
MailboxListener.MailboxDeletion(null, MAILBOX_PATH) {};
+        QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty());
+        QuotaCount quotaCount = QuotaCount.count(123);
+        QuotaSize quotaSize = QuotaSize.size(456);
+        MailboxListener.MailboxDeletion event = new 
MailboxListener.MailboxDeletion(null, MAILBOX_PATH, quotaRoot, quotaCount, 
quotaSize) {};
         defaultDelegatingMailboxListener.event(event);
         MailboxListener.MailboxEvent secondEvent = new 
MailboxListener.MailboxEvent(null, OTHER_MAILBOX_PATH) {};
         defaultDelegatingMailboxListener.event(secondEvent);

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4214bdf/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
index cbc1ae3..524ad7d 100644
--- 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
+++ 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxAnnotationListenerTest.java
@@ -26,7 +26,10 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.mockito.Mockito.when;
 
 import java.util.List;
+import java.util.Optional;
 
+import org.apache.james.core.quota.QuotaCount;
+import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.mock.MockMailboxSession;
@@ -34,6 +37,7 @@ import org.apache.james.mailbox.model.MailboxAnnotation;
 import org.apache.james.mailbox.model.MailboxAnnotationKey;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.model.TestId;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.mail.AnnotationMapper;
@@ -77,7 +81,10 @@ public class MailboxAnnotationListenerTest {
         eventFactory = new EventFactory();
         mailbox = new SimpleMailbox(MailboxPath.forUser("user", "name"), 
UID_VALIDITY, mailboxId);
 
-        deleteEvent = eventFactory.mailboxDeleted(mailboxSession, mailbox);
+        QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty());
+        QuotaCount quotaCount = QuotaCount.count(123);
+        QuotaSize quotaSize = QuotaSize.size(456);
+        deleteEvent = eventFactory.mailboxDeleted(mailboxSession, mailbox, 
quotaRoot, quotaCount, quotaSize);
 
         
when(mailboxSessionMapperFactory.getAnnotationMapper(eq(deleteEvent.getSession()))).thenReturn(annotationMapper);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4214bdf/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/BroadcastDelegatingMailboxListenerTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/BroadcastDelegatingMailboxListenerTest.java
 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/BroadcastDelegatingMailboxListenerTest.java
index 94460c7..a0d6ac8 100644
--- 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/BroadcastDelegatingMailboxListenerTest.java
+++ 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/BroadcastDelegatingMailboxListenerTest.java
@@ -25,10 +25,15 @@ import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.mockito.Mockito.when;
 
+import java.util.Optional;
+
+import org.apache.james.core.quota.QuotaCount;
+import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.store.event.EventSerializer;
 import org.apache.james.mailbox.store.publisher.MessageConsumer;
 import org.apache.james.mailbox.store.publisher.Publisher;
@@ -166,7 +171,10 @@ public class BroadcastDelegatingMailboxListenerTest {
 
     @Test
     public void deletionDistantEventsShouldBeWellHandled() throws Exception {
-        final MailboxListener.MailboxEvent event = new 
MailboxListener.MailboxDeletion(mailboxSession, MAILBOX_PATH);
+        QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty());
+        QuotaCount quotaCount = QuotaCount.count(123);
+        QuotaSize quotaSize = QuotaSize.size(456);
+        MailboxListener.MailboxEvent event = new 
MailboxListener.MailboxDeletion(mailboxSession, MAILBOX_PATH, quotaRoot, 
quotaCount, quotaSize);
         broadcastDelegatingMailboxListener.addListener(MAILBOX_PATH, 
mailboxEventCollector, mailboxSession);
         when(mockedEventSerializer.deSerializeEvent(BYTES)).thenReturn(event);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4214bdf/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/RegisteredDelegatingMailboxListenerTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/RegisteredDelegatingMailboxListenerTest.java
 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/RegisteredDelegatingMailboxListenerTest.java
index 259174b..b904e53 100644
--- 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/RegisteredDelegatingMailboxListenerTest.java
+++ 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/distributed/RegisteredDelegatingMailboxListenerTest.java
@@ -26,11 +26,16 @@ import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.mockito.Mockito.when;
 
+import java.util.Optional;
+
+import org.apache.james.core.quota.QuotaCount;
+import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.store.event.EventSerializer;
 import org.apache.james.mailbox.store.publisher.MessageConsumer;
 import org.apache.james.mailbox.store.publisher.Publisher;
@@ -157,7 +162,10 @@ public class RegisteredDelegatingMailboxListenerTest {
 
     @Test
     public void deletionEventsShouldBeWellHandled() throws Exception {
-        MailboxListener.MailboxEvent event = new 
MailboxListener.MailboxDeletion(mailboxSession, MAILBOX_PATH);
+        QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty());
+        QuotaCount quotaCount = QuotaCount.count(123);
+        QuotaSize quotaSize = QuotaSize.size(456);
+        MailboxListener.MailboxEvent event = new 
MailboxListener.MailboxDeletion(mailboxSession, MAILBOX_PATH, quotaRoot, 
quotaCount, quotaSize);
         testee.addListener(MAILBOX_PATH, mailboxEventCollector, 
mailboxSession);
         verify(mockedMailboxPathRegister).register(MAILBOX_PATH);
         
when(mockedMailboxPathRegister.getTopics(MAILBOX_PATH)).thenReturn(Sets.newHashSet(TOPIC,
 TOPIC_2));

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4214bdf/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java
 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java
index 629cced..f6d68b8 100644
--- 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java
+++ 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java
@@ -21,10 +21,13 @@ package org.apache.james.mailbox.store.json;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
+import java.util.Optional;
 import java.util.TreeMap;
 
 import javax.mail.Flags;
 
+import org.apache.james.core.quota.QuotaCount;
+import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageUid;
@@ -32,6 +35,7 @@ import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.MessageMetaData;
+import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.model.TestId;
 import org.apache.james.mailbox.model.TestMessageId;
 import org.apache.james.mailbox.model.UpdatedFlags;
@@ -133,12 +137,18 @@ public abstract class EventSerializerTest {
 
     @Test
     public void mailboxDeletionShouldBeWellConverted() throws Exception {
-        MailboxListener.MailboxEvent event = 
eventFactory.mailboxDeleted(mailboxSession, mailbox);
+        QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty());
+        QuotaCount quotaCount = QuotaCount.count(123);
+        QuotaSize quotaSize = QuotaSize.size(456);
+        MailboxListener.MailboxDeletion event = 
eventFactory.mailboxDeleted(mailboxSession, mailbox, quotaRoot, quotaCount, 
quotaSize);
         byte[] serializedEvent = serializer.serializeEvent(event);
-        MailboxListener.MailboxEvent deserializedEvent = 
serializer.deSerializeEvent(serializedEvent);
+        MailboxListener.MailboxDeletion deserializedEvent = 
(MailboxListener.MailboxDeletion) serializer.deSerializeEvent(serializedEvent);
         
assertThat(deserializedEvent.getMailboxPath()).isEqualTo(event.getMailboxPath());
         
assertThat(deserializedEvent.getSession().getSessionId()).isEqualTo(event.getSession().getSessionId());
         
assertThat(deserializedEvent).isInstanceOf(MailboxListener.MailboxDeletion.class);
+        assertThat(deserializedEvent.getQuotaRoot()).isEqualTo(quotaRoot);
+        
assertThat(deserializedEvent.getDeletedMessageCount()).isEqualTo(quotaCount);
+        
assertThat(deserializedEvent.getTotalDeletedSize()).isEqualTo(quotaSize);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4214bdf/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
index 158cd97..f2f2385 100644
--- 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
+++ 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/ListeningCurrentQuotaUpdaterTest.java
@@ -29,6 +29,8 @@ import java.util.Optional;
 
 import javax.mail.Flags;
 
+import org.apache.james.core.quota.QuotaCount;
+import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.model.MailboxPath;
@@ -105,4 +107,15 @@ public class ListeningCurrentQuotaUpdaterTest {
         verify(mockedCurrentQuotaManager, never()).increase(QUOTA_ROOT, 0, 0);
     }
 
+    @Test
+    public void mailboxDeletionEventShouldDecreaseCurrentQuotaValues() throws 
Exception {
+        MailboxListener.MailboxDeletion deletion = 
mock(MailboxListener.MailboxDeletion.class);
+        when(deletion.getMailboxPath()).thenReturn(MAILBOX_PATH);
+        when(deletion.getQuotaRoot()).thenReturn(QUOTA_ROOT);
+        
when(deletion.getDeletedMessageCount()).thenReturn(QuotaCount.count(10));
+        when(deletion.getTotalDeletedSize()).thenReturn(QuotaSize.size(5));
+        
when(mockedQuotaRootResolver.getQuotaRoot(MAILBOX_PATH)).thenReturn(QUOTA_ROOT);
+        testee.event(deletion);
+        verify(mockedCurrentQuotaManager).decrease(QUOTA_ROOT, 10, 5);
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/a4214bdf/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/registrations/GlobalRegistrationTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/registrations/GlobalRegistrationTest.java
 
b/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/registrations/GlobalRegistrationTest.java
index 86fe5b6..2717c05 100644
--- 
a/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/registrations/GlobalRegistrationTest.java
+++ 
b/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/registrations/GlobalRegistrationTest.java
@@ -23,9 +23,12 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 import java.util.Optional;
 
+import org.apache.james.core.quota.QuotaCount;
+import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.QuotaRoot;
 import org.apache.james.mailbox.store.event.EventFactory;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
 import org.junit.Before;
@@ -63,7 +66,10 @@ public class GlobalRegistrationTest {
 
     @Test
     public void pathToIndexShouldBeNullifiedByDeletedEvents() {
-        MailboxListener.MailboxEvent event = 
eventFactory.mailboxDeleted(session, MAILBOX);
+        QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty());
+        QuotaCount quotaCount = QuotaCount.count(123);
+        QuotaSize quotaSize = QuotaSize.size(456);
+        MailboxListener.MailboxEvent event = 
eventFactory.mailboxDeleted(session, MAILBOX, quotaRoot, quotaCount, quotaSize);
         globalRegistration.event(event);
         
assertThat(globalRegistration.getPathToIndex(INBOX)).isEqualTo(Optional.empty());
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to