Revert "JAMES-1778 VacationResponse should be marked as unactivated if outside of time range"
This reverts commit 50e19442a8b3e7c16c2675b1486ee68ae1f03d0a. Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/6a657fb9 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/6a657fb9 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/6a657fb9 Branch: refs/heads/master Commit: 6a657fb962441d0a62c349d1fe9a2e532744fd3a Parents: 8fcd660 Author: Raphael Ouazana <[email protected]> Authored: Wed Jul 13 10:27:35 2016 +0200 Committer: Raphael Ouazana <[email protected]> Committed: Wed Jul 20 10:38:59 2016 +0200 ---------------------------------------------------------------------- .../CassandraGetVacationResponseTest.java | 6 +- .../jmap/FixedDateZonedDateTimeProvider.java | 7 -- .../integration/GetVacationResponseTest.java | 7 +- .../MemoryGetVacationResponseMethodTest.java | 6 +- .../jmap/methods/GetVacationResponseMethod.java | 7 +- .../james/jmap/model/VacationResponse.java | 9 +- .../methods/GetVacationResponseMethodTest.java | 89 +------------------- .../james/jmap/model/VacationResponseTest.java | 52 ------------ 8 files changed, 12 insertions(+), 171 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/6a657fb9/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraGetVacationResponseTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraGetVacationResponseTest.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraGetVacationResponseTest.java index 66f1687..1421a2e 100644 --- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraGetVacationResponseTest.java +++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraGetVacationResponseTest.java @@ -25,7 +25,6 @@ import org.apache.james.backends.cassandra.EmbeddedCassandra; import org.apache.james.jmap.methods.integration.GetVacationResponseTest; import org.apache.james.mailbox.elasticsearch.EmbeddedElasticSearch; import org.apache.james.modules.CassandraJmapServerModule; -import org.apache.james.util.date.ZonedDateTimeProvider; import org.junit.Rule; import org.junit.rules.RuleChain; import org.junit.rules.TemporaryFolder; @@ -42,11 +41,10 @@ public class CassandraGetVacationResponseTest extends GetVacationResponseTest { .around(embeddedElasticSearch); @Override - protected GuiceJamesServer createJmapServer(ZonedDateTimeProvider zonedDateTimeProvider) { + protected GuiceJamesServer createJmapServer() { return new GuiceJamesServer() .combineWith(CassandraJamesServerMain.cassandraServerModule) - .overrideWith(new CassandraJmapServerModule(temporaryFolder, embeddedElasticSearch, cassandra), - binder -> binder.bind(ZonedDateTimeProvider.class).toInstance(zonedDateTimeProvider)); + .overrideWith(new CassandraJmapServerModule(temporaryFolder, embeddedElasticSearch, cassandra)); } @Override http://git-wip-us.apache.org/repos/asf/james-project/blob/6a657fb9/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/FixedDateZonedDateTimeProvider.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/FixedDateZonedDateTimeProvider.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/FixedDateZonedDateTimeProvider.java index b7dc00c..fd0c24c 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/FixedDateZonedDateTimeProvider.java +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/FixedDateZonedDateTimeProvider.java @@ -27,13 +27,6 @@ public class FixedDateZonedDateTimeProvider implements ZonedDateTimeProvider { private ZonedDateTime zonedDateTime; - public FixedDateZonedDateTimeProvider() { - } - - public FixedDateZonedDateTimeProvider(ZonedDateTime zonedDateTime) { - this.zonedDateTime = zonedDateTime; - } - public void setFixedDateTime(ZonedDateTime zonedDateTime) { this.zonedDateTime = zonedDateTime; } http://git-wip-us.apache.org/repos/asf/james-project/blob/6a657fb9/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetVacationResponseTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetVacationResponseTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetVacationResponseTest.java index a9e7460..8521b75 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetVacationResponseTest.java +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetVacationResponseTest.java @@ -30,12 +30,10 @@ import java.time.ZonedDateTime; import java.util.Optional; import org.apache.james.GuiceJamesServer; -import org.apache.james.jmap.FixedDateZonedDateTimeProvider; import org.apache.james.jmap.JmapAuthentication; import org.apache.james.jmap.api.access.AccessToken; import org.apache.james.jmap.api.vacation.AccountId; import org.apache.james.jmap.api.vacation.Vacation; -import org.apache.james.util.date.ZonedDateTimeProvider; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -47,7 +45,6 @@ import com.jayway.restassured.http.ContentType; public abstract class GetVacationResponseTest { - private static final ZonedDateTime ZONED_DATE_TIME_2014 = ZonedDateTime.parse("2014-10-15T14:10:00Z"); private static final String NAME = "[0][0]"; private static final String ARGUMENTS = "[0][1]"; private static final String USERS_DOMAIN = "domain.tld"; @@ -55,7 +52,7 @@ public abstract class GetVacationResponseTest { public static final String PASSWORD = "password"; public static final String SUBJECT = "subject"; - protected abstract GuiceJamesServer createJmapServer(ZonedDateTimeProvider zonedDateTimeProvider); + protected abstract GuiceJamesServer createJmapServer(); protected abstract void await(); @@ -64,7 +61,7 @@ public abstract class GetVacationResponseTest { @Before public void setup() throws Throwable { - jmapServer = createJmapServer(new FixedDateZonedDateTimeProvider(ZONED_DATE_TIME_2014)); + jmapServer = createJmapServer(); jmapServer.start(); RestAssured.requestSpecification = new RequestSpecBuilder() http://git-wip-us.apache.org/repos/asf/james-project/blob/6a657fb9/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryGetVacationResponseMethodTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryGetVacationResponseMethodTest.java b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryGetVacationResponseMethodTest.java index c2c3a92..69e0d2b 100644 --- a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryGetVacationResponseMethodTest.java +++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryGetVacationResponseMethodTest.java @@ -23,7 +23,6 @@ import org.apache.james.GuiceJamesServer; import org.apache.james.MemoryJamesServerMain; import org.apache.james.jmap.methods.integration.GetVacationResponseTest; import org.apache.james.jmap.servers.MemoryJmapServerModule; -import org.apache.james.util.date.ZonedDateTimeProvider; import org.junit.Rule; import org.junit.rules.TemporaryFolder; @@ -33,11 +32,10 @@ public class MemoryGetVacationResponseMethodTest extends GetVacationResponseTest public TemporaryFolder temporaryFolder = new TemporaryFolder(); @Override - protected GuiceJamesServer createJmapServer(ZonedDateTimeProvider zonedDateTimeProvider) { + protected GuiceJamesServer createJmapServer() { return new GuiceJamesServer() .combineWith(MemoryJamesServerMain.inMemoryServerModule) - .overrideWith(new MemoryJmapServerModule(temporaryFolder), - binder -> binder.bind(ZonedDateTimeProvider.class).toInstance(zonedDateTimeProvider)); + .overrideWith(new MemoryJmapServerModule(temporaryFolder)); } @Override http://git-wip-us.apache.org/repos/asf/james-project/blob/6a657fb9/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetVacationResponseMethod.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetVacationResponseMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetVacationResponseMethod.java index e50bc31..f5f8752 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetVacationResponseMethod.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetVacationResponseMethod.java @@ -31,7 +31,6 @@ import org.apache.james.jmap.model.GetVacationRequest; import org.apache.james.jmap.model.GetVacationResponse; import org.apache.james.jmap.model.VacationResponse; import org.apache.james.mailbox.MailboxSession; -import org.apache.james.util.date.ZonedDateTimeProvider; import com.google.common.base.Preconditions; @@ -41,12 +40,10 @@ public class GetVacationResponseMethod implements Method { public static final Response.Name RESPONSE_NAME = Response.name("vacationResponse"); private final VacationRepository vacationRepository; - private final ZonedDateTimeProvider zonedDateTimeProvider; @Inject - public GetVacationResponseMethod(VacationRepository vacationRepository, ZonedDateTimeProvider zonedDateTimeProvider) { + public GetVacationResponseMethod(VacationRepository vacationRepository) { this.vacationRepository = vacationRepository; - this.zonedDateTimeProvider = zonedDateTimeProvider; } @Override @@ -78,7 +75,7 @@ public class GetVacationResponseMethod implements Method { return GetVacationResponse.builder() .accountId(mailboxSession.getUser().getUserName()) .vacationResponse(VacationResponse.builder() - .fromVacation(vacation, zonedDateTimeProvider.get()) + .fromVacation(vacation) .build()) .build(); } http://git-wip-us.apache.org/repos/asf/james-project/blob/6a657fb9/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/VacationResponse.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/VacationResponse.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/VacationResponse.java index 0a3a713..751dfa9 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/VacationResponse.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/VacationResponse.java @@ -96,9 +96,9 @@ public class VacationResponse { return this; } - public Builder fromVacation(Vacation vacation, ZonedDateTime zonedDateTime) { + public Builder fromVacation(Vacation vacation) { this.id = Vacation.ID; - this.isEnabled = computeEnabledState(vacation, zonedDateTime); + this.isEnabled = Optional.of(vacation.isEnabled()); this.fromDate = vacation.getFromDate(); this.toDate = vacation.getToDate(); this.textBody = vacation.getTextBody(); @@ -107,11 +107,6 @@ public class VacationResponse { return this; } - private Optional<Boolean> computeEnabledState(Vacation vacation, ZonedDateTime zonedDateTime) { - return Optional.of(vacation.isEnabled()) - .map(enabled -> enabled && vacation.isActiveAtDate(zonedDateTime)); - } - public VacationResponse build() { boolean enabled = isEnabled.orElse(DEFAULT_DISABLED); if (enabled) { http://git-wip-us.apache.org/repos/asf/james-project/blob/6a657fb9/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetVacationResponseMethodTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetVacationResponseMethodTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetVacationResponseMethodTest.java index 10f19e8..2bb3902 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetVacationResponseMethodTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetVacationResponseMethodTest.java @@ -23,7 +23,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import java.time.ZonedDateTime; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.stream.Stream; @@ -38,29 +37,23 @@ import org.apache.james.jmap.model.GetVacationResponse; import org.apache.james.jmap.model.SetMailboxesRequest; import org.apache.james.jmap.model.VacationResponse; import org.apache.james.mailbox.MailboxSession; -import org.apache.james.util.date.ZonedDateTimeProvider; import org.junit.Before; import org.junit.Test; public class GetVacationResponseMethodTest { public static final String USERNAME = "username"; - public static final ZonedDateTime ZONED_DATE_TIME_2014 = ZonedDateTime.parse("2014-09-30T14:10:00Z"); - public static final ZonedDateTime ZONED_DATE_TIME_2015 = ZonedDateTime.parse("2015-09-30T14:10:00Z"); - public static final ZonedDateTime ZONED_DATE_TIME_2016 = ZonedDateTime.parse("2016-09-30T14:10:00Z"); private GetVacationResponseMethod testee; private VacationRepository vacationRepository; private MailboxSession mailboxSession; private MailboxSession.User user; - private ZonedDateTimeProvider zonedDateTimeProvider; @Before public void setUp() { vacationRepository = mock(VacationRepository.class); mailboxSession = mock(MailboxSession.class); user = mock(MailboxSession.User.class); - zonedDateTimeProvider = mock(ZonedDateTimeProvider.class); - testee = new GetVacationResponseMethod(vacationRepository, zonedDateTimeProvider); + testee = new GetVacationResponseMethod(vacationRepository); } @Test(expected = NullPointerException.class) @@ -94,7 +87,6 @@ public class GetVacationResponseMethodTest { when(vacationRepository.retrieveVacation(AccountId.fromString(USERNAME))).thenReturn(CompletableFuture.completedFuture(vacation)); when(mailboxSession.getUser()).thenReturn(user); when(user.getUserName()).thenReturn(USERNAME); - when(zonedDateTimeProvider.get()).thenReturn(ZONED_DATE_TIME_2015); GetVacationRequest getVacationRequest = GetVacationRequest.builder().build(); @@ -106,84 +98,7 @@ public class GetVacationResponseMethodTest { .response(GetVacationResponse.builder() .accountId(USERNAME) .vacationResponse(VacationResponse.builder() - .id(Vacation.ID) - .enabled(true) - .textBody(Optional.of("I am in vacation")) - .subject(Optional.of("subject")) - .build()) - .build()) - .build(); - assertThat(result).containsExactly(expected); - } - - @Test - public void processShouldMarkOutDatedVacationAsUnactivated() { - ClientId clientId = mock(ClientId.class); - Vacation vacation = Vacation.builder() - .enabled(true) - .textBody("I am in vacation") - .subject(Optional.of("subject")) - .fromDate(Optional.of(ZONED_DATE_TIME_2014)) - .toDate(Optional.of(ZONED_DATE_TIME_2015)) - .build(); - when(vacationRepository.retrieveVacation(AccountId.fromString(USERNAME))).thenReturn(CompletableFuture.completedFuture(vacation)); - when(mailboxSession.getUser()).thenReturn(user); - when(user.getUserName()).thenReturn(USERNAME); - when(zonedDateTimeProvider.get()).thenReturn(ZONED_DATE_TIME_2016); - - GetVacationRequest getVacationRequest = GetVacationRequest.builder().build(); - - Stream<JmapResponse> result = testee.process(getVacationRequest, clientId, mailboxSession); - - JmapResponse expected = JmapResponse.builder() - .clientId(clientId) - .responseName(GetVacationResponseMethod.RESPONSE_NAME) - .response(GetVacationResponse.builder() - .accountId(USERNAME) - .vacationResponse(VacationResponse.builder() - .enabled(false) - .id(Vacation.ID) - .textBody(Optional.of("I am in vacation")) - .subject(Optional.of("subject")) - .fromDate(Optional.of(ZONED_DATE_TIME_2014)) - .toDate(Optional.of(ZONED_DATE_TIME_2015)) - .build()) - .build()) - .build(); - assertThat(result).containsExactly(expected); - } - - @Test - public void processShouldMarkTooEarlyVacationAsUnactivated() { - ClientId clientId = mock(ClientId.class); - Vacation vacation = Vacation.builder() - .enabled(true) - .textBody("I am in vacation") - .subject(Optional.of("subject")) - .fromDate(Optional.of(ZONED_DATE_TIME_2015)) - .toDate(Optional.of(ZONED_DATE_TIME_2016)) - .build(); - when(vacationRepository.retrieveVacation(AccountId.fromString(USERNAME))).thenReturn(CompletableFuture.completedFuture(vacation)); - when(mailboxSession.getUser()).thenReturn(user); - when(user.getUserName()).thenReturn(USERNAME); - when(zonedDateTimeProvider.get()).thenReturn(ZONED_DATE_TIME_2014); - - GetVacationRequest getVacationRequest = GetVacationRequest.builder().build(); - - Stream<JmapResponse> result = testee.process(getVacationRequest, clientId, mailboxSession); - - JmapResponse expected = JmapResponse.builder() - .clientId(clientId) - .responseName(GetVacationResponseMethod.RESPONSE_NAME) - .response(GetVacationResponse.builder() - .accountId(USERNAME) - .vacationResponse(VacationResponse.builder() - .enabled(false) - .id(Vacation.ID) - .textBody(Optional.of("I am in vacation")) - .subject(Optional.of("subject")) - .fromDate(Optional.of(ZONED_DATE_TIME_2015)) - .toDate(Optional.of(ZONED_DATE_TIME_2016)) + .fromVacation(vacation) .build()) .build()) .build(); http://git-wip-us.apache.org/repos/asf/james-project/blob/6a657fb9/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/VacationResponseTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/VacationResponseTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/VacationResponseTest.java index d3aaeb9..503acdf 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/VacationResponseTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/VacationResponseTest.java @@ -25,7 +25,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.time.ZonedDateTime; import java.util.Optional; -import org.apache.james.jmap.api.vacation.Vacation; import org.junit.Test; public class VacationResponseTest { @@ -36,9 +35,6 @@ public class VacationResponseTest { public static final ZonedDateTime FROM_DATE = ZonedDateTime.parse("2016-04-15T11:56:32.224+07:00[Asia/Vientiane]"); public static final ZonedDateTime TO_DATE = ZonedDateTime.parse("2016-04-16T11:56:32.224+07:00[Asia/Vientiane]"); public static final String SUBJECT = "subject"; - public static final ZonedDateTime ZONED_DATE_TIME_2014 = ZonedDateTime.parse("2014-09-30T14:10:00Z"); - public static final ZonedDateTime ZONED_DATE_TIME_2015 = ZonedDateTime.parse("2015-09-30T14:10:00Z"); - public static final ZonedDateTime ZONED_DATE_TIME_2016 = ZonedDateTime.parse("2016-09-30T14:10:00Z"); @Test public void vacationResponseBuilderShouldBeConstructedWithTheRightInformation() { @@ -112,52 +108,4 @@ public class VacationResponseTest { assertThat(vacationResponse.getHtmlBody()).contains(MESSAGE); } - @Test - public void fromVacationShouldMarkOutDatedVacationAsDisabled() { - VacationResponse vacationResponse = VacationResponse.builder() - .fromVacation( - Vacation.builder() - .enabled(true) - .textBody("Any text") - .fromDate(Optional.of(ZONED_DATE_TIME_2014)) - .toDate(Optional.of(ZONED_DATE_TIME_2015)) - .build(), - ZONED_DATE_TIME_2016) - .build(); - - assertThat(vacationResponse.isEnabled()).isFalse(); - } - - @Test - public void fromVacationShouldMarkTooEarlyVacationAsDisabled() { - VacationResponse vacationResponse = VacationResponse.builder() - .fromVacation( - Vacation.builder() - .enabled(true) - .textBody("Any text") - .fromDate(Optional.of(ZONED_DATE_TIME_2015)) - .toDate(Optional.of(ZONED_DATE_TIME_2016)) - .build(), - ZONED_DATE_TIME_2014) - .build(); - - assertThat(vacationResponse.isEnabled()).isFalse(); - } - - @Test - public void fromVacationShouldMarkInRangeVacationAsEnabled() { - VacationResponse vacationResponse = VacationResponse.builder() - .fromVacation( - Vacation.builder() - .enabled(true) - .textBody("Any text") - .fromDate(Optional.of(ZONED_DATE_TIME_2014)) - .toDate(Optional.of(ZONED_DATE_TIME_2016)) - .build(), - ZONED_DATE_TIME_2015) - .build(); - - assertThat(vacationResponse.isEnabled()).isTrue(); - } - } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
