Repository: james-project
Updated Branches:
  refs/heads/master b316b4cbf -> 223dd8198


http://git-wip-us.apache.org/repos/asf/james-project/blob/f185db6f/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java
 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java
index 46d552f..0591409 100644
--- 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java
+++ 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java
@@ -39,7 +39,9 @@ import org.slf4j.LoggerFactory;
 
 import com.github.fge.lambdas.Throwing;
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
 import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
 
 public class MailboxUtils<Id extends MailboxId> {
 
@@ -148,4 +150,11 @@ public class MailboxUtils<Id extends MailboxId> {
                     
mailboxMapperFactory.getMailboxMapper(mailboxSession).hasChildren(mailbox, 
mailboxSession.getPathDelimiter())))
                 .orElse(false);
     }
+
+    public Optional<MailboxPath> mailboxPathFromMailboxId(String mailboxId, 
MailboxSession mailboxSession) {
+        Preconditions.checkState(!Strings.isNullOrEmpty(mailboxId), 
"'mailboxId' is mandatory");
+        Preconditions.checkState(mailboxSession != null, "'mailboxId' is 
mandatory");
+        return mailboxFromMailboxId(mailboxId, mailboxSession)
+                .map(mailbox -> getMailboxPath(mailbox, mailboxSession));
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f185db6f/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessorTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessorTest.java
 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessorTest.java
index fe10145..acbe5b0 100644
--- 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessorTest.java
+++ 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessorTest.java
@@ -27,7 +27,7 @@ import org.apache.james.jmap.model.MailboxCreationId;
 import org.apache.james.jmap.model.SetError;
 import org.apache.james.jmap.model.SetMailboxesRequest;
 import org.apache.james.jmap.model.SetMailboxesResponse;
-import org.apache.james.jmap.model.mailbox.MailboxRequest;
+import org.apache.james.jmap.model.mailbox.MailboxCreateRequest;
 import org.apache.james.jmap.utils.MailboxUtils;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
@@ -53,7 +53,7 @@ public class SetMailboxesCreationProcessorTest {
         String parentId = "parentId";
         MailboxCreationId mailboxCreationId = MailboxCreationId.of("1");
         SetMailboxesRequest request = SetMailboxesRequest.builder()
-                .create(mailboxCreationId, 
MailboxRequest.builder().name("name").parentId(parentId).build())
+                .create(mailboxCreationId, 
MailboxCreateRequest.builder().name("name").parentId(parentId).build())
                 .build();
 
         MailboxSession mailboxSession = mock(MailboxSession.class);

http://git-wip-us.apache.org/repos/asf/james-project/blob/f185db6f/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesMethodTest.java
 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesMethodTest.java
index f79f90c..c2f83b6 100644
--- 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesMethodTest.java
+++ 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesMethodTest.java
@@ -32,7 +32,7 @@ import org.apache.james.jmap.model.MailboxCreationId;
 import org.apache.james.jmap.model.SetMailboxesRequest;
 import org.apache.james.jmap.model.SetMailboxesResponse;
 import org.apache.james.jmap.model.mailbox.Mailbox;
-import org.apache.james.jmap.model.mailbox.MailboxRequest;
+import org.apache.james.jmap.model.mailbox.MailboxCreateRequest;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.store.TestId;
 import org.junit.Test;
@@ -90,7 +90,7 @@ public class SetMailboxesMethodTest {
     @Test
     public void processShouldCallCreatorProcessorWhenCreationRequest() {
         MailboxCreationId creationId = MailboxCreationId.of("create-id01");
-        MailboxRequest fooFolder = 
MailboxRequest.builder().name("fooFolder").build();
+        MailboxCreateRequest fooFolder = 
MailboxCreateRequest.builder().name("fooFolder").build();
         SetMailboxesRequest creationRequest = 
SetMailboxesRequest.builder().create(creationId, fooFolder).build();
 
         Mailbox createdfooFolder = 
Mailbox.builder().name("fooFolder").id("fooId").build();

http://git-wip-us.apache.org/repos/asf/james-project/blob/f185db6f/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessorTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessorTest.java
 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessorTest.java
new file mode 100644
index 0000000..73e2146
--- /dev/null
+++ 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessorTest.java
@@ -0,0 +1,82 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap.methods;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Optional;
+
+import org.apache.james.jmap.model.SetError;
+import org.apache.james.jmap.model.SetMailboxesRequest;
+import org.apache.james.jmap.model.SetMailboxesResponse;
+import org.apache.james.jmap.model.mailbox.Mailbox;
+import org.apache.james.jmap.model.mailbox.MailboxUpdateRequest;
+import org.apache.james.jmap.utils.MailboxUtils;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.store.TestId;
+import org.junit.Before;
+import org.junit.Test;
+
+public class SetMailboxesUpdateProcessorTest {
+
+    private MailboxManager mockedMailboxManager;
+    private MailboxUtils<TestId> mockedMailboxUtils;
+    private MailboxSession mockedMailboxSession;
+    private SetMailboxesUpdateProcessor<TestId> sut;
+
+    @Before
+    @SuppressWarnings("unchecked")
+    public void setup() {
+        mockedMailboxManager = mock(MailboxManager.class);
+        mockedMailboxUtils = mock(MailboxUtils.class);
+        mockedMailboxSession = mock(MailboxSession.class);
+        sut = new SetMailboxesUpdateProcessor<>(mockedMailboxUtils, 
mockedMailboxManager);
+    }
+
+    @Test
+    public void processShouldReturnNotUpdatedWhenMailboxExceptionOccured() 
throws Exception {
+        // Given
+        String mailboxId = "1";
+        String newParentId = "newParentId";
+        MailboxPath newParentMailboxPath = new MailboxPath("#private", "user", 
"newParentName");
+        SetMailboxesRequest request = SetMailboxesRequest.builder()
+                .update(mailboxId, 
MailboxUpdateRequest.builder().parentId(newParentId).build())
+                .build();
+        Mailbox mailbox = Mailbox.builder().id(mailboxId).name("name").build();
+        when(mockedMailboxUtils.mailboxFromMailboxId(mailboxId, 
mockedMailboxSession))
+            .thenReturn(Optional.of(mailbox));
+        when(mockedMailboxUtils.mailboxPathFromMailboxId(newParentId, 
mockedMailboxSession))
+            .thenReturn(Optional.of(newParentMailboxPath));
+        when(mockedMailboxUtils.hasChildren(mailboxId, mockedMailboxSession))
+            .thenThrow(new MailboxException());
+
+        // When
+        SetMailboxesResponse setMailboxesResponse = sut.process(request, 
mockedMailboxSession);
+
+        // Then
+        assertThat(setMailboxesResponse.getUpdated()).isEmpty();
+        
assertThat(setMailboxesResponse.getNotUpdated()).containsEntry(mailboxId, 
SetError.builder().type("anErrorOccurred").description("An error occurred when 
updating the mailbox").build());
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/f185db6f/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMailboxesRequestTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMailboxesRequestTest.java
 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMailboxesRequestTest.java
index bafe9f1..9a0d984 100644
--- 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMailboxesRequestTest.java
+++ 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMailboxesRequestTest.java
@@ -21,7 +21,9 @@ package org.apache.james.jmap.model;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import org.apache.commons.lang.NotImplementedException;
-import org.apache.james.jmap.model.mailbox.MailboxRequest;
+import org.apache.james.jmap.model.mailbox.MailboxCreateRequest;
+import org.apache.james.jmap.model.mailbox.MailboxUpdateRequest;
+import org.apache.james.mailbox.exception.MailboxException;
 import org.junit.Test;
 
 import com.google.common.collect.ImmutableList;
@@ -39,25 +41,28 @@ public class SetMailboxesRequestTest {
         SetMailboxesRequest.builder().ifInState("1");
     }
 
-    @Test(expected=NotImplementedException.class)
-    public void builderShouldThrowWhenUpdate() {
-        SetMailboxesRequest.builder().update(ImmutableMap.of());
-    }
-    
     @Test
-    public void builderShouldWork() {
+    public void builderShouldWork() throws MailboxException {
+        //Given
         MailboxCreationId creationId = MailboxCreationId.of("creationId");
-        MailboxRequest mailboxRequest = MailboxRequest.builder()
+        String mailboxId = "mailboxId";
+        MailboxCreateRequest mailboxRequest = MailboxCreateRequest.builder()
             .name("mailboxRequest")
             .build();
         ImmutableList<String> destroy = ImmutableList.of("destroyId");
-        SetMailboxesRequest expected = new 
SetMailboxesRequest(ImmutableMap.of(creationId, mailboxRequest), destroy);
-        
+        MailboxUpdateRequest mailboxUpdateRequest = 
MailboxUpdateRequest.builder()
+            .name("mailboxUpdateRequest")
+            .build();
+        SetMailboxesRequest expected = new 
SetMailboxesRequest(ImmutableMap.of(creationId, mailboxRequest), 
ImmutableMap.of(mailboxId, mailboxUpdateRequest), destroy);
+
+        //When
         SetMailboxesRequest actual = SetMailboxesRequest.builder()
             .create(creationId, mailboxRequest)
+            .update(mailboxId, mailboxUpdateRequest)
             .destroy(destroy)
             .build();
-        
+
+        //Then
         assertThat(actual).isEqualToComparingFieldByField(expected);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f185db6f/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMailboxesResponseTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMailboxesResponseTest.java
 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMailboxesResponseTest.java
index 9cc6281..959fce6 100644
--- 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMailboxesResponseTest.java
+++ 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/SetMailboxesResponseTest.java
@@ -36,15 +36,19 @@ public class SetMailboxesResponseTest {
                 .id("1")
                 .name("myBox")
                 .build());
+        ImmutableList<String> updated = ImmutableList.of("2");
+        ImmutableList<String> destroyed = ImmutableList.of("3");
         ImmutableMap<MailboxCreationId, SetError> notCreated = 
ImmutableMap.of(MailboxCreationId.of("dead-beef-defec8"), 
SetError.builder().type("created").build());
-        ImmutableList<String> destroyed = ImmutableList.of("2");
-        ImmutableMap<String, SetError> notDestroyed  = ImmutableMap.of("2", 
SetError.builder().type("destroyed").build());
-        SetMailboxesResponse expected = new SetMailboxesResponse(created, 
notCreated, destroyed, notDestroyed);
+        ImmutableMap<String, SetError> notUpdated = ImmutableMap.of("4", 
SetError.builder().type("updated").build());
+        ImmutableMap<String, SetError> notDestroyed  = ImmutableMap.of("5", 
SetError.builder().type("destroyed").build());
+        SetMailboxesResponse expected = new SetMailboxesResponse(created, 
updated, destroyed, notCreated, notUpdated, notDestroyed);
 
         SetMailboxesResponse setMessagesResponse = 
SetMailboxesResponse.builder()
             .created(created)
+            .updated(updated)
             .destroyed(destroyed)
             .notCreated(notCreated)
+            .notUpdated(notUpdated)
             .notDestroyed(notDestroyed)
             .build();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/f185db6f/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxCreateRequestTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxCreateRequestTest.java
 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxCreateRequestTest.java
new file mode 100644
index 0000000..72e2d37
--- /dev/null
+++ 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxCreateRequestTest.java
@@ -0,0 +1,80 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.jmap.model.mailbox;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.apache.commons.lang.NotImplementedException;
+import org.junit.Test;
+
+public class MailboxCreateRequestTest {
+
+    @Test
+    public void builderShouldThrowOnNullRole() {
+        assertThatThrownBy(() -> 
MailboxCreateRequest.builder().role(null)).isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    public void builderShouldThrowWhenRoleDefine() {
+        assertThatThrownBy(() -> 
MailboxCreateRequest.builder().role(Role.ARCHIVE)).isInstanceOf(NotImplementedException.class);
+    }
+
+    @Test
+    public void builderShouldThrowOnNullId() {
+        assertThatThrownBy(() -> 
MailboxCreateRequest.builder().id(null)).isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    public void builderShouldThrowOnNullSortOrder() {
+        assertThatThrownBy(() -> 
MailboxCreateRequest.builder().sortOrder(null)).isInstanceOf(NullPointerException.class);
+    }
+    
+    @Test
+    public void builderShouldThrowOnSortOrderDefine() {
+        assertThatThrownBy(() -> 
MailboxCreateRequest.builder().sortOrder(SortOrder.of(123))).isInstanceOf(NotImplementedException.class);
+    }    
+
+    @Test
+    public void builderShouldThrowOnNullParentId() {
+        assertThatThrownBy(() -> 
MailboxCreateRequest.builder().parentId(null)).isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    public void builderShouldThrowOnNullName() {
+        assertThatThrownBy(() -> 
MailboxCreateRequest.builder().name(null)).isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    public void builderShouldRequireName() {
+        assertThatThrownBy(() -> MailboxCreateRequest.builder().build())
+            .isInstanceOf(IllegalStateException.class)
+            .hasMessageContaining("name");
+    }
+
+    @Test
+    public void builderShouldBuildWhenName() {
+        MailboxCreateRequest request = 
MailboxCreateRequest.builder().name("foo").build();
+        assertThat(request.getName()).isEqualTo("foo");
+        assertThat(request.getId()).isEmpty();
+        assertThat(request.getParentId()).isEmpty();
+        assertThat(request.getSortOrder()).isEmpty();
+        assertThat(request.getRole()).isEmpty();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/f185db6f/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxRequestTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxRequestTest.java
 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxRequestTest.java
deleted file mode 100644
index e5265f3..0000000
--- 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxRequestTest.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-package org.apache.james.jmap.model.mailbox;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-
-import org.apache.commons.lang.NotImplementedException;
-import org.junit.Test;
-
-public class MailboxRequestTest {
-
-    @Test
-    public void builderShouldThrowOnNullRole() {
-        assertThatThrownBy(() -> 
MailboxRequest.builder().role(null)).isInstanceOf(NullPointerException.class);
-    }
-
-    @Test
-    public void builderShouldThrowWhenRoleDefine() {
-        assertThatThrownBy(() -> 
MailboxRequest.builder().role(Role.ARCHIVE)).isInstanceOf(NotImplementedException.class);
-    }
-
-    @Test
-    public void builderShouldThrowOnNullId() {
-        assertThatThrownBy(() -> 
MailboxRequest.builder().id(null)).isInstanceOf(NullPointerException.class);
-    }
-
-    @Test
-    public void builderShouldThrowOnNullSortOrder() {
-        assertThatThrownBy(() -> 
MailboxRequest.builder().sortOrder(null)).isInstanceOf(NullPointerException.class);
-    }
-    
-    @Test
-    public void builderShouldThrowOnSortOrderDefine() {
-        assertThatThrownBy(() -> 
MailboxRequest.builder().sortOrder(SortOrder.of(123))).isInstanceOf(NotImplementedException.class);
-    }    
-
-    @Test
-    public void builderShouldThrowOnNullParentId() {
-        assertThatThrownBy(() -> 
MailboxRequest.builder().parentId(null)).isInstanceOf(NullPointerException.class);
-    }
-
-    @Test
-    public void builderShouldThrowOnNullName() {
-        assertThatThrownBy(() -> 
MailboxRequest.builder().name(null)).isInstanceOf(NullPointerException.class);
-    }
-
-    @Test
-    public void builderShouldRequireName() {
-        assertThatThrownBy(() -> MailboxRequest.builder().build())
-            .isInstanceOf(IllegalStateException.class)
-            .hasMessageContaining("name");
-    }
-
-    @Test
-    public void builderShouldBuildWhenName() {
-        MailboxRequest request = MailboxRequest.builder().name("foo").build();
-        assertThat(request.getName()).isEqualTo("foo");
-        assertThat(request.getId()).isEmpty();
-        assertThat(request.getParentId()).isEmpty();
-        assertThat(request.getSortOrder()).isEmpty();
-        assertThat(request.getRole()).isEmpty();
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/f185db6f/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxUpdateRequestTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxUpdateRequestTest.java
 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxUpdateRequestTest.java
new file mode 100644
index 0000000..a2ec816
--- /dev/null
+++ 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxUpdateRequestTest.java
@@ -0,0 +1,60 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap.model.mailbox;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Optional;
+
+import org.junit.Test;
+
+public class MailboxUpdateRequestTest {
+    
+    @Test
+    public void getParentIdShouldReturnEmptyWhenNotGiven() throws Exception {
+        //Given
+        MailboxUpdateRequest testee = MailboxUpdateRequest.builder().name("my 
box").build() ;
+        //When
+        Optional<String> actual = testee.getParentId();
+        //Then
+        assertThat(actual).isEmpty();
+    }
+
+    @Test
+    public void getParentIdShouldReturnNullWhenNullParentIdGiven() throws 
Exception {
+        //Given
+        MailboxUpdateRequest testee = MailboxUpdateRequest.builder().name("my 
box").parentId(null).build() ;
+        //When
+        Optional<String> actual = testee.getParentId();
+        //Then
+        assertThat(actual).isNull();
+    }
+
+    @Test
+    public void getParentIdShouldReturnParentIdWhenParentIdGiven() throws 
Exception {
+        //Given
+        String expected = "A";
+        MailboxUpdateRequest testee = 
MailboxUpdateRequest.builder().parentId(expected).name("my box").build() ;
+        //When
+        Optional<String> actual = testee.getParentId();
+        //Then
+        assertThat(actual).contains(expected);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/f185db6f/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailboxUtilsTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailboxUtilsTest.java
 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailboxUtilsTest.java
index 6accb7a..c13782c 100644
--- 
a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailboxUtilsTest.java
+++ 
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailboxUtilsTest.java
@@ -184,6 +184,45 @@ public class MailboxUtilsTest {
     }
 
     @Test
+    public void mailboxPathFromMailboxIdShouldReturnPresentWhenExists() throws 
Exception {
+        MailboxPath mailboxPath = new MailboxPath("#private", user, "myBox");
+        mailboxManager.createMailbox(mailboxPath, mailboxSession);
+        InMemoryId mailboxId = 
mailboxMapperFactory.getMailboxMapper(mailboxSession)
+                .findMailboxByPath(mailboxPath)
+                .getMailboxId();
+
+        Optional<MailboxPath> actual = 
sut.mailboxPathFromMailboxId(mailboxId.serialize(), mailboxSession);
+        assertThat(actual).isPresent();
+        assertThat(actual.get()).isEqualTo(mailboxPath);
+    }
+
+    @Test
+    public void mailboxPathFromMailboxIdShouldReturnAbsentWhenDoesntExist() 
throws Exception {
+        Optional<MailboxPath> mailboxPath = 
sut.mailboxPathFromMailboxId("123", mailboxSession);
+        assertThat(mailboxPath).isEmpty();
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void mailboxPathFromMailboxIdShouldThrowWhenNullMailboxId() throws 
Exception {
+        sut.mailboxPathFromMailboxId(null, mailboxSession);
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void mailboxPathFromMailboxIdShouldThrowWhenNullMailboxSession() 
throws Exception {
+        sut.mailboxPathFromMailboxId("A", null);
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void 
mailboxPathFromMailboxIdShouldThrowWhenNullMailboxSessionAndMailboxId() throws 
Exception {
+        sut.mailboxPathFromMailboxId(null, null);
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void mailboxPathFromMailboxIdShouldReturnAbsentWhenEmptyMailboxId() 
throws Exception {
+        sut.mailboxPathFromMailboxId("", mailboxSession);
+    }
+
+    @Test
     public void getMailboxPathShouldReturnThePathWhenRootMailbox() throws 
Exception {
         MailboxPath expected = new MailboxPath("#private", user, "myBox");
         mailboxManager.createMailbox(expected, mailboxSession);


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

Reply via email to