@Override public Optional<MailRepository> get(MailRepositoryUrl url) { if (urlStore.contains(url)) { return Optional.of(select(url)); } return Optional.empty(); }
@Test public void selectShouldNotAddUrlWhenProtocolDoNotExist() { assertThatThrownBy(() -> repositoryStore.select(UNKNOWN_PROTOCOL_REPO)); assertThat(urlStore.listDistinct()).isEmpty(); }
@Test public void selectingARegisteredProtocolShouldWork() { assertThat(repositoryStore.select(MEMORY1_REPO)) .isInstanceOf(MemoryMailRepository.class); }
@Test public void getByPathShouldReturnPreviouslyCreatedMatchingMailRepositories() { MailRepository mailRepositoryFile = repositoryStore.select(MEMORY1_REPO); MailRepository mailRepositoryArbitrary = repositoryStore.select(MEMORY2_REPO); assertThat(repositoryStore.getByPath(PATH_REPO)) .contains(mailRepositoryFile) .contains(mailRepositoryArbitrary); }
@Test public void getUrlsShouldReturnUsedUrls() { MailRepositoryUrl url1 = MailRepositoryUrl.from("memory1://repo1"); MailRepositoryUrl url2 = MailRepositoryUrl.from("memory1://repo2"); MailRepositoryUrl url3 = MailRepositoryUrl.from("memory1://repo3"); repositoryStore.select(url1); repositoryStore.select(url2); repositoryStore.select(url3); assertThat(repositoryStore.getUrls()).containsOnly(url1, url2, url3); }
@Test public void getByPathShouldReturnEmptyWhenNoMailRepositoriesAreMatching() { repositoryStore.select(MEMORY1_REPO); assertThat(repositoryStore.getByPath(MailRepositoryPath.from("unknown"))) .isEmpty(); }
@Test(expected = MailRepositoryStore.MailRepositoryStoreException.class) public void selectingANonRegisteredProtocolShouldFail() { repositoryStore.select(MailRepositoryUrl.from("proto://repo")); }
@Test public void getShouldReturnPreviouslyCreatedMailRepository() { MailRepository mailRepository = repositoryStore.select(MEMORY1_REPO); assertThat(repositoryStore.get(MEMORY1_REPO)) .contains(mailRepository); }
@Test public void getByPathShouldReturnPreviouslyCreatedMatchingMailRepository() { MailRepository mailRepository = repositoryStore.select(MEMORY1_REPO); assertThat(repositoryStore.getByPath(PATH_REPO)) .contains(mailRepository); }
@Test public void getPathsShouldReturnUsedUrls() { MailRepositoryPath path1 = MailRepositoryPath.from("repo1"); MailRepositoryPath path2 = MailRepositoryPath.from("repo1"); MailRepositoryPath path3 = MailRepositoryPath.from("repo1"); repositoryStore.select(MailRepositoryUrl.fromPathAndProtocol(path1, "memory1")); repositoryStore.select(MailRepositoryUrl.fromPathAndProtocol(path2, "memory1")); repositoryStore.select(MailRepositoryUrl.fromPathAndProtocol(path3, "memory1")); assertThat(repositoryStore.getPaths()).containsOnly(path1, path2, path3); }
@Test public void reprocessingShouldEmptyRepository() throws Exception { MailRepository repository = mailRepositoryStore.select(MailRepositoryUrl.fromPathAndProtocol(PATH, MEMORY_PROTOCOL)); repository.store(mail1); repository.store(mail2); repository.store(mail3); reprocessingService.reprocessAll(PATH, NO_TARGET_PROCESSOR, SPOOL, NOOP_CONSUMER); assertThat(repository.list()).isEmpty(); }
@Test public void reprocessingOneShouldRemoveMailFromRepository() throws Exception { MailRepository repository = mailRepositoryStore.select(MailRepositoryUrl.fromPathAndProtocol(PATH, MEMORY_PROTOCOL)); repository.store(mail1); repository.store(mail2); repository.store(mail3); reprocessingService.reprocess(PATH, KEY_2, NO_TARGET_PROCESSOR, SPOOL); assertThat(repository.list()).containsOnly(KEY_1, KEY_3); }
@Test public void reprocessingOneShouldEnqueueMail() throws Exception { MailRepository repository = mailRepositoryStore.select(MailRepositoryUrl.fromPathAndProtocol(PATH, MEMORY_PROTOCOL)); repository.store(mail1); repository.store(mail2); repository.store(mail3); reprocessingService.reprocess(PATH, KEY_2, NO_TARGET_PROCESSOR, SPOOL); assertThat(queueFactory.getQueue(SPOOL).get() .browse()) .extracting(item -> item.getMail().getName()) .containsOnly(NAME_2); }
@Test public void reprocessingShouldEnqueueAllMails() throws Exception { MailRepository repository = mailRepositoryStore.select(MailRepositoryUrl.fromPathAndProtocol(PATH, MEMORY_PROTOCOL)); repository.store(mail1); repository.store(mail2); repository.store(mail3); reprocessingService.reprocessAll(PATH, NO_TARGET_PROCESSOR, SPOOL, NOOP_CONSUMER); assertThat(queueFactory.getQueue(SPOOL).get() .browse()) .extracting(item -> item.getMail().getName()) .containsOnly(NAME_1, NAME_2, NAME_3); }
@Test void serviceShouldStoreMailInRepository() throws Exception { mailet.init(DEFAULT_MAILET_CONFIG); String mailName = "mailName"; mailet.service(FakeMail.builder() .name(mailName) .sender(MailAddressFixture.SENDER) .build()); MailRepository mailRepository = mailRepositoryStore.select(JAMES_LOCAL_REPOSITORY_URL); assertThat(mailRepository.list()) .extracting(mailRepository::retrieve) .extracting(Mail::getName) .containsOnly(mailName); }