james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [1/2] james-project git commit: JAMES-2425 Do not leak protocol over webadmin
Date Wed, 27 Jun 2018 13:51:04 GMT
Repository: james-project
Updated Branches:
  refs/heads/master c9f8c9c72 -> ee71575a6


http://git-wip-us.apache.org/repos/asf/james-project/blob/ee71575a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
index 4f752c9..c451ff4 100644
--- a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
@@ -59,6 +59,7 @@ import org.apache.james.core.MailAddress;
 import org.apache.james.core.builder.MimeMessageBuilder;
 import org.apache.james.core.builder.MimeMessageBuilder.BodyPartBuilder;
 import org.apache.james.mailrepository.api.MailKey;
+import org.apache.james.mailrepository.api.MailRepositoryPath;
 import org.apache.james.mailrepository.api.MailRepositoryStore;
 import org.apache.james.mailrepository.api.MailRepositoryUrl;
 import org.apache.james.mailrepository.memory.MemoryMailRepository;
@@ -86,6 +87,7 @@ import org.eclipse.jetty.http.HttpStatus;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.mockito.stubbing.Answer;
 
 import com.github.steveash.guavate.Guavate;
 import com.google.common.collect.ImmutableList;
@@ -97,14 +99,17 @@ import com.jayway.restassured.parsing.Parser;
 public class MailRepositoriesRoutesTest {
 
     private static final MailRepositoryUrl URL_MY_REPO = MailRepositoryUrl.from("url://myRepo");
-    private static final String URL_ESCAPED_MY_REPO = "url%3A%2F%2FmyRepo";
-    private static final String MY_REPO_MAILS = "url%3A%2F%2FmyRepo/mails";
+    private static final MailRepositoryPath PATH_MY_REPO = MailRepositoryPath.from("myRepo");
+    private static final String PATH_ESCAPED_MY_REPO = "myRepo";
+    private static final String MY_REPO_MAILS = "myRepo/mails";
     private static final String CUSTOM_QUEUE = "customQueue";
     private static final String NAME_1 = "name1";
     private static final String NAME_2 = "name2";
+    private static final Answer<?> RETURN_NO_MAIL_REPOSITORY = (invocation) -> Stream.empty();
     private WebAdminServer webAdminServer;
     private MailRepositoryStore mailRepositoryStore;
     private MemoryMailRepository mailRepository;
+    private Answer<?> returnMailRepository;
     private ManageableMailQueue spoolQueue;
     private ManageableMailQueue customQueue;
 
@@ -112,6 +117,7 @@ public class MailRepositoriesRoutesTest {
     public void setUp() throws Exception {
         mailRepositoryStore = mock(MailRepositoryStore.class);
         mailRepository = new MemoryMailRepository();
+        returnMailRepository = (invocation) -> Stream.of(mailRepository);
 
         MemoryTaskManager taskManager = new MemoryTaskManager();
         JsonTransformer jsonTransformer = new JsonTransformer();
@@ -144,8 +150,10 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void putMailRepositoryShouldReturnOkWhenRepositoryIsCreated() throws Exception {
-        when()
-            .put(URL_ESCAPED_MY_REPO)
+        given()
+            .parameters("protocol", "url")
+        .when()
+            .put(PATH_ESCAPED_MY_REPO)
         .then()
             .statusCode(HttpStatus.NO_CONTENT_204);
 
@@ -155,13 +163,17 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void putMailRepositoryShouldReturnOkWhenRepositoryAlreadyExists() throws Exception {
-        when()
-            .put(URL_ESCAPED_MY_REPO)
+        given()
+            .parameters("protocol", "url")
+        .when()
+            .put(PATH_ESCAPED_MY_REPO)
         .then()
             .statusCode(HttpStatus.NO_CONTENT_204);
 
-        when()
-            .put(URL_ESCAPED_MY_REPO)
+        given()
+            .parameters("protocol", "url")
+        .when()
+            .put(PATH_ESCAPED_MY_REPO)
         .then()
             .statusCode(HttpStatus.NO_CONTENT_204);
 
@@ -174,19 +186,21 @@ public class MailRepositoriesRoutesTest {
         when(mailRepositoryStore.create(any()))
             .thenThrow(new MailRepositoryStore.MailRepositoryStoreException("Error while selecting repository url://myRepo"));
 
-        when()
-            .put(URL_ESCAPED_MY_REPO)
+        given()
+            .parameters("protocol", "url")
+        .when()
+            .put(PATH_ESCAPED_MY_REPO)
         .then()
             .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
             .body("statusCode", is(500))
             .body("type", is(ErrorResponder.ErrorType.SERVER_ERROR.getType()))
-            .body("message", is("Error while creating a mail repository with url 'url://myRepo'"))
+            .body("message", is("Error while creating a mail repository with path 'myRepo' and protocol 'url'"))
             .body("details", is("Error while selecting repository url://myRepo"));
     }
 
     @Test
     public void getMailRepositoriesShouldReturnEmptyWhenEmpty() {
-        when(mailRepositoryStore.getUrls()).thenReturn(Stream.empty());
+        when(mailRepositoryStore.getPaths()).thenAnswer(RETURN_NO_MAIL_REPOSITORY);
 
         List<Object> mailRepositories =
             when()
@@ -204,22 +218,22 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void getMailRepositoriesShouldReturnRepositoryWhenOne() {
-        when(mailRepositoryStore.getUrls())
-            .thenReturn(Stream.of(URL_MY_REPO));
+        when(mailRepositoryStore.getPaths())
+            .thenAnswer((invocation) -> Stream.of(PATH_MY_REPO));
 
         when()
             .get()
         .then()
             .statusCode(HttpStatus.OK_200)
             .body("", hasSize(1))
-            .body("[0].repository", is(URL_MY_REPO.asString()))
-            .body("[0].id", is(URL_ESCAPED_MY_REPO));
+            .body("[0].repository", is(PATH_MY_REPO.asString()))
+            .body("[0].path", is(PATH_ESCAPED_MY_REPO));
     }
 
     @Test
     public void getMailRepositoriesShouldReturnTwoRepositoriesWhenTwo() {
-        ImmutableList<MailRepositoryUrl> myRepositories = ImmutableList.of(URL_MY_REPO, MailRepositoryUrl.from("url://mySecondRepo"));
-        when(mailRepositoryStore.getUrls())
+        ImmutableList<MailRepositoryPath> myRepositories = ImmutableList.of(PATH_MY_REPO, MailRepositoryPath.from("mySecondRepo"));
+        when(mailRepositoryStore.getPaths())
             .thenReturn(myRepositories.stream());
 
         List<String> mailRepositories =
@@ -235,24 +249,24 @@ public class MailRepositoriesRoutesTest {
 
         assertThat(mailRepositories)
             .containsOnlyElementsOf(myRepositories.stream()
-                .map(MailRepositoryUrl::asString)
+                .map(MailRepositoryPath::asString)
                 .collect(Guavate.toImmutableList()));
     }
 
     @Test
     public void listingKeysShouldReturnNotFoundWhenNoRepository() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.empty());
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(RETURN_NO_MAIL_REPOSITORY);
 
         when()
             .get(MY_REPO_MAILS)
         .then()
             .statusCode(HttpStatus.NOT_FOUND_404)
-            .body("message", is("The repository 'url%3A%2F%2FmyRepo' (decoded value: 'url://myRepo') does not exist"));
+            .body("message", is("myRepo does not exist"));
     }
 
     @Test
     public void listingKeysShouldReturnEmptyWhenNoMail() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
 
         when()
             .get(MY_REPO_MAILS)
@@ -263,7 +277,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void listingKeysShouldReturnContainedKeys() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
 
         mailRepository.store(FakeMail.builder()
             .name("name1")
@@ -282,7 +296,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void listingKeysShouldApplyLimitAndOffset() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
 
         mailRepository.store(FakeMail.builder()
             .name("name1")
@@ -307,7 +321,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void listingKeysShouldHandleErrorGracefully() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO))
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO))
             .thenThrow(new MailRepositoryStore.MailRepositoryStoreException("message"));
 
         when()
@@ -348,7 +362,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void listingKeysShouldReturnEmptyWhenOffsetExceedsSize() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
 
         mailRepository.store(FakeMail.builder()
             .name("name1")
@@ -397,7 +411,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void listingKeysShouldIgnoreZeroedOffset() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
 
         mailRepository.store(FakeMail.builder()
             .name(NAME_1)
@@ -431,33 +445,33 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void retrievingRepositoryShouldReturnNotFoundWhenNone() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.empty());
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(RETURN_NO_MAIL_REPOSITORY);
 
         given()
-            .get(URL_ESCAPED_MY_REPO)
+            .get(PATH_ESCAPED_MY_REPO)
         .then()
             .statusCode(HttpStatus.NOT_FOUND_404);
     }
 
     @Test
     public void retrievingRepositoryShouldReturnBasicInformation() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
 
         given()
-            .get(URL_ESCAPED_MY_REPO)
+            .get(PATH_ESCAPED_MY_REPO)
         .then()
             .statusCode(HttpStatus.OK_200)
             .contentType(ContentType.JSON)
-            .body("repository", is(URL_MY_REPO.asString()))
-            .body("id", is(URL_ESCAPED_MY_REPO));
+            .body("repository", is(PATH_MY_REPO.asString()))
+            .body("path", is(PATH_ESCAPED_MY_REPO));
     }
 
     @Test
     public void retrievingRepositorySizeShouldReturnZeroWhenEmpty() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
 
         given()
-            .get(URL_ESCAPED_MY_REPO)
+            .get(PATH_ESCAPED_MY_REPO)
         .then()
             .statusCode(HttpStatus.OK_200)
             .contentType(ContentType.JSON)
@@ -466,14 +480,14 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void retrievingRepositorySizeShouldReturnNumberOfContainedMails() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
 
         mailRepository.store(FakeMail.builder()
             .name(NAME_1)
             .build());
 
         given()
-            .get(URL_ESCAPED_MY_REPO)
+            .get(PATH_ESCAPED_MY_REPO)
         .then()
             .statusCode(HttpStatus.OK_200)
             .contentType(ContentType.JSON)
@@ -482,7 +496,8 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void retrievingAMailShouldDisplayItsInformation() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
+
         String name = NAME_1;
         String sender = "sender@domain";
         String recipient1 = "recipient1@domain";
@@ -504,7 +519,7 @@ public class MailRepositoriesRoutesTest {
             .build());
 
         when()
-            .get(URL_ESCAPED_MY_REPO + "/mails/" + name)
+            .get(PATH_ESCAPED_MY_REPO + "/mails/" + name)
         .then()
             .statusCode(HttpStatus.OK_200)
             .body("name", is(name))
@@ -520,7 +535,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void retrievingAMailShouldDisplayAllAdditionalFieldsWhenRequested() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
         String name = NAME_1;
 
         BodyPartBuilder textMessage = MimeMessageBuilder.bodyPartBuilder()
@@ -571,7 +586,7 @@ public class MailRepositoriesRoutesTest {
             given()
                 .parameters("additionalFields", "attributes,headers,textBody,htmlBody,messageSize,perRecipientsHeaders")
             .when()
-                .get(URL_ESCAPED_MY_REPO + "/mails/" + name)
+            .get(PATH_ESCAPED_MY_REPO + "/mails/" + NAME_1)
             .then()
             .extract()
                 .body()
@@ -623,7 +638,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void retrievingAMailShouldDisplayAllValidAdditionalFieldsWhenRequested() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
         String name = NAME_1;
         String sender = "sender@domain";
         String recipient1 = "recipient1@domain";
@@ -638,7 +653,7 @@ public class MailRepositoriesRoutesTest {
         given()
             .parameters("additionalFields", ",,,messageSize")
         .when()
-            .get(URL_ESCAPED_MY_REPO + "/mails/" + name)
+            .get(PATH_ESCAPED_MY_REPO + "/mails/" + NAME_1)
         .then()
             .statusCode(HttpStatus.OK_200)
             .body("name", is(name))
@@ -653,7 +668,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void retrievingAMailShouldDisplayCorrectlyEncodedHeadersInValidAdditionalFieldsWhenRequested() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
         String name = NAME_1;
         String sender = "sender@domain";
         String recipient1 = "recipient1@domain";
@@ -671,7 +686,7 @@ public class MailRepositoriesRoutesTest {
         given()
             .parameters("additionalFields", "headers")
         .when()
-            .get(URL_ESCAPED_MY_REPO + "/mails/" + name)
+            .get(PATH_ESCAPED_MY_REPO + "/mails/" + NAME_1)
         .then()
             .statusCode(HttpStatus.OK_200)
             .body("name", is(name))
@@ -681,7 +696,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void retrievingAMailShouldDisplayAllValidAdditionalFieldsEvenTheDuplicatedOnesWhenRequested() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
         String name = NAME_1;
         String sender = "sender@domain";
         String recipient1 = "recipient1@domain";
@@ -696,7 +711,7 @@ public class MailRepositoriesRoutesTest {
         given()
             .parameters("additionalFields", "messageSize,messageSize")
         .when()
-            .get(URL_ESCAPED_MY_REPO + "/mails/" + name)
+            .get(PATH_ESCAPED_MY_REPO + "/mails/" + NAME_1)
         .then()
             .statusCode(HttpStatus.OK_200)
             .body("name", is(name))
@@ -711,7 +726,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void retrievingAMailShouldFailWhenAnUnknownFieldIsRequested() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
         String name = NAME_1;
         String sender = "sender@domain";
         String recipient1 = "recipient1@domain";
@@ -726,7 +741,7 @@ public class MailRepositoriesRoutesTest {
         given()
             .parameters("additionalFields", "nonExistingField")
         .when()
-            .get(URL_ESCAPED_MY_REPO + "/mails/" + name)
+            .get(PATH_ESCAPED_MY_REPO + "/mails/" + NAME_1)
         .then()
             .statusCode(HttpStatus.BAD_REQUEST_400)
             .body("statusCode", is(400))
@@ -736,14 +751,14 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void retrievingAMailShouldNotFailWhenOnlyNameProperty() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
 
         mailRepository.store(FakeMail.builder()
             .name(NAME_1)
             .build());
 
         when()
-            .get(URL_ESCAPED_MY_REPO + "/mails/" + NAME_1)
+            .get(PATH_ESCAPED_MY_REPO + "/mails/" + NAME_1)
         .then()
             .statusCode(HttpStatus.OK_200)
             .body("name", is(NAME_1))
@@ -755,11 +770,11 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void retrievingAMailShouldFailWhenUnknown() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
 
         String name = "name";
         when()
-            .get(URL_ESCAPED_MY_REPO + "/mails/" + name)
+            .get(PATH_ESCAPED_MY_REPO + "/mails/" + name)
         .then()
             .statusCode(HttpStatus.NOT_FOUND_404)
             .body("statusCode", is(404))
@@ -774,7 +789,7 @@ public class MailRepositoriesRoutesTest {
                 .build();
         RestAssured.registerParser(Constants.RFC822_CONTENT_TYPE, Parser.TEXT);
 
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
 
         String name = NAME_1;
         FakeMail mail = FakeMail.builder()
@@ -788,7 +803,7 @@ public class MailRepositoriesRoutesTest {
         String actualContent = given()
             .accept(Constants.RFC822_CONTENT_TYPE)
         .when()
-            .get(URL_ESCAPED_MY_REPO + "/mails/" + name)
+            .get(PATH_ESCAPED_MY_REPO + "/mails/" + name)
         .then()
             .statusCode(HttpStatus.OK_200)
             .header("Content-Length", "471")
@@ -807,13 +822,13 @@ public class MailRepositoriesRoutesTest {
             .build();
         RestAssured.registerParser(Constants.RFC822_CONTENT_TYPE, Parser.TEXT);
 
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
 
         String name = "name";
         given()
             .accept(Constants.RFC822_CONTENT_TYPE)
         .when()
-            .get(URL_ESCAPED_MY_REPO + "/mails/" + name)
+            .get(PATH_ESCAPED_MY_REPO + "/mails/" + name)
         .then()
             .statusCode(HttpStatus.NOT_FOUND_404)
             .body("statusCode", is(404))
@@ -823,7 +838,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void deletingAMailShouldRemoveIt() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
 
         mailRepository.store(FakeMail.builder()
             .name(NAME_1)
@@ -833,10 +848,10 @@ public class MailRepositoriesRoutesTest {
             .build());
 
         given()
-            .delete(URL_ESCAPED_MY_REPO + "/mails/" + NAME_1);
+            .delete(PATH_ESCAPED_MY_REPO + "/mails/" + NAME_1);
 
         when()
-            .get(URL_ESCAPED_MY_REPO + "/mails")
+            .get(PATH_ESCAPED_MY_REPO + "/mails")
             .then()
             .statusCode(HttpStatus.OK_200)
             .body("", hasSize(1))
@@ -845,34 +860,34 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void deletingAMailShouldReturnOkWhenExist() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
 
         mailRepository.store(FakeMail.builder()
             .name(NAME_1)
             .build());
 
         when()
-            .delete(URL_ESCAPED_MY_REPO + "/mails/" + NAME_1)
+            .delete(PATH_ESCAPED_MY_REPO + "/mails/" + NAME_1)
         .then()
             .statusCode(HttpStatus.NO_CONTENT_204);
     }
 
     @Test
     public void deletingAMailShouldReturnOkWhenNotExist() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
 
         when()
-            .delete(URL_ESCAPED_MY_REPO + "/mails/name")
+            .delete(PATH_ESCAPED_MY_REPO + "/mails/name")
         .then()
             .statusCode(HttpStatus.NO_CONTENT_204);
     }
 
     @Test
     public void deletingAllMailsShouldCreateATask() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
 
         when()
-            .delete(URL_ESCAPED_MY_REPO + "/mails")
+            .delete(PATH_ESCAPED_MY_REPO + "/mails")
         .then()
             .statusCode(HttpStatus.CREATED_201)
             .header("Location", is(notNullValue()))
@@ -881,7 +896,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void clearTaskShouldHaveDetails() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
 
         mailRepository.store(FakeMail.builder()
             .name(NAME_1)
@@ -891,7 +906,7 @@ public class MailRepositoriesRoutesTest {
             .build());
 
         String taskId = with()
-            .delete(URL_ESCAPED_MY_REPO + "/mails")
+            .delete(PATH_ESCAPED_MY_REPO + "/mails")
             .jsonPath()
             .get("taskId");
 
@@ -903,7 +918,7 @@ public class MailRepositoriesRoutesTest {
             .body("status", is("completed"))
             .body("taskId", is(notNullValue()))
             .body("type", is(ClearMailRepositoryTask.TYPE))
-            .body("additionalInformation.repositoryUrl", is(URL_MY_REPO.asString()))
+            .body("additionalInformation.repositoryPath", is(PATH_MY_REPO.asString()))
             .body("additionalInformation.initialCount", is(2))
             .body("additionalInformation.remainingCount", is(0))
             .body("startedDate", is(notNullValue()))
@@ -913,7 +928,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void clearTaskShouldRemoveAllTheMailsFromTheMailRepository() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
 
         mailRepository.store(FakeMail.builder()
             .name(NAME_1)
@@ -923,7 +938,7 @@ public class MailRepositoriesRoutesTest {
             .build());
 
         String taskId = with()
-            .delete(URL_ESCAPED_MY_REPO + "/mails")
+            .delete(PATH_ESCAPED_MY_REPO + "/mails")
             .jsonPath()
             .get("taskId");
 
@@ -932,7 +947,7 @@ public class MailRepositoriesRoutesTest {
             .get(taskId + "/await");
 
         when()
-            .get(URL_ESCAPED_MY_REPO + "/mails")
+            .get(PATH_ESCAPED_MY_REPO + "/mails")
         .then()
             .statusCode(HttpStatus.OK_200)
             .body("", hasSize(0));
@@ -940,38 +955,38 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void patchShouldReturnNotFoundWhenNoMailRepository() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.empty());
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(RETURN_NO_MAIL_REPOSITORY);
 
         when()
-            .delete(URL_ESCAPED_MY_REPO + "/mails")
+            .delete(PATH_ESCAPED_MY_REPO + "/mails")
         .then()
             .statusCode(HttpStatus.NOT_FOUND_404)
             .body("statusCode", is(404))
             .body("type", is(ErrorResponder.ErrorType.NOT_FOUND.getType()))
-            .body("message", is(URL_MY_REPO.asString() + " does not exist"));
+            .body("message", is(PATH_MY_REPO.asString() + " does not exist"));
     }
 
     @Test
     public void deleteShouldReturnNotFoundWhenNoMailRepository() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.empty());
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(RETURN_NO_MAIL_REPOSITORY);
 
         when()
-            .delete(URL_ESCAPED_MY_REPO + "/mails/any")
+            .delete(PATH_ESCAPED_MY_REPO + "/mails/any")
         .then()
             .statusCode(HttpStatus.NOT_FOUND_404)
             .body("statusCode", is(404))
             .body("type", is(ErrorResponder.ErrorType.NOT_FOUND.getType()))
-            .body("message", is(URL_MY_REPO.asString() + " does not exist"));
+            .body("message", is(PATH_MY_REPO.asString() + " does not exist"));
     }
 
     @Test
     public void reprocessingAllTaskShouldCreateATask() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
 
         given()
             .param("action", "reprocess")
         .when()
-            .patch(URL_ESCAPED_MY_REPO + "/mails")
+            .patch(PATH_ESCAPED_MY_REPO + "/mails")
         .then()
             .statusCode(HttpStatus.CREATED_201)
             .header("Location", is(notNullValue()))
@@ -985,7 +1000,7 @@ public class MailRepositoriesRoutesTest {
         given()
             .param("action", "invalid")
         .when()
-            .patch(URL_ESCAPED_MY_REPO + "/mails")
+            .patch(PATH_ESCAPED_MY_REPO + "/mails")
         .then()
             .statusCode(HttpStatus.BAD_REQUEST_400)
             .body("statusCode", is(400))
@@ -998,7 +1013,7 @@ public class MailRepositoriesRoutesTest {
         when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
 
         when()
-            .patch(URL_ESCAPED_MY_REPO + "/mails")
+            .patch(PATH_ESCAPED_MY_REPO + "/mails")
         .then()
             .statusCode(HttpStatus.BAD_REQUEST_400)
             .body("statusCode", is(400))
@@ -1008,7 +1023,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void reprocessingAllTaskShouldIncludeDetailsWhenDefaultValues() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
         mailRepository.store(FakeMail.builder()
             .name(NAME_1)
             .build());
@@ -1018,7 +1033,7 @@ public class MailRepositoriesRoutesTest {
 
         String taskId = with()
             .param("action", "reprocess")
-            .patch(URL_ESCAPED_MY_REPO + "/mails")
+            .patch(PATH_ESCAPED_MY_REPO + "/mails")
             .jsonPath()
             .get("taskId");
 
@@ -1030,7 +1045,7 @@ public class MailRepositoriesRoutesTest {
             .body("status", is("completed"))
             .body("taskId", is(notNullValue()))
             .body("type", is(ReprocessingAllMailsTask.TYPE))
-            .body("additionalInformation.repositoryUrl", is(URL_MY_REPO.asString()))
+            .body("additionalInformation.repositoryPath", is(PATH_MY_REPO.asString()))
             .body("additionalInformation.initialCount", is(2))
             .body("additionalInformation.remainingCount", is(0))
             .body("additionalInformation.targetProcessor", isEmptyOrNullString())
@@ -1042,7 +1057,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void reprocessingAllTaskShouldIncludeDetails() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
         String name1 = "name1";
         String name2 = "name2";
         mailRepository.store(FakeMail.builder()
@@ -1057,7 +1072,7 @@ public class MailRepositoriesRoutesTest {
             .param("action", "reprocess")
             .param("queue", CUSTOM_QUEUE)
             .param("processor", transport)
-            .patch(URL_ESCAPED_MY_REPO + "/mails")
+            .patch(PATH_ESCAPED_MY_REPO + "/mails")
             .jsonPath()
             .get("taskId");
 
@@ -1069,7 +1084,7 @@ public class MailRepositoriesRoutesTest {
             .body("status", is("completed"))
             .body("taskId", is(notNullValue()))
             .body("type", is(ReprocessingAllMailsTask.TYPE))
-            .body("additionalInformation.repositoryUrl", is(URL_MY_REPO.asString()))
+            .body("additionalInformation.repositoryPath", is(PATH_MY_REPO.asString()))
             .body("additionalInformation.initialCount", is(2))
             .body("additionalInformation.remainingCount", is(0))
             .body("additionalInformation.targetProcessor", is(transport))
@@ -1081,7 +1096,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void reprocessingAllTaskShouldClearMailRepository() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
         String name1 = "name1";
         String name2 = "name2";
         mailRepository.store(FakeMail.builder()
@@ -1096,7 +1111,7 @@ public class MailRepositoriesRoutesTest {
             .param("action", "reprocess")
             .param("queue", CUSTOM_QUEUE)
             .param("processor", transport)
-            .patch(URL_ESCAPED_MY_REPO + "/mails")
+            .patch(PATH_ESCAPED_MY_REPO + "/mails")
             .jsonPath()
             .get("taskId");
 
@@ -1109,7 +1124,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void reprocessingAllTaskShouldEnqueueMailsOnDefaultQueue() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
         mailRepository.store(FakeMail.builder()
             .name(NAME_1)
             .build());
@@ -1119,7 +1134,7 @@ public class MailRepositoriesRoutesTest {
 
         String taskId = with()
             .param("action", "reprocess")
-            .patch(URL_ESCAPED_MY_REPO + "/mails")
+            .patch(PATH_ESCAPED_MY_REPO + "/mails")
             .jsonPath()
             .get("taskId");
 
@@ -1135,7 +1150,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void reprocessingAllTaskShouldPreserveStateWhenProcessorIsNotSpecified() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
         String state1 = "state1";
         String state2 = "state2";
         mailRepository.store(FakeMail.builder()
@@ -1149,7 +1164,7 @@ public class MailRepositoriesRoutesTest {
 
         String taskId = with()
             .param("action", "reprocess")
-            .patch(URL_ESCAPED_MY_REPO + "/mails")
+            .patch(PATH_ESCAPED_MY_REPO + "/mails")
             .jsonPath()
             .get("taskId");
 
@@ -1165,7 +1180,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void reprocessingAllTaskShouldOverWriteStateWhenProcessorSpecified() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
         String state1 = "state1";
         String state2 = "state2";
         mailRepository.store(FakeMail.builder()
@@ -1181,7 +1196,7 @@ public class MailRepositoriesRoutesTest {
         String taskId = with()
             .param("action", "reprocess")
             .param("processor", transport)
-            .patch(URL_ESCAPED_MY_REPO + "/mails")
+            .patch(PATH_ESCAPED_MY_REPO + "/mails")
             .jsonPath()
             .get("taskId");
 
@@ -1197,7 +1212,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void reprocessingAllTaskShouldEnqueueMailsOnSpecifiedQueue() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
         mailRepository.store(FakeMail.builder()
             .name(NAME_1)
             .build());
@@ -1208,7 +1223,7 @@ public class MailRepositoriesRoutesTest {
         String taskId = with()
             .param("action", "reprocess")
             .param("queue", CUSTOM_QUEUE)
-            .patch(URL_ESCAPED_MY_REPO + "/mails")
+            .patch(PATH_ESCAPED_MY_REPO + "/mails")
             .jsonPath()
             .get("taskId");
 
@@ -1233,7 +1248,7 @@ public class MailRepositoriesRoutesTest {
         given()
             .param("action", "reprocess")
         .when()
-            .patch(URL_ESCAPED_MY_REPO + "/mails/name1")
+            .patch(PATH_ESCAPED_MY_REPO + "/mails/name1")
         .then()
             .statusCode(HttpStatus.CREATED_201)
             .header("Location", is(notNullValue()))
@@ -1251,7 +1266,7 @@ public class MailRepositoriesRoutesTest {
         given()
             .param("action", "invalid")
         .when()
-            .patch(URL_ESCAPED_MY_REPO + "/mails/" + NAME_1)
+            .patch(PATH_ESCAPED_MY_REPO + "/mails/" + NAME_1)
         .then()
             .statusCode(HttpStatus.BAD_REQUEST_400)
             .body("statusCode", is(400))
@@ -1268,7 +1283,7 @@ public class MailRepositoriesRoutesTest {
             .build());
 
         when()
-            .patch(URL_ESCAPED_MY_REPO + "/mails/" + NAME_1)
+            .patch(PATH_ESCAPED_MY_REPO + "/mails/" + NAME_1)
         .then()
             .statusCode(HttpStatus.BAD_REQUEST_400)
             .body("statusCode", is(400))
@@ -1278,7 +1293,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void reprocessingOneTaskShouldIncludeDetailsWhenDefaultValues() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
         String name1 = "name1";
         String name2 = "name2";
         mailRepository.store(FakeMail.builder()
@@ -1290,7 +1305,7 @@ public class MailRepositoriesRoutesTest {
 
         String taskId = with()
             .param("action", "reprocess")
-            .patch(URL_ESCAPED_MY_REPO + "/mails/" + NAME_1)
+            .patch(PATH_ESCAPED_MY_REPO + "/mails/" + NAME_1)
             .jsonPath()
             .get("taskId");
 
@@ -1302,7 +1317,7 @@ public class MailRepositoriesRoutesTest {
             .body("status", is("completed"))
             .body("taskId", is(notNullValue()))
             .body("type", is(ReprocessingOneMailTask.TYPE))
-            .body("additionalInformation.repositoryUrl", is(URL_MY_REPO.asString()))
+            .body("additionalInformation.repositoryPath", is(PATH_MY_REPO.asString()))
             .body("additionalInformation.mailKey", is(NAME_1))
             .body("additionalInformation.targetProcessor", isEmptyOrNullString())
             .body("additionalInformation.targetQueue", is(MailQueueFactory.SPOOL))
@@ -1313,7 +1328,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void reprocessingOneTaskShouldIncludeDetails() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
         String name1 = "name1";
         String name2 = "name2";
         mailRepository.store(FakeMail.builder()
@@ -1328,7 +1343,7 @@ public class MailRepositoriesRoutesTest {
             .param("action", "reprocess")
             .param("queue", CUSTOM_QUEUE)
             .param("processor", transport)
-            .patch(URL_ESCAPED_MY_REPO + "/mails/" + NAME_1)
+            .patch(PATH_ESCAPED_MY_REPO + "/mails/" + NAME_1)
             .jsonPath()
             .get("taskId");
 
@@ -1340,7 +1355,7 @@ public class MailRepositoriesRoutesTest {
             .body("status", is("completed"))
             .body("taskId", is(notNullValue()))
             .body("type", is(ReprocessingOneMailTask.TYPE))
-            .body("additionalInformation.repositoryUrl", is(URL_MY_REPO.asString()))
+            .body("additionalInformation.repositoryPath", is(PATH_MY_REPO.asString()))
             .body("additionalInformation.mailKey", is(NAME_1))
             .body("additionalInformation.targetProcessor", is(transport))
             .body("additionalInformation.targetQueue", is(CUSTOM_QUEUE))
@@ -1351,7 +1366,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void reprocessingOneTaskShouldRemoveMailFromRepository() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
         String name1 = "name1";
         String name2 = "name2";
         mailRepository.store(FakeMail.builder()
@@ -1366,7 +1381,7 @@ public class MailRepositoriesRoutesTest {
             .param("action", "reprocess")
             .param("queue", CUSTOM_QUEUE)
             .param("processor", transport)
-            .patch(URL_ESCAPED_MY_REPO + "/mails/" + NAME_1)
+            .patch(PATH_ESCAPED_MY_REPO + "/mails/" + NAME_1)
             .jsonPath()
             .get("taskId");
 
@@ -1380,7 +1395,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void reprocessingOneTaskShouldEnqueueMailsOnDefaultQueue() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
         mailRepository.store(FakeMail.builder()
             .name(NAME_1)
             .build());
@@ -1390,7 +1405,7 @@ public class MailRepositoriesRoutesTest {
 
         String taskId = with()
             .param("action", "reprocess")
-            .patch(URL_ESCAPED_MY_REPO + "/mails/" + NAME_1)
+            .patch(PATH_ESCAPED_MY_REPO + "/mails/" + NAME_1)
             .jsonPath()
             .get("taskId");
 
@@ -1406,7 +1421,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void reprocessingOneTaskShouldPreserveStateWhenProcessorIsNotSpecified() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
         String state1 = "state1";
         String state2 = "state2";
         mailRepository.store(FakeMail.builder()
@@ -1420,7 +1435,7 @@ public class MailRepositoriesRoutesTest {
 
         String taskId = with()
             .param("action", "reprocess")
-            .patch(URL_ESCAPED_MY_REPO + "/mails/" + NAME_1)
+            .patch(PATH_ESCAPED_MY_REPO + "/mails/" + NAME_1)
             .jsonPath()
             .get("taskId");
 
@@ -1436,7 +1451,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void reprocessingOneTaskShouldOverWriteStateWhenProcessorSpecified() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
         String state1 = "state1";
         String state2 = "state2";
         mailRepository.store(FakeMail.builder()
@@ -1452,7 +1467,7 @@ public class MailRepositoriesRoutesTest {
         String taskId = with()
             .param("action", "reprocess")
             .param("processor", transport)
-            .patch(URL_ESCAPED_MY_REPO + "/mails/" + NAME_1)
+            .patch(PATH_ESCAPED_MY_REPO + "/mails/" + NAME_1)
             .jsonPath()
             .get("taskId");
 
@@ -1468,7 +1483,7 @@ public class MailRepositoriesRoutesTest {
 
     @Test
     public void reprocessingOneTaskShouldEnqueueMailsOnSpecifiedQueue() throws Exception {
-        when(mailRepositoryStore.get(URL_MY_REPO)).thenReturn(Optional.of(mailRepository));
+        when(mailRepositoryStore.getByPath(PATH_MY_REPO)).thenAnswer(returnMailRepository);
         mailRepository.store(FakeMail.builder()
             .name(NAME_1)
             .build());
@@ -1479,7 +1494,7 @@ public class MailRepositoriesRoutesTest {
         String taskId = with()
             .param("action", "reprocess")
             .param("queue", CUSTOM_QUEUE)
-            .patch(URL_ESCAPED_MY_REPO + "/mails/" + NAME_1)
+            .patch(PATH_ESCAPED_MY_REPO + "/mails/" + NAME_1)
             .jsonPath()
             .get("taskId");
 
@@ -1506,7 +1521,7 @@ public class MailRepositoriesRoutesTest {
         String taskId = with()
             .param("action", "reprocess")
             .param("queue", CUSTOM_QUEUE)
-            .patch(URL_ESCAPED_MY_REPO + "/mails/" + "unknown")
+            .patch(PATH_ESCAPED_MY_REPO + "/mails/" + "unknown")
             .jsonPath()
             .get("taskId");
 
@@ -1531,7 +1546,7 @@ public class MailRepositoriesRoutesTest {
         String taskId = with()
             .param("action", "reprocess")
             .param("queue", CUSTOM_QUEUE)
-            .patch(URL_ESCAPED_MY_REPO + "/mails/" + "unknown")
+            .patch(PATH_ESCAPED_MY_REPO + "/mails/" + "unknown")
             .jsonPath()
             .get("taskId");
 
@@ -1556,7 +1571,7 @@ public class MailRepositoriesRoutesTest {
         String taskId = with()
             .param("action", "reprocess")
             .param("queue", CUSTOM_QUEUE)
-            .patch(URL_ESCAPED_MY_REPO + "/mails/" + "unknown")
+            .patch(PATH_ESCAPED_MY_REPO + "/mails/" + "unknown")
             .jsonPath()
             .get("taskId");
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/ee71575a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/MailRepositoryStoreServiceTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/MailRepositoryStoreServiceTest.java b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/MailRepositoryStoreServiceTest.java
index b505244..6fac837 100644
--- a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/MailRepositoryStoreServiceTest.java
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/MailRepositoryStoreServiceTest.java
@@ -31,22 +31,22 @@ import javax.mail.internet.MimeMessage;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.james.mailrepository.api.MailKey;
+import org.apache.james.mailrepository.api.MailRepositoryPath;
 import org.apache.james.mailrepository.api.MailRepositoryStore;
-import org.apache.james.mailrepository.api.MailRepositoryUrl;
 import org.apache.james.mailrepository.memory.MemoryMailRepository;
 import org.apache.james.server.core.MimeMessageInputStream;
 import org.apache.james.util.ClassLoaderUtils;
 import org.apache.james.util.streams.Limit;
 import org.apache.james.util.streams.Offset;
 import org.apache.james.webadmin.dto.MailKeyDTO;
-import org.apache.james.webadmin.dto.MailRepositoryResponse;
+import org.apache.james.webadmin.dto.SingleMailRepositoryResponse;
 import org.apache.mailet.base.test.FakeMail;
 import org.junit.Before;
 import org.junit.Test;
 
 public class MailRepositoryStoreServiceTest {
-    private static final MailRepositoryUrl FIRST_REPOSITORY = MailRepositoryUrl.from("url://repository");
-    private static final MailRepositoryUrl SECOND_REPOSITORY = MailRepositoryUrl.from("url://repository2");
+    private static final MailRepositoryPath FIRST_REPOSITORY_PATH = MailRepositoryPath.from("repository");
+    private static final MailRepositoryPath SECOND_REPOSITORY_PATH = MailRepositoryPath.from("repository2");
     private static final MailKey NAME_1 = new MailKey("name1");
     private static final MailKey NAME_2 = new MailKey("name2");
 
@@ -63,49 +63,49 @@ public class MailRepositoryStoreServiceTest {
 
     @Test
     public void listMailRepositoriesShouldReturnEmptyWhenEmpty() {
-        when(mailRepositoryStore.getUrls()).thenReturn(Stream.empty());
+        when(mailRepositoryStore.getPaths()).thenReturn(Stream.empty());
 
         assertThat(testee.listMailRepositories()).isEmpty();
     }
 
     @Test
     public void listMailRepositoriesShouldReturnOneRepositoryWhenOne() {
-        when(mailRepositoryStore.getUrls())
-            .thenReturn(Stream.of(FIRST_REPOSITORY));
+        when(mailRepositoryStore.getPaths())
+            .thenReturn(Stream.of(FIRST_REPOSITORY_PATH));
         assertThat(testee.listMailRepositories())
-            .extracting(MailRepositoryResponse::getRepository)
-            .containsOnly(FIRST_REPOSITORY.asString());
+            .extracting(SingleMailRepositoryResponse::getRepository)
+            .containsOnly(FIRST_REPOSITORY_PATH.asString());
     }
 
     @Test
     public void listMailRepositoriesShouldReturnTwoRepositoriesWhentwo() {
-        when(mailRepositoryStore.getUrls())
-            .thenReturn(Stream.of(FIRST_REPOSITORY, SECOND_REPOSITORY));
+        when(mailRepositoryStore.getPaths())
+            .thenReturn(Stream.of(FIRST_REPOSITORY_PATH, SECOND_REPOSITORY_PATH));
         assertThat(testee.listMailRepositories())
-            .extracting(MailRepositoryResponse::getRepository)
-            .containsOnly(FIRST_REPOSITORY.asString(), SECOND_REPOSITORY.asString());
+            .extracting(SingleMailRepositoryResponse::getRepository)
+            .containsOnly(FIRST_REPOSITORY_PATH.asString(), SECOND_REPOSITORY_PATH.asString());
     }
 
     @Test
     public void listMailsShouldThrowWhenMailRepositoryStoreThrows() throws Exception {
-        when(mailRepositoryStore.get(FIRST_REPOSITORY))
+        when(mailRepositoryStore.getByPath(FIRST_REPOSITORY_PATH))
             .thenThrow(new MailRepositoryStore.MailRepositoryStoreException("message"));
 
-        assertThatThrownBy(() -> testee.listMails(FIRST_REPOSITORY, Offset.none(), Limit.unlimited()))
+        assertThatThrownBy(() -> testee.listMails(FIRST_REPOSITORY_PATH, Offset.none(), Limit.unlimited()))
             .isInstanceOf(MailRepositoryStore.MailRepositoryStoreException.class);
     }
 
     @Test
     public void listMailsShouldReturnEmptyWhenMailRepositoryIsEmpty() throws Exception {
-        when(mailRepositoryStore.get(FIRST_REPOSITORY)).thenReturn(Optional.of(repository));
+        when(mailRepositoryStore.getByPath(FIRST_REPOSITORY_PATH)).thenReturn(Stream.of(repository));
 
-        assertThat(testee.listMails(FIRST_REPOSITORY, Offset.none(), Limit.unlimited()).get())
+        assertThat(testee.listMails(FIRST_REPOSITORY_PATH, Offset.none(), Limit.unlimited()).get())
             .isEmpty();
     }
 
     @Test
     public void listMailsShouldReturnContainedMailKeys() throws Exception {
-        when(mailRepositoryStore.get(FIRST_REPOSITORY)).thenReturn(Optional.of(repository));
+        when(mailRepositoryStore.getByPath(FIRST_REPOSITORY_PATH)).thenReturn(Stream.of(repository));
 
         repository.store(FakeMail.builder()
             .name(NAME_1.asString())
@@ -114,13 +114,13 @@ public class MailRepositoryStoreServiceTest {
             .name(NAME_2.asString())
             .build());
 
-        assertThat(testee.listMails(FIRST_REPOSITORY, Offset.none(), Limit.unlimited()).get())
+        assertThat(testee.listMails(FIRST_REPOSITORY_PATH, Offset.none(), Limit.unlimited()).get())
             .containsOnly(new MailKeyDTO(NAME_1), new MailKeyDTO(NAME_2));
     }
 
     @Test
     public void listMailsShouldApplyLimitAndOffset() throws Exception {
-        when(mailRepositoryStore.get(FIRST_REPOSITORY)).thenReturn(Optional.of(repository));
+        when(mailRepositoryStore.getByPath(FIRST_REPOSITORY_PATH)).thenReturn(Stream.of(repository));
 
         repository.store(FakeMail.builder()
             .name(NAME_1.asString())
@@ -132,38 +132,38 @@ public class MailRepositoryStoreServiceTest {
             .name("name3")
             .build());
 
-        assertThat(testee.listMails(FIRST_REPOSITORY, Offset.from(1), Limit.from(1)).get())
+        assertThat(testee.listMails(FIRST_REPOSITORY_PATH, Offset.from(1), Limit.from(1)).get())
             .containsOnly(new MailKeyDTO(NAME_2));
     }
 
     @Test
     public void retrieveMessageShouldThrownWhenUnknownRepository() throws Exception {
-        when(mailRepositoryStore.get(MailRepositoryUrl.from("proto://unkown"))).thenReturn(Optional.empty());
+        when(mailRepositoryStore.getByPath(FIRST_REPOSITORY_PATH)).thenReturn(Stream.of());
 
-        assertThatThrownBy(() -> testee.retrieveMessage(FIRST_REPOSITORY, NAME_1))
-            .isInstanceOf(NullPointerException.class);
+        assertThatThrownBy(() -> testee.retrieveMessage(FIRST_REPOSITORY_PATH, NAME_1))
+            .isNotInstanceOf(NullPointerException.class);
     }
 
     @Test
     public void retrieveMessageShouldThrowWhenMailRepositoryStoreThrows() throws Exception {
-        when(mailRepositoryStore.get(FIRST_REPOSITORY))
+        when(mailRepositoryStore.getByPath(FIRST_REPOSITORY_PATH))
             .thenThrow(new MailRepositoryStore.MailRepositoryStoreException("message"));
 
-        assertThatThrownBy(() -> testee.retrieveMessage(FIRST_REPOSITORY, NAME_1))
+        assertThatThrownBy(() -> testee.retrieveMessage(FIRST_REPOSITORY_PATH, NAME_1))
             .isInstanceOf(MailRepositoryStore.MailRepositoryStoreException.class);
     }
 
     @Test
     public void retrieveMessageShouldReturnEmptyWhenMailNotFound() throws Exception {
-        when(mailRepositoryStore.get(FIRST_REPOSITORY)).thenReturn(Optional.of(repository));
+        when(mailRepositoryStore.getByPath(FIRST_REPOSITORY_PATH)).thenReturn(Stream.of(repository));
 
-        assertThat(testee.retrieveMessage(FIRST_REPOSITORY, NAME_1))
+        assertThat(testee.retrieveMessage(FIRST_REPOSITORY_PATH, NAME_1))
             .isEmpty();
     }
 
     @Test
     public void retrieveMessageShouldReturnTheMessageWhenMailExists() throws Exception {
-        when(mailRepositoryStore.get(FIRST_REPOSITORY)).thenReturn(Optional.of(repository));
+        when(mailRepositoryStore.getByPath(FIRST_REPOSITORY_PATH)).thenReturn(Stream.of(repository));
 
         FakeMail mail = FakeMail.builder()
             .name(NAME_1.asString())
@@ -171,7 +171,7 @@ public class MailRepositoryStoreServiceTest {
             .build();
         repository.store(mail);
 
-        Optional<MimeMessage> mimeMessage = testee.retrieveMessage(FIRST_REPOSITORY, NAME_1);
+        Optional<MimeMessage> mimeMessage = testee.retrieveMessage(FIRST_REPOSITORY_PATH, NAME_1);
         assertThat(mimeMessage).isNotEmpty();
 
         String eml = IOUtils.toString(new MimeMessageInputStream(mimeMessage.get()), StandardCharsets.UTF_8);

http://git-wip-us.apache.org/repos/asf/james-project/blob/ee71575a/src/site/markdown/server/manage-webadmin.md
----------------------------------------------------------------------
diff --git a/src/site/markdown/server/manage-webadmin.md b/src/site/markdown/server/manage-webadmin.md
index 6708a26..a161a97 100644
--- a/src/site/markdown/server/manage-webadmin.md
+++ b/src/site/markdown/server/manage-webadmin.md
@@ -1220,13 +1220,13 @@ Response codes:
 ### Create a mail repository
 
 ```
-curl -XPUT http://ip:port/mailRepositories/encodedUrlOfTheRepository
+curl -XPUT http://ip:port/mailRepositories/encodedPathOfTheRepository?protocol=someProtocol
 ```
 
-Resource name `encodedUrlOfTheRepository` should be the resource id of the created mail repository. Example:
+Resource name `encodedPathOfTheRepository` should be the resource path of the created mail repository. Example:
 
 ```
-curl -XPUT http://ip:port/mailRepositories/file%3A%2F%2FmailRepo
+curl -XPUT http://ip:port/mailRepositories/mailRepo?protocol=file
 ```
 
 Response codes:
@@ -1244,20 +1244,20 @@ The answer looks like:
 ```
 [
     {
-        "repository": "file://var/mail/error/",
-        "id": "file%3A%2F%2Fvar%2Fmail%2Ferror%2F"
+        "repository": "var/mail/error/",
+        "path": "var%2Fmail%2Ferror%2F"
     },
     {
-        "repository": "file://var/mail/relay-denied/",
-        "id": "file%3A%2F%2Fvar%2Fmail%2Frelay-denied%2F"
+        "repository": "var/mail/relay-denied/",
+        "path": "var%2Fmail%2Frelay-denied%2F"
     },
     {
-        "repository": "file://var/mail/spam/",
-        "id": "file%3A%2F%2Fvar%2Fmail%2Fspam%2F"
+        "repository": "var/mail/spam/",
+        "path": "var%2Fmail%2Fspam%2F"
     },
     {
-        "repository": "file://var/mail/address-error/",
-        "id": "file%3A%2F%2Fvar%2Fmail%2Faddress-error%2F"
+        "repository": "var/mail/address-error/",
+        "path": "var%2Fmail%2Faddress-error%2F"
     }
 ]
 ```
@@ -1271,21 +1271,21 @@ Response codes:
 ### Getting additional information for a mail repository
 
 ```
-curl -XGET http://ip:port/mailRepositories/encodedUrlOfTheRepository/
+curl -XGET http://ip:port/mailRepositories/encodedPathOfTheRepository/
 ```
 
-Resource name `encodedUrlOfTheRepository` should be the resource id of an existing mail repository. Example:
+Resource name `encodedPathOfTheRepository` should be the resource path of an existing mail repository. Example:
 
 ```
-curl -XGET http://ip:port/mailRepositories/file%3A%2F%2Fvar%2Fmail%2Ferror%2F/
+curl -XGET http://ip:port/mailRepositories/var%2Fmail%2Ferror%2F/
 ```
 
 The answer looks like:
 
 ```
 {
-   "repository": "file://var/mail/error/",
-   "id": "file%3A%2F%2Fvar%2Fmail%2Ferror%2F",
+   "repository": "var/mail/error/",
+   "path": "mail%2Ferror%2F",
    "size": 243
 }
 ```
@@ -1298,13 +1298,13 @@ Response codes:
 ### Listing mails contained in a mail repository
 
 ```
-curl -XGET http://ip:port/mailRepositories/encodedUrlOfTheRepository/mails
+curl -XGET http://ip:port/mailRepositories/encodedPathOfTheRepository/mails
 ```
 
-Resource name `encodedUrlOfTheRepository` should be the resource id of an existing mail repository. Example:
+Resource name `encodedPathOfTheRepository` should be the resource path of an existing mail repository. Example:
 
 ```
-curl -XGET http://ip:port/mailRepositories/file%3A%2F%2Fvar%2Fmail%2Ferror%2F/mails
+curl -XGET http://ip:port/mailRepositories/var%2Fmail%2Ferror%2F/mails
 ```
 
 The answer will contains all mailKey contained in that repository.
@@ -1326,7 +1326,7 @@ You can pass additional URL parameters to this call in order to limit the output
 Example:
 
 ```
-curl -XGET http://ip:port/mailRepositories/file%3A%2F%2Fvar%2Fmail%2Ferror%2F/mails?limit=100&offset=500
+curl -XGET http://ip:port/mailRepositories/var%2Fmail%2Ferror%2F/mails?limit=100&offset=500
 ```
 
 Response codes:
@@ -1338,13 +1338,13 @@ Response codes:
 ### Reading/downloading a mail details
 
 ```
-curl -XGET http://ip:port/mailRepositories/encodedUrlOfTheRepository/mails/mailKey
+curl -XGET http://ip:port/mailRepositories/encodedPathOfTheRepository/mails/mailKey
 ```
 
-Resource name `encodedUrlOfTheRepository` should be the resource id of an existing mail repository. Resource name `mailKey` should be the key of a mail stored in that repository. Example:
+Resource name `encodedPathOfTheRepository` should be the resource path of an existing mail repository. Resource name `mailKey` should be the key of a mail stored in that repository. Example:
 
 ```
-curl -XGET http://ip:port/mailRepositories/file%3A%2F%2Fvar%2Fmail%2Ferror%2F/mails/mail-key-1
+curl -XGET http://ip:port/mailRepositories/var%2Fmail%2Ferror%2F/mails/mail-key-1
 ```
 
 If the Accept header in the request is "application/json", then the response looks like:
@@ -1427,13 +1427,13 @@ Response codes:
 ### Removing a mail from a mail repository
 
 ```
-curl -XDELETE http://ip:port/mailRepositories/encodedUrlOfTheRepository/mails/mailKey
+curl -XDELETE http://ip:port/mailRepositories/encodedPathOfTheRepository/mails/mailKey
 ```
 
-Resource name `encodedUrlOfTheRepository` should be the resource id of an existing mail repository. Resource name `mailKey` should be the key of a mail stored in that repository. Example:
+Resource name `encodedPathOfTheRepository` should be the resource path of an existing mail repository. Resource name `mailKey` should be the key of a mail stored in that repository. Example:
 
 ```
-curl -XDELETE http://ip:port/mailRepositories/file%3A%2F%2Fvar%2Fmail%2Ferror%2F/mails/mail-key-1
+curl -XDELETE http://ip:port/mailRepositories/var%2Fmail%2Ferror%2F/mails/mail-key-1
 ```
 
 Response codes:
@@ -1445,13 +1445,13 @@ Response codes:
 
 
 ```
-curl -XDELETE http://ip:port/mailRepositories/encodedUrlOfTheRepository/mails
+curl -XDELETE http://ip:port/mailRepositories/encodedPathOfTheRepository/mails
 ```
 
-Resource name `encodedUrlOfTheRepository` should be the resource id of an existing mail repository. Example:
+Resource name `encodedPathOfTheRepository` should be the resource path of an existing mail repository. Example:
 
 ```
-curl -XDELETE http://ip:port/mailRepositories/file%3A%2F%2Fvar%2Fmail%2Ferror%2F/mails
+curl -XDELETE http://ip:port/mailRepositories/var%2Fmail%2Ferror%2F/mails
 ```
 
 The response to that request will be the scheduled `taskId` :
@@ -1477,7 +1477,7 @@ The scheduled task will have the following type `clearMailRepository` and the fo
 
 ```
 {
-  "repositoryUrl":"file://var/mail/error/",
+  "repositoryPath":"var/mail/error/",
   "initialCount": 243,
   "remainingCount": 17
 }
@@ -1490,15 +1490,15 @@ Sometime, you want to re-process emails stored in a mail repository. For instanc
 To reprocess mails from a repository:
 
 ```
-curl -XPATCH http://ip:port/mailRepositories/encodedUrlOfTheRepository/mails?action=reprocess
+curl -XPATCH http://ip:port/mailRepositories/encodedPathOfTheRepository/mails?action=reprocess
 ```
 
-Resource name `encodedUrlOfTheRepository` should be the resource id of an existing mail repository. Example:
+Resource name `encodedPathOfTheRepository` should be the resource path of an existing mail repository. Example:
 
 For instance:
 
 ```
-curl -XPATCH http://ip:port/mailRepositories/file%3A%2F%2Fvar%2Fmail%2Ferror%2F/mails?action=reprocess
+curl -XPATCH http://ip:port/mailRepositories/var%2Fmail%2Ferror%2F/mails?action=reprocess
 ```
 
 Additional query paramaters are supported:
@@ -1509,7 +1509,7 @@ Additional query paramaters are supported:
 For instance:
 
 ```
-curl -XPATCH http://ip:port/mailRepositories/file%3A%2F%2Fvar%2Fmail%2Ferror%2F/mails?action=reprocess&processor=transport&queue=spool
+curl -XPATCH http://ip:port/mailRepositories/var%2Fmail%2Ferror%2F/mails?action=reprocess&processor=transport&queue=spool
 ```
 
 Note that the `action` query parameter is compulsary and can only take value `reprocess`.
@@ -1538,7 +1538,7 @@ The scheduled task will have the following type `reprocessingAllTask` and the fo
 
 ```
 {
-  "repositoryUrl":"file://var/mail/error/",
+  "repositoryPath":"var/mail/error/",
   "targetQueue":"spool",
   "targetProcessor":"transport",
   "initialCount": 243,
@@ -1551,15 +1551,15 @@ The scheduled task will have the following type `reprocessingAllTask` and the fo
 To reprocess a specific mail from a mail repository:
 
 ```
-curl -XPATCH http://ip:port/mailRepositories/encodedUrlOfTheRepository/mails/mailKey?action=reprocess
+curl -XPATCH http://ip:port/mailRepositories/encodedPathOfTheRepository/mails/mailKey?action=reprocess
 ```
 
-Resource name `encodedUrlOfTheRepository` should be the resource id of an existing mail repository. Resource name `mailKey` should be the key of a mail stored in that repository. Example:
+Resource name `encodedPathOfTheRepository` should be the resource id of an existing mail repository. Resource name `mailKey` should be the key of a mail stored in that repository. Example:
 
 For instance:
 
 ```
-curl -XPATCH http://ip:port/mailRepositories/file%3A%2F%2Fvar%2Fmail%2Ferror%2F/mails/name1?action=reprocess
+curl -XPATCH http://ip:port/mailRepositories/var%2Fmail%2Ferror%2F/mails/name1?action=reprocess
 ```
 
 Additional query paramaters are supported:
@@ -1570,7 +1570,7 @@ Additional query paramaters are supported:
 For instance:
 
 ```
-curl -XPATCH http://ip:port/mailRepositories/file%3A%2F%2Fvar%2Fmail%2Ferror%2F/mails/name1?action=reprocess&processor=transport&queue=spool
+curl -XPATCH http://ip:port/mailRepositories/var%2Fmail%2Ferror%2F/mails/name1?action=reprocess&processor=transport&queue=spool
 ```
 
 Note that the `action` query parameter is compulsary and can only take value `reprocess`.
@@ -1599,7 +1599,7 @@ The scheduled task will have the following type `reprocessingOneTask` and the fo
 
 ```
 {
-  "repositoryUrl":"file://var/mail/error/",
+  "repositoryPath":"var/mail/error/",
   "targetQueue":"spool",
   "targetProcessor":"transport",
   "mailKey":"name1"


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message