1 19 20 package org.apache.james.mailboxmanager.redundant; 21 22 import java.io.IOException ; 23 import java.util.ArrayList ; 24 import java.util.Collection ; 25 import java.util.Iterator ; 26 27 import javax.mail.MessagingException ; 28 29 import org.apache.mailet.Mail; 30 31 public abstract class AbstractMailRepositoryNativeTestCase extends 32 AbstractMailRepositorySelfTestCase { 33 34 public void testStore() throws MessagingException , IOException { 35 Collection added = new ArrayList (); 36 for (int i = 0; i < 10; i++) { 37 Mail m = generateMail(); 38 mailRepository.store(m); 39 assertNativeMessageCountEquals(i + 1); 40 added.add(m.getMessage()); 41 assertNativeMessagesEqual(added); 42 } 43 } 44 45 public void testStoreRemoveByMailOrKey() throws MessagingException , 46 IOException { 47 Collection added = new ArrayList (); 48 for (int i = 0; i < 10; i++) { 49 Mail m1 = generateMail(); 50 Mail m2 = generateMail(); 51 mailRepository.store(m1); 52 assertNativeMessageCountEquals(i + 1); 53 mailRepository.store(m2); 54 assertNativeMessageCountEquals(i + 2); 55 if (i % 2 == 0) { 56 mailRepository.remove(m1); 57 } else { 58 mailRepository.remove(m1.getName()); 59 } 60 assertNativeMessageCountEquals(i + 1); 61 added.add(m2.getMessage()); 62 } 63 assertNativeMessagesEqual(added); 64 } 65 66 public void testStoreRemoveByCollection() throws MessagingException , 67 IOException { 68 Collection retain = new ArrayList (); 69 Collection delete = new ArrayList (); 70 71 for (int i = 0; i < 10; i++) { 72 Mail m1 = generateMail(); 73 mailRepository.store(m1); 74 assertNativeMessageCountEquals(i + 1); 75 if (i % 2 == 0) { 76 delete.add(m1); 77 } else { 78 retain.add(m1.getMessage()); 79 } 80 } 81 mailRepository.remove(delete); 82 assertNativeMessageCountEquals(5); 83 assertNativeMessagesEqual(retain); 84 } 85 86 90 public void testListRetrieve() throws MessagingException , IOException { 91 try { 92 Collection added = new ArrayList (); 93 for (int i = 0; i < 10; i++) { 94 Mail m = generateMail(); 95 nativeStoreMessage(m.getMessage()); 96 added.add(m.getMessage()); 97 } 98 assertNativeMessageCountEquals(10); 99 assertNativeMessagesEqual(added); 100 101 Collection retrieved = new ArrayList (); 102 for (Iterator it= mailRepository.list(); it.hasNext();) { 103 String key = (String ) it.next(); 104 assertNotNull("key is null",key); 105 Mail m=mailRepository.retrieve(key); 106 assertNotNull("Mail is null",m); 107 assertNotNull("key of Mail is null",key); 108 assertEquals("key differs",key,m.getName()); 109 retrieved.add(m.getMessage()); 110 } 111 assertEquals("number of retrieved messages differs",10,retrieved.size()); 112 assertTrue("messages differ",messageSetsEqual(added,retrieved)); 113 114 115 } catch (NativeMethodNotSupportetException e) { 116 117 } 118 } 119 public void testListRemove() throws MessagingException , IOException { 120 try { 121 Collection added = new ArrayList (); 122 for (int i = 0; i < 10; i++) { 123 Mail m = generateMail(); 124 nativeStoreMessage(m.getMessage()); 125 added.add(m.getMessage()); 126 } 127 assertNativeMessageCountEquals(10); 128 int count=10; 129 for (Iterator it= mailRepository.list(); it.hasNext();) { 130 String key = (String ) it.next(); 131 assertNotNull("key is null",key); 132 mailRepository.remove(key); 133 count--; 134 assertNativeMessageCountEquals(count); 135 } 136 } catch (NativeMethodNotSupportetException e) { 137 138 } 139 } 140 141 142 } 143 | Popular Tags |