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 ba...@apache.org on 2006/05/10 18:46:58 UTC

svn commit: r405795 [1/5] - in /james/server/trunk: ./ src/test/org/apache/james/ src/test/org/apache/james/core/ src/test/org/apache/james/mailrepository/ src/test/org/apache/james/pop3server/ src/test/org/apache/james/remotemanager/ src/test/org/apac...

Author: bago
Date: Wed May 10 09:46:54 2006
New Revision: 405795

URL: http://svn.apache.org/viewcvs?rev=405795&view=rev
Log:
Fix newlines in test classes, added a fixcrlf for test folder to the build.xml, added svn:eol-style native to the test files.

Added:
    james/server/trunk/src/test/org/apache/james/mailrepository/
    james/server/trunk/src/test/org/apache/james/mailrepository/JDBCMailRepositoryTest.java   (with props)
Modified:
    james/server/trunk/build.xml
    james/server/trunk/src/test/org/apache/james/JamesTest.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/JamesTestConfiguration.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/core/MailImplTest.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/core/MailTestAllImplementations.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/core/MimeMessageCopyOnWriteProxyTest.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/core/MimeMessageFromMimeMessageTest.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/core/MimeMessageFromSharedStreamTest.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/core/MimeMessageFromStreamTest.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/core/MimeMessageTest.java   (props changed)
    james/server/trunk/src/test/org/apache/james/core/MimeMessageUtilTest.java   (props changed)
    james/server/trunk/src/test/org/apache/james/core/MimeMessageWrapperTest.java   (props changed)
    james/server/trunk/src/test/org/apache/james/pop3server/POP3ServerTest.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/pop3server/POP3TestConfiguration.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/remotemanager/RemoteManagerTest.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/remotemanager/RemoteManagerTestConfiguration.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/services/MailServerTestAllImplementations.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/smtpserver/SMTPServerTest.java
    james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockContext.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockLogger.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockServiceManager.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockSocketManager.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockStore.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/test/mock/avalon/MockThreadManager.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/test/mock/james/MockMailRepository.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/test/mock/james/MockMailServer.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/test/mock/james/MockSpoolRepository.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/test/mock/james/MockUsersStore.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/test/mock/javaxmail/MockMimeMessage.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/test/mock/mailet/MockMailContext.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/test/mock/mailet/MockMailetConfig.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/test/util/Util.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/transport/LinearProcessorTest.java   (props changed)
    james/server/trunk/src/test/org/apache/james/transport/mailets/AddFooterTest.java   (props changed)
    james/server/trunk/src/test/org/apache/james/userrepository/MockUsersRepository.java   (contents, props changed)
    james/server/trunk/src/test/org/apache/james/util/ExtraDotOutputStreamTest.java   (contents, props changed)

Modified: james/server/trunk/build.xml
URL: http://svn.apache.org/viewcvs/james/server/trunk/build.xml?rev=405795&r1=405794&r2=405795&view=diff
==============================================================================
--- james/server/trunk/build.xml (original)
+++ james/server/trunk/build.xml Wed May 10 09:46:54 2006
@@ -144,6 +144,7 @@
       <fixcrlf srcdir="${java.dir}" includes="**/*.minfo" eol="lf" tab="remove" tablength="4" />
       <fixcrlf srcdir="${java.dir}" includes="**/*.xinfo" eol="lf" tab="remove" tablength="4" />
       <fixcrlf srcdir="${java.dir}" includes="**/*.html" eol="lf" tab="remove" tablength="4" />
+      <fixcrlf srcdir="${junitjava.dir}" includes="**/*.java" eol="lf" tab="remove" tablength="4" />
       <!-- fixcrlf srcdir="${xdocs.dir}" includes="**/*.xml" eol="lf" tab="remove" tablength="4" / -->
       <fixcrlf srcdir="${conf.dir}" includes="**/*.xml" eol="lf" tab="remove" tablength="4" />
       <fixcrlf srcdir="${metainf.dir}" includes="**/*" eol="lf" tab="remove" tablength="4" />      

