@Test public void configureShouldNotThrowOnEmptyConfiguration() throws Exception { repositoryStore = new MemoryMailRepositoryStore(urlStore, Sets.newHashSet( new MemoryMailRepositoryProvider())); repositoryStore.configure(new HierarchicalConfiguration()); repositoryStore.init(); }
@Override public Optional<MailRepository> get(MailRepositoryUrl url) { if (urlStore.contains(url)) { return Optional.of(select(url)); } return Optional.empty(); }
@Test public void putMailRepositoryShouldReturnOkWhenRepositoryAlreadyExists() throws Exception { given() .params("protocol", "memory") .when() .put(PATH_ESCAPED_MY_REPO) .then() .statusCode(HttpStatus.NO_CONTENT_204); given() .params("protocol", "memory") .when() .put(PATH_ESCAPED_MY_REPO) .then() .statusCode(HttpStatus.NO_CONTENT_204); assertThat(mailRepositoryStore.get(URL_MY_REPO)) .isNotEmpty() .containsInstanceOf(MemoryMailRepository.class); assertThat(mailRepositoryStore.getByPath(PATH_MY_REPO)) .hasSize(1); }
@Test public void getShouldReturnEmptyWhenUrlNotInUse() { assertThat(repositoryStore.get(MEMORY1_REPO)) .isEmpty(); }
@Test public void getByPathShouldReturnEmptyWhenUrlNotInUse() { assertThat(repositoryStore.getByPath(PATH_REPO)) .isEmpty(); }
@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 getShouldReturnRepositoryWhenUrlExists() { urlStore.add(MEMORY1_REPO); assertThat(repositoryStore.get(MEMORY1_REPO)) .isNotEmpty(); }
@Test public void getByPathShouldReturnRepositoryWhenUrlExists() { urlStore.add(MEMORY1_REPO); assertThat(repositoryStore.getByPath(MEMORY1_REPO.getPath())) .isNotEmpty(); }
@Test public void configureShouldThrowWhenNonValidClassesAreProvided() throws Exception { repositoryStore = new MemoryMailRepositoryStore(urlStore, Sets.newHashSet( new MemoryMailRepositoryProvider())); repositoryStore.configure(new FileConfigurationProvider(fileSystem, configuration).getConfiguration("fakemailrepositorystore")); assertThatThrownBy(() -> repositoryStore.init()) .isInstanceOf(ConfigurationException.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 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 selectShouldNotReturnDifferentResultsWhenUsedInAConcurrentEnvironment() throws Exception { MailRepositoryUrl url = MailRepositoryUrl.from("memory1://repo"); int threadCount = 10; ConcurrentTestRunner.builder() .operation((threadNb, operationNb) -> repositoryStore.select(url) .store(FakeMail.builder() .name("name" + threadNb) .mimeMessage(MimeMessageBuilder.mimeMessageBuilder() .setText("Any body")) .build())) .threadCount(10) .runSuccessfullyWithin(Duration.ofMinutes(1)); long actualSize = repositoryStore.get(url).get().size(); assertThat(actualSize).isEqualTo(threadCount); }