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/11/28 13:56:43 UTC
svn commit: r1716956 - in /james/project/trunk/mailbox:
cassandra/src/main/java/org/apache/james/mailbox/cassandra/
cassandra/src/test/java/org/apache/james/mailbox/cassandra/
hbase/src/main/java/org/apache/james/mailbox/hbase/
hbase/src/test/java/org/...
Author: btellier
Date: Sat Nov 28 12:56:43 2015
New Revision: 1716956
URL: http://svn.apache.org/viewvc?rev=1716956&view=rev
Log:
MAILBOX-211 Introduce a way to deserialize Mailbox Ids
Added:
james/project/trunk/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxIdDeserializer.java
james/project/trunk/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxIdDeserializerTest.java
james/project/trunk/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/HBaseMailboxIdDeserializer.java
james/project/trunk/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxIdDeserializerTest.java
james/project/trunk/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxIdDeserializer.java
james/project/trunk/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxIdDeserializerTest.java
james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxIdDeserializer.java
james/project/trunk/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxIdDeserializerTest.java
james/project/trunk/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirMailboxIdDeserializer.java
james/project/trunk/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxIdDeserializerTest.java
james/project/trunk/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxIdDeserializer.java
james/project/trunk/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxIdDeserializerTest.java
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxIdDeserialisationException.java
james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxIdDeserializer.java
james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/TestIdDeserializer.java
Modified:
james/project/trunk/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/user/model/JCRSubscription.java
Added: james/project/trunk/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxIdDeserializer.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxIdDeserializer.java?rev=1716956&view=auto
==============================================================================
--- james/project/trunk/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxIdDeserializer.java (added)
+++ james/project/trunk/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxIdDeserializer.java Sat Nov 28 12:56:43 2015
@@ -0,0 +1,38 @@
+/****************************************************************
+ * 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.mailbox.cassandra;
+
+import org.apache.james.mailbox.store.mail.model.MailboxIdDeserialisationException;
+import org.apache.james.mailbox.store.mail.model.MailboxIdDeserializer;
+
+import java.util.UUID;
+
+public class CassandraMailboxIdDeserializer implements MailboxIdDeserializer<CassandraId> {
+
+ @Override
+ public CassandraId deserialize(String serializedMailboxId) throws MailboxIdDeserialisationException {
+ try {
+ return CassandraId.of(UUID.fromString(serializedMailboxId));
+ } catch (Exception e) {
+ throw new MailboxIdDeserialisationException("Error de-serialising " + serializedMailboxId, e);
+ }
+ }
+
+}
Added: james/project/trunk/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxIdDeserializerTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxIdDeserializerTest.java?rev=1716956&view=auto
==============================================================================
--- james/project/trunk/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxIdDeserializerTest.java (added)
+++ james/project/trunk/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMailboxIdDeserializerTest.java Sat Nov 28 12:56:43 2015
@@ -0,0 +1,53 @@
+/****************************************************************
+ * 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.mailbox.cassandra;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.mailbox.store.mail.model.MailboxIdDeserialisationException;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.UUID;
+
+public class CassandraMailboxIdDeserializerTest {
+
+ private static final String UUID_STRING = "5530370f-44c6-4647-990e-7768ce5131d4";
+ private static final String MALFORMED_UUID_STRING = "xyz";
+ private static final CassandraId CASSANDRA_ID = CassandraId.of(UUID.fromString(UUID_STRING));
+
+ private CassandraMailboxIdDeserializer mailboxIdDeserializer;
+
+ @Before
+ public void setUp() {
+ mailboxIdDeserializer = new CassandraMailboxIdDeserializer();
+ }
+
+ @Test
+ public void deserializeShouldWork() throws Exception {
+ assertThat(mailboxIdDeserializer.deserialize(UUID_STRING)).isEqualTo(CASSANDRA_ID);
+ }
+
+ @Test(expected = MailboxIdDeserialisationException.class)
+ public void deserializeShouldThrowOnMalformedData() throws Exception {
+ mailboxIdDeserializer.deserialize(MALFORMED_UUID_STRING);
+ }
+
+}
Added: james/project/trunk/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/HBaseMailboxIdDeserializer.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/HBaseMailboxIdDeserializer.java?rev=1716956&view=auto
==============================================================================
--- james/project/trunk/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/HBaseMailboxIdDeserializer.java (added)
+++ james/project/trunk/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/HBaseMailboxIdDeserializer.java Sat Nov 28 12:56:43 2015
@@ -0,0 +1,36 @@
+/****************************************************************
+ * 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.mailbox.hbase;
+
+import org.apache.james.mailbox.store.mail.model.MailboxIdDeserialisationException;
+import org.apache.james.mailbox.store.mail.model.MailboxIdDeserializer;
+import java.util.UUID;
+
+public class HBaseMailboxIdDeserializer implements MailboxIdDeserializer<HBaseId> {
+
+ @Override
+ public HBaseId deserialize(String serializedMailboxId) throws MailboxIdDeserialisationException {
+ try {
+ return HBaseId.of(UUID.fromString(serializedMailboxId));
+ } catch (Exception e) {
+ throw new MailboxIdDeserialisationException("Error deserializing " + serializedMailboxId, e);
+ }
+ }
+}
Added: james/project/trunk/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxIdDeserializerTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxIdDeserializerTest.java?rev=1716956&view=auto
==============================================================================
--- james/project/trunk/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxIdDeserializerTest.java (added)
+++ james/project/trunk/mailbox/hbase/src/test/java/org/apache/james/mailbox/hbase/HBaseMailboxIdDeserializerTest.java Sat Nov 28 12:56:43 2015
@@ -0,0 +1,53 @@
+/****************************************************************
+ * 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.mailbox.hbase;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.mailbox.store.mail.model.MailboxIdDeserialisationException;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.UUID;
+
+public class HBaseMailboxIdDeserializerTest {
+
+ private static final String UUID_STRING = "5530370f-44c6-4647-990e-7768ce5131d4";
+ private static final String MALFORMED_UUID_STRING = "xyz";
+ private static final HBaseId HBASE_ID = HBaseId.of(UUID.fromString(UUID_STRING));
+
+ private HBaseMailboxIdDeserializer mailboxIdDeserializer;
+
+ @Before
+ public void setUp() {
+ mailboxIdDeserializer = new HBaseMailboxIdDeserializer();
+ }
+
+ @Test
+ public void deserializeShouldWork() throws Exception {
+ assertThat(mailboxIdDeserializer.deserialize(UUID_STRING)).isEqualTo(HBASE_ID);
+ }
+
+ @Test(expected = MailboxIdDeserialisationException.class)
+ public void deserializeShouldThrowOnMalformedData() throws Exception {
+ mailboxIdDeserializer.deserialize(MALFORMED_UUID_STRING);
+ }
+
+}
Added: james/project/trunk/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxIdDeserializer.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxIdDeserializer.java?rev=1716956&view=auto
==============================================================================
--- james/project/trunk/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxIdDeserializer.java (added)
+++ james/project/trunk/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMailboxIdDeserializer.java Sat Nov 28 12:56:43 2015
@@ -0,0 +1,30 @@
+/****************************************************************
+ * 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.mailbox.jcr;
+
+import org.apache.james.mailbox.store.mail.model.MailboxIdDeserializer;
+
+public class JCRMailboxIdDeserializer implements MailboxIdDeserializer<JCRId> {
+
+ @Override
+ public JCRId deserialize(String serializedMailboxId) {
+ return JCRId.of(serializedMailboxId);
+ }
+}
Modified: james/project/trunk/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/user/model/JCRSubscription.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/user/model/JCRSubscription.java?rev=1716956&r1=1716955&r2=1716956&view=diff
==============================================================================
--- james/project/trunk/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/user/model/JCRSubscription.java (original)
+++ james/project/trunk/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/user/model/JCRSubscription.java Sat Nov 28 12:56:43 2015
@@ -62,7 +62,7 @@ public class JCRSubscription implements
/*
* (non-Javadoc)
*
- * @see org.apache.james.mailbox.store.user.model.Subscription#getMailbox()
+ * @see org.apache.james.mailbox.store.user.model.Subscription#getMailboxPath()
*/
public String getMailbox() {
return mailbox;
Added: james/project/trunk/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxIdDeserializerTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxIdDeserializerTest.java?rev=1716956&view=auto
==============================================================================
--- james/project/trunk/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxIdDeserializerTest.java (added)
+++ james/project/trunk/mailbox/jcr/src/test/java/org/apache/james/mailbox/jcr/JCRMailboxIdDeserializerTest.java Sat Nov 28 12:56:43 2015
@@ -0,0 +1,45 @@
+/****************************************************************
+ * 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.mailbox.jcr;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.mailbox.store.mail.model.MailboxIdDeserializer;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JCRMailboxIdDeserializerTest {
+
+ private static final String SERIALIZED_ID = "some_string";
+ private static final JCRId JCR_ID = JCRId.of(SERIALIZED_ID);
+
+ private MailboxIdDeserializer mailboxIdDeserializer;
+
+ @Before
+ public void setUp() {
+ mailboxIdDeserializer = new JCRMailboxIdDeserializer();
+ }
+
+ @Test
+ public void deserializeShouldWork() throws Exception {
+ assertThat(mailboxIdDeserializer.deserialize(SERIALIZED_ID)).isEqualTo(JCR_ID);
+ }
+
+}
Added: james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxIdDeserializer.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxIdDeserializer.java?rev=1716956&view=auto
==============================================================================
--- james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxIdDeserializer.java (added)
+++ james/project/trunk/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMailboxIdDeserializer.java Sat Nov 28 12:56:43 2015
@@ -0,0 +1,35 @@
+/****************************************************************
+ * 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.mailbox.jpa;
+
+import org.apache.james.mailbox.store.mail.model.MailboxIdDeserialisationException;
+import org.apache.james.mailbox.store.mail.model.MailboxIdDeserializer;
+
+public class JPAMailboxIdDeserializer implements MailboxIdDeserializer<JPAId> {
+
+ @Override
+ public JPAId deserialize(String serializedMailboxId) throws MailboxIdDeserialisationException {
+ try {
+ return JPAId.of(Long.valueOf(serializedMailboxId));
+ } catch (Exception e) {
+ throw new MailboxIdDeserialisationException("Error deserializing " + serializedMailboxId, e);
+ }
+ }
+}
Added: james/project/trunk/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxIdDeserializerTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxIdDeserializerTest.java?rev=1716956&view=auto
==============================================================================
--- james/project/trunk/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxIdDeserializerTest.java (added)
+++ james/project/trunk/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxIdDeserializerTest.java Sat Nov 28 12:56:43 2015
@@ -0,0 +1,51 @@
+/****************************************************************
+ * 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.mailbox.jpa;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.mailbox.store.mail.model.MailboxIdDeserialisationException;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JPAMailboxIdDeserializerTest {
+
+ private static final String SERIALIZED_ID = "123456789012";
+ private static final String MALFORMED_SERIALIZED_ID = "abcz";
+ private static final JPAId JPA_ID = JPAId.of(Long.valueOf(SERIALIZED_ID));
+
+ private JPAMailboxIdDeserializer mailboxIdDeserializer;
+
+ @Before
+ public void setUp() {
+ mailboxIdDeserializer = new JPAMailboxIdDeserializer();
+ }
+
+ @Test
+ public void deserializeShouldWork() throws Exception {
+ assertThat(mailboxIdDeserializer.deserialize(SERIALIZED_ID)).isEqualTo(JPA_ID);
+ }
+
+ @Test(expected = MailboxIdDeserialisationException.class)
+ public void deserializeShouldThrowOnMalformedData() throws Exception {
+ mailboxIdDeserializer.deserialize(MALFORMED_SERIALIZED_ID);
+ }
+
+}
Added: james/project/trunk/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirMailboxIdDeserializer.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirMailboxIdDeserializer.java?rev=1716956&view=auto
==============================================================================
--- james/project/trunk/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirMailboxIdDeserializer.java (added)
+++ james/project/trunk/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/MaildirMailboxIdDeserializer.java Sat Nov 28 12:56:43 2015
@@ -0,0 +1,35 @@
+/****************************************************************
+ * 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.mailbox.maildir;
+
+import org.apache.james.mailbox.store.mail.model.MailboxIdDeserialisationException;
+import org.apache.james.mailbox.store.mail.model.MailboxIdDeserializer;
+
+public class MaildirMailboxIdDeserializer implements MailboxIdDeserializer<MaildirId> {
+
+ @Override
+ public MaildirId deserialize(String serializedMailboxId) throws MailboxIdDeserialisationException {
+ try {
+ return MaildirId.of(Integer.valueOf(serializedMailboxId));
+ } catch (Exception e) {
+ throw new MailboxIdDeserialisationException("Can not deserialize " + serializedMailboxId, e);
+ }
+ }
+}
Added: james/project/trunk/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxIdDeserializerTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxIdDeserializerTest.java?rev=1716956&view=auto
==============================================================================
--- james/project/trunk/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxIdDeserializerTest.java (added)
+++ james/project/trunk/mailbox/maildir/src/test/java/org/apache/james/mailbox/maildir/MaildirMailboxIdDeserializerTest.java Sat Nov 28 12:56:43 2015
@@ -0,0 +1,52 @@
+/****************************************************************
+ * 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.mailbox.maildir;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.mailbox.store.mail.model.MailboxIdDeserialisationException;
+import org.apache.james.mailbox.store.mail.model.MailboxIdDeserializer;
+import org.junit.Before;
+import org.junit.Test;
+
+public class MaildirMailboxIdDeserializerTest {
+
+ private static final String SERIALIZED_ID = "123";
+ private static final String MALFORMED_SERIALIZED_ID = "az";
+ private static final MaildirId MAILDIR_ID = MaildirId.of(Integer.valueOf(SERIALIZED_ID));
+
+ private MailboxIdDeserializer mailboxIdDeserializer;
+
+ @Before
+ public void setUp() {
+ mailboxIdDeserializer = new MaildirMailboxIdDeserializer();
+ }
+
+ @Test
+ public void deserializeShouldWork() throws Exception {
+ assertThat(mailboxIdDeserializer.deserialize(SERIALIZED_ID)).isEqualTo(MAILDIR_ID);
+ }
+
+ @Test(expected = MailboxIdDeserialisationException.class)
+ public void deserializeShouldThrowOnMalformedData() throws Exception {
+ mailboxIdDeserializer.deserialize(MALFORMED_SERIALIZED_ID);
+ }
+
+}
Added: james/project/trunk/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxIdDeserializer.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxIdDeserializer.java?rev=1716956&view=auto
==============================================================================
--- james/project/trunk/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxIdDeserializer.java (added)
+++ james/project/trunk/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxIdDeserializer.java Sat Nov 28 12:56:43 2015
@@ -0,0 +1,36 @@
+/****************************************************************
+ * 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.mailbox.inmemory;
+
+import org.apache.james.mailbox.store.mail.model.MailboxIdDeserialisationException;
+import org.apache.james.mailbox.store.mail.model.MailboxIdDeserializer;
+
+public class InMemoryMailboxIdDeserializer implements MailboxIdDeserializer<InMemoryId> {
+
+ @Override
+ public InMemoryId deserialize(String serializedMailboxId) throws MailboxIdDeserialisationException {
+ try {
+ return InMemoryId.of(Long.valueOf(serializedMailboxId));
+ } catch (Exception e) {
+ throw new MailboxIdDeserialisationException("Error deserializing " + serializedMailboxId, e);
+ }
+ }
+
+}
Added: james/project/trunk/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxIdDeserializerTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxIdDeserializerTest.java?rev=1716956&view=auto
==============================================================================
--- james/project/trunk/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxIdDeserializerTest.java (added)
+++ james/project/trunk/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMailboxIdDeserializerTest.java Sat Nov 28 12:56:43 2015
@@ -0,0 +1,52 @@
+/****************************************************************
+ * 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.mailbox.inmemory;
+
+import org.apache.james.mailbox.store.mail.model.MailboxIdDeserialisationException;
+import org.apache.james.mailbox.store.mail.model.MailboxIdDeserializer;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class InMemoryMailboxIdDeserializerTest {
+
+ private static final String SERIALIZED_ID = "1234567890123";
+ private static final String MALFORMED_SERIALIZED_ID = "aEZ";
+ private static final InMemoryId IN_MEMORY_ID = InMemoryId.of(Long.valueOf(SERIALIZED_ID));
+
+ private MailboxIdDeserializer mailboxIdDeserializer;
+
+ @Before
+ public void setUp() {
+ mailboxIdDeserializer = new InMemoryMailboxIdDeserializer();
+ }
+
+ @Test
+ public void deserializeShouldWork() throws MailboxIdDeserialisationException {
+ assertThat(mailboxIdDeserializer.deserialize(SERIALIZED_ID)).isEqualTo(IN_MEMORY_ID);
+ }
+
+ @Test(expected = MailboxIdDeserialisationException.class)
+ public void deserializeShouldThrowOnMalformedData() throws MailboxIdDeserialisationException {
+ mailboxIdDeserializer.deserialize(MALFORMED_SERIALIZED_ID);
+ }
+
+}
Added: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxIdDeserialisationException.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxIdDeserialisationException.java?rev=1716956&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxIdDeserialisationException.java (added)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxIdDeserialisationException.java Sat Nov 28 12:56:43 2015
@@ -0,0 +1,36 @@
+/****************************************************************
+ * 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.mailbox.store.mail.model;
+
+import org.apache.james.mailbox.exception.MailboxException;
+
+public class MailboxIdDeserialisationException extends MailboxException {
+
+ public MailboxIdDeserialisationException() {
+ }
+
+ public MailboxIdDeserialisationException(String message) {
+ super(message);
+ }
+
+ public MailboxIdDeserialisationException(String msg, Exception cause) {
+ super(msg, cause);
+ }
+}
Added: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxIdDeserializer.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxIdDeserializer.java?rev=1716956&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxIdDeserializer.java (added)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MailboxIdDeserializer.java Sat Nov 28 12:56:43 2015
@@ -0,0 +1,26 @@
+/****************************************************************
+ * 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.mailbox.store.mail.model;
+
+public interface MailboxIdDeserializer<Id extends MailboxId> {
+
+ Id deserialize(String serializedMailboxId) throws MailboxIdDeserialisationException;
+
+}
Added: james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/TestIdDeserializer.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/TestIdDeserializer.java?rev=1716956&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/TestIdDeserializer.java (added)
+++ james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/TestIdDeserializer.java Sat Nov 28 12:56:43 2015
@@ -0,0 +1,31 @@
+/****************************************************************
+ * 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.mailbox.store;
+
+import org.apache.james.mailbox.store.mail.model.MailboxIdDeserializer;
+
+public class TestIdDeserializer implements MailboxIdDeserializer<TestId> {
+
+ @Override
+ public TestId deserialize(String serializedMailboxId) {
+ return TestId.of(Long.valueOf(serializedMailboxId));
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org