Modified: james/server/trunk/src/test/org/apache/james/JamesTest.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/JamesTest.java?rev=405795&r1=405794&r2=405795&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/JamesTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/JamesTest.java Wed May 10 09:46:54 2006
@@ -1,80 +1,80 @@
-/***********************************************************************
- * Copyright (c) 2000-2006 The Apache Software Foundation.             *
- * All rights reserved.                                                *
- * ------------------------------------------------------------------- *
- * Licensed 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;
-
-import org.apache.avalon.cornerstone.services.store.Store;
-import org.apache.avalon.framework.container.ContainerUtil;
-import org.apache.james.services.MailServer;
-import org.apache.james.services.MailServerTestAllImplementations;
-import org.apache.james.services.UsersRepository;
-import org.apache.james.services.UsersStore;
-import org.apache.james.test.mock.avalon.MockContext;
-import org.apache.james.test.mock.avalon.MockLogger;
-import org.apache.james.test.mock.avalon.MockServiceManager;
-import org.apache.james.test.mock.avalon.MockStore;
-import org.apache.james.test.mock.james.MockUsersStore;
-import org.apache.james.test.mock.james.MockMailRepository;
-import org.apache.james.userrepository.MockUsersRepository;
-
-import java.io.File;
-
-public class JamesTest extends MailServerTestAllImplementations {
-
-    public MailServer createMailServer() {
-        James james = new James();
-        james.service(setUpServiceManager());
-        MockLogger mockLogger = new MockLogger();
-        mockLogger.disableDebug();
-        ContainerUtil.enableLogging(james, mockLogger);
-        try {
-            JamesTestConfiguration conf = new JamesTestConfiguration();
-            conf.init();
-            ContainerUtil.configure(james, conf);
-            ContainerUtil.contextualize(james, new MockContext(File.createTempFile("james_test", "tmp")));
-            ContainerUtil.initialize(james);
-        } catch (Exception e) {
-            e.printStackTrace();
-            fail("James.initialize() failed");
-        }
-        return james;
-    }
-
-    private MockServiceManager setUpServiceManager() {
-        MockServiceManager serviceManager = new MockServiceManager();
-        MockUsersRepository mockUsersRepository = new MockUsersRepository();
-        serviceManager.put(UsersRepository.ROLE, mockUsersRepository);
-        serviceManager.put(UsersStore.ROLE, new MockUsersStore(mockUsersRepository));
-        MockStore mockStore = new MockStore();
-        mockStore.add(EXISTING_USER_NAME, new MockMailRepository());
-        serviceManager.put(Store.ROLE, mockStore);
-        return serviceManager;
-    }
-
-    public boolean allowsPasswordlessUser() {
-        return false;
-    }
-
-    public boolean canTestUserExists() {
-        return true;
-    }
-
-    public boolean isUserExisting(MailServer mailServerImpl, String username) {
-        return ((James)mailServerImpl).isLocalUser(username);
-    }
-}
+/***********************************************************************
+ * Copyright (c) 2000-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed 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;
+
+import org.apache.avalon.cornerstone.services.store.Store;
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.james.services.MailServer;
+import org.apache.james.services.MailServerTestAllImplementations;
+import org.apache.james.services.UsersRepository;
+import org.apache.james.services.UsersStore;
+import org.apache.james.test.mock.avalon.MockContext;
+import org.apache.james.test.mock.avalon.MockLogger;
+import org.apache.james.test.mock.avalon.MockServiceManager;
+import org.apache.james.test.mock.avalon.MockStore;
+import org.apache.james.test.mock.james.MockUsersStore;
+import org.apache.james.test.mock.james.MockMailRepository;
+import org.apache.james.userrepository.MockUsersRepository;
+
+import java.io.File;
+
+public class JamesTest extends MailServerTestAllImplementations {
+
+    public MailServer createMailServer() {
+        James james = new James();
+        james.service(setUpServiceManager());
+        MockLogger mockLogger = new MockLogger();
+        mockLogger.disableDebug();
+        ContainerUtil.enableLogging(james, mockLogger);
+        try {
+            JamesTestConfiguration conf = new JamesTestConfiguration();
+            conf.init();
+            ContainerUtil.configure(james, conf);
+            ContainerUtil.contextualize(james, new MockContext(File.createTempFile("james_test", "tmp")));
+            ContainerUtil.initialize(james);
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("James.initialize() failed");
+        }
+        return james;
+    }
+
+    private MockServiceManager setUpServiceManager() {
+        MockServiceManager serviceManager = new MockServiceManager();
+        MockUsersRepository mockUsersRepository = new MockUsersRepository();
+        serviceManager.put(UsersRepository.ROLE, mockUsersRepository);
+        serviceManager.put(UsersStore.ROLE, new MockUsersStore(mockUsersRepository));
+        MockStore mockStore = new MockStore();
+        mockStore.add(EXISTING_USER_NAME, new MockMailRepository());
+        serviceManager.put(Store.ROLE, mockStore);
+        return serviceManager;
+    }
+
+    public boolean allowsPasswordlessUser() {
+        return false;
+    }
+
+    public boolean canTestUserExists() {
+        return true;
+    }
+
+    public boolean isUserExisting(MailServer mailServerImpl, String username) {
+        return ((James)mailServerImpl).isLocalUser(username);
+    }
+}

Propchange: james/server/trunk/src/test/org/apache/james/JamesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/trunk/src/test/org/apache/james/JamesTestConfiguration.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/JamesTestConfiguration.java?rev=405795&r1=405794&r2=405795&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/JamesTestConfiguration.java (original)
+++ james/server/trunk/src/test/org/apache/james/JamesTestConfiguration.java Wed May 10 09:46:54 2006
@@ -1,49 +1,49 @@
-/***********************************************************************
- * Copyright (c) 2000-2006 The Apache Software Foundation.             *
- * All rights reserved.                                                *
- * ------------------------------------------------------------------- *
- * Licensed 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;
-
-import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.james.test.util.Util;
-
-public class JamesTestConfiguration extends DefaultConfiguration {
-    
-    public JamesTestConfiguration() {
-        super("James");
-    }
-
-    public void init() {
-
-        //setAttribute("enabled", true);
-
-        DefaultConfiguration serverNamesConfig = new DefaultConfiguration("servernames");
-        serverNamesConfig.setAttribute("autodetect", false);
-        serverNamesConfig.addChild(Util.getValuedConfiguration("servername", "localhost"));
-        addChild(serverNamesConfig);
-
-        DefaultConfiguration inboxRepositoryConfig = new DefaultConfiguration("inboxRepository");
-
-        DefaultConfiguration repositoryConfig = new DefaultConfiguration("repository");
-        repositoryConfig.setAttribute("destinationURL", "db://maildb/inbox/");
-        repositoryConfig.setAttribute("type", "MAIL");
-        inboxRepositoryConfig.addChild(repositoryConfig);
-
-        addChild(inboxRepositoryConfig);
-    }
-
-}
+/***********************************************************************
+ * Copyright (c) 2000-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed 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;
+
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.james.test.util.Util;
+
+public class JamesTestConfiguration extends DefaultConfiguration {
+    
+    public JamesTestConfiguration() {
+        super("James");
+    }
+
+    public void init() {
+
+        //setAttribute("enabled", true);
+
+        DefaultConfiguration serverNamesConfig = new DefaultConfiguration("servernames");
+        serverNamesConfig.setAttribute("autodetect", false);
+        serverNamesConfig.addChild(Util.getValuedConfiguration("servername", "localhost"));
+        addChild(serverNamesConfig);
+
+        DefaultConfiguration inboxRepositoryConfig = new DefaultConfiguration("inboxRepository");
+
+        DefaultConfiguration repositoryConfig = new DefaultConfiguration("repository");
+        repositoryConfig.setAttribute("destinationURL", "db://maildb/inbox/");
+        repositoryConfig.setAttribute("type", "MAIL");
+        inboxRepositoryConfig.addChild(repositoryConfig);
+
+        addChild(inboxRepositoryConfig);
+    }
+
+}

Propchange: james/server/trunk/src/test/org/apache/james/JamesTestConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/trunk/src/test/org/apache/james/core/MailImplTest.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/core/MailImplTest.java?rev=405795&r1=405794&r2=405795&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/core/MailImplTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/core/MailImplTest.java Wed May 10 09:46:54 2006
@@ -1,96 +1,96 @@
-/***********************************************************************
- * Copyright (c) 2000-2006 The Apache Software Foundation.             *
- * All rights reserved.                                                *
- * ------------------------------------------------------------------- *
- * Licensed 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.core;
-
-import org.apache.james.test.mock.james.MockMailServer;
-import org.apache.james.test.mock.javaxmail.MockMimeMessage;
-import org.apache.mailet.MailAddress;
-import org.apache.mailet.Mail;
-
-import javax.mail.MessagingException;
-import java.util.ArrayList;
-
-public class MailImplTest extends MailTestAllImplementations {
-
-    protected Mail createMailImplementation() {
-        return new MailImpl();
-    }
-
-    public void testConstr1() throws MessagingException {
-        MailImpl mail = new MailImpl();
-
-        helperTestInitialState(mail);
-        helperTestMessageSize(mail, 0); // MimeMessageWrapper default is 0
-        assertNull("no initial message", mail.getMessage());
-        assertNull("no initial sender", mail.getSender());
-        assertNull("no initial name", mail.getName());
-    }
-
-    public void testConstr2() throws MessagingException {
-        ArrayList recepients = new ArrayList();
-        String name = new MockMailServer().getId();
-        String sender = "sender@localhost";
-        MailAddress senderMailAddress = new MailAddress(sender);
-        MailImpl mail = new MailImpl(name, senderMailAddress, recepients);
-
-        helperTestInitialState(mail); // MimeMessageWrapper default is 0
-        helperTestMessageSize(mail, 0); // MimeMessageWrapper default is 0
-        assertNull("no initial message", mail.getMessage());
-        assertEquals("sender", sender, mail.getSender().toString());
-        assertEquals("name", name, mail.getName());
-
-        mail.setMessage(new MockMimeMessage());
-        assertNotNull("message", mail.getMessage());
-    }
-
-    public void testConstr3() throws MessagingException {
-        ArrayList recepients = new ArrayList();
-        String name = new MockMailServer().getId();
-        String sender = "sender@localhost";
-        MailAddress senderMailAddress = new MailAddress(sender);
-        MockMimeMessage mimeMessage = new MockMimeMessage();
-        MailImpl mail = new MailImpl(name, senderMailAddress, recepients, mimeMessage);
-
-        helperTestInitialState(mail); 
-        helperTestMessageSize(mail, 0);
-        assertEquals("initial message", mimeMessage.getMessageID(), mail.getMessage().getMessageID());
-        assertEquals("sender", sender, mail.getSender().toString());
-        assertEquals("name", name, mail.getName());
-    }
-
-    public void testDuplicate() throws MessagingException {
-        MailImpl mail = new MailImpl();
-        MailImpl duplicate = (MailImpl) mail.duplicate();
-        assertNotSame("is real duplicate", mail, duplicate);
-        helperTestInitialState(duplicate);
-        helperTestMessageSize(duplicate, 0);
-    }
-
-    public void testDuplicateNewName() throws MessagingException {
-        String newName = "aNewName";
-        
-        MailImpl mail = new MailImpl();
-        assertFalse("before + after names differ", newName.equals(mail.getName()));
-        
-        MailImpl duplicate = (MailImpl) mail.duplicate(newName);
-        assertEquals("new name set", newName, duplicate.getName());
-        helperTestInitialState(duplicate);
-        helperTestMessageSize(duplicate, 0);
-    }
-}
+/***********************************************************************
+ * Copyright (c) 2000-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.core;
+
+import org.apache.james.test.mock.james.MockMailServer;
+import org.apache.james.test.mock.javaxmail.MockMimeMessage;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.Mail;
+
+import javax.mail.MessagingException;
+import java.util.ArrayList;
+
+public class MailImplTest extends MailTestAllImplementations {
+
+    protected Mail createMailImplementation() {
+        return new MailImpl();
+    }
+
+    public void testConstr1() throws MessagingException {
+        MailImpl mail = new MailImpl();
+
+        helperTestInitialState(mail);
+        helperTestMessageSize(mail, 0); // MimeMessageWrapper default is 0
+        assertNull("no initial message", mail.getMessage());
+        assertNull("no initial sender", mail.getSender());
+        assertNull("no initial name", mail.getName());
+    }
+
+    public void testConstr2() throws MessagingException {
+        ArrayList recepients = new ArrayList();
+        String name = new MockMailServer().getId();
+        String sender = "sender@localhost";
+        MailAddress senderMailAddress = new MailAddress(sender);
+        MailImpl mail = new MailImpl(name, senderMailAddress, recepients);
+
+        helperTestInitialState(mail); // MimeMessageWrapper default is 0
+        helperTestMessageSize(mail, 0); // MimeMessageWrapper default is 0
+        assertNull("no initial message", mail.getMessage());
+        assertEquals("sender", sender, mail.getSender().toString());
+        assertEquals("name", name, mail.getName());
+
+        mail.setMessage(new MockMimeMessage());
+        assertNotNull("message", mail.getMessage());
+    }
+
+    public void testConstr3() throws MessagingException {
+        ArrayList recepients = new ArrayList();
+        String name = new MockMailServer().getId();
+        String sender = "sender@localhost";
+        MailAddress senderMailAddress = new MailAddress(sender);
+        MockMimeMessage mimeMessage = new MockMimeMessage();
+        MailImpl mail = new MailImpl(name, senderMailAddress, recepients, mimeMessage);
+
+        helperTestInitialState(mail); 
+        helperTestMessageSize(mail, 0);
+        assertEquals("initial message", mimeMessage.getMessageID(), mail.getMessage().getMessageID());
+        assertEquals("sender", sender, mail.getSender().toString());
+        assertEquals("name", name, mail.getName());
+    }
+
+    public void testDuplicate() throws MessagingException {
+        MailImpl mail = new MailImpl();
+        MailImpl duplicate = (MailImpl) mail.duplicate();
+        assertNotSame("is real duplicate", mail, duplicate);
+        helperTestInitialState(duplicate);
+        helperTestMessageSize(duplicate, 0);
+    }
+
+    public void testDuplicateNewName() throws MessagingException {
+        String newName = "aNewName";
+        
+        MailImpl mail = new MailImpl();
+        assertFalse("before + after names differ", newName.equals(mail.getName()));
+        
+        MailImpl duplicate = (MailImpl) mail.duplicate(newName);
+        assertEquals("new name set", newName, duplicate.getName());
+        helperTestInitialState(duplicate);
+        helperTestMessageSize(duplicate, 0);
+    }
+}

Propchange: james/server/trunk/src/test/org/apache/james/core/MailImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/trunk/src/test/org/apache/james/core/MailTestAllImplementations.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/core/MailTestAllImplementations.java?rev=405795&r1=405794&r2=405795&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/core/MailTestAllImplementations.java (original)
+++ james/server/trunk/src/test/org/apache/james/core/MailTestAllImplementations.java Wed May 10 09:46:54 2006
@@ -1,69 +1,69 @@
-/***********************************************************************
- * Copyright (c) 2000-2006 The Apache Software Foundation.             *
- * All rights reserved.                                                *
- * ------------------------------------------------------------------- *
- * Licensed 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.core;
-
-import junit.framework.TestCase;
-
-import javax.mail.MessagingException;
-
-import org.apache.mailet.Mail;
-
-/**
- * testing common behavior of Mail implementors. subclasses automatically get their Mail-behavior tested.
- */
-public abstract class MailTestAllImplementations extends TestCase {
-
-    /** provide the concrete implementation to test */
-    protected abstract Mail createMailImplementation();
-
-    protected void helperTestInitialState(Mail mail) throws MessagingException {
-        assertFalse("no initial attributes", mail.hasAttributes());
-        assertNull("no initial error", mail.getErrorMessage());
-        assertNotNull("initial last update set", mail.getLastUpdated());
-        try {
-            assertTrue("no initial recipient", mail.getRecipients().isEmpty());
-        } catch (NullPointerException e) {
-            // current behavior. *BUT*, shouldn't this method better return with an empty list?!
-        }
-        assertEquals("initial remote address is localhost ip", "127.0.0.1", mail.getRemoteAddr());
-        assertEquals("initial remote host is localhost", "localhost", mail.getRemoteHost());
-        assertEquals("default initial state", Mail.DEFAULT, mail.getState());
-    }
-
-    protected void helperTestMessageSize(Mail mail, int expectedMsgSize) throws MessagingException {
-        try {
-            assertEquals("initial message size == " + expectedMsgSize, expectedMsgSize, mail.getMessageSize());
-        } catch (NullPointerException e) {
-            // current behavior. *BUT*, shouldn't this method return more gracefully?!
-        }
-    }
-
-    public void testAttributes() {
-        Mail mail = createMailImplementation();
-        assertFalse("no initial attributes", mail.hasAttributes());
-        assertFalse("attributes initially empty", mail.getAttributeNames().hasNext());
-        assertNull("not found on emtpy list", mail.getAttribute("test"));
-        assertNull("no previous item with key", mail.setAttribute("testKey", "testValue"));
-        assertEquals("item found", "testValue", mail.getAttribute("testKey"));
-        assertTrue("has attribute", mail.hasAttributes());
-        assertEquals("item removed", "testValue", mail.removeAttribute("testKey"));
-        assertNull("item no longer found", mail.getAttribute("testKey"));
-    }
-
-}
+/***********************************************************************
+ * Copyright (c) 2000-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.core;
+
+import junit.framework.TestCase;
+
+import javax.mail.MessagingException;
+
+import org.apache.mailet.Mail;
+
+/**
+ * testing common behavior of Mail implementors. subclasses automatically get their Mail-behavior tested.
+ */
+public abstract class MailTestAllImplementations extends TestCase {
+
+    /** provide the concrete implementation to test */
+    protected abstract Mail createMailImplementation();
+
+    protected void helperTestInitialState(Mail mail) throws MessagingException {
+        assertFalse("no initial attributes", mail.hasAttributes());
+        assertNull("no initial error", mail.getErrorMessage());
+        assertNotNull("initial last update set", mail.getLastUpdated());
+        try {
+            assertTrue("no initial recipient", mail.getRecipients().isEmpty());
+        } catch (NullPointerException e) {
+            // current behavior. *BUT*, shouldn't this method better return with an empty list?!
+        }
+        assertEquals("initial remote address is localhost ip", "127.0.0.1", mail.getRemoteAddr());
+        assertEquals("initial remote host is localhost", "localhost", mail.getRemoteHost());
+        assertEquals("default initial state", Mail.DEFAULT, mail.getState());
+    }
+
+    protected void helperTestMessageSize(Mail mail, int expectedMsgSize) throws MessagingException {
+        try {
+            assertEquals("initial message size == " + expectedMsgSize, expectedMsgSize, mail.getMessageSize());
+        } catch (NullPointerException e) {
+            // current behavior. *BUT*, shouldn't this method return more gracefully?!
+        }
+    }
+
+    public void testAttributes() {
+        Mail mail = createMailImplementation();
+        assertFalse("no initial attributes", mail.hasAttributes());
+        assertFalse("attributes initially empty", mail.getAttributeNames().hasNext());
+        assertNull("not found on emtpy list", mail.getAttribute("test"));
+        assertNull("no previous item with key", mail.setAttribute("testKey", "testValue"));
+        assertEquals("item found", "testValue", mail.getAttribute("testKey"));
+        assertTrue("has attribute", mail.hasAttributes());
+        assertEquals("item removed", "testValue", mail.removeAttribute("testKey"));
+        assertNull("item no longer found", mail.getAttribute("testKey"));
+    }
+
+}

