1 17 18 package org.apache.james.imapserver; 19 20 import org.apache.james.imapserver.store.ImapMailbox; 21 import org.apache.james.imapserver.store.InMemoryStore; 22 import org.apache.james.imapserver.store.MailboxException; 23 import org.apache.james.services.User; 24 import org.apache.james.userrepository.DefaultUser; 25 26 import junit.framework.TestCase; 27 28 44 public class ImapHostTest extends TestCase 45 implements ImapConstants 46 { 47 private ImapHost imapHost; 48 private User user; 49 50 public ImapHostTest( String s ) 51 { 52 super( s ); 53 } 54 55 protected void setUp() throws Exception 56 { 57 super.setUp(); 58 user = new DefaultUser( "user", null ); 59 60 imapHost = getHostImplementation(); 61 imapHost.createPrivateMailAccount( user ); 62 } 63 64 protected ImapHost getHostImplementation() 65 { 66 return new JamesImapHost( new InMemoryStore() ); 67 } 68 69 72 public void testCreatePersonal() throws Exception 73 { 74 create( "test" ); 76 assertMailbox( "test", true ); 77 78 create("test.another" ); 80 assertMailbox( "test", true ); 81 assertMailbox( "test.another", true ); 82 83 create( "this.is.another.mailbox"); 86 assertMailbox( "this", false ); 87 assertMailbox( "this.is", false ); 88 assertMailbox( "this.is.another", false ); 89 assertMailbox( "this.is.another.mailbox", true ); 90 91 create( "this.is.yet.another.mailbox"); 93 assertMailbox( "this", false ); 94 assertMailbox( "this.is", false ); 95 assertMailbox( "this.is.yet", false ); 96 assertMailbox( "this.is.yet.another", false ); 97 assertMailbox( "this.is.yet.another.mailbox", true ); 98 } 99 100 104 public void testDelete() throws Exception 105 { 106 create( "test" ); 108 assertMailbox( "test", true ); 109 delete( "test" ); 110 assertNoMailbox( "test"); 111 112 create( "one" ); 115 create( "one.two" ); 116 assertMailbox( "one", true ); 117 assertMailbox( "one.two", true ); 118 delete( "one"); 119 assertMailbox( "one", false); 120 assertMailbox( "one.two", true ); 121 122 try 124 { 125 delete( "one" ); 126 fail( "Should not be able to delete a non-selectabl mailbox which has children." ); 127 } 128 catch( MailboxException e ) 129 { 130 } 132 133 delete( "one.two"); 135 delete( "one"); 136 assertNoMailbox( "one.two" ); 137 assertNoMailbox( "one" ); 138 } 139 140 144 private void assertMailbox( String name, boolean selectable ) throws MailboxException 145 { 146 ImapMailbox mailbox = imapHost.getMailbox( user, name ); 147 assertNotNull( "Mailbox <" + name + "> expected to exist in store.", 148 mailbox ); 149 if ( selectable ) 150 { 151 assertTrue( "Mailbox <" + name + "> not selectable.", 152 mailbox.isSelectable() ); 153 } 154 else 155 { 156 assertTrue( "Mailbox <" + name + "> should not be selectable.", 157 ! mailbox.isSelectable() ); 158 } 159 } 160 161 164 private void assertNoMailbox( String name ) throws Exception 165 { 166 ImapMailbox mailbox = imapHost.getMailbox( user, name ); 167 assertNull( "Mailbox <" + name + "> should not exist.", 168 mailbox ); 169 } 170 171 174 private ImapMailbox create( String name ) throws Exception 175 { 176 return imapHost.createMailbox( user, name ); 177 } 178 179 182 private void delete( String name ) throws Exception 183 { 184 imapHost.deleteMailbox( user, name ); 185 } 186 } 187 | Popular Tags |