powered by Jive Software

Unit testing and account creation during test

Hi,

I have a strange problem while trying to do unit tests with smack and jive messenger 2.2.0

Basically I want to create a new account in the testcase and look for a shared group which is visible to all users. Afterwards the user account is deleted.

This works pretty well for the first time the test is executed. The second time there is no shared group in the users roster. Working with the debugger I can see that there are no iq packets sent from the server regarding the shared groups for the second time. This means instead of:

sent. This is reproducable until I restart the server. Then it works again one time and the second time it fails again. So it looks like the account is not completely deleted in the server cache or something like that. May be I did something wrong. The basic steps:

//create the account and log in

conn = new XMPPConnection(“localhost”);

conn.getAccountManager().createAccount(“visitor1”, “test”);

conn.close();

conn = new XMPPConnection(“localhost”);

conn.login(“visitor1”, “test”);

//test for the group

RosterGroup group = conn.getRoster().getGroup(“ABC”);

assertNotNull(“group should be visible in all rosters”,group);

//logout

finally {

try {

conn.getAccountManager().deleteAccount();

} catch (XMPPException e) {e.printStackTrace();}

conn.close();

}

Anything else I need to do?

Thanks,

Markus

I’'ve resolved a similar problem by generating a new userName for each test.

OK, this is a workaround but no solution. It scares me a little bit that it seems not to be possible in jivemessenger to cleanly delete an account and recreate it without restarting.

here is a unit test which reproduces the error. Simply create a group ABC in the admin GUI which is visible in all users roaster (and to be on the safe side join the group with one client).

Now execute the test and it should fail on the secound assert. May be I’'m misusing the API but I think it is a bug.

import junit.framework.TestCase;

import org.jivesoftware.smack.XMPPConnection;

import org.jivesoftware.smack.XMPPException;

public class TestUserSelfSignup extends TestCase {

public void testSignup() {

XMPPConnection conn = null;

try {

conn = new XMPPConnection(“localhost”);

conn.getAccountManager().createAccount(“login”, “test”);

conn.close();

conn = new XMPPConnection(“localhost”);

conn.login(“login”, “test”);

assertNotNull(conn.getRoster().getGroup(“ABC”));

conn.getAccountManager().deleteAccount();

conn.close();

conn = new XMPPConnection(“localhost”);

conn.getAccountManager().createAccount(“login”, “test”);

conn.close();

conn = new XMPPConnection(“localhost”);

conn.login(“login”, “test”);

//should fail here

assertNotNull(conn.getRoster().getGroup(“ABC”));

conn.getAccountManager().deleteAccount();

} catch (XMPPException e) {

e.printStackTrace();

fail(“No Exception should be raised.”);

} finally {

conn.close();

}

}

}