Propchange: james/server/trunk/src/test/org/apache/james/core/MailTestAllImplementations.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/trunk/src/test/org/apache/james/core/MimeMessageCopyOnWriteProxyTest.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/core/MimeMessageCopyOnWriteProxyTest.java?rev=405795&r1=405794&r2=405795&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/core/MimeMessageCopyOnWriteProxyTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/core/MimeMessageCopyOnWriteProxyTest.java Wed May 10 09:46:54 2006
@@ -1,266 +1,266 @@
-/***********************************************************************
- * Copyright (c) 1999-2006 The Apache Software Foundation.             *
- * All rights reserved.                                                *
- * ------------------------------------------------------------------- *
- * Licensed 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.core;
-
-import org.apache.avalon.framework.container.ContainerUtil;
-import org.apache.mailet.Mail;
-import org.apache.mailet.MailAddress;
-
-import javax.mail.MessagingException;
-import javax.mail.Session;
-import javax.mail.internet.MimeMessage;
-import javax.mail.util.SharedByteArrayInputStream;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-public class MimeMessageCopyOnWriteProxyTest extends MimeMessageFromStreamTest {
-
-    String content = "Subject: foo\r\nContent-Transfer-Encoding2: plain";
-    String sep = "\r\n\r\n";
-    String body = "bar\r\n.\r\n";
-
-    protected MimeMessage getMessageFromSources(String sources) throws Exception {
-        MimeMessageInputStreamSource mmis = null;
-        try {
-            mmis = new MimeMessageInputStreamSource("test", new SharedByteArrayInputStream(sources.getBytes()));
-        } catch (MessagingException e) {
-        }
-        return new MimeMessageCopyOnWriteProxy(mmis);
-//        return new MimeMessage(Session.getDefaultInstance(new Properties()),new ByteArrayInputStream(sources.getBytes()));
-    }
-
-    public void testMessageCloning1() throws Exception {
-        ArrayList r = new ArrayList();
-        r.add(new MailAddress("recipient@test.com"));
-        MimeMessageCopyOnWriteProxy messageFromSources = (MimeMessageCopyOnWriteProxy) getMessageFromSources(content+sep+body);
-        MailImpl mail = new MailImpl("test",new MailAddress("test@test.com"),r,messageFromSources);
-        MailImpl m2 = (MailImpl) mail.duplicate();
-        System.out.println("mail: "+getReferences(mail.getMessage())+" m2: "+getReferences(m2.getMessage()));
-        assertNotSame(m2,mail);
-        assertNotSame(m2.getMessage(),mail.getMessage());
-        // test that the wrapped message is the same
-        assertTrue(isSameMimeMessage(m2.getMessage(),mail.getMessage()));
-        // test it is the same after read only operations!
-        mail.getMessage().getSubject();
-        assertTrue(isSameMimeMessage(m2.getMessage(),mail.getMessage()));
-        mail.getMessage().setText("new body");
-        mail.getMessage().saveChanges();
-        // test it is different after a write operation!
-        mail.getMessage().setSubject("new Subject");
-        assertTrue(!isSameMimeMessage(m2.getMessage(),mail.getMessage()));
-        ContainerUtil.dispose(mail);
-        ContainerUtil.dispose(m2);
-        ContainerUtil.dispose(messageFromSources);
-    }
-
-    
-    public void testMessageCloning2() throws Exception {
-        ArrayList r = new ArrayList();
-        r.add(new MailAddress("recipient@test.com"));
-        MimeMessageCopyOnWriteProxy messageFromSources = (MimeMessageCopyOnWriteProxy) getMessageFromSources(content+sep+body);
-        MailImpl mail = new MailImpl("test",new MailAddress("test@test.com"),r,messageFromSources);
-        MailImpl m2 = (MailImpl) mail.duplicate();
-        System.out.println("mail: "+getReferences(mail.getMessage())+" m2: "+getReferences(m2.getMessage()));
-        assertNotSame(m2,mail);
-        assertNotSame(m2.getMessage(),mail.getMessage());
-        // test that the wrapped message is the same
-        assertTrue(isSameMimeMessage(m2.getMessage(),mail.getMessage()));
-        // test it is the same after real only operations!
-        m2.getMessage().getSubject();
-        assertTrue(isSameMimeMessage(m2.getMessage(),mail.getMessage()));
-        m2.getMessage().setText("new body");
-        m2.getMessage().saveChanges();
-        // test it is different after a write operation!
-        m2.getMessage().setSubject("new Subject");
-        assertTrue(!isSameMimeMessage(m2.getMessage(),mail.getMessage()));
-        // check that the subjects are correct on both mails!
-        assertEquals(m2.getMessage().getSubject(),"new Subject");
-        assertEquals(mail.getMessage().getSubject(),"foo");
-        // cloning again the messages
-        Mail m2clone = m2.duplicate();
-        assertTrue(isSameMimeMessage(m2clone.getMessage(),m2.getMessage()));
-        MimeMessage mm = getWrappedMessage(m2.getMessage());
-        assertNotSame(m2.getMessage(),m2clone.getMessage());
-        // test that m2clone has a valid wrapped message
-        MimeMessage mm3 = getWrappedMessage(m2clone.getMessage());
-        assertNotNull(mm3);
-        // dispose m2 and check that the clone has still a valid message and it is the same!
-        ContainerUtil.dispose(m2);
-        assertEquals(mm3,getWrappedMessage(m2clone.getMessage()));
-        // change the message that should be not referenced by m2 that has
-        // been disposed, so it should not clone it!
-        m2clone.getMessage().setSubject("new Subject 2");
-        m2clone.getMessage().setText("new Body 3");
-        assertTrue(isSameMimeMessage(m2clone.getMessage(),mm));
-        ContainerUtil.dispose(mail);
-        ContainerUtil.dispose(messageFromSources);
-    }
-    
-    /**
-     * If I create a new MimeMessageCopyOnWriteProxy from another MimeMessageCopyOnWriteProxy,
-     * I remove references to the first and I change the second, then it should not clone
-     */
-    public void testMessageAvoidCloning() throws Exception {
-        ArrayList r = new ArrayList();
-        r.add(new MailAddress("recipient@test.com"));
-        MimeMessageCopyOnWriteProxy messageFromSources = (MimeMessageCopyOnWriteProxy) getMessageFromSources(content+sep+body);
-        MailImpl mail = new MailImpl("test",new MailAddress("test@test.com"),r,messageFromSources);
-        // cloning the message
-        Mail mailClone = mail.duplicate();
-        assertTrue(isSameMimeMessage(mailClone.getMessage(),mail.getMessage()));
-        MimeMessage mm = getWrappedMessage(mail.getMessage());
-        assertNotSame(mail.getMessage(),mailClone.getMessage());
-        // dispose mail and check that the clone has still a valid message and it is the same!
-        ContainerUtil.dispose(mail);
-        ContainerUtil.dispose(messageFromSources);
-        // need to add a gc and a wait, because the original mimemessage should be finalized before the test.
-        System.gc();
-        Thread.sleep(1000);
-        // dumb test
-        assertTrue(isSameMimeMessage(mailClone.getMessage(),mailClone.getMessage()));
-        // change the message that should be not referenced by mail that has
-        // been disposed, so it should not clone it!
-        mailClone.getMessage().setSubject("new Subject 2");
-        mailClone.getMessage().setText("new Body 3");
-        assertTrue(isSameMimeMessage(mailClone.getMessage(),mm));
-        ContainerUtil.dispose(mailClone);
-        ContainerUtil.dispose(mm);
-    }
-
-    
-    /**
-     * If I create a new MimeMessageCopyOnWriteProxy from a MimeMessage and I change the new 
-     * message, the original should be unaltered and the proxy should clone the message.
-     */
-    public void testMessageCloning3() throws Exception {
-        ArrayList r = new ArrayList();
-        r.add(new MailAddress("recipient@test.com"));
-        MimeMessage m = new MimeMessage(Session.getDefaultInstance(new Properties(null)));
-        m.setText("CIPS");
-        MailImpl mail = new MailImpl("test",new MailAddress("test@test.com"),r,m);
-        assertTrue(isSameMimeMessage(m,mail.getMessage()));
-        // change the message that should be not referenced by mail that has
-        // been disposed, so it should not clone it!
-        System.gc();
-        Thread.sleep(100);
-        mail.getMessage().setSubject("new Subject 2");
-        mail.getMessage().setText("new Body 3");
-        System.gc();
-        Thread.sleep(100);
-        assertFalse(isSameMimeMessage(m,mail.getMessage()));
-        ContainerUtil.dispose(mail);
-        ContainerUtil.dispose(m);
-    }
-
-    
-    public void testMessageDisposing() throws Exception {
-        ArrayList r = new ArrayList();
-        r.add(new MailAddress("recipient@test.com"));
-        MimeMessageCopyOnWriteProxy messageFromSources = (MimeMessageCopyOnWriteProxy) getMessageFromSources(content+sep+body);
-        MailImpl mail = new MailImpl("test",new MailAddress("test@test.com"),r,messageFromSources);
-        // cloning the message
-        MailImpl mailClone = (MailImpl) mail.duplicate();
-        ContainerUtil.dispose(mail);
-
-        assertNotNull(getWrappedMessage(mailClone.getMessage()));
-        assertNull(mail.getMessage());
-
-        ContainerUtil.dispose(mailClone);
-        
-        assertNull(mailClone.getMessage());
-        assertNull(mail.getMessage());
-        ContainerUtil.dispose(mail);
-        ContainerUtil.dispose(messageFromSources);
-    }
-    
-    public void testNPE1() throws MessagingException, InterruptedException {
-        ArrayList recipients = new ArrayList();
-        recipients.add(new MailAddress("recipient@test.com"));
-        MimeMessageCopyOnWriteProxy mw = new MimeMessageCopyOnWriteProxy(
-                new MimeMessageInputStreamSource(
-                        "test",
-                        new SharedByteArrayInputStream(
-                                ("Return-path: return@test.com\r\n"+
-                                 "Content-Transfer-Encoding: plain\r\n"+
-                                 "Subject: test\r\n\r\n"+
-                                 "Body Text\r\n").getBytes())));
-        
-        MimeMessageCopyOnWriteProxy mw2 = new MimeMessageCopyOnWriteProxy(mw);
-        ContainerUtil.dispose(mw2);
-        mw2 = null;
-        System.gc();
-        Thread.sleep(1000);
-        // the NPE was inside this call
-        mw.getMessageSize();
-        ContainerUtil.dispose(mw);
-    }
-
-    
-    /**
-     * This test throw a NullPointerException when the original message was created by
-     * a MimeMessageInputStreamSource.
-     */
-    public void testMessageCloningViaCoW3() throws Exception {
-        MimeMessage mmorig = getSimpleMessage();
-        
-        MimeMessage mm = new MimeMessageCopyOnWriteProxy(mmorig);
-        
-        ContainerUtil.dispose(mmorig);
-        mmorig = null;
-        System.gc();
-        Thread.sleep(200);
-
-        try {
-            mm.writeTo(System.out);
-        } catch (Exception e) {
-            e.printStackTrace();
-            fail("Exception while writing the message to output");
-        }
-        
-        ContainerUtil.dispose(mmorig);
-    }
-
-    private static String getReferences(MimeMessage m) {
-        StringBuffer ref = new StringBuffer("/");
-        while (m instanceof MimeMessageCopyOnWriteProxy) {
-            ref.append(((MimeMessageCopyOnWriteProxy) m).refCount.getReferenceCount()+"/");
-            m = ((MimeMessageCopyOnWriteProxy) m).getWrappedMessage();
-        }
-        if (m instanceof MimeMessageWrapper) {
-            ref.append("W");
-        } else if (m instanceof MimeMessage) {
-            ref.append("M");
-        } else {
-            ref.append(m.getClass());
-        }
-        return ref.toString();
-    }
-    
-    private static MimeMessage getWrappedMessage(MimeMessage m) {
-        while (m instanceof MimeMessageCopyOnWriteProxy) {
-          m = ((MimeMessageCopyOnWriteProxy) m).getWrappedMessage();
-        }
-        return m;
-    }
-    
-    private static boolean isSameMimeMessage(MimeMessage first, MimeMessage second) {
-        return getWrappedMessage(first) == getWrappedMessage(second);
-        
-    }
-
-}
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.core;
+
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.internet.MimeMessage;
+import javax.mail.util.SharedByteArrayInputStream;
+
+import java.util.ArrayList;
+import java.util.Properties;
+
+public class MimeMessageCopyOnWriteProxyTest extends MimeMessageFromStreamTest {
+
+    String content = "Subject: foo\r\nContent-Transfer-Encoding2: plain";
+    String sep = "\r\n\r\n";
+    String body = "bar\r\n.\r\n";
+
+    protected MimeMessage getMessageFromSources(String sources) throws Exception {
+        MimeMessageInputStreamSource mmis = null;
+        try {
+            mmis = new MimeMessageInputStreamSource("test", new SharedByteArrayInputStream(sources.getBytes()));
+        } catch (MessagingException e) {
+        }
+        return new MimeMessageCopyOnWriteProxy(mmis);
+//        return new MimeMessage(Session.getDefaultInstance(new Properties()),new ByteArrayInputStream(sources.getBytes()));
+    }
+
+    public void testMessageCloning1() throws Exception {
+        ArrayList r = new ArrayList();
+        r.add(new MailAddress("recipient@test.com"));
+        MimeMessageCopyOnWriteProxy messageFromSources = (MimeMessageCopyOnWriteProxy) getMessageFromSources(content+sep+body);
+        MailImpl mail = new MailImpl("test",new MailAddress("test@test.com"),r,messageFromSources);
+        MailImpl m2 = (MailImpl) mail.duplicate();
+        System.out.println("mail: "+getReferences(mail.getMessage())+" m2: "+getReferences(m2.getMessage()));
+        assertNotSame(m2,mail);
+        assertNotSame(m2.getMessage(),mail.getMessage());
+        // test that the wrapped message is the same
+        assertTrue(isSameMimeMessage(m2.getMessage(),mail.getMessage()));
+        // test it is the same after read only operations!
+        mail.getMessage().getSubject();
+        assertTrue(isSameMimeMessage(m2.getMessage(),mail.getMessage()));
+        mail.getMessage().setText("new body");
+        mail.getMessage().saveChanges();
+        // test it is different after a write operation!
+        mail.getMessage().setSubject("new Subject");
+        assertTrue(!isSameMimeMessage(m2.getMessage(),mail.getMessage()));
+        ContainerUtil.dispose(mail);
+        ContainerUtil.dispose(m2);
+        ContainerUtil.dispose(messageFromSources);
+    }
+
+    
+    public void testMessageCloning2() throws Exception {
+        ArrayList r = new ArrayList();
+        r.add(new MailAddress("recipient@test.com"));
+        MimeMessageCopyOnWriteProxy messageFromSources = (MimeMessageCopyOnWriteProxy) getMessageFromSources(content+sep+body);
+        MailImpl mail = new MailImpl("test",new MailAddress("test@test.com"),r,messageFromSources);
+        MailImpl m2 = (MailImpl) mail.duplicate();
+        System.out.println("mail: "+getReferences(mail.getMessage())+" m2: "+getReferences(m2.getMessage()));
+        assertNotSame(m2,mail);
+        assertNotSame(m2.getMessage(),mail.getMessage());
+        // test that the wrapped message is the same
+        assertTrue(isSameMimeMessage(m2.getMessage(),mail.getMessage()));
+        // test it is the same after real only operations!
+        m2.getMessage().getSubject();
+        assertTrue(isSameMimeMessage(m2.getMessage(),mail.getMessage()));
+        m2.getMessage().setText("new body");
+        m2.getMessage().saveChanges();
+        // test it is different after a write operation!
+        m2.getMessage().setSubject("new Subject");
+        assertTrue(!isSameMimeMessage(m2.getMessage(),mail.getMessage()));
+        // check that the subjects are correct on both mails!
+        assertEquals(m2.getMessage().getSubject(),"new Subject");
+        assertEquals(mail.getMessage().getSubject(),"foo");
+        // cloning again the messages
+        Mail m2clone = m2.duplicate();
+        assertTrue(isSameMimeMessage(m2clone.getMessage(),m2.getMessage()));
+        MimeMessage mm = getWrappedMessage(m2.getMessage());
+        assertNotSame(m2.getMessage(),m2clone.getMessage());
+        // test that m2clone has a valid wrapped message
+        MimeMessage mm3 = getWrappedMessage(m2clone.getMessage());
+        assertNotNull(mm3);
+        // dispose m2 and check that the clone has still a valid message and it is the same!
+        ContainerUtil.dispose(m2);
+        assertEquals(mm3,getWrappedMessage(m2clone.getMessage()));
+        // change the message that should be not referenced by m2 that has
+        // been disposed, so it should not clone it!
+        m2clone.getMessage().setSubject("new Subject 2");
+        m2clone.getMessage().setText("new Body 3");
+        assertTrue(isSameMimeMessage(m2clone.getMessage(),mm));
+        ContainerUtil.dispose(mail);
+        ContainerUtil.dispose(messageFromSources);
+    }
+    
+    /**
+     * If I create a new MimeMessageCopyOnWriteProxy from another MimeMessageCopyOnWriteProxy,
+     * I remove references to the first and I change the second, then it should not clone
+     */
+    public void testMessageAvoidCloning() throws Exception {
+        ArrayList r = new ArrayList();
+        r.add(new MailAddress("recipient@test.com"));
+        MimeMessageCopyOnWriteProxy messageFromSources = (MimeMessageCopyOnWriteProxy) getMessageFromSources(content+sep+body);
+        MailImpl mail = new MailImpl("test",new MailAddress("test@test.com"),r,messageFromSources);
+        // cloning the message
+        Mail mailClone = mail.duplicate();
+        assertTrue(isSameMimeMessage(mailClone.getMessage(),mail.getMessage()));
+        MimeMessage mm = getWrappedMessage(mail.getMessage());
+        assertNotSame(mail.getMessage(),mailClone.getMessage());
+        // dispose mail and check that the clone has still a valid message and it is the same!
+        ContainerUtil.dispose(mail);
+        ContainerUtil.dispose(messageFromSources);
+        // need to add a gc and a wait, because the original mimemessage should be finalized before the test.
+        System.gc();
+        Thread.sleep(1000);
+        // dumb test
+        assertTrue(isSameMimeMessage(mailClone.getMessage(),mailClone.getMessage()));
+        // change the message that should be not referenced by mail that has
+        // been disposed, so it should not clone it!
+        mailClone.getMessage().setSubject("new Subject 2");
+        mailClone.getMessage().setText("new Body 3");
+        assertTrue(isSameMimeMessage(mailClone.getMessage(),mm));
+        ContainerUtil.dispose(mailClone);
+        ContainerUtil.dispose(mm);
+    }
+
+    
+    /**
+     * If I create a new MimeMessageCopyOnWriteProxy from a MimeMessage and I change the new 
+     * message, the original should be unaltered and the proxy should clone the message.
+     */
+    public void testMessageCloning3() throws Exception {
+        ArrayList r = new ArrayList();
+        r.add(new MailAddress("recipient@test.com"));
+        MimeMessage m = new MimeMessage(Session.getDefaultInstance(new Properties(null)));
+        m.setText("CIPS");
+        MailImpl mail = new MailImpl("test",new MailAddress("test@test.com"),r,m);
+        assertTrue(isSameMimeMessage(m,mail.getMessage()));
+        // change the message that should be not referenced by mail that has
+        // been disposed, so it should not clone it!
+        System.gc();
+        Thread.sleep(100);
+        mail.getMessage().setSubject("new Subject 2");
+        mail.getMessage().setText("new Body 3");
+        System.gc();
+        Thread.sleep(100);
+        assertFalse(isSameMimeMessage(m,mail.getMessage()));
+        ContainerUtil.dispose(mail);
+        ContainerUtil.dispose(m);
+    }
+
+    
+    public void testMessageDisposing() throws Exception {
+        ArrayList r = new ArrayList();
+        r.add(new MailAddress("recipient@test.com"));
+        MimeMessageCopyOnWriteProxy messageFromSources = (MimeMessageCopyOnWriteProxy) getMessageFromSources(content+sep+body);
+        MailImpl mail = new MailImpl("test",new MailAddress("test@test.com"),r,messageFromSources);
+        // cloning the message
+        MailImpl mailClone = (MailImpl) mail.duplicate();
+        ContainerUtil.dispose(mail);
+
+        assertNotNull(getWrappedMessage(mailClone.getMessage()));
+        assertNull(mail.getMessage());
+
+        ContainerUtil.dispose(mailClone);
+        
+        assertNull(mailClone.getMessage());
+        assertNull(mail.getMessage());
+        ContainerUtil.dispose(mail);
+        ContainerUtil.dispose(messageFromSources);
+    }
+    
+    public void testNPE1() throws MessagingException, InterruptedException {
+        ArrayList recipients = new ArrayList();
+        recipients.add(new MailAddress("recipient@test.com"));
+        MimeMessageCopyOnWriteProxy mw = new MimeMessageCopyOnWriteProxy(
+                new MimeMessageInputStreamSource(
+                        "test",
+                        new SharedByteArrayInputStream(
+                                ("Return-path: return@test.com\r\n"+
+                                 "Content-Transfer-Encoding: plain\r\n"+
+                                 "Subject: test\r\n\r\n"+
+                                 "Body Text\r\n").getBytes())));
+        
+        MimeMessageCopyOnWriteProxy mw2 = new MimeMessageCopyOnWriteProxy(mw);
+        ContainerUtil.dispose(mw2);
+        mw2 = null;
+        System.gc();
+        Thread.sleep(1000);
+        // the NPE was inside this call
+        mw.getMessageSize();
+        ContainerUtil.dispose(mw);
+    }
+
+    
+    /**
+     * This test throw a NullPointerException when the original message was created by
+     * a MimeMessageInputStreamSource.
+     */
+    public void testMessageCloningViaCoW3() throws Exception {
+        MimeMessage mmorig = getSimpleMessage();
+        
+        MimeMessage mm = new MimeMessageCopyOnWriteProxy(mmorig);
+        
+        ContainerUtil.dispose(mmorig);
+        mmorig = null;
+        System.gc();
+        Thread.sleep(200);
+
+        try {
+            mm.writeTo(System.out);
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("Exception while writing the message to output");
+        }
+        
+        ContainerUtil.dispose(mmorig);
+    }
+
+    private static String getReferences(MimeMessage m) {
+        StringBuffer ref = new StringBuffer("/");
+        while (m instanceof MimeMessageCopyOnWriteProxy) {
+            ref.append(((MimeMessageCopyOnWriteProxy) m).refCount.getReferenceCount()+"/");
+            m = ((MimeMessageCopyOnWriteProxy) m).getWrappedMessage();
+        }
+        if (m instanceof MimeMessageWrapper) {
+            ref.append("W");
+        } else if (m instanceof MimeMessage) {
+            ref.append("M");
+        } else {
+            ref.append(m.getClass());
+        }
+        return ref.toString();
+    }
+    
+    private static MimeMessage getWrappedMessage(MimeMessage m) {
+        while (m instanceof MimeMessageCopyOnWriteProxy) {
+          m = ((MimeMessageCopyOnWriteProxy) m).getWrappedMessage();
+        }
+        return m;
+    }
+    
+    private static boolean isSameMimeMessage(MimeMessage first, MimeMessage second) {
+        return getWrappedMessage(first) == getWrappedMessage(second);
+        
+    }
+
+}

