@Test public void getShouldReturnEmptyWhenUrlNotInUse() { assertThat(repositoryStore.get(MEMORY1_REPO)) .isEmpty(); }
@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 getShouldReturnPreviouslyCreatedMailRepository() { MailRepository mailRepository = repositoryStore.select(MEMORY1_REPO); assertThat(repositoryStore.get(MEMORY1_REPO)) .contains(mailRepository); }
@Test public void getShouldReturnRepositoryWhenUrlExists() { urlStore.add(MEMORY1_REPO); assertThat(repositoryStore.get(MEMORY1_REPO)) .isNotEmpty(); }
@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); }
@Test public void putMailRepositoryShouldReturnOkWhenRepositoryIsCreated() { 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); }