FileDocCategorySizeDatePackage
TestUserManager.javaAPI DocAzureus 3.0.3.43355Tue Sep 06 06:44:54 BST 2005org.gudy.azureus2.ui.console.multiuser

TestUserManager

public class TestUserManager extends TestCase
test class for the UserManager object
author
pauld

Fields Summary
private InMemoryUserManager
manager
private org.gudy.azureus2.ui.console.UserProfile
profile1
private org.gudy.azureus2.ui.console.UserProfile
profile2
Constructors Summary
Methods Summary
protected voidsetUp()

		super.setUp();
		
		manager = new InMemoryUserManager(null);
		profile1 = new UserProfile();
		profile1.setUsername("myuser1");
		profile1.setPassword("mypassword");
		manager.addUser(profile1);
		profile2 = new UserProfile();
		profile2.setUsername("myuser2");
		profile2.setPassword("zigzag");
		profile2.setUserType(UserProfile.USER);
		manager.addUser(profile2);		
	
protected voidtearDown()

		super.tearDown();
	
public voidtestAuthenticate()

		assertEquals( "verify authentication succeeds", profile1, manager.authenticate("myuser1", "mypassword"));
		assertNull( "verify authentication fails", manager.authenticate("myuser1", "mypassword_shouldfail"));
	
public voidtestLoadSave()

		ByteArrayOutputStream out = new ByteArrayOutputStream();
		manager.save(out);
		System.out.println("Saved to: " + new String(out.toByteArray()));
		ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
		InMemoryUserManager newManager = new InMemoryUserManager(null);
		newManager.load(in);
		UserProfile profile3 = new UserProfile();
		profile3.setUserType(UserProfile.GUEST);
		profile3.setUsername("user3");
		profile3.setPassword("whatever");
		assertTrue( manager.getUsers().contains(profile1 ) );
		assertTrue( manager.getUsers().contains(profile2 ) );
		assertFalse( manager.getUsers().contains(profile3 ) );
		assertTrue( newManager.getUsers().contains(profile1 ) );
		assertTrue( newManager.getUsers().contains(profile2 ) );
		assertFalse( newManager.getUsers().contains(profile3 ) );