Propchange: james/server/trunk/src/test/org/apache/james/core/MimeMessageCopyOnWriteProxyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/trunk/src/test/org/apache/james/core/MimeMessageFromMimeMessageTest.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/core/MimeMessageFromMimeMessageTest.java?rev=405795&r1=405794&r2=405795&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/core/MimeMessageFromMimeMessageTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/core/MimeMessageFromMimeMessageTest.java Wed May 10 09:46:54 2006
@@ -1,27 +1,27 @@
-/***********************************************************************
- * Copyright (c) 1999-2006 The Apache Software Foundation.             *
- * All rights reserved.                                                *
- * ------------------------------------------------------------------- *
- * Licensed 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.core;
-
-import javax.mail.internet.MimeMessage;
-
-public class MimeMessageFromMimeMessageTest extends MimeMessageFromStreamTest {
-    
-    protected MimeMessage getMessageFromSources(String sources) throws Exception {
-        return new MimeMessage(super.getMessageFromSources(sources));
-    }
-
-}
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.core;
+
+import javax.mail.internet.MimeMessage;
+
+public class MimeMessageFromMimeMessageTest extends MimeMessageFromStreamTest {
+    
+    protected MimeMessage getMessageFromSources(String sources) throws Exception {
+        return new MimeMessage(super.getMessageFromSources(sources));
+    }
+
+}

Propchange: james/server/trunk/src/test/org/apache/james/core/MimeMessageFromMimeMessageTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/trunk/src/test/org/apache/james/core/MimeMessageFromSharedStreamTest.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/core/MimeMessageFromSharedStreamTest.java?rev=405795&r1=405794&r2=405795&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/core/MimeMessageFromSharedStreamTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/core/MimeMessageFromSharedStreamTest.java Wed May 10 09:46:54 2006
@@ -1,32 +1,32 @@
-/***********************************************************************
- * Copyright (c) 1999-2006 The Apache Software Foundation.             *
- * All rights reserved.                                                *
- * ------------------------------------------------------------------- *
- * Licensed 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.core;
-
-import javax.mail.util.SharedByteArrayInputStream;
-
-import javax.mail.Session;
-import javax.mail.internet.MimeMessage;
-
-import java.util.Properties;
-
-public class MimeMessageFromSharedStreamTest extends MimeMessageFromStreamTest {
-    
-    protected MimeMessage getMessageFromSources(String sources) throws Exception {
-        return new MimeMessage(Session.getDefaultInstance(new Properties()),new SharedByteArrayInputStream(sources.getBytes()));
-    }
-
-}
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.core;
+
+import javax.mail.util.SharedByteArrayInputStream;
+
+import javax.mail.Session;
+import javax.mail.internet.MimeMessage;
+
+import java.util.Properties;
+
+public class MimeMessageFromSharedStreamTest extends MimeMessageFromStreamTest {
+    
+    protected MimeMessage getMessageFromSources(String sources) throws Exception {
+        return new MimeMessage(Session.getDefaultInstance(new Properties()),new SharedByteArrayInputStream(sources.getBytes()));
+    }
+
+}

Propchange: james/server/trunk/src/test/org/apache/james/core/MimeMessageFromSharedStreamTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/trunk/src/test/org/apache/james/core/MimeMessageFromStreamTest.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/core/MimeMessageFromStreamTest.java?rev=405795&r1=405794&r2=405795&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/core/MimeMessageFromStreamTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/core/MimeMessageFromStreamTest.java Wed May 10 09:46:54 2006
@@ -1,48 +1,48 @@
-/***********************************************************************
- * Copyright (c) 1999-2006 The Apache Software Foundation.             *
- * All rights reserved.                                                *
- * ------------------------------------------------------------------- *
- * Licensed 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.core;
-
-import javax.mail.Session;
-import javax.mail.internet.MimeMessage;
-
-import java.io.ByteArrayInputStream;
-import java.util.Properties;
-
-public class MimeMessageFromStreamTest extends MimeMessageTest {
-    
-    protected MimeMessage getMessageFromSources(String sources) throws Exception {
-        return new MimeMessage(Session.getDefaultInstance(new Properties()),new ByteArrayInputStream(sources.getBytes()));
-    }
-
-    protected MimeMessage getMultipartMessage() throws Exception {
-        return getMessageFromSources(getMultipartMessageSource());
-    }
-
-    protected MimeMessage getSimpleMessage() throws Exception {
-        return getMessageFromSources(getSimpleMessageCleanedSource());
-    }
-
-    protected MimeMessage getMissingEncodingAddHeaderMessage() throws Exception {
-        return getMessageFromSources(getMissingEncodingAddHeaderSource());
-    }
-
-    protected MimeMessage getMissingEncodingMessage() throws Exception {
-        return getMessageFromSources(getMissingEncodingMessageSource());
-    }
-
-
-}
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.core;
+
+import javax.mail.Session;
+import javax.mail.internet.MimeMessage;
+
+import java.io.ByteArrayInputStream;
+import java.util.Properties;
+
+public class MimeMessageFromStreamTest extends MimeMessageTest {
+    
+    protected MimeMessage getMessageFromSources(String sources) throws Exception {
+        return new MimeMessage(Session.getDefaultInstance(new Properties()),new ByteArrayInputStream(sources.getBytes()));
+    }
+
+    protected MimeMessage getMultipartMessage() throws Exception {
+        return getMessageFromSources(getMultipartMessageSource());
+    }
+
+    protected MimeMessage getSimpleMessage() throws Exception {
+        return getMessageFromSources(getSimpleMessageCleanedSource());
+    }
+
+    protected MimeMessage getMissingEncodingAddHeaderMessage() throws Exception {
+        return getMessageFromSources(getMissingEncodingAddHeaderSource());
+    }
+
+    protected MimeMessage getMissingEncodingMessage() throws Exception {
+        return getMessageFromSources(getMissingEncodingMessageSource());
+    }
+
+
+}

Propchange: james/server/trunk/src/test/org/apache/james/core/MimeMessageFromStreamTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/server/trunk/src/test/org/apache/james/core/MimeMessageTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/server/trunk/src/test/org/apache/james/core/MimeMessageUtilTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/server/trunk/src/test/org/apache/james/core/MimeMessageWrapperTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



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