1 16 17 package org.apache.commons.net.pop3; 18 19 import junit.framework.TestCase; 20 import junit.framework.TestSuite; 21 import java.io.Reader ; 22 23 41 public class POP3ConstructorTest extends TestCase 42 { 43 String user = TestSetupParameters.user; 44 String emptyUser = TestSetupParameters.emptyuser; 45 String password = TestSetupParameters.password; 46 String mailhost = TestSetupParameters.mailhost; 47 48 51 public POP3ConstructorTest(String name) 52 { 53 super(name); 54 } 55 56 60 public static TestSuite suite() 61 { 62 return (new TestSuite(POP3ConstructorTest.class)); 63 } 64 65 66 71 public void testConstants() 72 { 73 assertEquals(110, POP3.DEFAULT_PORT); 75 assertEquals(-1, POP3.DISCONNECTED_STATE); 76 assertEquals(0, POP3.AUTHORIZATION_STATE); 77 assertEquals(1, POP3.TRANSACTION_STATE); 78 assertEquals(2, POP3.UPDATE_STATE); 79 80 assertEquals(0, POP3Command.USER); 82 assertEquals(1, POP3Command.PASS); 83 assertEquals(2, POP3Command.QUIT); 84 assertEquals(3, POP3Command.STAT); 85 assertEquals(4, POP3Command.LIST); 86 assertEquals(5, POP3Command.RETR); 87 assertEquals(6, POP3Command.DELE); 88 assertEquals(7, POP3Command.NOOP); 89 assertEquals(8, POP3Command.RSET); 90 assertEquals(9, POP3Command.APOP); 91 assertEquals(10, POP3Command.TOP); 92 assertEquals(11, POP3Command.UIDL); 93 } 94 95 99 public void testPOP3DefaultConstructor() 100 { 101 POP3 pop = new POP3(); 102 103 assertEquals(110, pop.getDefaultPort()); 104 assertEquals(POP3.DISCONNECTED_STATE, pop.getState()); 105 assertNull(pop._reader); 106 assertNotNull(pop._replyLines); 107 } 108 109 113 public void testPOP3ClientStateTransition() throws Exception 114 { 115 POP3Client pop = new POP3Client(); 116 117 assertEquals(110, pop.getDefaultPort()); 119 assertEquals(POP3.DISCONNECTED_STATE, pop.getState()); 120 assertNull(pop._reader); 121 assertNotNull(pop._replyLines); 122 123 pop.connect(mailhost); 125 assertEquals(POP3.AUTHORIZATION_STATE, pop.getState()); 126 127 pop.login(user, password); 129 assertEquals(POP3.TRANSACTION_STATE, pop.getState()); 130 131 pop.noop(); 133 assertEquals(POP3.TRANSACTION_STATE, pop.getState()); 134 pop.status(); 135 assertEquals(POP3.TRANSACTION_STATE, pop.getState()); 136 137 POP3MessageInfo[] msg = pop.listMessages(); 139 140 if (msg.length > 0) 141 { 142 pop.deleteMessage(1); 143 assertEquals(POP3.TRANSACTION_STATE, pop.getState()); 144 145 pop.reset(); 146 assertEquals(POP3.TRANSACTION_STATE, pop.getState()); 147 148 pop.listMessage(1); 149 assertEquals(POP3.TRANSACTION_STATE, pop.getState()); 150 151 pop.listMessages(); 152 assertEquals(POP3.TRANSACTION_STATE, pop.getState()); 153 154 pop.listUniqueIdentifier(1); 155 assertEquals(POP3.TRANSACTION_STATE, pop.getState()); 156 157 pop.listUniqueIdentifiers(); 158 assertEquals(POP3.TRANSACTION_STATE, pop.getState()); 159 160 Reader r = pop.retrieveMessage(1); 161 assertEquals(POP3.TRANSACTION_STATE, pop.getState()); 162 163 while(!r.ready()) 165 { 166 Thread.sleep(10); 167 } 168 r.close(); 169 r = null; 170 171 r = pop.retrieveMessageTop(1, 10); 172 assertEquals(POP3.TRANSACTION_STATE, pop.getState()); 173 174 while(!r.ready()) 176 { 177 Thread.sleep(10); 178 } 179 r.close(); 180 r = null; 181 182 } 183 184 pop.logout(); 186 assertEquals(POP3.UPDATE_STATE, pop.getState()); 187 } 188 } 189 | Popular Tags |