http://git-wip-us.apache.org/repos/asf/james-project/blob/60919d85/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java ---------------------------------------------------------------------- diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java index 4ce097d..9a81746 100644 --- a/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java +++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/QuotaUsageUpdatedEventSerializationTest.java @@ -20,6 +20,7 @@ package org.apache.james.event.json; import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; +import static org.apache.james.event.json.SerializerFixture.EVENT_ID; import static org.apache.james.event.json.SerializerFixture.EVENT_SERIALIZER; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -48,6 +49,7 @@ class QuotaUsageUpdatedEventSerializationTest { .build(); private static final Instant INSTANT = Instant.parse("2018-11-13T12:00:55Z"); private final MailboxListener.QuotaUsageUpdatedEvent eventWithUserContainsUsername = new MailboxListener.QuotaUsageUpdatedEvent( + EVENT_ID, User.fromUsername("onlyUsername"), QUOTA_ROOT, QUOTA_COUNT, @@ -56,6 +58,7 @@ class QuotaUsageUpdatedEventSerializationTest { private final String quotaUsageUpdatedEvent = "{" + " \"QuotaUsageUpdatedEvent\":{" + + " \"eventId\":\"6e0dd59d-660e-4d9b-b22f-0354479f47b4\"," + " \"quotaRoot\":\"foo\"," + " \"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," + " \"time\":\"2018-11-13T12:00:55Z\"," + @@ -81,6 +84,7 @@ class QuotaUsageUpdatedEventSerializationTest { String quotaUsageUpdatedEvent = "{" + " \"QuotaUsageUpdatedEvent\":{" + + " \"eventId\":\"6e0dd59d-660e-4d9b-b22f-0354479f47b4\"," + " \"quotaRoot\":\"foo\"," + " \"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," + " \"time\":\"2018-11-13T12:00:55Z\"," + @@ -97,11 +101,12 @@ class QuotaUsageUpdatedEventSerializationTest { String quotaUsageUpdatedEvent = "{" + " \"QuotaUsageUpdatedEvent\":{" + + " \"eventId\":\"6e0dd59d-660e-4d9b-b22f-0354479f47b4\"," + " \"quotaRoot\":\"foo\"," + " \"time\":\"2018-11-13T12:00:55Z\"," + " \"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," + " \"user\":\"onlyUsername\"" + - " }" + + " }" + "}"; assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get()) @@ -113,11 +118,12 @@ class QuotaUsageUpdatedEventSerializationTest { String quotaUsageUpdatedEvent = "{" + " \"QuotaUsageUpdatedEvent\":{" + + " \"eventId\":\"6e0dd59d-660e-4d9b-b22f-0354479f47b4\"," + " \"quotaRoot\":\"foo\"," + " \"time\":\"2018-11-13T12:00:55Z\"," + " \"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{}}," + " \"user\":\"onlyUsername\"" + - " }" + + " }" + "}"; assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get()) @@ -129,11 +135,12 @@ class QuotaUsageUpdatedEventSerializationTest { String quotaUsageUpdatedEvent = "{" + " \"QuotaUsageUpdatedEvent\":{" + + " \"eventId\":\"6e0dd59d-660e-4d9b-b22f-0354479f47b4\"," + " \"quotaRoot\":\"foo\"," + " \"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{\"Domain\":100}}," + " \"sizeQuota\":{\"used\":1234,\"limit\":10000,\"limits\":{}}," + " \"user\":\"user\"" + - " }" + + " }" + "}"; assertThatThrownBy(() -> EVENT_SERIALIZER.fromJson(quotaUsageUpdatedEvent).get()) @@ -145,6 +152,7 @@ class QuotaUsageUpdatedEventSerializationTest { String quotaUsageUpdatedEvent = "{" + " \"QuotaUsageUpdatedEvent\":{" + + " \"eventId\":\"6e0dd59d-660e-4d9b-b22f-0354479f47b4\"," + " \"quotaRoot\":\"foo\"," + " \"countQuota\":{\"used\":12,\"limit\":100,\"limits\":{\"Domain\":100}}," + " \"time\":\"\"," +
http://git-wip-us.apache.org/repos/asf/james-project/blob/60919d85/mailbox/event/json/src/test/java/org/apache/james/event/json/SerializerFixture.java ---------------------------------------------------------------------- diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/SerializerFixture.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/SerializerFixture.java index 5d9bcaf..14eb14d 100644 --- a/mailbox/event/json/src/test/java/org/apache/james/event/json/SerializerFixture.java +++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/SerializerFixture.java @@ -19,10 +19,15 @@ package org.apache.james.event.json; + +import org.apache.james.mailbox.Event; import org.apache.james.mailbox.model.TestId; import org.apache.james.mailbox.model.TestMessageId; public interface SerializerFixture { JsonSerialize DTO_JSON_SERIALIZE = new JsonSerialize(new TestId.Factory(), new TestMessageId.Factory()); EventSerializer EVENT_SERIALIZER = new EventSerializer(new TestId.Factory(), new TestMessageId.Factory()); + + String SERIALIZED_EVENT_ID = "6e0dd59d-660e-4d9b-b22f-0354479f47b4"; + Event.EventId EVENT_ID = Event.EventId.of(SERIALIZED_EVENT_ID); } http://git-wip-us.apache.org/repos/asf/james-project/blob/60919d85/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/EventIdTest.java ---------------------------------------------------------------------- diff --git a/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/EventIdTest.java b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/EventIdTest.java new file mode 100644 index 0000000..0c5b7c0 --- /dev/null +++ b/mailbox/event/json/src/test/java/org/apache/james/event/json/dtos/EventIdTest.java @@ -0,0 +1,65 @@ +/**************************************************************** + * 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.event.json.dtos; + +import static org.apache.james.event.json.SerializerFixture.DTO_JSON_SERIALIZE; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.apache.james.event.json.SerializerFixture; +import org.junit.jupiter.api.Test; + +import play.api.libs.json.JsError; +import play.api.libs.json.JsNull$; +import play.api.libs.json.JsNumber; +import play.api.libs.json.JsString; +import scala.math.BigDecimal; + +class EventIdTest { + @Test + void eventIdShouldBeWellSerialized() { + assertThat(DTO_JSON_SERIALIZE.eventIdWrites().writes(SerializerFixture.EVENT_ID)) + .isEqualTo(new JsString(SerializerFixture.SERIALIZED_EVENT_ID)); + } + + @Test + void eventIdShouldBeWellDeSerialized() { + assertThat(DTO_JSON_SERIALIZE.eventIdReads().reads(new JsString(SerializerFixture.SERIALIZED_EVENT_ID)).get()) + .isEqualTo(SerializerFixture.EVENT_ID); + } + + @Test + void eventIdDeserializationShouldReturnErrorWhenNumber() { + assertThat(DTO_JSON_SERIALIZE.eventIdReads().reads(new JsNumber(BigDecimal.valueOf(18)))) + .isInstanceOf(JsError.class); + } + + @Test + void eventIdDeserializationShouldReturnErrorWhenNull() { + assertThat(DTO_JSON_SERIALIZE.eventIdReads().reads(JsNull$.MODULE$)) + .isInstanceOf(JsError.class); + } + + @Test + void eventIdDeserializationShouldThrowWhenInvalid() { + assertThatThrownBy(() -> DTO_JSON_SERIALIZE.eventIdReads().reads(new JsString("invalid"))) + .isInstanceOf(IllegalArgumentException.class); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/60919d85/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdConfigurationChangesTest.java ---------------------------------------------------------------------- diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdConfigurationChangesTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdConfigurationChangesTest.java index 3114c65..adfdccf 100644 --- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdConfigurationChangesTest.java +++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdConfigurationChangesTest.java @@ -29,6 +29,7 @@ import static org.apache.james.mailbox.quota.model.QuotaThresholdFixture.mailetC import static org.assertj.core.api.Assertions.assertThat; import org.apache.james.eventsourcing.eventstore.EventStore; +import org.apache.james.mailbox.Event; import org.apache.james.mailbox.quota.QuotaFixture.Counts; import org.apache.james.mailbox.quota.QuotaFixture.Sizes; import org.apache.james.mailbox.quota.mailing.QuotaMailingListenerConfiguration; @@ -37,6 +38,7 @@ import org.apache.mailet.base.test.FakeMailContext; import org.junit.jupiter.api.Test; public interface QuotaThresholdConfigurationChangesTest { + Event.EventId EVENT_ID = Event.EventId.of("6e0dd59d-660e-4d9b-b22f-0354479f47b4"); QuotaMailingListenerConfiguration CONFIGURATION_50 = QuotaMailingListenerConfiguration.builder() .addThreshold(_50) @@ -51,14 +53,19 @@ public interface QuotaThresholdConfigurationChangesTest { .gracePeriod(GRACE_PERIOD) .build(); + static EventFactory.RequireQuotaCount<EventFactory.RequireQuotaSize<EventFactory.RequireInstant<EventFactory.QuotaUsageUpdatedFinalStage>>> eventBase() { + return EventFactory.quotaUpdated() + .eventId(EVENT_ID) + .user(BOB_USER) + .quotaRoot(QUOTAROOT); + } + @Test default void shouldNotSendMailWhenNoNewExceededThresholdAfterThresholdIncrease(EventStore store) throws Exception { FakeMailContext mailetContext = mailetContext(); QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._55_PERCENT) .instant(NOW) @@ -68,9 +75,7 @@ public interface QuotaThresholdConfigurationChangesTest { mailetContext.resetSentMails(); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._55_PERCENT) .instant(NOW) @@ -84,9 +89,7 @@ public interface QuotaThresholdConfigurationChangesTest { FakeMailContext mailetContext = mailetContext(); QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_75); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._92_PERCENT) .instant(NOW) @@ -96,9 +99,7 @@ public interface QuotaThresholdConfigurationChangesTest { mailetContext.resetSentMails(); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._92_PERCENT) .instant(NOW) @@ -112,9 +113,7 @@ public interface QuotaThresholdConfigurationChangesTest { FakeMailContext mailetContext = mailetContext(); QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._92_PERCENT) .instant(NOW) @@ -124,9 +123,7 @@ public interface QuotaThresholdConfigurationChangesTest { mailetContext.resetSentMails(); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._92_PERCENT) .instant(NOW) @@ -140,9 +137,7 @@ public interface QuotaThresholdConfigurationChangesTest { FakeMailContext mailetContext = mailetContext(); QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._30_PERCENT) .instant(NOW) @@ -152,9 +147,7 @@ public interface QuotaThresholdConfigurationChangesTest { mailetContext.resetSentMails(); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._30_PERCENT) .instant(NOW) @@ -168,9 +161,7 @@ public interface QuotaThresholdConfigurationChangesTest { FakeMailContext mailetContext = mailetContext(); QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_75); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._30_PERCENT) .instant(NOW) @@ -179,9 +170,7 @@ public interface QuotaThresholdConfigurationChangesTest { testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50); mailetContext.resetSentMails(); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._30_PERCENT) .instant(NOW) @@ -195,9 +184,7 @@ public interface QuotaThresholdConfigurationChangesTest { FakeMailContext mailetContext = mailetContext(); QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_75); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._60_PERCENT) .instant(NOW) @@ -207,9 +194,7 @@ public interface QuotaThresholdConfigurationChangesTest { mailetContext.resetSentMails(); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._60_PERCENT) .instant(NOW) @@ -223,9 +208,7 @@ public interface QuotaThresholdConfigurationChangesTest { FakeMailContext mailetContext = mailetContext(); QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._92_PERCENT) .instant(NOW) @@ -236,9 +219,7 @@ public interface QuotaThresholdConfigurationChangesTest { mailetContext.resetSentMails(); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._92_PERCENT) .instant(NOW) @@ -252,9 +233,7 @@ public interface QuotaThresholdConfigurationChangesTest { FakeMailContext mailetContext = mailetContext(); QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._60_PERCENT) .instant(NOW) @@ -265,9 +244,7 @@ public interface QuotaThresholdConfigurationChangesTest { mailetContext.resetSentMails(); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._60_PERCENT) .instant(NOW) @@ -281,9 +258,7 @@ public interface QuotaThresholdConfigurationChangesTest { FakeMailContext mailetContext = mailetContext(); QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_75); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._92_PERCENT) .instant(NOW) @@ -294,9 +269,7 @@ public interface QuotaThresholdConfigurationChangesTest { mailetContext.resetSentMails(); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._92_PERCENT) .instant(NOW) @@ -311,9 +284,7 @@ public interface QuotaThresholdConfigurationChangesTest { QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50_75); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._92_PERCENT) .instant(NOW) @@ -323,9 +294,7 @@ public interface QuotaThresholdConfigurationChangesTest { mailetContext.resetSentMails(); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._92_PERCENT) .instant(NOW) @@ -340,9 +309,7 @@ public interface QuotaThresholdConfigurationChangesTest { QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50_75); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._92_PERCENT) .instant(NOW) @@ -352,9 +319,7 @@ public interface QuotaThresholdConfigurationChangesTest { mailetContext.resetSentMails(); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._92_PERCENT) .instant(NOW) @@ -369,9 +334,7 @@ public interface QuotaThresholdConfigurationChangesTest { QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, CONFIGURATION_50_75); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._60_PERCENT) .instant(NOW) @@ -381,9 +344,7 @@ public interface QuotaThresholdConfigurationChangesTest { mailetContext.resetSentMails(); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._60_PERCENT) .instant(NOW) http://git-wip-us.apache.org/repos/asf/james-project/blob/60919d85/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java ---------------------------------------------------------------------- diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java index cefec6e..3f76a88 100644 --- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java +++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdMailingIntegrationTest.java @@ -38,6 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.time.Duration; import org.apache.james.eventsourcing.eventstore.EventStore; +import org.apache.james.mailbox.Event; import org.apache.james.mailbox.quota.QuotaFixture.Counts; import org.apache.james.mailbox.quota.QuotaFixture.Sizes; import org.apache.james.mailbox.quota.mailing.QuotaMailingListenerConfiguration; @@ -47,15 +48,21 @@ import org.apache.mailet.base.test.FakeMailContext; import org.junit.jupiter.api.Test; public interface QuotaThresholdMailingIntegrationTest { + Event.EventId EVENT_ID = Event.EventId.of("6e0dd59d-660e-4d9b-b22f-0354479f47b4"); + + static EventFactory.RequireQuotaCount<EventFactory.RequireQuotaSize<EventFactory.RequireInstant<EventFactory.QuotaUsageUpdatedFinalStage>>> eventBase() { + return EventFactory.quotaUpdated() + .eventId(EVENT_ID) + .user(BOB_USER) + .quotaRoot(QUOTAROOT); + } @Test default void shouldNotSendMailWhenUnderAllThresholds(EventStore store) throws Exception { FakeMailContext mailetContext = mailetContext(); QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._30_PERCENT) .instant(NOW) @@ -69,18 +76,14 @@ public interface QuotaThresholdMailingIntegrationTest { FakeMailContext mailetContext = mailetContext(); QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._55_PERCENT) .instant(ONE_HOUR_AGO) .build()); mailetContext.resetSentMails(); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._55_PERCENT) .instant(NOW) @@ -93,25 +96,19 @@ public interface QuotaThresholdMailingIntegrationTest { default void shouldNotSendMailWhenThresholdOverPassedRecently(EventStore store) throws Exception { FakeMailContext mailetContext = mailetContext(); QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._55_PERCENT) .instant(TWELVE_HOURS_AGO) .build()); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._30_PERCENT) .instant(SIX_HOURS_AGO) .build()); mailetContext.resetSentMails(); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._55_PERCENT) .instant(NOW) @@ -125,9 +122,7 @@ public interface QuotaThresholdMailingIntegrationTest { FakeMailContext mailetContext = mailetContext(); QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._55_PERCENT) .instant(NOW) @@ -140,17 +135,13 @@ public interface QuotaThresholdMailingIntegrationTest { default void shouldNotSendDuplicates(EventStore store) throws Exception { FakeMailContext mailetContext = mailetContext(); QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._55_PERCENT) .instant(ONE_HOUR_AGO) .build()); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._55_PERCENT) .instant(NOW) @@ -163,17 +154,13 @@ public interface QuotaThresholdMailingIntegrationTest { default void shouldNotifySeparatelyCountAndSize(EventStore store) throws Exception { FakeMailContext mailetContext = mailetContext(); QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._55_PERCENT) .instant(ONE_HOUR_AGO) .build()); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._52_PERCENT) .quotaSize(Sizes._60_PERCENT) .instant(NOW) @@ -187,9 +174,7 @@ public interface QuotaThresholdMailingIntegrationTest { FakeMailContext mailetContext = mailetContext(); QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._52_PERCENT) .quotaSize(Sizes._55_PERCENT) .instant(NOW) @@ -202,25 +187,19 @@ public interface QuotaThresholdMailingIntegrationTest { default void shouldSendMailWhenThresholdOverPassedOverGracePeriod(EventStore store) throws Exception { FakeMailContext mailetContext = mailetContext(); QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._55_PERCENT) .instant(TWELVE_DAYS_AGO) .build()); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._30_PERCENT) .instant(SIX_DAYS_AGO) .build()); mailetContext.resetSentMails(); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._55_PERCENT) .instant(NOW) @@ -233,18 +212,14 @@ public interface QuotaThresholdMailingIntegrationTest { default void shouldNotSendMailWhenNoThresholdUpdateForCount(EventStore store) throws Exception { FakeMailContext mailetContext = mailetContext(); QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._32_PERCENT) .quotaSize(Sizes._55_PERCENT) .instant(TWO_DAYS_AGO) .build()); mailetContext.resetSentMails(); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._60_PERCENT) .instant(TWO_DAYS_AGO) @@ -257,25 +232,19 @@ public interface QuotaThresholdMailingIntegrationTest { default void shouldNotSendMailWhenThresholdOverPassedRecentlyForCount(EventStore store) throws Exception { FakeMailContext mailetContext = mailetContext(); QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._52_PERCENT) .quotaSize(Sizes._30_PERCENT) .instant(TWELVE_HOURS_AGO) .build()); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._30_PERCENT) .instant(SIX_HOURS_AGO) .build()); mailetContext.resetSentMails(); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._52_PERCENT) .quotaSize(Sizes._30_PERCENT) .instant(NOW) @@ -289,9 +258,7 @@ public interface QuotaThresholdMailingIntegrationTest { FakeMailContext mailetContext = mailetContext(); QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._52_PERCENT) .quotaSize(Sizes._30_PERCENT) .instant(TWELVE_HOURS_AGO) @@ -304,25 +271,19 @@ public interface QuotaThresholdMailingIntegrationTest { default void shouldSendMailWhenThresholdOverPassedOverGracePeriodForCount(EventStore store) throws Exception { FakeMailContext mailetContext = mailetContext(); QuotaThresholdListenersTestSystem testee = new QuotaThresholdListenersTestSystem(mailetContext, store, DEFAULT_CONFIGURATION); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._52_PERCENT) .quotaSize(Sizes._30_PERCENT) .instant(TWELVE_DAYS_AGO) .build()); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._30_PERCENT) .instant(SIX_DAYS_AGO) .build()); mailetContext.resetSentMails(); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._52_PERCENT) .quotaSize(Sizes._30_PERCENT) .instant(NOW) @@ -340,16 +301,12 @@ public interface QuotaThresholdMailingIntegrationTest { .gracePeriod(GRACE_PERIOD) .build()); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._52_PERCENT) .quotaSize(Sizes._30_PERCENT) .instant(NOW) .build()); - testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + testee.event(eventBase() .quotaCount(Counts._85_PERCENT) .quotaSize(Sizes._42_PERCENT) .instant(NOW) @@ -369,9 +326,7 @@ public interface QuotaThresholdMailingIntegrationTest { .build()); ConcurrentTestRunner.builder() - .operation((threadNb, step) -> testee.event(EventFactory.quotaUpdated() - .user(BOB_USER) - .quotaRoot(QUOTAROOT) + .operation((threadNb, step) -> testee.event(eventBase() .quotaCount(Counts._40_PERCENT) .quotaSize(Sizes._55_PERCENT) .instant(NOW) http://git-wip-us.apache.org/repos/asf/james-project/blob/60919d85/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java ---------------------------------------------------------------------- diff --git a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java index 4f33fe5..cd369f3 100644 --- a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java +++ b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/events/ElasticSearchQuotaMailboxListenerTest.java @@ -50,6 +50,7 @@ import org.junit.rules.RuleChain; import org.junit.rules.TemporaryFolder; public class ElasticSearchQuotaMailboxListenerTest { + private static Event.EventId EVENT_ID = Event.EventId.of("6e0dd59d-660e-4d9b-b22f-0354479f47b4"); private static final int BATCH_SIZE = 1; private static final Event DUMB_EVENT = mock(Event.class); @@ -94,6 +95,7 @@ public class ElasticSearchQuotaMailboxListenerTest { @Test public void eventShouldIndexEventWhenQuotaEvent() throws Exception { quotaMailboxListener.event(EventFactory.quotaUpdated() + .eventId(EVENT_ID) .user(BOB_USER) .quotaRoot(QUOTAROOT) .quotaCount(Counts._52_PERCENT) http://git-wip-us.apache.org/repos/asf/james-project/blob/60919d85/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJsonTest.java ---------------------------------------------------------------------- diff --git a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJsonTest.java b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJsonTest.java index be9a938..b5eb274 100644 --- a/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJsonTest.java +++ b/mailbox/plugin/quota-search-elasticsearch/src/test/java/org/apache/james/quota/search/elasticsearch/json/QuotaRatioToElasticSearchJsonTest.java @@ -27,6 +27,7 @@ import java.util.Optional; import org.apache.james.core.Domain; import org.apache.james.core.User; +import org.apache.james.mailbox.Event; import org.apache.james.mailbox.MailboxListener.QuotaUsageUpdatedEvent; import org.apache.james.mailbox.model.QuotaRoot; import org.apache.james.mailbox.quota.QuotaFixture; @@ -35,18 +36,19 @@ import org.apache.james.util.ClassLoaderUtils; import org.junit.jupiter.api.Test; class QuotaRatioToElasticSearchJsonTest { + private static Event.EventId EVENT_ID = Event.EventId.of("6e0dd59d-660e-4d9b-b22f-0354479f47b4"); @Test void quotaRatioShouldBeWellConvertedToJson() throws IOException { String user = "u...@domain.org"; QuotaUsageUpdatedEvent event = EventFactory.quotaUpdated() + .eventId(EVENT_ID) .user(User.fromUsername(user)) .quotaRoot(QuotaRoot.quotaRoot(user, Optional.of(Domain.of("domain.org")))) .quotaCount(QuotaFixture.Counts._52_PERCENT) .quotaSize(QuotaFixture.Sizes._55_PERCENT) .instant(Instant.now()) .build(); - QuotaRatioToElasticSearchJson quotaRatioToElasticSearchJson = new QuotaRatioToElasticSearchJson(); String convertToJson = quotaRatioToElasticSearchJson.convertToJson(user, event); @@ -59,6 +61,7 @@ class QuotaRatioToElasticSearchJsonTest { void quotaRatioShouldBeWellConvertedToJsonWhenNoDomain() throws IOException { String user = "user"; QuotaUsageUpdatedEvent event = EventFactory.quotaUpdated() + .eventId(EVENT_ID) .user(User.fromUsername(user)) .quotaRoot(QuotaRoot.quotaRoot(user, Optional.empty())) .quotaCount(QuotaFixture.Counts._52_PERCENT) http://git-wip-us.apache.org/repos/asf/james-project/blob/60919d85/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java ---------------------------------------------------------------------- diff --git a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java index a46d836..e1647ae 100644 --- a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java +++ b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java @@ -233,6 +233,7 @@ public class SpamAssassinListenerTest { SimpleMailboxMessage message = createMessage(inbox); MailboxListener.Added addedEvent = EventFactory.added() + .randomEventId() .mailboxSession(MAILBOX_SESSION) .mailbox(inbox) .addMessage(message) @@ -248,6 +249,7 @@ public class SpamAssassinListenerTest { SimpleMailboxMessage message = createMessage(mailbox1); MailboxListener.Added addedEvent = EventFactory.added() + .randomEventId() .mailboxSession(MAILBOX_SESSION) .mailbox(mailbox1) .addMessage(message) http://git-wip-us.apache.org/repos/asf/james-project/blob/60919d85/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 310fa05..55c0262 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 @@ -513,6 +513,7 @@ public class StoreMailboxManager implements MailboxManager { mapper.execute(Mapper.toTransaction(() -> mailboxIds.add(mapper.save(m)))); // notify listeners delegatingListener.event(EventFactory.mailboxAdded() + .randomEventId() .mailboxSession(mailboxSession) .mailbox(m) .build()); @@ -560,6 +561,7 @@ public class StoreMailboxManager implements MailboxManager { SimpleMailbox m = new SimpleMailbox(mailbox); mailboxMapper.delete(mailbox); delegatingListener.event(EventFactory.mailboxDeleted() + .randomEventId() .mailboxSession(session) .mailbox(mailbox) .quotaRoot(quotaRoot) @@ -605,6 +607,7 @@ public class StoreMailboxManager implements MailboxManager { mapper.save(mailbox); delegatingListener.event(EventFactory.mailboxRenamed() + .randomEventId() .mailboxSession(session) .mailboxId(mailbox.getMailboxId()) .oldPath(from) @@ -622,6 +625,7 @@ public class StoreMailboxManager implements MailboxManager { sub.setName(subNewName); mapper.save(sub); delegatingListener.event(EventFactory.mailboxRenamed() + .randomEventId() .mailboxSession(session) .mailboxId(sub.getMailboxId()) .oldPath(fromPath) http://git-wip-us.apache.org/repos/asf/james-project/blob/60919d85/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java index 7e01114..3efdb14 100644 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java @@ -219,6 +219,7 @@ public class StoreMessageIdManager implements MessageIdManager { MailboxMapper mailboxMapper = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession); for (MetadataWithMailboxId metadataWithMailboxId : metadataWithMailbox) { delegatingMailboxListener.event(EventFactory.expunged() + .randomEventId() .mailboxSession(mailboxSession) .mailbox(mailboxMapper.findMailboxById(metadataWithMailboxId.mailboxId)) .addMetaData(metadataWithMailboxId.messageMetaData) @@ -300,6 +301,7 @@ public class StoreMessageIdManager implements MessageIdManager { for (MailboxId mailboxId: mailboxesToRemove) { messageIdMapper.delete(message.getMessageId(), mailboxesToRemove); delegatingMailboxListener.event(EventFactory.expunged() + .randomEventId() .mailboxSession(mailboxSession) .mailbox(mailboxMapper.findMailboxById(mailboxId)) .addMetaData(eventPayload) @@ -316,6 +318,7 @@ public class StoreMessageIdManager implements MessageIdManager { Mailbox mailbox = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId); delegatingMailboxListener.event(EventFactory.flagsUpdated() + .randomEventId() .mailboxSession(mailboxSession) .mailbox(mailbox) .updatedFlag(updatedFlags) @@ -382,6 +385,7 @@ public class StoreMessageIdManager implements MessageIdManager { save(mailboxSession, messageIdMapper, copy); delegatingMailboxListener.event(EventFactory.added() + .randomEventId() .mailboxSession(mailboxSession) .mailbox(mailboxMapper.findMailboxById(mailboxId)) .addMessage(copy) http://git-wip-us.apache.org/repos/asf/james-project/blob/60919d85/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java index 4b5e994..a92914c 100644 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java @@ -257,6 +257,7 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana Map<MessageUid, MessageMetaData> uids = deleteMarkedInMailbox(set, mailboxSession); delegatingMailboxListener.event(EventFactory.expunged() + .randomEventId() .mailboxSession(mailboxSession) .mailbox(getMailboxEntity()) .metaData(ImmutableSortedMap.copyOf(uids)) @@ -403,6 +404,7 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana Mailbox mailbox = getMailboxEntity(); MailboxMessage copy = copyMessage(message); delegatingMailboxListener.event(EventFactory.added() + .randomEventId() .mailboxSession(mailboxSession) .mailbox(mailbox) .addMessage(copy) @@ -564,6 +566,7 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana List<UpdatedFlags> updatedFlags = Iterators.toStream(it).collect(Guavate.toImmutableList()); delegatingMailboxListener.event(EventFactory.flagsUpdated() + .randomEventId() .mailboxSession(mailboxSession) .mailbox(getMailboxEntity()) .updatedFlags(updatedFlags) @@ -727,6 +730,7 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana } delegatingMailboxListener.event(EventFactory.added() + .randomEventId() .mailboxSession(session) .mailbox(to.getMailboxEntity()) .metaData(copiedUids) @@ -755,11 +759,13 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana } delegatingMailboxListener.event(EventFactory.added() + .randomEventId() .mailboxSession(session) .mailbox(to.getMailboxEntity()) .metaData(moveUids) .build()); delegatingMailboxListener.event(EventFactory.expunged() + .randomEventId() .mailboxSession(session) .mailbox(getMailboxEntity()) .addMetaData(moveResult.getOriginalMessages()) http://git-wip-us.apache.org/repos/asf/james-project/blob/60919d85/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java index bcd6959..84bc1f0 100644 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java @@ -140,6 +140,7 @@ public class StoreRightManager implements RightManager { ACLDiff aclDiff = mapper.updateACL(mailbox, mailboxACLCommand); delegatingMailboxListener.event(EventFactory.aclUpdated() + .randomEventId() .mailboxSession(session) .mailbox(mailbox) .aclDiff(aclDiff) @@ -222,6 +223,7 @@ public class StoreRightManager implements RightManager { ACLDiff aclDiff = mapper.setACL(mailbox, mailboxACL); delegatingMailboxListener.event(EventFactory.aclUpdated() + .randomEventId() .mailboxSession(session) .mailbox(mailbox) .aclDiff(aclDiff) http://git-wip-us.apache.org/repos/asf/james-project/blob/60919d85/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 6dd75a9..5ad8d09 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 @@ -27,6 +27,7 @@ import java.util.SortedMap; import org.apache.james.core.User; import org.apache.james.core.quota.QuotaCount; import org.apache.james.core.quota.QuotaSize; +import org.apache.james.mailbox.Event; import org.apache.james.mailbox.MailboxListener; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.MessageMoveEvent; @@ -48,6 +49,15 @@ import com.google.common.collect.ImmutableSortedMap; public class EventFactory { @FunctionalInterface + public interface RequireEventId<T> { + T eventId(Event.EventId eventId); + + default T randomEventId() { + return eventId(Event.EventId.random()); + } + } + + @FunctionalInterface public interface RequireUser<T> { T user(User user); } @@ -172,15 +182,17 @@ public class EventFactory { } @FunctionalInterface - public interface RequireMailboxEvent<T> extends RequireSession<RequireMailbox<T>> {} + public interface RequireMailboxEvent<T> extends RequireEventId<RequireSession<RequireMailbox<T>>> {} public static class MailboxAddedFinalStage { + private final Event.EventId eventId; private final MailboxPath path; private final MailboxId mailboxId; private final User user; private final MailboxSession.SessionId sessionId; - MailboxAddedFinalStage(MailboxPath path, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId) { + MailboxAddedFinalStage(Event.EventId eventId, MailboxPath path, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId) { + this.eventId = eventId; this.path = path; this.mailboxId = mailboxId; this.user = user; @@ -193,18 +205,20 @@ public class EventFactory { Preconditions.checkNotNull(user); Preconditions.checkNotNull(sessionId); - return new MailboxListener.MailboxAdded(sessionId, user, path, mailboxId); + return new MailboxListener.MailboxAdded(sessionId, user, path, mailboxId, eventId); } } public static class AddedFinalStage { + private final Event.EventId eventId; private final MailboxPath path; private final MailboxId mailboxId; private final User user; private final MailboxSession.SessionId sessionId; private final ImmutableSortedMap<MessageUid, MessageMetaData> metaData; - AddedFinalStage(MailboxPath path, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId, Map<MessageUid, MessageMetaData> metaData) { + AddedFinalStage(Event.EventId eventId, MailboxPath path, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId, Map<MessageUid, MessageMetaData> metaData) { + this.eventId = eventId; this.path = path; this.mailboxId = mailboxId; this.user = user; @@ -219,18 +233,20 @@ public class EventFactory { Preconditions.checkNotNull(sessionId); Preconditions.checkNotNull(metaData); - return new MailboxListener.Added(sessionId, user, path, mailboxId, metaData); + return new MailboxListener.Added(sessionId, user, path, mailboxId, metaData, eventId); } } public static class ExpungedFinalStage { + private final Event.EventId eventId; private final MailboxPath path; private final MailboxId mailboxId; private final User user; private final MailboxSession.SessionId sessionId; private final ImmutableSortedMap<MessageUid, MessageMetaData> metaData; - ExpungedFinalStage(MailboxPath path, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId, Map<MessageUid, MessageMetaData> metaData) { + ExpungedFinalStage(Event.EventId eventId, MailboxPath path, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId, Map<MessageUid, MessageMetaData> metaData) { + this.eventId = eventId; this.path = path; this.mailboxId = mailboxId; this.user = user; @@ -245,18 +261,20 @@ public class EventFactory { Preconditions.checkNotNull(sessionId); Preconditions.checkNotNull(metaData); - return new MailboxListener.Expunged(sessionId, user, path, mailboxId, metaData); + return new MailboxListener.Expunged(sessionId, user, path, mailboxId, metaData, eventId); } } public static class MailboxAclUpdatedFinalStage { + private final Event.EventId eventId; private final MailboxPath path; private final MailboxId mailboxId; private final User user; private final MailboxSession.SessionId sessionId; private final ACLDiff aclDiff; - MailboxAclUpdatedFinalStage(MailboxPath path, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId, ACLDiff aclDiff) { + MailboxAclUpdatedFinalStage(Event.EventId eventId, MailboxPath path, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId, ACLDiff aclDiff) { + this.eventId = eventId; this.path = path; this.mailboxId = mailboxId; this.user = user; @@ -271,11 +289,12 @@ public class EventFactory { Preconditions.checkNotNull(sessionId); Preconditions.checkNotNull(aclDiff); - return new MailboxListener.MailboxACLUpdated(sessionId, user, path, aclDiff, mailboxId); + return new MailboxListener.MailboxACLUpdated(sessionId, user, path, aclDiff, mailboxId, eventId); } } public static class MailboxDeletionFinalStage { + private final Event.EventId eventId; private final MailboxPath path; private final MailboxId mailboxId; private final User user; @@ -284,7 +303,8 @@ public class EventFactory { private final QuotaCount deletedMessageCount; private final QuotaSize totalDeletedSize; - MailboxDeletionFinalStage(MailboxPath path, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId, QuotaRoot quotaRoot, QuotaCount deletedMessageCount, QuotaSize totalDeletedSize) { + MailboxDeletionFinalStage(Event.EventId eventId, MailboxPath path, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId, QuotaRoot quotaRoot, QuotaCount deletedMessageCount, QuotaSize totalDeletedSize) { + this.eventId = eventId; this.path = path; this.mailboxId = mailboxId; this.user = user; @@ -303,18 +323,20 @@ public class EventFactory { Preconditions.checkNotNull(deletedMessageCount); Preconditions.checkNotNull(totalDeletedSize); - return new MailboxListener.MailboxDeletion(sessionId, user, path, quotaRoot, deletedMessageCount, totalDeletedSize, mailboxId); + return new MailboxListener.MailboxDeletion(sessionId, user, path, quotaRoot, deletedMessageCount, totalDeletedSize, mailboxId, eventId); } } public static class MailboxRenamedFinalStage { + private final Event.EventId eventId; private final MailboxPath oldPath; private final MailboxId mailboxId; private final User user; private final MailboxSession.SessionId sessionId; private final MailboxPath newPath; - MailboxRenamedFinalStage(MailboxPath oldPath, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId, MailboxPath newPath) { + MailboxRenamedFinalStage(Event.EventId eventId, MailboxPath oldPath, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId, MailboxPath newPath) { + this.eventId = eventId; this.oldPath = oldPath; this.mailboxId = mailboxId; this.user = user; @@ -330,18 +352,20 @@ public class EventFactory { Preconditions.checkNotNull(user); Preconditions.checkNotNull(sessionId); - return new MailboxListener.MailboxRenamed(sessionId, user, oldPath, mailboxId, newPath); + return new MailboxListener.MailboxRenamed(sessionId, user, oldPath, mailboxId, newPath, eventId); } } public static class FlagsUpdatedFinalStage { + private final Event.EventId eventId; private final MailboxPath path; private final MailboxId mailboxId; private final User user; private final MailboxSession.SessionId sessionId; private final ImmutableList<UpdatedFlags> updatedFlags; - FlagsUpdatedFinalStage(MailboxPath path, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId, ImmutableList<UpdatedFlags> updatedFlags) { + FlagsUpdatedFinalStage(Event.EventId eventId, MailboxPath path, MailboxId mailboxId, User user, MailboxSession.SessionId sessionId, ImmutableList<UpdatedFlags> updatedFlags) { + this.eventId = eventId; this.path = path; this.mailboxId = mailboxId; this.user = user; @@ -357,18 +381,20 @@ public class EventFactory { Preconditions.checkNotNull(sessionId); Preconditions.checkNotNull(updatedFlags); - return new MailboxListener.FlagsUpdated(sessionId, user, path, mailboxId, updatedFlags); + return new MailboxListener.FlagsUpdated(sessionId, user, path, mailboxId, updatedFlags, eventId); } } public static final class QuotaUsageUpdatedFinalStage { + private final Event.EventId eventId; private final User user; private final QuotaRoot quotaRoot; private final Quota<QuotaCount> countQuota; private final Quota<QuotaSize> sizeQuota; private final Instant instant; - QuotaUsageUpdatedFinalStage(User user, QuotaRoot quotaRoot, Quota<QuotaCount> countQuota, Quota<QuotaSize> sizeQuota, Instant instant) { + QuotaUsageUpdatedFinalStage(Event.EventId eventId, User user, QuotaRoot quotaRoot, Quota<QuotaCount> countQuota, Quota<QuotaSize> sizeQuota, Instant instant) { + this.eventId = eventId; this.user = user; this.quotaRoot = quotaRoot; this.countQuota = countQuota; @@ -377,41 +403,41 @@ public class EventFactory { } public MailboxListener.QuotaUsageUpdatedEvent build() { - return new MailboxListener.QuotaUsageUpdatedEvent(user, quotaRoot, countQuota, sizeQuota, instant); + return new MailboxListener.QuotaUsageUpdatedEvent(eventId, user, quotaRoot, countQuota, sizeQuota, instant); } } public static RequireMailboxEvent<RequireMetadata<AddedFinalStage>> added() { - return user -> sessionId -> mailboxId -> path -> metaData -> new AddedFinalStage(path, mailboxId, user, sessionId, metaData); + return eventId -> user -> sessionId -> mailboxId -> path -> metaData -> new AddedFinalStage(eventId, path, mailboxId, user, sessionId, metaData); } public static RequireMailboxEvent<RequireMetadata<ExpungedFinalStage>> expunged() { - return user -> sessionId -> mailboxId -> path -> metaData -> new ExpungedFinalStage(path, mailboxId, user, sessionId, metaData); + return eventId -> user -> sessionId -> mailboxId -> path -> metaData -> new ExpungedFinalStage(eventId, path, mailboxId, user, sessionId, metaData); } public static RequireMailboxEvent<RequireUpdatedFlags<FlagsUpdatedFinalStage>> flagsUpdated() { - return user -> sessionId -> mailboxId -> path -> updatedFlags -> new FlagsUpdatedFinalStage(path, mailboxId, user, sessionId, updatedFlags); + return eventId -> user -> sessionId -> mailboxId -> path -> updatedFlags -> new FlagsUpdatedFinalStage(eventId, path, mailboxId, user, sessionId, updatedFlags); } - public static RequireSession<RequireMailboxId<RequireOldPath<RequireNewPath<MailboxRenamedFinalStage>>>> mailboxRenamed() { - return user -> sessionId -> mailboxId -> oldPath -> newPath -> new MailboxRenamedFinalStage(oldPath, mailboxId, user, sessionId, newPath); + public static RequireEventId<RequireSession<RequireMailboxId<RequireOldPath<RequireNewPath<MailboxRenamedFinalStage>>>>> mailboxRenamed() { + return eventId -> user -> sessionId -> mailboxId -> oldPath -> newPath -> new MailboxRenamedFinalStage(eventId, oldPath, mailboxId, user, sessionId, newPath); } public static RequireMailboxEvent<RequireQuotaRoot<RequireQuotaCountValue<RequireQuotaSizeValue<MailboxDeletionFinalStage>>>> mailboxDeleted() { - return user -> sessionId -> mailboxId -> path -> quotaRoot -> quotaCount -> quotaSize -> new MailboxDeletionFinalStage( - path, mailboxId, user, sessionId, quotaRoot, quotaCount, quotaSize); + return eventId -> user -> sessionId -> mailboxId -> path -> quotaRoot -> quotaCount -> quotaSize -> new MailboxDeletionFinalStage( + eventId, path, mailboxId, user, sessionId, quotaRoot, quotaCount, quotaSize); } public static RequireMailboxEvent<MailboxAddedFinalStage> mailboxAdded() { - return user -> sessionId -> mailboxId -> path -> new MailboxAddedFinalStage(path, mailboxId, user, sessionId); + return eventId -> user -> sessionId -> mailboxId -> path -> new MailboxAddedFinalStage(eventId, path, mailboxId, user, sessionId); } public static RequireMailboxEvent<RequireAclDiff<MailboxAclUpdatedFinalStage>> aclUpdated() { - return user -> sessionId -> mailboxId -> path -> aclDiff -> new MailboxAclUpdatedFinalStage(path, mailboxId, user, sessionId, aclDiff); + return eventId -> user -> sessionId -> mailboxId -> path -> aclDiff -> new MailboxAclUpdatedFinalStage(eventId, path, mailboxId, user, sessionId, aclDiff); } - public static RequireUser<RequireQuotaRoot<RequireQuotaCount<RequireQuotaSize<RequireInstant<QuotaUsageUpdatedFinalStage>>>>> quotaUpdated() { - return user -> quotaRoot -> quotaCount -> quotaSize -> instant -> new QuotaUsageUpdatedFinalStage(user, quotaRoot, quotaCount, quotaSize, instant); + public static RequireEventId<RequireUser<RequireQuotaRoot<RequireQuotaCount<RequireQuotaSize<RequireInstant<QuotaUsageUpdatedFinalStage>>>>>> quotaUpdated() { + return eventId -> user -> quotaRoot -> quotaCount -> quotaSize -> instant -> new QuotaUsageUpdatedFinalStage(eventId, user, quotaRoot, quotaCount, quotaSize, instant); } public static MessageMoveEvent.Builder moved() { http://git-wip-us.apache.org/repos/asf/james-project/blob/60919d85/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 e27bccc..e00c087 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 @@ -91,6 +91,7 @@ public class ListeningCurrentQuotaUpdater implements MailboxListener, QuotaUpdat } delegatingMailboxListener.event( EventFactory.quotaUpdated() + .randomEventId() .user(expunged.getUser()) .quotaRoot(quotaRoot) .quotaCount(quotaManager.getMessageQuota(quotaRoot)) @@ -112,6 +113,7 @@ public class ListeningCurrentQuotaUpdater implements MailboxListener, QuotaUpdat } delegatingMailboxListener.event( EventFactory.quotaUpdated() + .randomEventId() .user(added.getUser()) .quotaRoot(quotaRoot) .quotaCount(quotaManager.getMessageQuota(quotaRoot)) http://git-wip-us.apache.org/repos/asf/james-project/blob/60919d85/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java index fd31281..6cc6933 100644 --- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java +++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java @@ -83,6 +83,7 @@ public class MessageIdManagerTestSystem { MailboxMessage message = createMessage(mailboxId, flags, messageId, uid); mapperFactory.getMessageMapper(mailboxSession).add(mailbox, message); mailboxManager.getDelegationListener().event(EventFactory.added() + .randomEventId() .mailboxSession(mailboxSession) .mailbox(mailbox) .addMessage(message) http://git-wip-us.apache.org/repos/asf/james-project/blob/60919d85/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 1bebdd5..9490f63 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 @@ -27,6 +27,7 @@ import static org.mockito.Mockito.when; import org.apache.james.core.User; import org.apache.james.core.quota.QuotaCount; import org.apache.james.core.quota.QuotaSize; +import org.apache.james.mailbox.Event; import org.apache.james.mailbox.MailboxListener; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.MailboxSessionUtil; @@ -84,7 +85,7 @@ public class DefaultDelegatingMailboxListenerTest { @Test public void eventShouldWork() { - MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(null, null, MAILBOX_PATH, MAILBOX_ID); + MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(null, null, MAILBOX_PATH, MAILBOX_ID, Event.EventId.random()); defaultDelegatingMailboxListener.event(event); assertThat(mailboxEventCollector.getEvents()).containsExactly(event); assertThat(eachNodeEventCollector.getEvents()).containsExactly(event); @@ -93,7 +94,7 @@ public class DefaultDelegatingMailboxListenerTest { @Test public void eventShouldOnlyTriggerMAILBOXListenerRelatedToTheEvent() { - MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(null, null, OTHER_MAILBOX_PATH, OTHER_MAILBOX_ID); + MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(null, null, OTHER_MAILBOX_PATH, OTHER_MAILBOX_ID, Event.EventId.random()); defaultDelegatingMailboxListener.event(event); assertThat(mailboxEventCollector.getEvents()).isEmpty(); assertThat(eachNodeEventCollector.getEvents()).containsExactly(event); @@ -105,9 +106,9 @@ public class DefaultDelegatingMailboxListenerTest { QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", null); QuotaCount deletedMessageCount = QuotaCount.count(123); QuotaSize totalDeletedSize = QuotaSize.size(456); - MailboxListener.MailboxDeletion event = new MailboxListener.MailboxDeletion(null, null, MAILBOX_PATH, quotaRoot, deletedMessageCount, totalDeletedSize, MAILBOX_ID); + MailboxListener.MailboxDeletion event = new MailboxListener.MailboxDeletion(null, null, MAILBOX_PATH, quotaRoot, deletedMessageCount, totalDeletedSize, MAILBOX_ID, Event.EventId.random()); defaultDelegatingMailboxListener.event(event); - MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxAdded(null, null, MAILBOX_PATH, MAILBOX_ID); + MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxAdded(null, null, MAILBOX_PATH, MAILBOX_ID, Event.EventId.random()); defaultDelegatingMailboxListener.event(secondEvent); assertThat(mailboxEventCollector.getEvents()).containsExactly(event); assertThat(eachNodeEventCollector.getEvents()).containsOnly(event, secondEvent); @@ -119,9 +120,9 @@ public class DefaultDelegatingMailboxListenerTest { QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", null); QuotaCount quotaCount = QuotaCount.count(123); QuotaSize quotaSize = QuotaSize.size(456); - MailboxListener.MailboxDeletion event = new MailboxListener.MailboxDeletion(null, null, MAILBOX_PATH, quotaRoot, quotaCount, quotaSize, MAILBOX_ID); + MailboxListener.MailboxDeletion event = new MailboxListener.MailboxDeletion(null, null, MAILBOX_PATH, quotaRoot, quotaCount, quotaSize, MAILBOX_ID, Event.EventId.random()); defaultDelegatingMailboxListener.event(event); - MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxAdded(null, null, OTHER_MAILBOX_PATH, MAILBOX_ID); + MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxAdded(null, null, OTHER_MAILBOX_PATH, MAILBOX_ID, Event.EventId.random()); defaultDelegatingMailboxListener.event(secondEvent); assertThat(mailboxEventCollector.getEvents()).containsExactly(event); assertThat(eachNodeEventCollector.getEvents()).containsOnly(event, secondEvent); @@ -131,7 +132,7 @@ public class DefaultDelegatingMailboxListenerTest { @Test public void removeListenerShouldWork() { defaultDelegatingMailboxListener.removeListener(MAILBOX_ID, mailboxEventCollector, null); - MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(null, null, MAILBOX_PATH, MAILBOX_ID); + MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(null, null, MAILBOX_PATH, MAILBOX_ID, Event.EventId.random()); defaultDelegatingMailboxListener.event(event); assertThat(mailboxEventCollector.getEvents()).isEmpty(); assertThat(eachNodeEventCollector.getEvents()).containsExactly(event); @@ -141,7 +142,7 @@ public class DefaultDelegatingMailboxListenerTest { @Test public void removeListenerShouldNotRemoveAListenerFromADifferentPath() { defaultDelegatingMailboxListener.removeListener(OTHER_MAILBOX_ID, mailboxEventCollector, null); - MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(null, null, MAILBOX_PATH, MAILBOX_ID); + MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(null, null, MAILBOX_PATH, MAILBOX_ID, Event.EventId.random()); defaultDelegatingMailboxListener.event(event); assertThat(mailboxEventCollector.getEvents()).containsExactly(event); assertThat(eachNodeEventCollector.getEvents()).containsExactly(event); @@ -151,7 +152,7 @@ public class DefaultDelegatingMailboxListenerTest { @Test public void removeGlobalListenerShouldWorkForONCE() { defaultDelegatingMailboxListener.removeGlobalListener(eachNodeEventCollector, null); - MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(null, null, MAILBOX_PATH, MAILBOX_ID); + MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(null, null, MAILBOX_PATH, MAILBOX_ID, Event.EventId.random()); defaultDelegatingMailboxListener.event(event); assertThat(mailboxEventCollector.getEvents()).containsExactly(event); assertThat(eachNodeEventCollector.getEvents()).isEmpty(); @@ -161,7 +162,7 @@ public class DefaultDelegatingMailboxListenerTest { @Test public void removeGlobalListenerShouldWorkForEACH_NODE() throws Exception { defaultDelegatingMailboxListener.removeGlobalListener(onceEventCollector, null); - MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(null, null, MAILBOX_PATH, MAILBOX_ID); + MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(null, null, MAILBOX_PATH, MAILBOX_ID, Event.EventId.random()); defaultDelegatingMailboxListener.event(event); assertThat(mailboxEventCollector.getEvents()).containsExactly(event); assertThat(eachNodeEventCollector.getEvents()).containsExactly(event); @@ -172,7 +173,7 @@ public class DefaultDelegatingMailboxListenerTest { public void listenersErrorsShouldNotBePropageted() throws Exception { MailboxSession session = MailboxSessionUtil.create("benwa"); MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(session.getSessionId(), - session.getUser(), MAILBOX_PATH, MAILBOX_ID); + session.getUser(), MAILBOX_PATH, MAILBOX_ID, Event.EventId.random()); MailboxListener mockedListener = mock(MailboxListener.class); when(mockedListener.getType()).thenReturn(MailboxListener.ListenerType.ONCE); doThrow(new RuntimeException()).when(mockedListener).event(event); @@ -185,7 +186,7 @@ public class DefaultDelegatingMailboxListenerTest { @Test public void listenersShouldReceiveEvents() { - MailboxListener.Added noopEvent = new MailboxListener.Added(MailboxSession.SessionId.of(18), User.fromUsername("bob"), MailboxPath.forUser("bob", "mailbox"), TestId.of(58), ImmutableSortedMap.of()); + MailboxListener.Added noopEvent = new MailboxListener.Added(MailboxSession.SessionId.of(18), User.fromUsername("bob"), MailboxPath.forUser("bob", "mailbox"), TestId.of(58), ImmutableSortedMap.of(), Event.EventId.random()); defaultDelegatingMailboxListener.event(noopEvent); http://git-wip-us.apache.org/repos/asf/james-project/blob/60919d85/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 1b55fb5..13efd68 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 @@ -30,6 +30,7 @@ import java.util.Optional; import org.apache.james.core.quota.QuotaCount; import org.apache.james.core.quota.QuotaSize; +import org.apache.james.mailbox.Event; import org.apache.james.mailbox.MailboxListener; import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxSession; @@ -78,6 +79,7 @@ public class MailboxAnnotationListenerTest { listener = new MailboxAnnotationListener(mailboxSessionMapperFactory, mailboxManager); deleteEvent = EventFactory.mailboxDeleted() + .randomEventId() .mailboxSession(mailboxSession) .mailboxId(mailboxId) .mailboxPath(MailboxPath.forUser("user", "name")) @@ -93,7 +95,7 @@ public class MailboxAnnotationListenerTest { @Test public void eventShouldDoNothingIfDoNotHaveMailboxDeletionEvent() { - MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(null, null, MAILBOX_PATH, MAILBOX_ID); + MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(null, null, MAILBOX_PATH, MAILBOX_ID, Event.EventId.random()); listener.event(event); verifyNoMoreInteractions(mailboxSessionMapperFactory); http://git-wip-us.apache.org/repos/asf/james-project/blob/60919d85/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java ---------------------------------------------------------------------- diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java index ef3934c..b6eff37 100644 --- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java +++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java @@ -32,6 +32,7 @@ import org.apache.commons.lang3.NotImplementedException; import org.apache.james.imap.api.ImapSessionState; import org.apache.james.imap.api.ImapSessionUtils; import org.apache.james.imap.api.process.ImapSession; +import org.apache.james.mailbox.Event; import org.apache.james.mailbox.MailboxListener; import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxSession; @@ -115,6 +116,7 @@ public class MailboxEventAnalyserTest { private static final int UID_VALIDITY = 1024; private static final SimpleMailbox DEFAULT_MAILBOX = new SimpleMailbox(MAILBOX_PATH, UID_VALIDITY, MAILBOX_ID); private static final MailboxListener.Added ADDED = EventFactory.added() + .randomEventId() .mailboxSession(MAILBOX_SESSION) .mailbox(DEFAULT_MAILBOX) .addMetaData(new MessageMetaData(MessageUid.of(11), 0, new Flags(), 45, new Date(), new DefaultMessageId())) @@ -156,7 +158,7 @@ public class MailboxEventAnalyserTest { @Test public void testShouldBeNoSizeChangeOnOtherEvent() { MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(MAILBOX_SESSION.getSessionId(), - MAILBOX_SESSION.getUser(), MAILBOX_PATH, MAILBOX_ID); + MAILBOX_SESSION.getUser(), MAILBOX_PATH, MAILBOX_ID, Event.EventId.random()); testee.event(event); @@ -181,6 +183,7 @@ public class MailboxEventAnalyserTest { @Test public void testShouldNotSetUidWhenNoSystemFlagChange() { MailboxListener.FlagsUpdated update = EventFactory.flagsUpdated() + .randomEventId() .mailboxSession(MAILBOX_SESSION) .mailbox(DEFAULT_MAILBOX) .updatedFlag(NOOP_UPDATED_FLAGS) @@ -194,6 +197,7 @@ public class MailboxEventAnalyserTest { @Test public void testShouldSetUidWhenSystemFlagChange() { MailboxListener.FlagsUpdated update = EventFactory.flagsUpdated() + .randomEventId() .mailboxSession(OTHER_MAILBOX_SESSION) .mailbox(DEFAULT_MAILBOX) .updatedFlag(ADD_ANSWERED_UPDATED_FLAGS) @@ -209,6 +213,7 @@ public class MailboxEventAnalyserTest { SelectedMailboxImpl analyser = this.testee; MailboxListener.FlagsUpdated update = EventFactory.flagsUpdated() + .randomEventId() .mailboxSession(MAILBOX_SESSION) .mailbox(DEFAULT_MAILBOX) .updatedFlag(ADD_ANSWERED_UPDATED_FLAGS) @@ -224,6 +229,7 @@ public class MailboxEventAnalyserTest { @Test public void testShouldSetUidWhenSystemFlagChangeDifferentSessionInSilentMode() { MailboxListener.FlagsUpdated update = EventFactory.flagsUpdated() + .randomEventId() .mailboxSession(OTHER_MAILBOX_SESSION) .mailbox(DEFAULT_MAILBOX) .updatedFlag(ADD_ANSWERED_UPDATED_FLAGS) @@ -239,6 +245,7 @@ public class MailboxEventAnalyserTest { @Test public void testShouldNotSetUidWhenSystemFlagChangeSameSessionInSilentMode() { MailboxListener.FlagsUpdated update = EventFactory.flagsUpdated() + .randomEventId() .mailboxSession(MAILBOX_SESSION) .mailbox(DEFAULT_MAILBOX) .updatedFlag(NOOP_UPDATED_FLAGS) @@ -254,6 +261,7 @@ public class MailboxEventAnalyserTest { @Test public void testShouldNotSetUidWhenOnlyRecentFlagUpdated() { MailboxListener.FlagsUpdated update = EventFactory.flagsUpdated() + .randomEventId() .mailboxSession(MAILBOX_SESSION) .mailbox(DEFAULT_MAILBOX) .updatedFlag(ADD_RECENT_UPDATED_FLAGS) http://git-wip-us.apache.org/repos/asf/james-project/blob/60919d85/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java ---------------------------------------------------------------------- diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java index 2e13921..0b4a0a8 100644 --- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java +++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java @@ -164,6 +164,7 @@ public class SelectedMailboxImplTest { private void emitEvent(MailboxListener mailboxListener) { mailboxListener.event(EventFactory.added() + .randomEventId() .mailboxSession(MailboxSessionUtil.create("user")) .mailbox(mailbox) .addMetaData(new MessageMetaData(EMITTED_EVENT_UID, MOD_SEQ, new Flags(), SIZE, new Date(), new DefaultMessageId())) --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org