@Test public void getVacationResponseShouldReturnStoredValueWithNonDefaultTimezone() { jmapGuiceProbe.modifyVacation(AccountId.fromString(ALICE), 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()); given() .header("Authorization", accessToken.serialize()) .body("[[" + "\"getVacationResponse\", " + "{}, " + "\"#0\"" + "]]") .when() .post("/jmap") .then() .statusCode(200) .body(NAME, equalTo("vacationResponse")) .body(ARGUMENTS + ".accountId", equalTo(ALICE)) .body(ARGUMENTS + ".list", hasSize(1)) .body(ARGUMENTS + ".list[0].id", equalTo("singleton")) .body(ARGUMENTS + ".list[0].fromDate", equalTo("2014-09-30T14:10:00+02:00")) .body(ARGUMENTS + ".list[0].toDate", equalTo("2016-04-15T11:56:32.224+07:00[Asia/Vientiane]")) .body(ARGUMENTS + ".list[0].isEnabled", equalTo(true)) .body(ARGUMENTS + ".list[0].textBody", equalTo("Test explaining my vacations")); }
@Test public void getVacationResponseShouldReturnStoredValue() { jmapGuiceProbe.modifyVacation(AccountId.fromString(ALICE), VacationPatch.builder() .isEnabled(true)
@Test public void accountIdIsNotSupported() { jmapGuiceProbe.modifyVacation(AccountId.fromString(ALICE), 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()); given() .header("Authorization", accessToken.serialize()) .body("[[" + "\"getVacationResponse\", " + "{\"accountId\":\"1\"}, " + "\"#0\"" + "]]") .when() .post("/jmap") .then() .statusCode(200) .body(NAME, equalTo("error")) .body(ARGUMENTS + ".type", equalTo("invalidArguments")) .body(ARGUMENTS + ".description", equalTo("The field 'accountId' of 'GetVacationRequest' is not supported")); }
@Test public void forwardingAnEmailShouldWork() throws Exception { jmapGuiceProbe.modifyVacation(AccountId.fromString(USER_WITH_DOMAIN), VacationPatch .builder() .isEnabled(true) .textBody(REASON) .build()); String externalMail = "ray@yopmail.com"; SMTPClient smtpClient = new SMTPClient(); smtpClient.connect(LOCALHOST_IP, guiceJamesServer.getProbe(SmtpGuiceProbe.class).getSmtpPort()); smtpClient.helo(DOMAIN); smtpClient.setSender(externalMail); smtpClient.rcpt("<" + USER_WITH_DOMAIN + ">"); smtpClient.sendShortMessageData("content"); calmlyAwait.atMost(1, TimeUnit.MINUTES) .untilAsserted(() -> fakeSmtp.assertEmailReceived(response -> response .body("[0].from", equalTo(USER_WITH_DOMAIN)) .body("[0].to[0]", equalTo(externalMail)) .body("[0].text", equalTo(REASON)))); } }
@Test public void setVacationResponseShouldAllowResets() { jmapGuiceProbe.modifyVacation(AccountId.fromString(USER), VacationPatch.builder() .textBody(ValuePatch.modifyTo("any value"))
@Test public void setVacationResponseShouldAllowPartialUpdates() { jmapGuiceProbe.modifyVacation(AccountId.fromString(USER), VacationPatch.builder() .textBody(ValuePatch.modifyTo("any value"))
String textBody = "any value"; String subject = "any subject"; jmapGuiceProbe.modifyVacation(AccountId.fromString(USER), VacationPatch.builder() .textBody(ValuePatch.modifyTo(textBody))
@Test public void getVacationResponseShouldReturnIsActivatedWhenInRange() { jmapGuiceProbe.modifyVacation(AccountId.fromString(ALICE), VacationPatch.builder() .isEnabled(true) .fromDate(DATE_2014) .toDate(DATE_2016) .textBody("Test explaining my vacations") .build()); given() .accept(ContentType.JSON) .contentType(ContentType.JSON) .header("Authorization", accessToken.serialize()) .body("[[" + "\"getVacationResponse\", " + "{}, " + "\"#0\"" + "]]") .when() .post("/jmap") .then() .statusCode(200) .body(NAME, equalTo("vacationResponse")) .body(ARGUMENTS + ".list[0].isActivated", equalTo(true)); }
@Test public void getVacationResponseShouldNotReturnIsActivatedWhenOutOfRange() { fixedDateZonedDateTimeProvider.setFixedDateTime(DATE_2014); jmapGuiceProbe.modifyVacation(AccountId.fromString(ALICE), VacationPatch.builder() .isEnabled(true) .fromDate(DATE_2015) .toDate(DATE_2016) .textBody("Test explaining my vacations") .build()); given() .accept(ContentType.JSON) .contentType(ContentType.JSON) .header("Authorization", accessToken.serialize()) .body("[[" + "\"getVacationResponse\", " + "{}, " + "\"#0\"" + "]]") .when() .post("/jmap") .then() .statusCode(200) .body(NAME, equalTo("vacationResponse")) .body(ARGUMENTS + ".list[0].isActivated", equalTo(false)); }
@Test public void jmapVacationShouldGenerateAReplyEvenWhenNoText() throws Exception { // Given AccessToken user1AccessToken = authenticateJamesUser(baseUri(guiceJamesServer), USER_1, PASSWORD); AccessToken user2AccessToken = authenticateJamesUser(baseUri(guiceJamesServer), USER_2, PASSWORD); jmapGuiceProbe.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)); }