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 jo...@apache.org on 2006/11/16 20:50:50 UTC
svn commit: r475896 [2/2] - in /james/server/sandbox/mailbox-namespaces/src:
conf/ java/org/apache/james/imapserver/
java/org/apache/james/mailboxmanager/impl/
java/org/apache/james/mailboxmanager/mailbox/
java/org/apache/james/mailboxmanager/mailstore...
Added: james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/impl/VirtualMailboxManagerFactoryTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/impl/VirtualMailboxManagerFactoryTest.java?view=auto&rev=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/impl/VirtualMailboxManagerFactoryTest.java (added)
+++ james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/impl/VirtualMailboxManagerFactoryTest.java Thu Nov 16 11:50:48 2006
@@ -0,0 +1,194 @@
+/****************************************************************
+ * 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.mailboxmanager.impl;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.james.mailboxmanager.mailstore.MailStoreMailboxManagerFactory;
+import org.apache.james.mailboxmanager.manager.MailboxManagerFactory;
+import org.apache.james.mailboxmanager.mock.MockMailboxManagerFactory;
+import org.apache.james.mailboxmanager.torque.TorqueMailboxManagerFactory;
+import org.apache.james.services.FileSystem;
+import org.apache.james.test.mock.avalon.MockLogger;
+import org.apache.james.test.mock.james.MockFileSystem;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
+import org.xml.sax.SAXException;
+
+public class VirtualMailboxManagerFactoryTest extends MockObjectTestCase {
+
+ VirtualMailboxManagerFactory virtualMailboxManagerFactory;
+
+ public void setUp() {
+ virtualMailboxManagerFactory = new VirtualMailboxManagerFactory();
+ }
+
+ public void testReadConf() throws ConfigurationException, SAXException,
+ IOException {
+ Configuration confFile = new DefaultConfigurationBuilder()
+ .buildFromFile("src/conf/james-config.xml");
+ Configuration conf = confFile.getChild("mailboxmanager", false).getChild("factory",false);
+ VirtualMailboxManagerFactory vmm = new VirtualMailboxManagerFactory();
+ vmm.enableLogging(new MockLogger());
+ vmm.configure(conf);
+ }
+
+ public void testVirtualRepositoryMix() throws Exception {
+ Configuration confFile = new DefaultConfigurationBuilder()
+ .build(getClass()
+ .getResourceAsStream(
+ "/org/apache/james/mailboxmanager/testdata/VirtualRepositoryMix.xml"));
+ Configuration conf = confFile.getChild("mailboxmanager", false).getChild("factory",false);
+
+ Mock mockService = mock(ServiceManager.class);
+ mockService.expects(once()).method("lookup").with(eq(FileSystem.ROLE))
+ .will(returnValue(new MockFileSystem()));
+
+ VirtualMailboxManagerFactory virtualMailboxManagerFactory = new VirtualMailboxManagerFactory();
+ virtualMailboxManagerFactory.enableLogging(new MockLogger());
+ virtualMailboxManagerFactory.configure(conf);
+ virtualMailboxManagerFactory.service((ServiceManager) mockService
+ .proxy());
+// virtualMailboxManagerFactory.initialize();
+
+ String[] expected = { "#system", "#user1", "#user2", "#user3", "#mail",
+ "#user" };
+ List resultList = new ArrayList(virtualMailboxManagerFactory
+ .getMountMap().keySet());
+ List expectedList = Arrays.asList(expected);
+ assertEquals(expectedList, resultList);
+
+ MailboxManagerFactory[] factories = new MailboxManagerFactory[expected.length];
+ for (int i = 0; i < factories.length; i++) {
+ factories[i] = (MailboxManagerFactory) virtualMailboxManagerFactory
+ .getMountMap().get(expected[i]);
+ }
+
+ assertSame(factories[1], factories[5]);
+ assertSame(factories[2], factories[3]);
+ assertNotSame(factories[1], factories[2]);
+ assertNotSame(factories[1], factories[0]);
+ assertNotSame(factories[0], factories[4]);
+
+ MockMailboxManagerFactory mockFactory1 = (MockMailboxManagerFactory) factories[1];
+ MockMailboxManagerFactory mockFactory2 = (MockMailboxManagerFactory) factories[2];
+
+ Configuration[] mounts = conf.getChild(
+ "mounts", false).getChildren("mount");
+
+ assertEquals(mounts[0].getChild("target", false),
+ mockFactory1.configuration);
+ assertEquals(mounts[1].getChild("target", false),
+ mockFactory2.configuration);
+
+// assertEquals(1, mockFactory1.init);
+// assertEquals(1, mockFactory2.init);
+
+ assertTrue(factories[0] instanceof MailStoreMailboxManagerFactory);
+ assertTrue(factories[4] instanceof TorqueMailboxManagerFactory);
+
+ }
+
+
+ public void testVirtualRepositoryMixWithInit() throws Exception {
+ Configuration confFile = new DefaultConfigurationBuilder()
+ .build(getClass()
+ .getResourceAsStream(
+ "/org/apache/james/mailboxmanager/testdata/VirtualRepositoryMix.xml"));
+ Configuration conf = confFile.getChild("mailboxmanager-without-torque", false).getChild("factory",false);
+
+
+ VirtualMailboxManagerFactory virtualMailboxManagerFactory = new VirtualMailboxManagerFactory();
+ virtualMailboxManagerFactory.enableLogging(new MockLogger());
+ virtualMailboxManagerFactory.configure(conf);
+ virtualMailboxManagerFactory.service(null);
+ virtualMailboxManagerFactory.initialize();
+
+ String[] expected = { "#system", "#user1", "#user2", "#user3", "#mail",
+ "#user" };
+ List resultList = new ArrayList(virtualMailboxManagerFactory
+ .getMountMap().keySet());
+ List expectedList = Arrays.asList(expected);
+ assertEquals(expectedList, resultList);
+
+ MailboxManagerFactory[] factories = new MailboxManagerFactory[expected.length];
+ for (int i = 0; i < factories.length; i++) {
+ factories[i] = (MailboxManagerFactory) virtualMailboxManagerFactory
+ .getMountMap().get(expected[i]);
+ }
+
+ assertSame(factories[1], factories[5]);
+ assertSame(factories[2], factories[3]);
+ assertNotSame(factories[1], factories[2]);
+ assertNotSame(factories[1], factories[0]);
+ assertNotSame(factories[0], factories[4]);
+
+ MockMailboxManagerFactory mockFactory1 = (MockMailboxManagerFactory) factories[1];
+ MockMailboxManagerFactory mockFactory2 = (MockMailboxManagerFactory) factories[2];
+ MockMailboxManagerFactory mockFactory4 = (MockMailboxManagerFactory) factories[4];
+
+ Configuration[] mounts = conf.getChild(
+ "mounts", false).getChildren("mount");
+
+ assertEquals(mounts[0].getChild("target", false),
+ mockFactory1.configuration);
+ assertEquals(mounts[1].getChild("target", false),
+ mockFactory2.configuration);
+ assertEquals(mounts[3].getChild("target", false),
+ mockFactory4.configuration);
+
+ assertEquals(1, mockFactory1.init);
+ assertEquals(1, mockFactory2.init);
+ assertEquals(1, mockFactory4.init);
+
+ assertTrue(factories[0] instanceof MailStoreMailboxManagerFactory);
+
+
+ }
+
+
+ public void testMountMap() {
+ Map mountMap = virtualMailboxManagerFactory.getMountMap();
+ String[] expected = { "xaaa", "xaab", "zaa", "b", "c" };
+ mountMap.put("c", "x");
+ mountMap.put("xaaa", "x");
+ mountMap.put("xaab", "x");
+ mountMap.put("zaa", "x");
+ mountMap.put("b", "x");
+ List resultList = new ArrayList(mountMap.keySet());
+ List expectedList = Arrays.asList(expected);
+ assertEquals(expectedList, resultList);
+ }
+
+ protected static Set toSet(Object[] o) {
+ return new HashSet(Arrays.asList(o));
+ }
+
+}
Propchange: james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/impl/VirtualMailboxManagerFactoryTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/impl/VirtualMailboxManagerTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/impl/VirtualMailboxManagerTest.java?view=auto&rev=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/impl/VirtualMailboxManagerTest.java (added)
+++ james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/impl/VirtualMailboxManagerTest.java Thu Nov 16 11:50:48 2006
@@ -0,0 +1,179 @@
+/****************************************************************
+ * 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.mailboxmanager.impl;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+import org.apache.james.mailboxmanager.ListResult;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.impl.VirtualMailboxManagerFactory.LengthComparator;
+import org.apache.james.mailboxmanager.manager.MailboxManager;
+import org.apache.james.mailboxmanager.manager.MailboxManagerFactory;
+import org.apache.james.mailboxmanager.mock.MockUser;
+import org.apache.james.services.User;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
+import org.jmock.core.Constraint;
+import org.jmock.core.constraint.IsEqual;
+import org.jmock.core.constraint.IsSame;
+
+public class VirtualMailboxManagerTest extends MockObjectTestCase {
+
+ protected User user = new MockUser();
+
+ protected VirtualMailboxManager virtualMailboxManager;
+
+ public void setUp() {
+ virtualMailboxManager = new VirtualMailboxManager();
+ virtualMailboxManager.setUser(user);
+ }
+
+ public void testGetMailboxManager() throws MailboxManagerException {
+ String[] points = { "#mail", "#mail.t1.t2", "#mail.t1", "#user",
+ "#user.t1.t2.t3" };
+ MailboxManager[] manager = new MailboxManager[] {
+ (MailboxManager) mock(MailboxManager.class).proxy(),
+ (MailboxManager) mock(MailboxManager.class).proxy(),
+ (MailboxManager) mock(MailboxManager.class).proxy(),
+ (MailboxManager) mock(MailboxManager.class).proxy(),
+ (MailboxManager) mock(MailboxManager.class).proxy() };
+ Mock[] mailboxManagerFactoryMocks = createMailboxManagerFactoryMocks(
+ manager, 2);
+ MailboxManagerFactory[] mailboxManagerFactories = proxyFactoryMocks(mailboxManagerFactoryMocks);
+
+ addMountPoints(points, mailboxManagerFactories);
+ assertSame(manager[0], virtualMailboxManager
+ .getMailboxManager("#mail.t3"));
+ assertSame(manager[0], virtualMailboxManager.getMailboxManager("#mail"));
+ assertSame(manager[1], virtualMailboxManager
+ .getMailboxManager("#mail.t1.t2"));
+ assertSame(manager[1], virtualMailboxManager
+ .getMailboxManager("#mail.t1.t2.t4"));
+ assertSame(manager[2], virtualMailboxManager
+ .getMailboxManager("#mail.t1"));
+ assertSame(manager[2], virtualMailboxManager
+ .getMailboxManager("#mail.t1.t3"));
+ assertSame(manager[3], virtualMailboxManager.getMailboxManager("#user"));
+ assertSame(manager[3], virtualMailboxManager
+ .getMailboxManager("#user.t2"));
+ assertSame(manager[4], virtualMailboxManager
+ .getMailboxManager("#user.t1.t2.t3"));
+ assertSame(manager[4], virtualMailboxManager
+ .getMailboxManager("#user.t1.t2.t3.t4"));
+ assertNull(virtualMailboxManager.getMailboxManager("#other"));
+
+ }
+
+ public void testList() throws MailboxManagerException {
+ String[] expected = { "#mail.t1.t2", "#mail.t1.t3", "#mail",
+ "#mail.group.t5", "#mail.group.6", "#system.t1" };
+ String[] points = { "#mail", "#mail.group", "#system" };
+ Mock[] mailboxManagerMocks = { mock(MailboxManager.class),
+ mock(MailboxManager.class), mock(MailboxManager.class) };
+ MailboxManager[] mailboxManager = proxyMocks(mailboxManagerMocks);
+ Mock[] mailboxManagerFactoryMocks = createMailboxManagerFactoryMocks(
+ mailboxManager, 1);
+ MailboxManagerFactory[] mailboxManagerFactories = proxyFactoryMocks(mailboxManagerFactoryMocks);
+
+ Constraint[] args = { new IsEqual(""), new IsEqual("%"),
+ new IsEqual(Boolean.FALSE) };
+
+ mailboxManagerMocks[0].expects(once()).method("list").with(args).will(
+ returnValue(generateListResults(new String[] { expected[0],
+ expected[1], expected[2] })));
+
+ mailboxManagerMocks[1].expects(once()).method("list").with(args).will(
+ returnValue(generateListResults(new String[] { expected[3],
+ expected[4] })));
+
+ mailboxManagerMocks[2].expects(once()).method("list").with(args).will(
+ returnValue(generateListResults(new String[] { expected[5] })));
+
+ addMountPoints(points, mailboxManagerFactories);
+
+ ListResult[] result = virtualMailboxManager.list("", "%", false);
+ assertEquals(expected.length, result.length);
+ assertEquals(new HashSet(Arrays.asList(expected)), toNamesSet(result));
+ System.out.println(toNamesSet(result));
+
+ }
+
+ protected Mock[] createMailboxManagerFactoryMocks(MailboxManager[] manager,
+ int expected) {
+ Mock[] mocks = new Mock[manager.length];
+ for (int i = 0; i < mocks.length; i++) {
+ mocks[i] = mock(MailboxManagerFactory.class);
+ mocks[i].expects(exactly(expected)).method(
+ "getMailboxManagerInstance").with(new IsSame(user)).will(
+ returnValue(manager[i]));
+ }
+ return mocks;
+ }
+
+ protected static MailboxManager[] proxyMocks(Mock[] mocks) {
+ MailboxManager[] managers = new MailboxManager[mocks.length];
+ for (int i = 0; i < mocks.length; i++) {
+ managers[i] = (MailboxManager) mocks[i].proxy();
+ }
+ return managers;
+ }
+
+ protected static MailboxManagerFactory[] proxyFactoryMocks(Mock[] mocks) {
+ MailboxManagerFactory[] factories = new MailboxManagerFactory[mocks.length];
+ for (int i = 0; i < mocks.length; i++) {
+ factories[i] = (MailboxManagerFactory) mocks[i].proxy();
+ }
+ return factories;
+ }
+
+ protected void addMountPoints(String[] points,
+ MailboxManagerFactory[] mailboxManagerFactories) {
+ Map mountMap = new TreeMap(new LengthComparator());
+ for (int i = 0; i < mailboxManagerFactories.length; i++) {
+
+ mountMap.put(points[i], mailboxManagerFactories[i]);
+ }
+ virtualMailboxManager.setMountMap(mountMap);
+ }
+
+ protected static Set toNamesSet(ListResult[] listResult) {
+ Set nameSet = new HashSet();
+ for (int i = 0; i < listResult.length; i++) {
+ nameSet.add(listResult[i].getName());
+ }
+ return nameSet;
+ }
+
+ protected static ListResult[] generateListResults(String[] names) {
+ ListResult[] result = new ListResult[names.length];
+ for (int i = 0; i < names.length; i++) {
+ result[i] = new ListResultImpl(names[i], ".");
+ }
+ return result;
+ }
+
+}
Propchange: james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/impl/VirtualMailboxManagerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/mailstore/MailStoreMailboxCacheTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/mailstore/MailStoreMailboxCacheTest.java?view=auto&rev=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/mailstore/MailStoreMailboxCacheTest.java (added)
+++ james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/mailstore/MailStoreMailboxCacheTest.java Thu Nov 16 11:50:48 2006
@@ -0,0 +1,95 @@
+/****************************************************************
+ * 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.mailboxmanager.mailstore;
+
+import java.util.Arrays;
+
+import org.apache.avalon.cornerstone.services.store.Store;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.mailbox.MailboxSession;
+import org.apache.james.services.MailRepository;
+import org.apache.james.test.mock.avalon.MockLogger;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
+import org.jmock.core.constraint.IsEqual;
+
+public class MailStoreMailboxCacheTest extends MockObjectTestCase {
+
+ MailstoreMailboxCache mailstoreMailboxCache;
+
+ public void setUp() {
+ mailstoreMailboxCache = new MailstoreMailboxCache();
+ mailstoreMailboxCache.enableLogging(new MockLogger());
+ mailstoreMailboxCache.setMountPoint("#mail");
+ mailstoreMailboxCache.setDestinationURL("file://var/mail/inboxes/");
+ }
+
+ public void testBuildUrlNoInbox() {
+ assertEquals("file://var/mail/inboxes/t1", mailstoreMailboxCache
+ .buildUrl("#mail.t1"));
+ assertEquals("file://var/mail/inboxes/t1.t2", mailstoreMailboxCache
+ .buildUrl("#mail.t1.t2"));
+ }
+
+ public void testBuildUrlInbox() {
+ assertEquals("file://var/mail/inboxes/t1", mailstoreMailboxCache
+ .buildUrl("#mail.t1.INBOX"));
+ assertEquals("file://var/mail/inboxes/t1.t2", mailstoreMailboxCache
+ .buildUrl("#mail.t1.t2.INBOX"));
+ }
+
+ public void testGetMailboxSession() throws MailboxManagerException,
+ ConfigurationException {
+
+ DefaultConfiguration repositoryConfiguration = new DefaultConfiguration(
+ "repository");
+
+ DefaultConfiguration expectedConfiguration = new DefaultConfiguration(
+ repositoryConfiguration);
+ expectedConfiguration.setAttribute("destinationURL",
+ "file://var/mail/inboxes/t1");
+
+ Mock store = mock(Store.class);
+ Mock mockRepository = mock(MailRepository.class);
+ store.expects(exactly(2)).method("select").with(
+ new IsEqual(expectedConfiguration)).will(
+ returnValue(mockRepository.proxy()));
+
+ mailstoreMailboxCache.setMailStore((Store) store.proxy());
+ mailstoreMailboxCache.setRepositoryConf(repositoryConfiguration);
+ MailboxSession s1 = mailstoreMailboxCache.getMailboxSession("#mail.t1.INBOX");
+ MailboxSession s2 = mailstoreMailboxCache.getMailboxSession("#mail.t1.INBOX");
+ assertNotSame(s1, s2);
+ s1.close();
+ MailboxSession s3 = mailstoreMailboxCache.getMailboxSession("#mail.t1.INBOX");
+ s3.close();
+ s2.close();
+
+ MailboxSession s4 = mailstoreMailboxCache.getMailboxSession("#mail.t1.INBOX");
+
+ String[] keys = new String[] { "test" };
+ mockRepository.expects(once()).method("list").withNoArguments().will(
+ returnIterator(keys));
+ assertEquals(Arrays.asList(keys), s4.list());
+ }
+
+}
Propchange: james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/mailstore/MailStoreMailboxCacheTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/mock/MockMailboxManagerFactory.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/mock/MockMailboxManagerFactory.java?view=auto&rev=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/mock/MockMailboxManagerFactory.java (added)
+++ james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/mock/MockMailboxManagerFactory.java Thu Nov 16 11:50:48 2006
@@ -0,0 +1,63 @@
+/****************************************************************
+ * 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.mailboxmanager.mock;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+import org.apache.james.mailboxmanager.manager.MailboxManager;
+import org.apache.james.mailboxmanager.manager.MailboxManagerFactory;
+import org.apache.james.services.User;
+
+public class MockMailboxManagerFactory implements MailboxManagerFactory, Configurable, Initializable {
+
+ public Configuration configuration;
+
+ public Set mountPoints = new HashSet() ;
+
+ public int init=0;
+
+ public void deleteEverything() throws MailboxManagerException {
+ }
+
+ public MailboxManager getMailboxManagerInstance(User user) throws MailboxManagerException {
+ return null;
+ }
+
+ public void configure(Configuration configuration) throws ConfigurationException {
+ this.configuration=configuration;
+
+ }
+
+
+ public void addMountPoint(String point) {
+ mountPoints.add(point);
+ }
+
+ public void initialize() throws Exception {
+ init++;
+ }
+
+}
Propchange: james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/mock/MockMailboxManagerFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/mock/TorqueMailboxManagerProviderSingleton.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/mock/TorqueMailboxManagerProviderSingleton.java?view=diff&rev=475896&r1=475895&r2=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/mock/TorqueMailboxManagerProviderSingleton.java (original)
+++ james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/mock/TorqueMailboxManagerProviderSingleton.java Thu Nov 16 11:50:48 2006
@@ -1,22 +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.mailboxmanager.mock;
-import org.apache.james.mailboxmanager.torque.TorqueMailboxManagerProvider;
+import org.apache.james.mailboxmanager.impl.DefaultMailboxManagerProvider;
+import org.apache.james.mailboxmanager.manager.MailboxManagerProvider;
+import org.apache.james.mailboxmanager.torque.TorqueMailboxManagerFactory;
import org.apache.james.test.mock.james.MockFileSystem;
public class TorqueMailboxManagerProviderSingleton {
- private static TorqueMailboxManagerProvider torqueMailboxManagerProvider;
+ private static DefaultMailboxManagerProvider defaultMailboxManagerProvider;
- public synchronized static TorqueMailboxManagerProvider getTorqueMailboxManagerProviderInstance() throws Exception {
- if (torqueMailboxManagerProvider==null) {
- torqueMailboxManagerProvider=new TorqueMailboxManagerProvider() {{
+ public synchronized static MailboxManagerProvider getTorqueMailboxManagerProviderInstance() throws Exception {
+ if (defaultMailboxManagerProvider==null) {
+ TorqueMailboxManagerFactory torqueMailboxManagerFactory=new TorqueMailboxManagerFactory() {{
setFileSystem(new MockFileSystem());
}};
- torqueMailboxManagerProvider.configureDefaults();
- torqueMailboxManagerProvider.initialize();
+ torqueMailboxManagerFactory.configureDefaults();
+ torqueMailboxManagerFactory.initialize();
+ defaultMailboxManagerProvider=new DefaultMailboxManagerProvider();
+ defaultMailboxManagerProvider.setMailboxManagerFactory(torqueMailboxManagerFactory);
}
- return torqueMailboxManagerProvider;
+ return defaultMailboxManagerProvider;
}
Added: james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/testdata/DefaultMailboxManagerConf.xml
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/testdata/DefaultMailboxManagerConf.xml?view=auto&rev=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/testdata/DefaultMailboxManagerConf.xml (added)
+++ james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/testdata/DefaultMailboxManagerConf.xml Thu Nov 16 11:50:48 2006
@@ -0,0 +1,23 @@
+<config>
+ <mailboxmanager>
+ <namespaces>
+ <usernamespace name="#mail" delimiter="." />
+ </namespaces>
+
+ <factory class="org.apache.james.mailboxmanager.mock.MockMailboxManagerFactory">
+ <mount>
+ <point point="#system" />
+ <target class="org.apache.james.mailboxmanager.impl.MailStoreMailboxManager">
+ <repository destinationURL="file://var/mail/" type="MAIL" />
+ </target>
+ </mount>
+ <mount>
+ <point point="#mail" />
+ <target type="service" service="org.apache.james.mailboxmanager.impl.MailStoreMailboxManager">
+ <repository destinationURL="file://var/mail/inboxes/" type="MAIL" />
+ </target>
+ </mount>
+ </factory>
+ </mailboxmanager>
+
+</config>
Propchange: james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/testdata/DefaultMailboxManagerConf.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/testdata/VirtualRepositoryMix.xml
URL: http://svn.apache.org/viewvc/james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/testdata/VirtualRepositoryMix.xml?view=auto&rev=475896
==============================================================================
--- james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/testdata/VirtualRepositoryMix.xml (added)
+++ james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/testdata/VirtualRepositoryMix.xml Thu Nov 16 11:50:48 2006
@@ -0,0 +1,110 @@
+<config>
+ <mailboxmanager>
+ <namespaces>
+ <usernamespace name="#mail" delimiter="."/>
+ </namespaces>
+ <factory
+ class="org.apache.james.mailboxmanager.impl.VirtualMailboxManagerFactory">
+ <mounts>
+ <mount>
+ <point point="#user"/>
+ <point point="#user1"/>
+ <target
+ class="org.apache.james.mailboxmanager.mock.MockMailboxManagerFactory">
+ <myconf attr="test"/>
+ </target>
+ </mount>
+
+ <mount>
+ <point point="#user2"/>
+ <point point="#user3"/>
+ <target
+ class="org.apache.james.mailboxmanager.mock.MockMailboxManagerFactory">
+ <myconf attr="test2"/>
+ </target>
+ </mount>
+ <mount>
+ <point point="#system"/>
+ <target
+ class="org.apache.james.mailboxmanager.mailstore.MailStoreMailboxManagerFactory">
+ <repository destinationURL="file://var/mail/"
+ type="MAIL"/>
+ </target>
+ </mount>
+ <mount>
+ <point point="#mail"/>
+ <target
+ class="org.apache.james.mailboxmanager.torque.TorqueMailboxManagerFactory">
+ <torque-properties>
+ <property name="torque.database.default"
+ value="mailboxmanager"/>
+ <property
+ name="torque.database.mailboxmanager.adapter"
+ value="derby"/>
+ <property
+ name="torque.dsfactory.mailboxmanager.factory"
+ value="org.apache.torque.dsfactory.SharedPoolDataSourceFactory"/>
+ <property
+ name="torque.dsfactory.mailboxmanager.connection.driver"
+ value="org.apache.derby.jdbc.EmbeddedDriver"/>
+ <property
+ name="torque.dsfactory.mailboxmanager.connection.url"
+ value="jdbc:derby:tmp/mailboxmanager-derbydb;create=true"/>
+ <property
+ name="torque.dsfactory.mailboxmanager.connection.user"
+ value="app"/>
+ <property
+ name="torque.dsfactory.mailboxmanager.connection.password"
+ value="app"/>
+ <property
+ name="torque.dsfactory.mailboxmanager.pool.maxActive"
+ value="100"/>
+ </torque-properties>
+ </target>
+ </mount>
+ </mounts>
+ </factory>
+ </mailboxmanager>
+ <mailboxmanager-without-torque>
+ <namespaces>
+ <usernamespace name="#mail" delimiter="."/>
+ </namespaces>
+ <factory
+ class="org.apache.james.mailboxmanager.impl.VirtualMailboxManagerFactory">
+ <mounts>
+ <mount>
+ <point point="#user"/>
+ <point point="#user1"/>
+ <target
+ class="org.apache.james.mailboxmanager.mock.MockMailboxManagerFactory">
+ <myconf attr="test"/>
+ </target>
+ </mount>
+
+ <mount>
+ <point point="#user2"/>
+ <point point="#user3"/>
+ <target
+ class="org.apache.james.mailboxmanager.mock.MockMailboxManagerFactory">
+ <myconf attr="test2"/>
+ </target>
+ </mount>
+ <mount>
+ <point point="#system"/>
+ <target
+ class="org.apache.james.mailboxmanager.mailstore.MailStoreMailboxManagerFactory">
+ <repository destinationURL="file://var/mail/"
+ type="MAIL"/>
+ </target>
+ </mount>
+ <mount>
+ <point point="#mail"/>
+ <target
+ class="org.apache.james.mailboxmanager.mock.MockMailboxManagerFactory">
+ <myconf attr="test3"/>
+ </target>
+ </mount>
+ </mounts>
+ </factory>
+ </mailboxmanager-without-torque>
+</config>
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
Re: About namespaces (Was: svn commit: r475896 [2/2])
Posted by Joachim Draeger <jd...@gmx.de>.
Hi Stefano,
Am Montag, den 20.11.2006, 13:03 +0100 schrieb Stefano Bagnara:
> thank you for the explanation. I'm not sure I understand why we need to
> use this namespaces in james.
> If I understood you javamail has this namespaces, ok, but I'm not sure
> it is simpler to keep this layer also in james...
IMAP needs them too, to announce the available "drives" to the client.
And I wouldn't call them a layer, because only the client has to care
about the interpretation. Apart from very few exceptions we only have
mailboxNames (Strings).
> The only real advantage I see in using namespaces against standard
> mountpoints is that namespaces allow you to specify a different
> hierarchy delimiter, otherwise we could simply consider the first part
> of the path as the namespace and we would have the same behaviours of
> using namespaces...
I'm not against doing this by convention. At the moment I'm even doing
that because I'm lazy. ;-)
Defining a global hierarchy delimiter would make some things easier.
We need to define the available namespaces (roots) somewhere for IMAP
and I think that it's a good idea to do it at a central point.
It could be reused by other services (e.g. JavaMail Store bridge).
The only alternative would be defining it privately for IMAP.
BTW: I appreciate your efforts to pull out complexity. :-) I consider
over-design a greater risk than inflexible features.
> What I like about the virtual provider is that I think greatly simplify
> our core concepts by removing the complexity of the current
> db/dbfile/file from most of the configuration. So I think we should
> introduce new layers only when they really give us advantages...
The VirtualMailboxManager is a layer. But it is completely transparent
for the API.
The accessing code just knows MailboxManagerProvider and MailboxManager.
The backend code needs to implement MailboxManagerFactory.
VirtualMailboxManager is interchangeable.
> Maybe I'm simply missing some "namespace" related feature....
Maybe because you consider it as layer. I would call it bookmark or
advise.
Well, I'm thinking much about this. I like the single unix root much
more than windows drives. ;-) But windows does not allow to use
different delimiters on that drives! ;-)
Joachim
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
Re: About namespaces (Was: svn commit: r475896 [2/2])
Posted by Stefano Bagnara <ap...@bago.org>.
Hi Joachim,
thank you for the explanation. I'm not sure I understand why we need to
use this namespaces in james.
If I understood you javamail has this namespaces, ok, but I'm not sure
it is simpler to keep this layer also in james...
The only real advantage I see in using namespaces against standard
mountpoints is that namespaces allow you to specify a different
hierarchy delimiter, otherwise we could simply consider the first part
of the path as the namespace and we would have the same behaviours of
using namespaces...
What I like about the virtual provider is that I think greatly simplify
our core concepts by removing the complexity of the current
db/dbfile/file from most of the configuration. So I think we should
introduce new layers only when they really give us advantages...
Maybe I'm simply missing some "namespace" related feature....
Stefano
Joachim Draeger wrote:
> Hi Stefano,
>
> Am Freitag, den 17.11.2006, 19:23 +0100 schrieb Stefano Bagnara:
>
>> Can you elaborate on the "namespaces"?
>> Is namespace only the first part of the path? Why do we deserve a
>> special name for it?
>
> It's again an IMAP thing. (JavaMail as being close to IMAP, supports it
> too).
>
> http://www.rfc-editor.org/rfc/rfc2342.txt
> http://java.sun.com/products/javamail/javadocs/javax/mail/Store.html#getSharedNamespaces()
>
> It's a bit like windows drives. So there can be more than one root. The
> client can ask for the namespaces
>
> 1. his personal (e.g. "#users.tester")
> 2. users (e.g. "#users")
> 3. shared (e.g. "#shared","#news","#system")
>
> and gets an idea where to look.
> The client can visualize this with different icons/structure.
> To make things more complicated each namespace can have its own
> hierarchy delimiter e.g. "." or "/". (useful when wiring different
> implementations together).
> A namespace has a prefix. But this prefix can be freely chosen. We just
> should use a commonly used scheme like "#xyz" as a prefix. There may be
> others.
> We can start by just supporting one hierarchy delimiter. I personally
> prefer ".".
>
> At the moment and for most operations the namespaces are just a
> configurable thing to propagate to the (imap) clients.
> Internally MailboxManager doesn't care which hierarchy delimiter or
> which prefix you use. (the "flat hierarchy" idea, mailbox names are just
> strings, we don't care for parents or childs).
> The only exception is the list command that allows a wildcard that does
> not match the hierarchy delimiter (-> rfc3501 6.3.8. LIST Command).
>
> Important: I consider them as independent from the virtual mounts. So to
> call the branch "mailbox-namespaces" was probably not well fitting. :-)
> It may be a common use to mount namespace prefixes to different
> backends, but it is not a limitation. You can mount to different
> backends in the same namespace.
>
> Conclusion:
> They are just configured and propagated through MailboxManagerProvider.
> The implementations don't have to care too much for them. The client
> does the interpretation.
>
>> (I'm not against it, I'm just trying to collect more information :-) )
>
> Great! I just thought about being less verbose this morning, because it
> takes so much time to elaborate unsolicited big proposals and
> explanations.
> So please review and ask such questions, I'll answer willingly! :-)
>
> Joachim
>
> P.S. the content in the config.xml is a placeholder without a backing
> implementation. static constants are used at the moment.
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
Re: About namespaces (Was: svn commit: r475896 [2/2])
Posted by Joachim Draeger <jd...@gmx.de>.
Hi Stefano,
Am Freitag, den 17.11.2006, 19:23 +0100 schrieb Stefano Bagnara:
> Can you elaborate on the "namespaces"?
> Is namespace only the first part of the path? Why do we deserve a
> special name for it?
It's again an IMAP thing. (JavaMail as being close to IMAP, supports it
too).
http://www.rfc-editor.org/rfc/rfc2342.txt
http://java.sun.com/products/javamail/javadocs/javax/mail/Store.html#getSharedNamespaces()
It's a bit like windows drives. So there can be more than one root. The
client can ask for the namespaces
1. his personal (e.g. "#users.tester")
2. users (e.g. "#users")
3. shared (e.g. "#shared","#news","#system")
and gets an idea where to look.
The client can visualize this with different icons/structure.
To make things more complicated each namespace can have its own
hierarchy delimiter e.g. "." or "/". (useful when wiring different
implementations together).
A namespace has a prefix. But this prefix can be freely chosen. We just
should use a commonly used scheme like "#xyz" as a prefix. There may be
others.
We can start by just supporting one hierarchy delimiter. I personally
prefer ".".
At the moment and for most operations the namespaces are just a
configurable thing to propagate to the (imap) clients.
Internally MailboxManager doesn't care which hierarchy delimiter or
which prefix you use. (the "flat hierarchy" idea, mailbox names are just
strings, we don't care for parents or childs).
The only exception is the list command that allows a wildcard that does
not match the hierarchy delimiter (-> rfc3501 6.3.8. LIST Command).
Important: I consider them as independent from the virtual mounts. So to
call the branch "mailbox-namespaces" was probably not well fitting. :-)
It may be a common use to mount namespace prefixes to different
backends, but it is not a limitation. You can mount to different
backends in the same namespace.
Conclusion:
They are just configured and propagated through MailboxManagerProvider.
The implementations don't have to care too much for them. The client
does the interpretation.
> (I'm not against it, I'm just trying to collect more information :-) )
Great! I just thought about being less verbose this morning, because it
takes so much time to elaborate unsolicited big proposals and
explanations.
So please review and ask such questions, I'll answer willingly! :-)
Joachim
P.S. the content in the config.xml is a placeholder without a backing
implementation. static constants are used at the moment.
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
About namespaces (Was: svn commit: r475896 [2/2])
Posted by Stefano Bagnara <ap...@bago.org>.
Hi Joachim,
First of all, great to see you already implemented all of this stuff!
I had this goal for months, but never found the time to really do that,
so a big thank you again!
Can you elaborate on the "namespaces"?
Is namespace only the first part of the path? Why do we deserve a
special name for it?
(I'm not against it, I'm just trying to collect more information :-) )
Stefano
joachim@apache.org wrote:
> +++ james/server/sandbox/mailbox-namespaces/src/test/org/apache/james/mailboxmanager/testdata/DefaultMailboxManagerConf.xml Thu Nov 16 11:50:48 2006
> @@ -0,0 +1,23 @@
> +<config>
> + <mailboxmanager>
> + <namespaces>
> + <usernamespace name="#mail" delimiter="." />
> + </namespaces>
> +
> + <factory class="org.apache.james.mailboxmanager.mock.MockMailboxManagerFactory">
> + <mount>
> + <point point="#system" />
> + <target class="org.apache.james.mailboxmanager.impl.MailStoreMailboxManager">
> + <repository destinationURL="file://var/mail/" type="MAIL" />
> + </target>
> + </mount>
> + <mount>
> + <point point="#mail" />
> + <target type="service" service="org.apache.james.mailboxmanager.impl.MailStoreMailboxManager">
> + <repository destinationURL="file://var/mail/inboxes/" type="MAIL" />
> + </target>
> + </mount>
> + </factory>
> + </mailboxmanager>
> +
> +</config>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org