public static URIBuilder baseUri(GuiceJamesServer jamesServer) { return new URIBuilder() .setScheme("http") .setHost("localhost") .setPort(jamesServer.getProbe(JmapGuiceProbe.class) .getJmapPort()) .setCharset(StandardCharsets.UTF_8); } }
jmapServer.getProbe(JmapGuiceProbe.class).addMailboxListener(new MailboxListener() { @Override public ListenerType getType() {
@Test public void setVacationResponseShouldAllowResets() { jmapGuiceProbe.modifyVacation(AccountId.fromString(USER), VacationPatch.builder() .textBody(ValuePatch.modifyTo("any value")) .body(ARGUMENTS + ".updated[0]", equalTo("singleton")); assertThat(jmapGuiceProbe.retrieveVacation(AccountId.fromString(USER))) .isEqualTo(Vacation.builder() .enabled(false)
@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")); }
@Given("^the user has a message \"([^\"]*)\" in \"([^\"]*)\" and \"([^\"]*)\" mailboxes with subject \"([^\"]*)\", content \"([^\"]*)\"$") public void appendMessageInTwoMailboxes(String messageName, String mailbox1, String mailbox2, String subject, String content) throws Exception { MessageId id = appendMessage(mailbox1, ContentType.noContentType(), subject, content, NO_HEADERS); String user = userStepdefs.getConnectedUser(); MailboxId mailboxId1 = mainStepdefs.getMailboxId(user, mailbox1); MailboxId mailboxId2 = mainStepdefs.getMailboxId(user, mailbox2); mainStepdefs.jmapServer.getProbe(JmapGuiceProbe.class).setInMailboxes(id, userStepdefs.getConnectedUser(), mailboxId1, mailboxId2); messageIdStepdefs.addMessageId(messageName, id); mainStepdefs.awaitMethod.run(); }
.body(ARGUMENTS + ".updated[0]", equalTo("singleton")); Vacation vacation = jmapGuiceProbe.retrieveVacation(AccountId.fromString(USER)); assertThat(vacation.getTextBody()).contains("Message explaining my wonderful vacations"); assertThat(vacation.isEnabled()).isTrue();
@Test public void getVacationResponseShouldReturnStoredValue() { jmapGuiceProbe.modifyVacation(AccountId.fromString(ALICE), VacationPatch.builder() .isEnabled(true)
@Test public void getMessageListShouldNotDuplicateMessagesInSeveralMailboxes() throws Exception { MailboxId mailboxId = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, ALICE, "mailbox"); MailboxId mailboxId2 = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, ALICE, "mailbox2"); ComposedMessageId message = mailboxProbe.appendMessage(ALICE, MailboxPath.forUser(ALICE, "mailbox"), new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); await(); jmapServer.getProbe(JmapGuiceProbe.class).setInMailboxes(message.getMessageId(), ALICE, mailboxId, mailboxId2); given() .header("Authorization", aliceAccessToken.serialize()) .body("[[\"getMessageList\", {}, \"#0\"]]") .when() .post("/jmap") .then() .statusCode(200) .body(NAME, equalTo("messageList")) .body(ARGUMENTS + ".messageIds", hasSize(1)); }
.body(ARGUMENTS + ".updated[0]", equalTo("singleton")); Vacation vacation = jmapGuiceProbe.retrieveVacation(AccountId.fromString(USER)); assertThat(vacation.getTextBody()).contains("Message explaining my wonderful vacations"); assertThat(vacation.getHtmlBody()).contains("<p>Here is the HTML version</p>");
@Before public void setup() throws Throwable { jmapServer = createJmapServer(); jmapServer.start(); RestAssured.requestSpecification = jmapRequestSpecBuilder .setPort(jmapServer.getProbe(JmapGuiceProbe.class).getJmapPort()) .build(); jmapServer.getProbe(DataProbeImpl.class) .fluent() .addDomain(DOMAIN) .addUser(USER, PASSWORD); }
@Test public void setVacationResponseShouldAllowPartialUpdates() { jmapGuiceProbe.modifyVacation(AccountId.fromString(USER), VacationPatch.builder() .textBody(ValuePatch.modifyTo("any value")) .body(ARGUMENTS + ".updated[0]", equalTo("singleton")); assertThat(jmapGuiceProbe.retrieveVacation(AccountId.fromString(USER))) .isEqualTo(Vacation.builder() .enabled(false)
@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")); }
@BeforeEach default void setup(GuiceJamesServer server) throws Exception { RestAssured.requestSpecification = new RequestSpecBuilder() .setContentType(ContentType.JSON) .setAccept(ContentType.JSON) .setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(StandardCharsets.UTF_8))) .setPort(server.getProbe(JmapGuiceProbe.class).getJmapPort()) .build(); }
String textBody = "any value"; String subject = "any subject"; jmapGuiceProbe.modifyVacation(AccountId.fromString(USER), VacationPatch.builder() .textBody(ValuePatch.modifyTo(textBody)) .body(ARGUMENTS + ".updated[0]", equalTo("singleton")); assertThat(jmapGuiceProbe.retrieveVacation(AccountId.fromString(USER))) .isEqualTo(Vacation.builder() .enabled(false)
@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)))); } }
@Before public void setup() throws Throwable { jmapServer = createJmapServer(); jmapServer.start(); jmapGuiceProbe = jmapServer.getProbe(JmapGuiceProbe.class); RestAssured.requestSpecification = jmapRequestSpecBuilder .setPort(jmapGuiceProbe.getJmapPort()) .build(); jmapServer.getProbe(DataProbeImpl.class) .fluent() .addDomain(DOMAIN) .addUser(USER, PASSWORD); accessToken = authenticateJamesUser(baseUri(jmapServer), USER, PASSWORD); }
@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)); }
@BeforeEach void setup(GuiceJamesServer server) throws Exception { server.getProbe(DataProbeImpl.class) .fluent() .addDomain(DOMAIN) .addUser(USERNAME, PASSWORD); RestAssured.requestSpecification = new RequestSpecBuilder() .setContentType(ContentType.JSON) .setAccept(ContentType.JSON) .setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(StandardCharsets.UTF_8))) .setPort(server.getProbe(JmapGuiceProbe.class).getJmapPort()) .build(); accessToken = authenticateJamesUser(baseUri(server), USERNAME, PASSWORD); timer = new Timer(); }
@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)); }
@Before public void setup() throws Throwable { fixedDateZonedDateTimeProvider = new FixedDateZonedDateTimeProvider(); fixedDateZonedDateTimeProvider.setFixedDateTime(DATE_2015); jmapServer = createJmapServer(fixedDateZonedDateTimeProvider); jmapServer.start(); jmapGuiceProbe = jmapServer.getProbe(JmapGuiceProbe.class); RestAssured.requestSpecification = jmapRequestSpecBuilder .setPort(jmapGuiceProbe.getJmapPort()) .build(); DataProbe dataProbe = jmapServer.getProbe(DataProbeImpl.class); dataProbe.addDomain(DOMAIN); dataProbe.addUser(ALICE, ALICE_PASSWORD); accessToken = authenticateJamesUser(baseUri(jmapServer), ALICE, ALICE_PASSWORD); }