@Test public void configurationShouldBeWellLoaded() throws Exception { jmapServer.getProbe(QuotaProbesImpl.class) .setMaxStorage(MailboxConstants.USER_NAMESPACE + "&" + HOMER, new SerializableQuotaValue<>(QuotaSize.size(100 * 1000))); bartSendMessageToHomer(); // Homer receives a mail big enough to trigger a 10% configured threshold calmlyAwait.atMost(30, TimeUnit.SECONDS) .until(() -> listMessageIdsForAccount(homerAccessToken).size() == 2); bartSendMessageToHomer(); // Homer receives a mail big enough to trigger a 20% configured threshold calmlyAwait.atMost(30, TimeUnit.SECONDS) .until(() -> listMessageIdsForAccount(homerAccessToken).size() == 4); List<String> ids = listMessageIdsForAccount(homerAccessToken); String idString = ids.stream() .map(id -> "\"" + id + "\"") .collect(Collectors.joining(",")); given() .header("Authorization", homerAccessToken.serialize()) .body("[[\"getMessages\", {\"ids\": [" + idString + "]}, \"#0\"]]") .when() .post("/jmap") .then() .statusCode(200) .log().ifValidationFails() .body(ARGUMENTS + ".list.textBody", hasItem(containsString("You currently occupy more than 10 % of the total size allocated to you"))) .body(ARGUMENTS + ".list.textBody", hasItem(containsString("You currently occupy more than 20 % of the total size allocated to you"))); }
@Test public void shouldSendANoticeWhenThresholdExceeded() throws Exception { jmapServer.getProbe(QuotaProbesImpl.class) .setMaxStorage(MailboxConstants.USER_NAMESPACE + "&" + HOMER, new SerializableQuotaValue<>(QuotaSize.size(100 * 1000))); bartSendMessageToHomer(); // Homer receives a mail big enough to trigger a configured threshold calmlyAwait.atMost(30, TimeUnit.SECONDS) .until(() -> listMessageIdsForAccount(homerAccessToken).size() == 2); List<String> ids = listMessageIdsForAccount(homerAccessToken); String idString = ids.stream() .map(id -> "\"" + id + "\"") .collect(Collectors.joining(",")); given() .header("Authorization", homerAccessToken.serialize()) .body("[[\"getMessages\", {\"ids\": [" + idString + "]}, \"#0\"]]") .when() .post("/jmap") .then() .statusCode(200) .log().ifValidationFails() .body(ARGUMENTS + ".list.subject", hasItem("Warning: Your email usage just exceeded a configured threshold")); }
@Test public void sendMDNShouldReturnCreatedMessageId() { bartSendMessageToHomer(); List<String> messageIds = listMessageIdsForAccount(homerAccessToken); String creationId = "creation-1"; given() .header("Authorization", homerAccessToken.serialize()) .body("[[\"setMessages\", {\"sendMDN\": {" + "\"" + creationId + "\":{" + " \"messageId\":\"" + messageIds.get(0) + "\"," + " \"subject\":\"subject\"," + " \"textBody\":\"textBody\"," + " \"reportingUA\":\"reportingUA\"," + " \"disposition\":{" + " \"actionMode\":\"automatic-action\"," + " \"sendingMode\":\"MDN-sent-automatically\"," + " \"type\":\"processed\"" + " }" + "}" + "}}, \"#0\"]]") .when() .post("/jmap") .then() .log().ifValidationFails() .statusCode(200) .body(NAME, equalTo("messagesSet")) .body(ARGUMENTS + ".MDNSent." + creationId, notNullValue()); }
@Test public void sendMDNShouldFailOnInvalidMessages() { sendAWrongInitialMessage(); List<String> messageIds = listMessageIdsForAccount(homerAccessToken);
String bartSentJmapMessageId = bartSendMessageToHomer(); String homerReceivedMessageId = Iterables.getOnlyElement(listMessageIdsForAccount(homerAccessToken));
private void sendAWrongInitialMessage() { String messageCreationId = "creationId"; String outboxId = getOutboxId(bartAccessToken); String requestBody = "[" + " [" + " \"setMessages\"," + " {" + " \"create\": { \"" + messageCreationId + "\" : {" + " \"from\": { \"name\": \"Bob\", \"email\": \"" + BART + "\"}," + " \"to\": [{ \"name\": \"User\", \"email\": \"" + HOMER + "\"}]," + " \"subject\": \"Message with an attachment\"," + " \"textBody\": \"Test body, plain text version\"," + " \"htmlBody\": \"Test <b>body</b>, HTML version\"," + " \"mailboxIds\": [\"" + outboxId + "\"] " + " }}" + " }," + " \"#0\"" + " ]" + "]"; with() .header("Authorization", bartAccessToken.serialize()) .body(requestBody) .post("/jmap") .then() .extract() .body() .path(ARGUMENTS + ".created." + messageCreationId + ".id"); calmlyAwait.until(() -> !listMessageIdsForAccount(homerAccessToken).isEmpty()); }
.path(ARGUMENTS + ".created." + messageCreationId + ".id"); calmlyAwait.until(() -> !listMessageIdsForAccount(homerAccessToken).isEmpty()); return id;
bartSendMessageToHomer(); List<String> messageIds = listMessageIdsForAccount(homerAccessToken);
bartSendMessageToHomer(); List<String> messageIds = listMessageIdsForAccount(homerAccessToken);