public static <U extends QuotaValue<U>> SerializableQuota<U> newInstance(U used, U max) { return new SerializableQuota<>( new SerializableQuotaValue<>(used), new SerializableQuotaValue<>(max) ); }
public static <U extends QuotaValue<U>> SerializableQuotaValue<U> valueOf(Optional<U> input) { return new SerializableQuotaValue<>(input.orElse(null)); }
@Test public void getGlobalMaxStorageCommandShouldWork() throws Exception { String[] arguments = { "-h", "127.0.0.1", "-p", "9999", CmdType.GETGLOBALMAXSTORAGEQUOTA.getCommand()}; CommandLine commandLine = ServerCmd.parseCommandLine(arguments); when(quotaProbe.getGlobalMaxStorage()).thenReturn(new SerializableQuotaValue<>(QuotaSize.size(1024L * 1024L * 1024L))); testee.executeCommandLine(commandLine); }
@Test public void getMaxStorageQuotaCommandShouldWork() throws Exception { String quotaroot = "#private&user@domain"; String[] arguments = { "-h", "127.0.0.1", "-p", "9999", CmdType.GETMAXSTORAGEQUOTA.getCommand(), quotaroot}; CommandLine commandLine = ServerCmd.parseCommandLine(arguments); when(quotaProbe.getMaxStorage(quotaroot)).thenReturn(new SerializableQuotaValue<>(QuotaSize.unlimited())); testee.executeCommandLine(commandLine); }
@Test public void getGlobalMaxMessageCountCommandShouldWork() throws Exception { String[] arguments = { "-h", "127.0.0.1", "-p", "9999", CmdType.GETGLOBALMAXMESSAGECOUNTQUOTA.getCommand()}; CommandLine commandLine = ServerCmd.parseCommandLine(arguments); when(quotaProbe.getGlobalMaxMessageCount()).thenReturn(new SerializableQuotaValue<>(QuotaCount.count(1024L * 1024L))); testee.executeCommandLine(commandLine); }
@Test public void getMaxMessageCountCommandShouldWork() throws Exception { String quotaroot = "#private&user@domain"; String[] arguments = { "-h", "127.0.0.1", "-p", "9999", CmdType.GETMAXMESSAGECOUNTQUOTA.getCommand(), quotaroot}; CommandLine commandLine = ServerCmd.parseCommandLine(arguments); when(quotaProbe.getMaxMessageCount(quotaroot)).thenReturn(new SerializableQuotaValue<>(QuotaCount.unlimited())); testee.executeCommandLine(commandLine); }
@Test public void setMaxMessageCountCommandShouldWork() throws Exception { String quotaroot = "#private&user@domain"; String[] arguments = { "-h", "127.0.0.1", "-p", "9999", CmdType.SETMAXMESSAGECOUNTQUOTA.getCommand(), quotaroot, "1000"}; CommandLine commandLine = ServerCmd.parseCommandLine(arguments); testee.executeCommandLine(commandLine); verify(quotaProbe).setMaxMessageCount(quotaroot, new SerializableQuotaValue<>(QuotaCount.count(1000))); }
@Test public void setGlobalMaxStorageCommandShouldWork() throws Exception { String[] arguments = { "-h", "127.0.0.1", "-p", "9999", CmdType.SETGLOBALMAXSTORAGEQUOTA.getCommand(), "1G"}; CommandLine commandLine = ServerCmd.parseCommandLine(arguments); testee.executeCommandLine(commandLine); verify(quotaProbe).setGlobalMaxStorage(new SerializableQuotaValue<>(QuotaSize.size(1024 * 1024 * 1024))); }
@Test public void setGlobalMaxStorageCommandShouldWorkWhenUnlimited() throws Exception { String[] arguments = { "-h", "127.0.0.1", "-p", "9999", "--", CmdType.SETGLOBALMAXSTORAGEQUOTA.getCommand(), "-1"}; CommandLine commandLine = ServerCmd.parseCommandLine(arguments); testee.executeCommandLine(commandLine); verify(quotaProbe).setGlobalMaxStorage(new SerializableQuotaValue<>(QuotaSize.unlimited())); }
@Test public void setMaxStorageCommandShouldWork() throws Exception { String quotaroot = "#private&user@domain"; String[] arguments = { "-h", "127.0.0.1", "-p", "9999", CmdType.SETMAXSTORAGEQUOTA.getCommand(), quotaroot, "5M"}; CommandLine commandLine = ServerCmd.parseCommandLine(arguments); testee.executeCommandLine(commandLine); verify(quotaProbe).setMaxStorage(quotaroot, new SerializableQuotaValue<>(QuotaSize.size(5 * 1024 * 1024))); }
@Test public void setGlobalMaxMessageCountCommandShouldWork() throws Exception { String[] arguments = { "-h", "127.0.0.1", "-p", "9999", CmdType.SETGLOBALMAXMESSAGECOUNTQUOTA.getCommand(), "1054"}; CommandLine commandLine = ServerCmd.parseCommandLine(arguments); testee.executeCommandLine(commandLine); verify(quotaProbe).setGlobalMaxMessageCount(new SerializableQuotaValue<>(QuotaCount.count(1054))); }
@Test public void setGlobalMaxMessageCountCommandShouldWorkWhenUnlimited() throws Exception { String[] arguments = { "-h", "127.0.0.1", "-p", "9999", "--", CmdType.SETGLOBALMAXMESSAGECOUNTQUOTA.getCommand(), "-1"}; CommandLine commandLine = ServerCmd.parseCommandLine(arguments); testee.executeCommandLine(commandLine); verify(quotaProbe).setGlobalMaxMessageCount(new SerializableQuotaValue<>(QuotaCount.unlimited())); }
@Test public void setMaxMessageCountCommandShouldWorkWhenUnlimited() throws Exception { String quotaroot = "#private&user@domain"; String[] arguments = { "-h", "127.0.0.1", "-p", "9999", "--", CmdType.SETMAXMESSAGECOUNTQUOTA.getCommand(), quotaroot, "-1"}; CommandLine commandLine = ServerCmd.parseCommandLine(arguments); testee.executeCommandLine(commandLine); verify(quotaProbe).setMaxMessageCount(quotaroot, new SerializableQuotaValue<>(QuotaCount.unlimited())); }
@Test public void setMaxStorageCommandShouldWorkWhenUnlimited() throws Exception { String quotaroot = "#private&user@domain"; String[] arguments = { "-h", "127.0.0.1", "-p", "9999", "--", CmdType.SETMAXSTORAGEQUOTA.getCommand(), quotaroot, "-1"}; CommandLine commandLine = ServerCmd.parseCommandLine(arguments); testee.executeCommandLine(commandLine); verify(quotaProbe).setMaxStorage(quotaroot, new SerializableQuotaValue<>(QuotaSize.unlimited())); }
@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 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"))); }