LoginTest::testLoginWithNoResource

Hi

The testLoginWithNoResource test, of which there is a snippet below, calls the version of createAccount(…) that just takes the username and password.

There is another version of createAccount(…) that also takes a map of values. The server I am working with requires additional values. Perhaps we could create these additional values as test properties and change this call to use those test properties if defined?

Regards

Nathan

public void testLoginWithNoResource() {

try {

XMPPConnection conn = createConnection();

conn.connect();

try {

conn.getAccountManager().createAccount(“user_1”, “user_1”);

} catch (XMPPException e) {

Here is a patch, which needs to be looked at carefully (even more so than usual).

Index: test/config/test-case.xml

===================================================================

— test/config/test-case.xml (revision 12905)

+++ test/config/test-case.xml (working copy)

@@ -2,15 +2,23 @@

  • localhost

  • 5222

  • localhost

  • 5222

  • user

    • chat

    • conference

    • chat

    • conference

    • false

    \ No newline at end of file

    Index: test/org/jivesoftware/smack/test/SmackTestCase.java

    ===================================================================

    — test/org/jivesoftware/smack/test/SmackTestCase.java (revision 12905)

    +++ test/org/jivesoftware/smack/test/SmackTestCase.java (working copy)

    @@ -31,7 +31,9 @@

    import java.net.URL;

    import java.util.ArrayList;

    import java.util.Enumeration;

    +import java.util.HashMap;

    import java.util.List;

    +import java.util.Map;

    /**

    • Base class for all the test cases which provides a pre-configured execution context. This

    @@ -57,6 +59,8 @@

    private String usernamePrefix = “user”;

    private String passwordPrefix;

    private boolean samePassword;

    • private boolean testAnonymousLogin = false;

    • private Map<String, String> accountCreationParameters = new HashMap<String, String>();

    private List createdUserIdx = new ArrayList();

    private String chatDomain = “chat”;

    @@ -353,7 +357,7 @@

    try {

    boolean found = false;

    // Try to load the configutation from an XML file specific for this test case

    •        Enumeration resources =
      
    •        Enumeration<URL> resources =
      

    ClassLoader.getSystemClassLoader().getResources(getConfigurationFilename());

    while (resources.hasMoreElements()) {

    found = parseURL((URL) resources.nextElement());

    @@ -416,6 +420,21 @@

    samePassword = “true”.equals(parser.getAttributeValue(0));

    passwordPrefix = parser.nextText();

    }

    •                else if (parser.getName().equals("testAnonymousLogin")) {
      
    •                    testAnonymousLogin = "true".equals(parser.nextText());
      
    •                }
      
    •                else if (parser.getName().equals("accountCreationParameters")) {
      
    •                    int numAttributes = parser.getAttributeCount();
      
    •                    String key = null;
      
    •                    String value = null;
      
    •                    for (int i = 0; i < numAttributes; i++) {
      
    •                        key = parser.getAttributeName(i);
      
    •                        value = parser.getAttributeValue(i);
      
    •                        accountCreationParameters.put(key, value);
      
    •                    }
      
    •                }
      

    }

    eventType = parser.next();

    }

    @@ -476,4 +495,11 @@

    }

    }

    • public boolean isTestAnonymousLogin() {

    •    return testAnonymousLogin;
      
    • }

    • public Map<String, String> getAccountCreationParameters() {

    •    return accountCreationParameters;
      
    • }

    }

    Index: test/org/jivesoftware/smack/LoginTest.java

    ===================================================================

    — test/org/jivesoftware/smack/LoginTest.java (revision 12905)

    +++ test/org/jivesoftware/smack/LoginTest.java (working copy)

    @@ -67,6 +67,11 @@

    • Check that the server handles anonymous users correctly.

    */

    public void testSASLAnonymousLogin() {

    •    if (!isTestAnonymousLogin()){
      
    •        return;
      
    •    }
      

    try {

    XMPPConnection conn1 = createConnection();

    XMPPConnection conn2 = createConnection();

    @@ -84,8 +89,8 @@

    assertNotNull(“Username is null”, StringUtils.parseName(conn2.getUser()));

    }

    catch (XMPPException e) {

    •            e.printStackTrace();
      
    •            //fail(e.getMessage());
      
    •          //  e.printStackTrace();
      
    •            fail(e.getMessage());
      

    }

    finally {

    // Close the connection

    @@ -103,6 +108,11 @@

    • Check that the server handles anonymous users correctly.

    */

    public void testNonSASLAnonymousLogin() {

    •    if (!isTestAnonymousLogin()){
      
    •        return;
      
    •    }
      

    try {

    ConnectionConfiguration config = new ConnectionConfiguration(getHost(), getPort());

    config.setSASLAuthenticationEnabled(false);

    @@ -147,27 +157,39 @@

    XMPPConnection conn = createConnection();

    conn.connect();

    try {

    •            conn.getAccountManager().createAccount("user_1", "user_1");
      
    •            conn.getAccountManager().createAccount("user_1", "user_1", getAccountCreationParameters());
      

    } catch (XMPPException e) {

    •            // Do nothing if the accout already exists
      
    •            // Do nothing if the account already exists
      

    if (e.getXMPPError().getCode() != 409) {

    throw e;

    }

    •            // Else recreate the connection, in case the server closed it as
      
    •            // a result of the error, so we can login.
      
    •            conn = createConnection();
      
    •            conn.connect();
      

    }

    conn.login(“user_1”, “user_1”, (String) null);

    if (conn.getSASLAuthentication().isAuthenticated()) {

    // Check that the server assigned a resource

    assertNotNull(“JID assigned by server is missing”, conn.getUser());

    assertNotNull(“JID assigned by server does not have a resource”,

    StringUtils.parseResource(conn.getUser()));

    •            conn.disconnect();
      
    •           conn.disconnect();
      

    }

    else {

    •            fail("User with no resource was able to log into the server");
      
    •            fail("User with no resource was not able to log into the server");
      

    }

    } catch (XMPPException e) {

    •        assertEquals("Wrong error code returned", 406, e.getXMPPError().getCode());
      
    •        if (e.getXMPPError() != null) {
      
    •            assertEquals("Wrong error code returned", 406, e.getXMPPError()
      
    •                    .getCode());
      
    •        } else {
      
    •            fail(e.getMessage());
      
    •        }
      

    }

    }
    patch.txt.zip (2145 Bytes)

Logged as SMACK-358.

Keep up the good work Nathan!