1 16 17 package org.apache.commons.net.pop3; 18 19 import junit.framework.TestCase; 20 import junit.framework.TestSuite; 21 22 import java.net.InetAddress ; 23 import java.io.IOException ; 24 25 26 44 public class POP3ClientTest extends TestCase 45 { 46 POP3Client p = null; 47 48 String user = TestSetupParameters.user; 49 String emptyUser = TestSetupParameters.emptyuser; 50 String password = TestSetupParameters.password; 51 String mailhost = TestSetupParameters.mailhost; 52 53 56 public POP3ClientTest(String name) 57 { 58 super(name); 59 } 60 61 65 public static TestSuite suite() 66 { 67 return (new TestSuite(POP3ClientTest.class)); 68 } 69 70 private void reset() throws IOException 71 { 72 if (p == null) 74 { 75 } 77 else if (p.isConnected()) 78 { 79 p.disconnect(); 80 } 81 p = null; 82 p = new POP3Client(); 83 } 84 85 private void connect() throws Exception 86 { 87 p.connect(InetAddress.getByName(mailhost)); 88 assertTrue(p.isConnected()); 89 assertEquals(POP3.AUTHORIZATION_STATE, p.getState()); 90 } 91 92 private void login() throws Exception 93 { 94 assertTrue(p.login(user, password)); 95 assertEquals(POP3.TRANSACTION_STATE, p.getState()); 96 } 97 98 102 public void testValidLoginWithNameAndPassword() throws Exception 103 { 104 reset(); 105 connect(); 106 107 login(); 109 } 110 111 114 public void testInvalidLoginWithBadName() throws Exception 115 { 116 reset(); 117 connect(); 118 119 assertFalse(p.login("badusername", password)); 121 } 122 123 126 public void testInvalidLoginWithBadPassword() throws Exception 127 { 128 reset(); 129 connect(); 130 131 assertFalse(p.login(user, "badpassword")); 133 } 134 135 139 public void testLoginFromWrongState() throws Exception 140 { 141 reset(); 142 143 assertFalse(p.login(user, password)); 146 147 connect(); 149 p.setState(POP3.TRANSACTION_STATE); 150 assertFalse(p.login(user, password)); 151 p.disconnect(); 152 153 connect(); 155 p.setState(POP3.UPDATE_STATE); 156 assertFalse(p.login(user, password)); 157 p.disconnect(); 158 } 159 160 164 public void testLogoutFromAllStates() throws Exception 165 { 166 reset(); 168 connect(); 169 login(); 170 assertTrue(p.logout()); 171 assertEquals(POP3.UPDATE_STATE, p.getState()); 172 173 reset(); 175 connect(); 176 login(); 177 p.setState(POP3.UPDATE_STATE); 178 assertTrue(p.logout()); 179 } 180 } 181 | Popular Tags |