JAMES-1781 Modify vacation integration tests accordingly
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/560f062b Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/560f062b Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/560f062b Branch: refs/heads/master Commit: 560f062b4212fd10d0f631f8f1f061fe152c14ba Parents: 1f5d03d Author: Benoit Tellier <[email protected]> Authored: Tue Jun 28 11:12:26 2016 +0700 Committer: Benoit Tellier <[email protected]> Committed: Thu Sep 29 12:50:50 2016 +0200 ---------------------------------------------------------------------- .../apache/james/utils/ExtendedServerProbe.java | 4 +- .../apache/james/utils/GuiceServerProbe.java | 6 +- .../james/jmap/VacationIntegrationTest.java | 26 ++++ .../integration/GetVacationResponseTest.java | 45 ++++--- .../integration/SetVacationResponseTest.java | 120 ++++++++++++++----- 5 files changed, 145 insertions(+), 56 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/560f062b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/ExtendedServerProbe.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/ExtendedServerProbe.java b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/ExtendedServerProbe.java index 20dbc81..4120abe 100644 --- a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/ExtendedServerProbe.java +++ b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/ExtendedServerProbe.java @@ -27,7 +27,7 @@ import javax.mail.Flags; import org.apache.james.cli.probe.ServerProbe; import org.apache.james.jmap.api.vacation.AccountId; import org.apache.james.jmap.api.vacation.Vacation; -import org.apache.james.jmap.api.vacation.VacationUpdate; +import org.apache.james.jmap.api.vacation.VacationPatch; import org.apache.james.mailbox.exception.BadCredentialsException; import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.model.MailboxPath; @@ -40,7 +40,7 @@ public interface ExtendedServerProbe extends ServerProbe { Mailbox getMailbox(String namespace, String user, String name); - void modifyVacation(AccountId accountId, VacationUpdate vacationUpdate); + void modifyVacation(AccountId accountId, VacationPatch vacationPatch); Vacation retrieveVacation(AccountId accountId); } http://git-wip-us.apache.org/repos/asf/james-project/blob/560f062b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceServerProbe.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceServerProbe.java b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceServerProbe.java index fcda3f9..4b313cc 100644 --- a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceServerProbe.java +++ b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceServerProbe.java @@ -36,7 +36,7 @@ import org.apache.james.domainlist.api.DomainList; import org.apache.james.jmap.api.vacation.AccountId; import org.apache.james.jmap.api.vacation.Vacation; import org.apache.james.jmap.api.vacation.VacationRepository; -import org.apache.james.jmap.api.vacation.VacationUpdate; +import org.apache.james.jmap.api.vacation.VacationPatch; import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.MessageManager; @@ -357,8 +357,8 @@ public class GuiceServerProbe implements ExtendedServerProbe { } @Override - public void modifyVacation(AccountId accountId, VacationUpdate vacationUpdate) { - vacationRepository.modifyVacation(accountId, vacationUpdate).join(); + public void modifyVacation(AccountId accountId, VacationPatch vacationPatch) { + vacationRepository.modifyVacation(accountId, vacationPatch).join(); } @Override http://git-wip-us.apache.org/repos/asf/james-project/blob/560f062b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/VacationIntegrationTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/VacationIntegrationTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/VacationIntegrationTest.java index 19a3f2b..dff1898 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/VacationIntegrationTest.java +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/VacationIntegrationTest.java @@ -33,6 +33,8 @@ import java.util.concurrent.TimeUnit; import org.apache.james.GuiceJamesServer; import org.apache.james.jmap.api.access.AccessToken; +import org.apache.james.jmap.api.vacation.AccountId; +import org.apache.james.jmap.api.vacation.VacationPatch; import org.apache.james.mailbox.model.MailboxConstants; import org.junit.After; import org.junit.Before; @@ -127,6 +129,30 @@ public abstract class VacationIntegrationTest { } @Test + public void jmapVacationShouldGenerateAReplyEvenWhenNoText() throws Exception { + // Given + AccessToken user1AccessToken = JmapAuthentication.authenticateJamesUser(USER_1, PASSWORD); + AccessToken user2AccessToken = JmapAuthentication.authenticateJamesUser(USER_2, PASSWORD); + guiceJamesServer.serverProbe().modifyVacation( + AccountId.fromString(USER_1), + VacationPatch.builder() + .isEnabled(true) + .build()); + + // When + String user2OutboxId = getOutboxId(user2AccessToken); + sendMail(user2AccessToken, user2OutboxId, "user|inbox|1"); + + // Then + // User 1 should well receive this mail + calmlyAwait.atMost(30, TimeUnit.SECONDS) + .until(() -> isTextMessageReceived(user1AccessToken, getInboxId(user1AccessToken), ORIGINAL_MESSAGE_TEXT_BODY, USER_2, USER_1)); + // User 2 should well receive a notification about user 1 vacation + calmlyAwait.atMost(30, TimeUnit.SECONDS) + .until( () -> isTextMessageReceived(user2AccessToken, getInboxId(user2AccessToken), "", USER_1, USER_2)); + } + + @Test public void jmapVacationShouldHaveSupportForHtmlMail() throws Exception { // Given AccessToken user1AccessToken = JmapAuthentication.authenticateJamesUser(USER_1, PASSWORD); http://git-wip-us.apache.org/repos/asf/james-project/blob/560f062b/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 3b67695..c93f6d8 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 @@ -27,14 +27,13 @@ import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.core.IsNull.nullValue; 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.jmap.api.vacation.VacationPatch; import org.apache.james.util.date.ZonedDateTimeProvider; import org.junit.After; import org.junit.Before; @@ -121,12 +120,12 @@ public abstract class GetVacationResponseTest { @Test public void getVacationResponseShouldReturnStoredValue() { jmapServer.serverProbe().modifyVacation(AccountId.fromString(USER), - Vacation.builder() - .enabled(true) - .fromDate(Optional.of(ZonedDateTime.parse("2014-09-30T14:10:00Z"))) - .toDate(Optional.of(ZonedDateTime.parse("2014-10-30T14:10:00Z"))) + VacationPatch.builder() + .isEnabled(true) + .fromDate(ZonedDateTime.parse("2014-09-30T14:10:00Z")) + .toDate(ZonedDateTime.parse("2014-10-30T14:10:00Z")) .textBody("Test explaining my vacations") - .subject(Optional.of(SUBJECT)) + .subject(SUBJECT) .htmlBody("<p>Test explaining my vacations</p>") .build()); @@ -156,10 +155,10 @@ public abstract class GetVacationResponseTest { @Test public void getVacationResponseShouldReturnStoredValueWithNonDefaultTimezone() { jmapServer.serverProbe().modifyVacation(AccountId.fromString(USER), - Vacation.builder() - .enabled(true) - .fromDate(Optional.of(ZonedDateTime.parse("2014-09-30T14:10:00+02:00"))) - .toDate(Optional.of(ZonedDateTime.parse("2016-04-15T11:56:32.224+07:00[Asia/Vientiane]"))) + VacationPatch.builder() + .isEnabled(true) + .fromDate(ZonedDateTime.parse("2014-09-30T14:10:00+02:00")) + .toDate(ZonedDateTime.parse("2016-04-15T11:56:32.224+07:00[Asia/Vientiane]")) .textBody("Test explaining my vacations") .build()); @@ -187,10 +186,10 @@ public abstract class GetVacationResponseTest { @Test public void getVacationResponseShouldReturnIsActivatedWhenInRange() { jmapServer.serverProbe().modifyVacation(AccountId.fromString(USER), - Vacation.builder() - .enabled(true) - .fromDate(Optional.of(DATE_2014)) - .toDate(Optional.of(DATE_2016)) + VacationPatch.builder() + .isEnabled(true) + .fromDate(DATE_2014) + .toDate(DATE_2016) .textBody("Test explaining my vacations") .build()); @@ -216,10 +215,10 @@ public abstract class GetVacationResponseTest { fixedDateZonedDateTimeProvider.setFixedDateTime(DATE_2014); jmapServer.serverProbe().modifyVacation(AccountId.fromString(USER), - Vacation.builder() - .enabled(true) - .fromDate(Optional.of(DATE_2015)) - .toDate(Optional.of(DATE_2016)) + VacationPatch.builder() + .isEnabled(true) + .fromDate(DATE_2015) + .toDate(DATE_2016) .textBody("Test explaining my vacations") .build()); @@ -243,10 +242,10 @@ public abstract class GetVacationResponseTest { @Test public void accountIdIsNotSupported() { jmapServer.serverProbe().modifyVacation(AccountId.fromString(USER), - Vacation.builder() - .enabled(true) - .fromDate(Optional.of(ZonedDateTime.parse("2014-09-30T14:10:00+02:00"))) - .toDate(Optional.of(ZonedDateTime.parse("2014-10-30T14:10:00+02:00"))) + VacationPatch.builder() + .isEnabled(true) + .fromDate(ZonedDateTime.parse("2014-09-30T14:10:00+02:00")) + .toDate(ZonedDateTime.parse("2014-10-30T14:10:00+02:00")) .textBody("Test explaining my vacations") .build()); http://git-wip-us.apache.org/repos/asf/james-project/blob/560f062b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java index 18414a6..64b2bc0 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetVacationResponseTest.java @@ -23,16 +23,18 @@ import static com.jayway.restassured.RestAssured.given; import static com.jayway.restassured.config.EncoderConfig.encoderConfig; import static com.jayway.restassured.config.RestAssuredConfig.newConfig; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import java.time.ZonedDateTime; +import java.util.Optional; import org.apache.james.GuiceJamesServer; 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.jmap.api.vacation.VacationPatch; +import org.apache.james.util.PatchedValue; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -140,12 +142,13 @@ public abstract class SetVacationResponseTest { @Test public void setVacationResponseShouldContainAnErrorWhenInvalidId() { + int id = 1; String bodyRequest = "[[" + "\"setVacationResponse\", " + "{" + "\"update\":{" + "\"singleton\" : {" + - "\"id\": \"1\"," + + "\"id\": \"" + id + "\"," + "\"isEnabled\": \"true\"," + "\"textBody\": \"Message explaining my wonderful vacations\"" + "}" + @@ -163,7 +166,7 @@ public abstract class SetVacationResponseTest { .statusCode(200) .body(NAME, equalTo("vacationResponseSet")) .body(ARGUMENTS + ".notUpdated.singleton.type", equalTo("invalidArguments")) - .body(ARGUMENTS + ".notUpdated.singleton.description", equalTo("There is one VacationResponse object per account, with id set to \"singleton\" and not to 1")); + .body(ARGUMENTS + ".notUpdated.singleton.description", equalTo("There is one VacationResponse object per account, with id set to \\\"singleton\\\" and not to " + id)); } @Test @@ -206,17 +209,57 @@ public abstract class SetVacationResponseTest { } @Test - public void setVacationResponseShouldHandleNamedTimeZone() { + public void setVacationResponseShouldAllowResets() { + jmapServer.serverProbe().modifyVacation(AccountId.fromString(USER), + VacationPatch.builder() + .textBody(PatchedValue.modifyTo("any value")) + .build()); + String bodyRequest = "[[" + "\"setVacationResponse\", " + "{" + "\"update\":{" + "\"singleton\" : {" + "\"id\": \"singleton\"," + - "\"isEnabled\": \"true\"," + - "\"textBody\": \"Message explaining my wonderful vacations\"," + - "\"fromDate\":\"2016-04-03T02:01+07:00[Asia/Vientiane]\"," + - "\"toDate\":\"2016-04-07T02:01+07:00[Asia/Vientiane]\"" + + "\"textBody\": null" + + "}" + + "}" + + "}, " + + "\"#0\"" + + "]]"; + + given() + .header("Authorization", accessToken.serialize()) + .body(bodyRequest) + .when() + .post("/jmap") + .then() + .statusCode(200) + .body(NAME, equalTo("vacationResponseSet")) + .body(ARGUMENTS + ".updated[0]", equalTo("singleton")); + + assertThat(jmapServer.serverProbe().retrieveVacation(AccountId.fromString(USER))) + .isEqualTo(Vacation.builder() + .enabled(false) + .build()); + } + + @Test + public void setVacationResponseShouldNotAlterAbsentProperties() { + String textBody = "any value"; + String subject = "any subject"; + jmapServer.serverProbe().modifyVacation(AccountId.fromString(USER), + VacationPatch.builder() + .textBody(PatchedValue.modifyTo(textBody)) + .build()); + + String bodyRequest = "[[" + + "\"setVacationResponse\", " + + "{" + + "\"update\":{" + + "\"singleton\" : {" + + "\"id\": \"singleton\"," + + "\"subject\": \"" + subject + "\"" + "}" + "}" + "}, " + @@ -224,6 +267,8 @@ public abstract class SetVacationResponseTest { "]]"; given() + .accept(ContentType.JSON) + .contentType(ContentType.JSON) .header("Authorization", accessToken.serialize()) .body(bodyRequest) .when() @@ -233,23 +278,29 @@ public abstract class SetVacationResponseTest { .body(NAME, equalTo("vacationResponseSet")) .body(ARGUMENTS + ".updated[0]", equalTo("singleton")); - Vacation vacation = jmapServer.serverProbe().retrieveVacation(AccountId.fromString(USER)); - assertThat(vacation.getTextBody()).contains("Message explaining my wonderful vacations"); - assertThat(vacation.isEnabled()).isTrue(); - assertThat(vacation.getFromDate()).contains(ZonedDateTime.parse("2016-04-03T02:01+07:00[Asia/Vientiane]")); - assertThat(vacation.getToDate()).contains(ZonedDateTime.parse("2016-04-07T02:01+07:00[Asia/Vientiane]")); + assertThat(jmapServer.serverProbe().retrieveVacation(AccountId.fromString(USER))) + .isEqualTo(Vacation.builder() + .enabled(false) + .subject(Optional.of(subject)) + .textBody(textBody) + .build()); } @Test - public void nullTextBodyShouldBeRejected() { + public void setVacationResponseShouldAllowPartialUpdates() { + jmapServer.serverProbe().modifyVacation(AccountId.fromString(USER), + VacationPatch.builder() + .textBody(PatchedValue.modifyTo("any value")) + .build()); + + String newTextBody = "Awesome text message 2"; String bodyRequest = "[[" + "\"setVacationResponse\", " + "{" + "\"update\":{" + "\"singleton\" : {" + "\"id\": \"singleton\"," + - "\"isEnabled\": \"true\"," + - "\"textBody\": null" + + "\"textBody\": \"" + newTextBody + "\"" + "}" + "}" + "}, " + @@ -259,24 +310,32 @@ public abstract class SetVacationResponseTest { given() .header("Authorization", accessToken.serialize()) .body(bodyRequest) - .when() + .when() .post("/jmap") - .then() + .then() .statusCode(200) - .body(NAME, equalTo("error")) - .body(ARGUMENTS + ".type", equalTo("invalidArguments")) - .body(ARGUMENTS + ".description", containsString("textBody or htmlBody property of vacationResponse object should not be null when enabled")); + .body(NAME, equalTo("vacationResponseSet")) + .body(ARGUMENTS + ".updated[0]", equalTo("singleton")); + + assertThat(jmapServer.serverProbe().retrieveVacation(AccountId.fromString(USER))) + .isEqualTo(Vacation.builder() + .enabled(false) + .textBody(newTextBody) + .build()); } @Test - public void noTextBodyShouldBeRejected() { + public void setVacationResponseShouldHandleNamedTimeZone() { String bodyRequest = "[[" + "\"setVacationResponse\", " + "{" + "\"update\":{" + "\"singleton\" : {" + "\"id\": \"singleton\"," + - "\"isEnabled\": \"true\"" + + "\"isEnabled\": \"true\"," + + "\"textBody\": \"Message explaining my wonderful vacations\"," + + "\"fromDate\":\"2016-04-03T02:01+07:00[Asia/Vientiane]\"," + + "\"toDate\":\"2016-04-07T02:01+07:00[Asia/Vientiane]\"" + "}" + "}" + "}, " + @@ -286,13 +345,18 @@ public abstract class SetVacationResponseTest { given() .header("Authorization", accessToken.serialize()) .body(bodyRequest) - .when() + .when() .post("/jmap") - .then() + .then() .statusCode(200) - .body(NAME, equalTo("error")) - .body(ARGUMENTS + ".type", equalTo("invalidArguments")) - .body(ARGUMENTS + ".description", containsString("textBody or htmlBody property of vacationResponse object should not be null when enabled")); + .body(NAME, equalTo("vacationResponseSet")) + .body(ARGUMENTS + ".updated[0]", equalTo("singleton")); + + Vacation vacation = jmapServer.serverProbe().retrieveVacation(AccountId.fromString(USER)); + assertThat(vacation.getTextBody()).contains("Message explaining my wonderful vacations"); + assertThat(vacation.isEnabled()).isTrue(); + assertThat(vacation.getFromDate()).contains(ZonedDateTime.parse("2016-04-03T02:01+07:00[Asia/Vientiane]")); + assertThat(vacation.getToDate()).contains(ZonedDateTime.parse("2016-04-07T02:01+07:00[Asia/Vientiane]")); } @Test --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
