1 11 12 package org.jivesoftware.smack; 13 14 import org.jivesoftware.smack.test.SmackTestCase; 15 16 21 public class LoginTest extends SmackTestCase { 22 23 public LoginTest(String arg0) { 24 super(arg0); 25 } 26 27 31 public void testInvalidLogin() { 32 try { 33 XMPPConnection connection = new XMPPConnection(getHost(), getPort()); 34 try { 35 connection.login("invaliduser" , "invalidpass"); 37 connection.close(); 38 fail("Invalid user was able to log into the server"); 39 } 40 catch (XMPPException e) { 41 assertEquals("Incorrect error code while login with an invalid user", 401, 42 e.getXMPPError().getCode()); 43 } 44 } 47 catch (Exception e) { 48 e.printStackTrace(); 49 fail(e.getMessage()); 50 } 51 } 52 53 56 public void testAnonymousLogin() { 57 try { 58 XMPPConnection conn1 = new XMPPConnection(getHost(), getPort()); 59 XMPPConnection conn2 = new XMPPConnection(getHost(), getPort()); 60 try { 61 conn1.loginAnonymously(); 63 conn2.loginAnonymously(); 64 } 65 catch (XMPPException e) { 66 e.printStackTrace(); 67 fail(e.getMessage()); 68 } 69 conn1.close(); 71 conn2.close(); 72 } 73 catch (Exception e) { 74 e.printStackTrace(); 75 fail(e.getMessage()); 76 } 77 } 78 79 82 public void testLoginWithNoResource() { 83 try { 84 XMPPConnection conn = new XMPPConnection(getHost(), getPort()); 85 try { 86 conn.getAccountManager().createAccount("user_1", "user_1"); 87 } catch (XMPPException e) { 88 if (e.getXMPPError().getCode() != 409) { 90 throw e; 91 } 92 } 93 conn.login("user_1", "user_1", null); 94 fail("User with no resource was able to log into the server"); 95 96 } catch (XMPPException e) { 97 assertEquals("Wrong error code returned", 406, e.getXMPPError().getCode()); 98 } 99 } 100 101 protected int getMaxConnections() { 102 return 0; 103 } 104 } 105 | Popular Tags |