You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2015/06/29 10:21:14 UTC

svn commit: r1688109 [6/6] - in /james/mailbox/trunk: caching/src/main/java/org/apache/james/mailbox/caching/ caching/src/main/java/org/apache/james/mailbox/caching/guava/ cassandra/src/main/java/org/apache/james/mailbox/cassandra/ cassandra/src/main/j...

Modified: james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageMapperTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageMapperTest.java?rev=1688109&r1=1688108&r2=1688109&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageMapperTest.java (original)
+++ james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageMapperTest.java Mon Jun 29 08:21:12 2015
@@ -19,6 +19,16 @@
 
 package org.apache.james.mailbox.store.mail.model;
 
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.mail.Flags;
+import javax.mail.util.SharedByteArrayInputStream;
+
 import org.apache.james.mailbox.FlagsBuilder;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxPath;
@@ -35,16 +45,7 @@ import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 
-import javax.mail.Flags;
-import javax.mail.util.SharedByteArrayInputStream;
-import java.io.IOException;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.Map;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public abstract class AbstractMessageMapperTest<Id> {
+public abstract class AbstractMessageMapperTest<Id extends MailboxId> {
 
     private final static char DELIMITER = ':';
     private static final int LIMIT = 10;

Modified: james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageTest.java?rev=1688109&r1=1688108&r2=1688109&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageTest.java (original)
+++ james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/AbstractMessageTest.java Mon Jun 29 08:21:12 2015
@@ -22,6 +22,7 @@ package org.apache.james.mailbox.store.m
 import static org.junit.Assert.*;
 
 import org.apache.james.mailbox.store.MessageBuilder;
+import org.apache.james.mailbox.store.TestId;
 import org.apache.james.mailbox.store.mail.model.Message;
 import org.junit.Test;
 
@@ -30,12 +31,12 @@ public class AbstractMessageTest {
     @Test
     public void testShouldReturnPositiveWhenFirstGreaterThanSecond()
             throws Exception {
-        Message<Long> one = buildMessage(100);
-        Message<Long> two = buildMessage(99);
+        Message<TestId> one = buildMessage(100);
+        Message<TestId> two = buildMessage(99);
         assertTrue( one.compareTo(two) > 0);
     }
 
-    private Message<Long> buildMessage(int uid) throws Exception {
+    private Message<TestId> buildMessage(int uid) throws Exception {
         MessageBuilder builder = new MessageBuilder();
         builder.uid = uid;
         return builder.build();
@@ -44,15 +45,15 @@ public class AbstractMessageTest {
     @Test
     public void testShouldReturnNegativeWhenFirstLessThanSecond()
             throws Exception {
-        Message<Long> one = buildMessage(98);
-        Message<Long> two = buildMessage(99);
+        Message<TestId> one = buildMessage(98);
+        Message<TestId> two = buildMessage(99);
         assertTrue( one.compareTo(two) < 0);
     }
 
     @Test
     public void testShouldReturnZeroWhenFirstEqualsSecond() throws Exception {
-        Message<Long> one = buildMessage(90);
-        Message<Long> two = buildMessage(90);
+        Message<TestId> one = buildMessage(90);
+        Message<TestId> two = buildMessage(90);
         assertEquals(0, one.compareTo(two));
     }
 }

Modified: james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxAssertTests.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxAssertTests.java?rev=1688109&r1=1688108&r2=1688109&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxAssertTests.java (original)
+++ james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxAssertTests.java Mon Jun 29 08:21:12 2015
@@ -20,18 +20,19 @@
 package org.apache.james.mailbox.store.mail.model;
 
 import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.store.TestId;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
 import org.junit.Test;
 
 public class MailboxAssertTests {
 
     private final static long UID_VALIDITY = 42;
-    private final static long MAILBOX_ID = 24;
+    private final static TestId MAILBOX_ID = TestId.of(24);
 
     @Test
     public void isEqualToShouldNotFailWithEqualMailbox() {
-        SimpleMailbox<Long> mailbox1 = new SimpleMailbox<Long>(new MailboxPath("namespace", "user", "name"), UID_VALIDITY);
-        SimpleMailbox<Long> mailbox2 = new SimpleMailbox<Long>(new MailboxPath("namespace", "user", "name"), UID_VALIDITY);
+        SimpleMailbox<TestId> mailbox1 = new SimpleMailbox<TestId>(new MailboxPath("namespace", "user", "name"), UID_VALIDITY);
+        SimpleMailbox<TestId> mailbox2 = new SimpleMailbox<TestId>(new MailboxPath("namespace", "user", "name"), UID_VALIDITY);
         mailbox1.setMailboxId(MAILBOX_ID);
         mailbox2.setMailboxId(MAILBOX_ID);
         MailboxAssert.assertThat(mailbox1).isEqualTo(mailbox2);
@@ -39,8 +40,8 @@ public class MailboxAssertTests {
 
     @Test(expected = AssertionError.class)
     public void isEqualToShouldFailWithNotEqualNamespace() {
-        SimpleMailbox<Long> mailbox1 = new SimpleMailbox<Long>(new MailboxPath("namespace", "user", "name"), UID_VALIDITY);
-        SimpleMailbox<Long> mailbox2 = new SimpleMailbox<Long>(new MailboxPath("other_namespace", "user", "name"), UID_VALIDITY);
+        SimpleMailbox<TestId> mailbox1 = new SimpleMailbox<TestId>(new MailboxPath("namespace", "user", "name"), UID_VALIDITY);
+        SimpleMailbox<TestId> mailbox2 = new SimpleMailbox<TestId>(new MailboxPath("other_namespace", "user", "name"), UID_VALIDITY);
         mailbox1.setMailboxId(MAILBOX_ID);
         mailbox2.setMailboxId(MAILBOX_ID);
         MailboxAssert.assertThat(mailbox1).isEqualTo(mailbox2);
@@ -48,8 +49,8 @@ public class MailboxAssertTests {
 
     @Test(expected = AssertionError.class)
     public void isEqualToShouldFailWithNotEqualUser() {
-        SimpleMailbox<Long> mailbox1 = new SimpleMailbox<Long>(new MailboxPath("namespace", "user", "name"), UID_VALIDITY);
-        SimpleMailbox<Long> mailbox2 = new SimpleMailbox<Long>(new MailboxPath("namespace", "other_user", "name"), UID_VALIDITY);
+        SimpleMailbox<TestId> mailbox1 = new SimpleMailbox<TestId>(new MailboxPath("namespace", "user", "name"), UID_VALIDITY);
+        SimpleMailbox<TestId> mailbox2 = new SimpleMailbox<TestId>(new MailboxPath("namespace", "other_user", "name"), UID_VALIDITY);
         mailbox1.setMailboxId(MAILBOX_ID);
         mailbox2.setMailboxId(MAILBOX_ID);
         MailboxAssert.assertThat(mailbox1).isEqualTo(mailbox2);
@@ -57,8 +58,8 @@ public class MailboxAssertTests {
 
     @Test(expected = AssertionError.class)
     public void isEqualToShouldFailWithNotEqualName() {
-        SimpleMailbox<Long> mailbox1 = new SimpleMailbox<Long>(new MailboxPath("namespace", "user", "name"), UID_VALIDITY);
-        SimpleMailbox<Long> mailbox2 = new SimpleMailbox<Long>(new MailboxPath("namespace", "user", "other_name"), UID_VALIDITY);
+        SimpleMailbox<TestId> mailbox1 = new SimpleMailbox<TestId>(new MailboxPath("namespace", "user", "name"), UID_VALIDITY);
+        SimpleMailbox<TestId> mailbox2 = new SimpleMailbox<TestId>(new MailboxPath("namespace", "user", "other_name"), UID_VALIDITY);
         mailbox1.setMailboxId(MAILBOX_ID);
         mailbox2.setMailboxId(MAILBOX_ID);
         MailboxAssert.assertThat(mailbox1).isEqualTo(mailbox2);
@@ -66,17 +67,17 @@ public class MailboxAssertTests {
 
     @Test(expected = AssertionError.class)
     public void isEqualToShouldFailWithNotEqualId() {
-        SimpleMailbox<Long> mailbox1 = new SimpleMailbox<Long>(new MailboxPath("namespace", "user", "name"), UID_VALIDITY);
-        SimpleMailbox<Long> mailbox2 = new SimpleMailbox<Long>(new MailboxPath("namespace", "user", "name"), UID_VALIDITY);
+        SimpleMailbox<TestId> mailbox1 = new SimpleMailbox<TestId>(new MailboxPath("namespace", "user", "name"), UID_VALIDITY);
+        SimpleMailbox<TestId> mailbox2 = new SimpleMailbox<TestId>(new MailboxPath("namespace", "user", "name"), UID_VALIDITY);
         mailbox1.setMailboxId(MAILBOX_ID);
-        mailbox2.setMailboxId(MAILBOX_ID + 1);
+        mailbox2.setMailboxId(TestId.of(MAILBOX_ID.id + 1));
         MailboxAssert.assertThat(mailbox1).isEqualTo(mailbox2);
     }
 
     @Test(expected = AssertionError.class)
     public void isEqualToShouldFailWithNotEqualUidValidity() {
-        SimpleMailbox<Long> mailbox1 = new SimpleMailbox<Long>(new MailboxPath("namespace", "user", "name"), UID_VALIDITY);
-        SimpleMailbox<Long> mailbox2 = new SimpleMailbox<Long>(new MailboxPath("namespace", "user", "name"), UID_VALIDITY + 1);
+        SimpleMailbox<TestId> mailbox1 = new SimpleMailbox<TestId>(new MailboxPath("namespace", "user", "name"), UID_VALIDITY);
+        SimpleMailbox<TestId> mailbox2 = new SimpleMailbox<TestId>(new MailboxPath("namespace", "user", "name"), UID_VALIDITY + 1);
         mailbox1.setMailboxId(MAILBOX_ID);
         mailbox2.setMailboxId(MAILBOX_ID);
         MailboxAssert.assertThat(mailbox1).isEqualTo(mailbox2);

Modified: james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/MapperProvider.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/MapperProvider.java?rev=1688109&r1=1688108&r2=1688109&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/MapperProvider.java (original)
+++ james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/MapperProvider.java Mon Jun 29 08:21:12 2015
@@ -23,7 +23,7 @@ import org.apache.james.mailbox.exceptio
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.MessageMapper;
 
-public interface MapperProvider<Id> {
+public interface MapperProvider<Id extends MailboxId> {
     MailboxMapper<Id> createMailboxMapper() throws MailboxException;
 
     MessageMapper<Id> createMessageMapper() throws MailboxException;

Modified: james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageAssertTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageAssertTest.java?rev=1688109&r1=1688108&r2=1688109&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageAssertTest.java (original)
+++ james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageAssertTest.java Mon Jun 29 08:21:12 2015
@@ -19,6 +19,7 @@
 
 package org.apache.james.mailbox.store.mail.model;
 
+import org.apache.james.mailbox.store.TestId;
 import org.apache.james.mailbox.store.mail.MessageMapper;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMessage;
@@ -26,12 +27,13 @@ import org.junit.Test;
 
 import javax.mail.Flags;
 import javax.mail.util.SharedByteArrayInputStream;
+
 import java.io.IOException;
 import java.util.Date;
 
 public class MessageAssertTest {
 
-    public static final long MAILBOX_ID = 42L;
+    public static final TestId MAILBOX_ID = TestId.of(42L);
     public static final long UID = 24L;
 
     @Test
@@ -39,10 +41,10 @@ public class MessageAssertTest {
         String headerString = "name: headerName\n\n";
         String bodyString = "body\n.\n";
         Date date = new Date();
-        SimpleMessage<Long> message1 = new SimpleMessage<Long>(date, headerString.length() + bodyString.length(),
+        SimpleMessage<TestId> message1 = new SimpleMessage<TestId>(date, headerString.length() + bodyString.length(),
             headerString.length(), new SharedByteArrayInputStream((headerString + bodyString).getBytes()), new Flags(), new PropertyBuilder(), MAILBOX_ID);
         message1.setUid(UID);
-        SimpleMessage<Long> message2 = new SimpleMessage<Long>(date, headerString.length() + bodyString.length(),
+        SimpleMessage<TestId> message2 = new SimpleMessage<TestId>(date, headerString.length() + bodyString.length(),
             headerString.length(), new SharedByteArrayInputStream((headerString + bodyString).getBytes()), new Flags(), new PropertyBuilder(), MAILBOX_ID);
         message2.setUid(UID);
         MessageAssert.assertThat(message1).isEqualTo(message2, MessageMapper.FetchType.Full);
@@ -53,11 +55,11 @@ public class MessageAssertTest {
         String headerString = "name: headerName\n\n";
         String bodyString = "body\n.\n";
         Date date = new Date();
-        SimpleMessage<Long> message1 = new SimpleMessage<Long>(date, headerString.length() + bodyString.length(),
+        SimpleMessage<TestId> message1 = new SimpleMessage<TestId>(date, headerString.length() + bodyString.length(),
             headerString.length(), new SharedByteArrayInputStream((headerString + bodyString).getBytes()), new Flags(), new PropertyBuilder(), MAILBOX_ID);
         message1.setUid(UID);
         bodyString = "work\n.\n";
-        SimpleMessage<Long> message2 = new SimpleMessage<Long>(date, headerString.length() + bodyString.length(),
+        SimpleMessage<TestId> message2 = new SimpleMessage<TestId>(date, headerString.length() + bodyString.length(),
             headerString.length(), new SharedByteArrayInputStream((headerString + bodyString).getBytes()), new Flags(), new PropertyBuilder(), MAILBOX_ID);
         message2.setUid(UID);
         MessageAssert.assertThat(message1).isEqualTo(message2, MessageMapper.FetchType.Headers);
@@ -68,11 +70,11 @@ public class MessageAssertTest {
         String headerString = "name: headerName\n\n";
         String bodyString = "body\n.\n";
         Date date = new Date();
-        SimpleMessage<Long> message1 = new SimpleMessage<Long>(date, headerString.length() + bodyString.length(),
+        SimpleMessage<TestId> message1 = new SimpleMessage<TestId>(date, headerString.length() + bodyString.length(),
             headerString.length(), new SharedByteArrayInputStream((headerString + bodyString).getBytes()), new Flags(), new PropertyBuilder(), MAILBOX_ID);
         message1.setUid(UID);
         bodyString = "work\n.\n";
-        SimpleMessage<Long> message2 = new SimpleMessage<Long>(date, headerString.length() + bodyString.length(),
+        SimpleMessage<TestId> message2 = new SimpleMessage<TestId>(date, headerString.length() + bodyString.length(),
             headerString.length(), new SharedByteArrayInputStream((headerString + bodyString).getBytes()), new Flags(), new PropertyBuilder(), MAILBOX_ID);
         message2.setUid(UID);
         MessageAssert.assertThat(message1).isEqualTo(message2, MessageMapper.FetchType.Body);

Modified: james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/MetadataMapAssertTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/MetadataMapAssertTest.java?rev=1688109&r1=1688108&r2=1688109&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/MetadataMapAssertTest.java (original)
+++ james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/MetadataMapAssertTest.java Mon Jun 29 08:21:12 2015
@@ -21,6 +21,7 @@ package org.apache.james.mailbox.store.m
 
 import org.apache.james.mailbox.model.MessageMetaData;
 import org.apache.james.mailbox.store.SimpleMessageMetaData;
+import org.apache.james.mailbox.store.TestId;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMessage;
 import org.junit.Before;
@@ -28,6 +29,7 @@ import org.junit.Test;
 
 import javax.mail.Flags;
 import javax.mail.util.SharedByteArrayInputStream;
+
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
@@ -39,13 +41,13 @@ public class MetadataMapAssertTest {
     private static final Date DATE = new Date();
     private static final String HEADER_STRING = "name: headerName\n\n";
     private static final String BODY_STRING = "body\\n.\\n";
-    private static final Long MAILBOX_ID = 12L;
+    private static final TestId MAILBOX_ID = TestId.of(12L);
 
-    private SimpleMessage<Long> message1;
+    private SimpleMessage<TestId> message1;
 
     @Before
     public void setUp() {
-        message1 = new SimpleMessage<Long>(DATE, HEADER_STRING.length() + BODY_STRING.length(),
+        message1 = new SimpleMessage<TestId>(DATE, HEADER_STRING.length() + BODY_STRING.length(),
             HEADER_STRING.length(), new SharedByteArrayInputStream((HEADER_STRING + BODY_STRING).getBytes()), new Flags(), new PropertyBuilder(), MAILBOX_ID);
         message1.setUid(UID);
         message1.setModSeq(MODSEQ);

Modified: james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMessageTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMessageTest.java?rev=1688109&r1=1688108&r2=1688109&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMessageTest.java (original)
+++ james/mailbox/trunk/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMessageTest.java Mon Jun 29 08:21:12 2015
@@ -30,14 +30,15 @@ import javax.mail.Flags;
 import javax.mail.util.SharedByteArrayInputStream;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.james.mailbox.store.TestId;
 import org.junit.Test;
 
 public class SimpleMessageTest {
     private static final Charset MESSAGE_CHARSET = Charset.forName("UTF-8");
     private static final String MESSAGE_CONTENT = "Simple message content without special characters";
     private static final String MESSAGE_CONTENT_SPECIAL_CHAR = "Simple message content with special characters: \"'(§è!çà$*`";
-    private static final SimpleMessage<Long> MESSAGE = buildMessage(MESSAGE_CONTENT);
-    private static final SimpleMessage<Long> MESSAGE_SPECIAL_CHAR = buildMessage(MESSAGE_CONTENT_SPECIAL_CHAR);
+    private static final SimpleMessage<TestId> MESSAGE = buildMessage(MESSAGE_CONTENT);
+    private static final SimpleMessage<TestId> MESSAGE_SPECIAL_CHAR = buildMessage(MESSAGE_CONTENT_SPECIAL_CHAR);
 
     @Test
     public void testSize() {
@@ -74,11 +75,11 @@ public class SimpleMessageTest {
                 new String(IOUtils.toByteArray(MESSAGE_SPECIAL_CHAR.getFullContent()),MESSAGE_CHARSET));
     }
 
-    private static SimpleMessage<Long> buildMessage(String content) {
-        return new SimpleMessage<Long>(Calendar.getInstance().getTime(),
+    private static SimpleMessage<TestId> buildMessage(String content) {
+        return new SimpleMessage<TestId>(Calendar.getInstance().getTime(),
                 content.length(), 0, new SharedByteArrayInputStream(
                         content.getBytes(MESSAGE_CHARSET)), new Flags(),
-                new PropertyBuilder(), 1L);
+                new PropertyBuilder(), TestId.of(1L));
     }
 
 }

Modified: james/mailbox/trunk/tool/src/test/java/org/apache/james/mailbox/copier/MailboxCopierTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/tool/src/test/java/org/apache/james/mailbox/copier/MailboxCopierTest.java?rev=1688109&r1=1688108&r2=1688109&view=diff
==============================================================================
--- james/mailbox/trunk/tool/src/test/java/org/apache/james/mailbox/copier/MailboxCopierTest.java (original)
+++ james/mailbox/trunk/tool/src/test/java/org/apache/james/mailbox/copier/MailboxCopierTest.java Mon Jun 29 08:21:12 2015
@@ -32,6 +32,7 @@ import org.apache.james.mailbox.acl.Simp
 import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
 import org.apache.james.mailbox.exception.BadCredentialsException;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.inmemory.InMemoryId;
 import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory;
 import org.apache.james.mailbox.mock.MockMailboxManager;
 import org.apache.james.mailbox.model.MailboxPath;
@@ -154,7 +155,7 @@ public class MailboxCopierTest {
         MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
         GroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver();
 
-        return new StoreMailboxManager<Long>(
+        return new StoreMailboxManager<InMemoryId>(
             new InMemoryMailboxSessionMapperFactory(), 
             new Authenticator() {
                 public boolean isAuthentic(String userid, CharSequence passwd) {

Modified: james/mailbox/trunk/zoo-seq-provider/src/main/java/org/apache/james/mailbox/store/mail/ZooUidProvider.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/zoo-seq-provider/src/main/java/org/apache/james/mailbox/store/mail/ZooUidProvider.java?rev=1688109&r1=1688108&r2=1688109&view=diff
==============================================================================
--- james/mailbox/trunk/zoo-seq-provider/src/main/java/org/apache/james/mailbox/store/mail/ZooUidProvider.java (original)
+++ james/mailbox/trunk/zoo-seq-provider/src/main/java/org/apache/james/mailbox/store/mail/ZooUidProvider.java Mon Jun 29 08:21:12 2015
@@ -24,14 +24,16 @@ import com.netflix.curator.framework.Cur
 import com.netflix.curator.framework.recipes.atomic.AtomicValue;
 import com.netflix.curator.framework.recipes.atomic.DistributedAtomicLong;
 import com.netflix.curator.retry.RetryOneTime;
+
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.store.mail.model.MailboxId;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 
 /**
  * ZooKeeper based implementation of a distributed sequential UID generator.
  */
-public class ZooUidProvider<E> implements UidProvider<E> {
+public class ZooUidProvider<E extends MailboxId> implements UidProvider<E> {
     // TODO: use ZK paths to store uid and modSeq, etc.
 
     public static final String UID_PATH_SUFFIX = "-uid";

Modified: james/mailbox/trunk/zoo-seq-provider/src/test/java/org/apache/james/mailbox/store/mail/ZooUidProviderTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/zoo-seq-provider/src/test/java/org/apache/james/mailbox/store/mail/ZooUidProviderTest.java?rev=1688109&r1=1688108&r2=1688109&view=diff
==============================================================================
--- james/mailbox/trunk/zoo-seq-provider/src/test/java/org/apache/james/mailbox/store/mail/ZooUidProviderTest.java (original)
+++ james/mailbox/trunk/zoo-seq-provider/src/test/java/org/apache/james/mailbox/store/mail/ZooUidProviderTest.java Mon Jun 29 08:21:12 2015
@@ -18,89 +18,178 @@
  ****************************************************************/
 package org.apache.james.mailbox.store.mail;
 
-import com.netflix.curator.RetryPolicy;
-import com.netflix.curator.framework.CuratorFramework;
-import com.netflix.curator.framework.CuratorFrameworkFactory;
-import com.netflix.curator.retry.RetryOneTime;
-import com.netflix.curator.test.TestingServer;
+import static org.junit.Assert.assertEquals;
+
 import java.util.UUID;
+
 import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.store.mail.model.MailboxId;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
 import org.junit.After;
-import static org.junit.Assert.*;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.netflix.curator.RetryPolicy;
+import com.netflix.curator.framework.CuratorFramework;
+import com.netflix.curator.framework.CuratorFrameworkFactory;
+import com.netflix.curator.retry.RetryOneTime;
+import com.netflix.curator.test.TestingServer;
+
 /**
  * Test for UID provider.
  */
 public class ZooUidProviderTest {
 
-    private static TestingServer testServer;
-    private static final int ZOO_TEST_PORT = 3123;
-    private final RetryPolicy retryPolicy = new RetryOneTime(1);
-    private CuratorFramework client;
-    private ZooUidProvider<UUID> uuidProvider;
-    private ZooUidProvider<Long> longProvider;
-    private SimpleMailbox<UUID> mailboxUUID;
-    private SimpleMailbox<Long> mailboxLong;
-    private UUID randomUUID = UUID.randomUUID();
-
-    @Before
-    public void setUp() throws Exception {
-        testServer = new TestingServer(ZOO_TEST_PORT);
-        client = CuratorFrameworkFactory.builder().connectString("localhost:" + ZOO_TEST_PORT).retryPolicy(retryPolicy).
-                namespace("JAMES").build();
-        client.start();
-        uuidProvider = new ZooUidProvider<UUID>(client, retryPolicy);
-        longProvider = new ZooUidProvider<Long>(client, retryPolicy);
-        MailboxPath path1 = new MailboxPath("namespacetest", "namespaceuser", "UUID");
-        MailboxPath path2 = new MailboxPath("namespacetest", "namespaceuser", "Long");
-        mailboxUUID = new SimpleMailbox<UUID>(path1, 1L);
-        mailboxUUID.setMailboxId(randomUUID);
-        mailboxLong = new SimpleMailbox<Long>(path2, 2L);
-        mailboxLong.setMailboxId(123L);
-    }
+    public static class LongId implements MailboxId {
 
-    @After
-    public void tearDown() throws Exception {
-        client.close();
-        testServer.close();
-    }
+        public final Long id;
 
-    /**
-     * Test of nextUid method, of class ZooUidProvider.
-     */
-    @Test
-    public void testNextUid() throws Exception {
-        System.out.println("Testing nextUid");
-        long result = uuidProvider.nextUid(null, mailboxUUID);
-        assertEquals("Next UID is 1", 1, result);
-        result = longProvider.nextUid(null, mailboxLong);
-        assertEquals("Next UID is 1", 1, result);
-    }
+        public LongId(long id) {
+            this.id = id;
+        }
+
+        @Override
+        public String serialize() {
+            return String.valueOf(id);
+        }
+
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = 1;
+            result = prime * result + ((id == null) ? 0 : id.hashCode());
+            return result;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj)
+                return true;
+            if (obj == null)
+                return false;
+            if (getClass() != obj.getClass())
+                return false;
+            LongId other = (LongId) obj;
+            if (id == null) {
+                if (other.id != null)
+                    return false;
+            } else if (!id.equals(other.id))
+                return false;
+            return true;
+        }
 
-    /**
-     * Test of lastUid method, of class ZooUidProvider.
-     */
-    @Test
-    public void testLastUid() throws Exception {
-        System.out.println("Testing lastUid");
-        long result = uuidProvider.lastUid(null, mailboxUUID);
-        assertEquals("Next UID is 0", 0, result);
-        result = uuidProvider.nextUid(null, mailboxUUID);
-        assertEquals("Next UID is 1", 1, result);
     }
 
-    /**
-     * Test of lastUid method, of class ZooUidProvider.
-     */
-    @Test
-    public void testLongLastUid() throws Exception {
-        System.out.println("Testing long lastUid");
-        long result = longProvider.lastUid(null, mailboxLong);
-        assertEquals("Next UID is 0", 0, result);
-        result = longProvider.nextUid(null, mailboxLong);
-        assertEquals("Next UID is 1", 1, result);
+    public static class UUIDId implements MailboxId {
+
+        private final UUID id;
+
+        public static UUIDId of(UUID id) {
+            return new UUIDId(id);
+        }
+
+        public UUIDId(UUID id) {
+            this.id = id;
+        }
+
+        @Override
+        public String serialize() {
+            return id.toString();
+        }
+
+        @Override
+        public int hashCode() {
+            final int prime = 31;
+            int result = 1;
+            result = prime * result + ((id == null) ? 0 : id.hashCode());
+            return result;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj)
+                return true;
+            if (obj == null)
+                return false;
+            if (getClass() != obj.getClass())
+                return false;
+            UUIDId other = (UUIDId) obj;
+            if (id == null) {
+                if (other.id != null)
+                    return false;
+            } else if (!id.equals(other.id))
+                return false;
+            return true;
+        }
+
     }
-}
+	
+		
+	    private static TestingServer testServer;
+	    private static final int ZOO_TEST_PORT = 3123;
+	    private final RetryPolicy retryPolicy = new RetryOneTime(1);
+	    private CuratorFramework client;
+	    private ZooUidProvider<UUIDId> uuidProvider;
+	    private ZooUidProvider<LongId> longProvider;
+	    private SimpleMailbox<UUIDId> mailboxUUID;
+	    private SimpleMailbox<LongId> mailboxLong;
+	    private UUID randomUUID = UUID.randomUUID();
+	
+	    @Before
+	    public void setUp() throws Exception {
+	        testServer = new TestingServer(ZOO_TEST_PORT);
+	        client = CuratorFrameworkFactory.builder().connectString("localhost:" + ZOO_TEST_PORT).retryPolicy(retryPolicy).
+	                namespace("JAMES").build();
+	        client.start();
+	        uuidProvider = new ZooUidProvider<UUIDId>(client, retryPolicy);
+	        longProvider = new ZooUidProvider<LongId>(client, retryPolicy);
+	        MailboxPath path1 = new MailboxPath("namespacetest", "namespaceuser", "UUID");
+	        MailboxPath path2 = new MailboxPath("namespacetest", "namespaceuser", "Long");
+	        mailboxUUID = new SimpleMailbox<UUIDId>(path1, 1L);
+	        mailboxUUID.setMailboxId(UUIDId.of(randomUUID));
+	        mailboxLong = new SimpleMailbox<LongId>(path2, 2L);
+	        mailboxLong.setMailboxId(new LongId(123L));
+	    }
+	
+	    @After
+	    public void tearDown() throws Exception {
+	        client.close();
+	        testServer.close();
+	    }
+	
+	    /**
+	     * Test of nextUid method, of class ZooUidProvider.
+	     */
+	    @Test
+	    public void testNextUid() throws Exception {
+	        System.out.println("Testing nextUid");
+	        long result = uuidProvider.nextUid(null, mailboxUUID);
+	        assertEquals("Next UID is 1", 1, result);
+	        result = longProvider.nextUid(null, mailboxLong);
+	        assertEquals("Next UID is 1", 1, result);
+	    }
+	
+	    /**
+	     * Test of lastUid method, of class ZooUidProvider.
+	     */
+	    @Test
+	    public void testLastUid() throws Exception {
+	        System.out.println("Testing lastUid");
+	        long result = uuidProvider.lastUid(null, mailboxUUID);
+	        assertEquals("Next UID is 0", 0, result);
+	        result = uuidProvider.nextUid(null, mailboxUUID);
+	        assertEquals("Next UID is 1", 1, result);
+	    }
+	
+	    /**
+	     * Test of lastUid method, of class ZooUidProvider.
+	     */
+	    @Test
+	    public void testLongLastUid() throws Exception {
+	        System.out.println("Testing long lastUid");
+	        long result = longProvider.lastUid(null, mailboxLong);
+	        assertEquals("Next UID is 0", 0, result);
+	        result = longProvider.nextUid(null, mailboxLong);
+	        assertEquals("Next UID is 1", 1, result);
+	    }
+	}



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