- Avoid code redundancy by moving SecurityAuthorityImpl

to an unique class.
- Connect the third MSN testing account when needed.
cusax-fix
Valentin Martinet 16 years ago
parent 3e5b096be3
commit d303e5e0b1

@ -0,0 +1,93 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.slick.protocol.generic;
import net.java.sip.communicator.service.protocol.*;
/**
* A very simple straight forward implementation of a security authority
* that would always return the same password (the one specified upon
* construction) when asked for credentials.
*/
public class SecurityAuthorityImpl
implements SecurityAuthority
{
/**
* The password to return when asked for credentials
*/
private char[] passwd = null;
private boolean isUserNameEditable = false;
/**
* Creates an instance of this class that would always return "passwd"
* when asked for credentials.
*
* @param passwd the password that this class should return when
* asked for credentials.
*/
public SecurityAuthorityImpl(char[] passwd)
{
this.passwd = passwd;
}
/**
* Returns a Credentials object associated with the specified realm.
* <p>
* @param realm The realm that the credentials are needed for.
* @param defaultValues the values to propose the user by default
* @return The credentials associated with the specified realm or null
* if none could be obtained.
*/
public UserCredentials obtainCredentials(String realm,
UserCredentials defaultValues)
{
defaultValues.setPassword(passwd);
return defaultValues;
}
/**
* Returns a Credentials object associated with the specified realm.
* <p>
* @param realm The realm that the credentials are needed for.
* @param defaultValues the values to propose the user by default
* @param reasonCode the reason for which we're obtaining the
* credentials.
* @return The credentials associated with the specified realm or null
* if none could be obtained.
*/
public UserCredentials obtainCredentials(String realm,
UserCredentials defaultValues,
int reasonCode)
{
return obtainCredentials(realm, defaultValues);
}
/**
* Sets the userNameEditable property, which should indicate if the
* user name could be changed by user or not.
*
* @param isUserNameEditable indicates if the user name could be changed
*/
public void setUserNameEditable(boolean isUserNameEditable)
{
this.isUserNameEditable = isUserNameEditable;
}
/**
* Indicates if the user name is currently editable, i.e. could be changed
* by user or not.
*
* @return <code>true</code> if the user name could be changed,
* <code>false</code> - otherwise.
*/
public boolean isUserNameEditable()
{
return isUserNameEditable;
}
}

@ -92,8 +92,18 @@ public void testCreateRoom()
// We wait some time to let the MsnSwitchboard attached to this room
// started...
try { Thread.sleep(10000); }
catch (InterruptedException e) { e.printStackTrace(); }
Object wait = new Object();
synchronized (wait)
{
try
{
wait.wait(10000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
// Check that we retrieved the only one room that should be available:
assertEquals("The room can't be retrieved",

@ -11,6 +11,7 @@
import junit.framework.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.slick.protocol.generic.*;
import net.java.sip.communicator.util.*;
/**
@ -272,88 +273,4 @@ public void waitForEvent(long waitFor)
}
/**
* A very simple straight forward implementation of a security authority
* that would always return the same password (the one specified upon
* construction) when asked for credentials.
*/
public class SecurityAuthorityImpl
implements SecurityAuthority
{
/**
* The password to return when asked for credentials
*/
private char[] passwd = null;
private boolean isUserNameEditable = false;
/**
* Creates an instance of this class that would always return "passwd"
* when asked for credentials.
*
* @param passwd the password that this class should return when
* asked for credentials.
*/
public SecurityAuthorityImpl(char[] passwd)
{
this.passwd = passwd;
}
/**
* Returns a Credentials object associated with the specified realm.
* <p>
* @param realm The realm that the credentials are needed for.
* @param defaultValues the values to propose the user by default
* @return The credentials associated with the specified realm or null
* if none could be obtained.
*/
public UserCredentials obtainCredentials(String realm,
UserCredentials defaultValues)
{
defaultValues.setPassword(passwd);
return defaultValues;
}
/**
* Returns a Credentials object associated with the specified realm.
* <p>
* @param realm The realm that the credentials are needed for.
* @param defaultValues the values to propose the user by default
* @param reasonCode the reason for which we're obtaining the
* credentials.
* @return The credentials associated with the specified realm or null
* if none could be obtained.
*/
public UserCredentials obtainCredentials(String realm,
UserCredentials defaultValues,
int reasonCode)
{
return obtainCredentials(realm, defaultValues);
}
/**
* Sets the userNameEditable property, which should indicate if the
* user name could be changed by user or not.
*
* @param isUserNameEditable indicates if the user name could be changed
*/
public void setUserNameEditable(boolean isUserNameEditable)
{
this.isUserNameEditable = isUserNameEditable;
}
/**
* Indicates if the user name is currently editable, i.e. could be changed
* by user or not.
*
* @return <code>true</code> if the user name could be changed,
* <code>false</code> - otherwise.
*/
public boolean isUserNameEditable()
{
return isUserNameEditable;
}
}
}

@ -21,8 +21,7 @@
*/
public class TestOperationSetAdHocMultiUserChatMsnImpl
extends TestOperationSetAdHocMultiUserChat
{
{
/**
* Creates the test with the specified method name.
*
@ -42,6 +41,8 @@ public static TestSuite suite()
{
TestSuite suite = new TestSuite();
suite.addTest(new TestOperationSetAdHocMultiUserChatMsnImpl(
"testRegisterAccount3"));
suite.addTest(new TestOperationSetAdHocMultiUserChatMsnImpl(
"prepareContactList"));
suite.addTest(new TestOperationSetAdHocMultiUserChatMsnImpl(
@ -56,7 +57,18 @@ public static TestSuite suite()
return suite;
}
public void testRegisterAccount3() throws OperationFailedException
{
fixture.provider3.register(
new SecurityAuthorityImpl(
System.getProperty(
MsnProtocolProviderServiceLick.ACCOUNT_3_PREFIX
+ ProtocolProviderFactory.PASSWORD).toCharArray()));
assertEquals(fixture.provider3.getRegistrationState(),
RegistrationState.REGISTERED);
}
public void start() throws Exception
{
fixture = new MsnSlickFixture();
@ -144,4 +156,87 @@ public void start() throws Exception
"An implementation of the service must provide an " +
"implementation of at least one of the PresenceOperationSets");
}
/**
* A very simple straight forward implementation of a security authority
* that would always return the same password (the one specified upon
* construction) when asked for credentials.
*/
public class SecurityAuthorityImpl
implements SecurityAuthority
{
/**
* The password to return when asked for credentials
*/
private char[] passwd = null;
private boolean isUserNameEditable = false;
/**
* Creates an instance of this class that would always return "passwd"
* when asked for credentials.
*
* @param passwd the password that this class should return when
* asked for credentials.
*/
public SecurityAuthorityImpl(char[] passwd)
{
this.passwd = passwd;
}
/**
* Returns a Credentials object associated with the specified realm.
* <p>
* @param realm The realm that the credentials are needed for.
* @param defaultValues the values to propose the user by default
* @param reasonCode the reason for which we're obtaining the
* credentials.
* @return The credentials associated with the specified realm or null
* if none could be obtained.
*/
public UserCredentials obtainCredentials(String realm,
UserCredentials defaultValues,
int reasonCode)
{
return obtainCredentials(realm, defaultValues);
}
/**
* Returns a Credentials object associated with the specified realm.
* <p>
* @param realm The realm that the credentials are needed for.
* @param defaultValues the values to propose the user by default
* @return The credentials associated with the specified realm or null
* if none could be obtained.
*/
public UserCredentials obtainCredentials(String realm,
UserCredentials defaultValues)
{
defaultValues.setPassword(passwd);
return defaultValues;
}
/**
* Sets the userNameEditable property, which should indicate if the
* user name could be changed by user or not.
*
* @param isUserNameEditable indicates if the user name could be changed
*/
public void setUserNameEditable(boolean isUserNameEditable)
{
this.isUserNameEditable = isUserNameEditable;
}
/**
* Indicates if the user name is currently editable, i.e. could be changed
* by user or not.
*
* @return <code>true</code> if the user name could be changed,
* <code>false</code> - otherwise.
*/
public boolean isUserNameEditable()
{
return isUserNameEditable;
}
}
}

@ -12,6 +12,7 @@
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.slick.protocol.generic.*;
import net.java.sip.communicator.util.*;
/**
@ -95,7 +96,6 @@ public void testRegister()
//they were properly dispatched.
fixture.provider1.addRegistrationStateChangeListener(regEvtCollector1);
fixture.provider2.addRegistrationStateChangeListener(regEvtCollector2);
fixture.provider3.addRegistrationStateChangeListener(regEvtCollector3);
//register all of our providers
fixture.provider1.register(new SecurityAuthorityImpl(
@ -104,9 +104,6 @@ public void testRegister()
fixture.provider2.register(new SecurityAuthorityImpl(
System.getProperty(MsnProtocolProviderServiceLick.ACCOUNT_2_PREFIX
+ ProtocolProviderFactory.PASSWORD).toCharArray()));
fixture.provider3.register(new SecurityAuthorityImpl(
System.getProperty(MsnProtocolProviderServiceLick.ACCOUNT_3_PREFIX
+ ProtocolProviderFactory.PASSWORD).toCharArray()));
//give it enough time to register. We won't really have to wait all this
//time since the registration event collector would notify us the moment
@ -115,7 +112,6 @@ public void testRegister()
regEvtCollector1.waitForEvent(15000);
regEvtCollector2.waitForEvent(40000);
regEvtCollector3.waitForEvent(60000);
//make sure that the registration process trigerred the corresponding
//events.
@ -142,24 +138,24 @@ public void testRegister()
.contains(RegistrationState.REGISTERED));
//now the same for provider 3
assertTrue(
"No events were dispatched during the registration process "
+"of provider3."
,regEvtCollector3.collectedNewStates.size() > 0);
assertTrue(
"No registration event notifying of registration was dispatched. "
+"All events were: " + regEvtCollector3.collectedNewStates
,regEvtCollector3.collectedNewStates
.contains(RegistrationState.REGISTERED));
// assertTrue(
// "No events were dispatched during the registration process "
// +"of provider3."
// ,regEvtCollector3.collectedNewStates.size() > 0);
//
// assertTrue(
// "No registration event notifying of registration was dispatched. "
// +"All events were: " + regEvtCollector3.collectedNewStates
// ,regEvtCollector3.collectedNewStates
// .contains(RegistrationState.REGISTERED));
fixture.provider1
.removeRegistrationStateChangeListener(regEvtCollector1);
fixture.provider2
.removeRegistrationStateChangeListener(regEvtCollector2);
fixture.provider3
.removeRegistrationStateChangeListener(regEvtCollector3);
// fixture.provider3
// .removeRegistrationStateChangeListener(regEvtCollector3);
}
@ -267,87 +263,4 @@ public void waitForEvent(long waitFor)
}
}
}
/**
* A very simple straight forward implementation of a security authority
* that would always return the same password (the one specified upon
* construction) when asked for credentials.
*/
public class SecurityAuthorityImpl
implements SecurityAuthority
{
/**
* The password to return when asked for credentials
*/
private char[] passwd = null;
private boolean isUserNameEditable = false;
/**
* Creates an instance of this class that would always return "passwd"
* when asked for credentials.
*
* @param passwd the password that this class should return when
* asked for credentials.
*/
public SecurityAuthorityImpl(char[] passwd)
{
this.passwd = passwd;
}
/**
* Returns a Credentials object associated with the specified realm.
* <p>
* @param realm The realm that the credentials are needed for.
* @param defaultValues the values to propose the user by default
* @param reasonCode the reason for which we're obtaining the
* credentials.
* @return The credentials associated with the specified realm or null
* if none could be obtained.
*/
public UserCredentials obtainCredentials(String realm,
UserCredentials defaultValues,
int reasonCode)
{
return obtainCredentials(realm, defaultValues);
}
/**
* Returns a Credentials object associated with the specified realm.
* <p>
* @param realm The realm that the credentials are needed for.
* @param defaultValues the values to propose the user by default
* @return The credentials associated with the specified realm or null
* if none could be obtained.
*/
public UserCredentials obtainCredentials(String realm,
UserCredentials defaultValues)
{
defaultValues.setPassword(passwd);
return defaultValues;
}
/**
* Sets the userNameEditable property, which should indicate if the
* user name could be changed by user or not.
*
* @param isUserNameEditable indicates if the user name could be changed
*/
public void setUserNameEditable(boolean isUserNameEditable)
{
this.isUserNameEditable = isUserNameEditable;
}
/**
* Indicates if the user name is currently editable, i.e. could be changed
* by user or not.
*
* @return <code>true</code> if the user name could be changed,
* <code>false</code> - otherwise.
*/
public boolean isUserNameEditable()
{
return isUserNameEditable;
}
}
}

@ -11,6 +11,7 @@
import junit.framework.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.slick.protocol.generic.*;
import net.java.sip.communicator.util.*;
/**
@ -265,87 +266,4 @@ public void waitForEvent(long waitFor)
}
}
}
/**
* A very simple straight forward implementation of a security authority
* that would always return the same password (the one specified upon
* construction) when asked for credentials.
*/
public class SecurityAuthorityImpl
implements SecurityAuthority
{
/**
* The password to return when asked for credentials
*/
private char[] passwd = null;
private boolean isUserNameEditable = false;
/**
* Creates an instance of this class that would always return "passwd"
* when asked for credentials.
*
* @param passwd the password that this class should return when
* asked for credentials.
*/
public SecurityAuthorityImpl(char[] passwd)
{
this.passwd = passwd;
}
/**
* Returns a Credentials object associated with the specified realm.
* <p>
* @param realm The realm that the credentials are needed for.
* @param defaultValues the values to propose the user by default
* @param reasonCode the reason for which we're obtaining the
* credentials.
* @return The credentials associated with the specified realm or null
* if none could be obtained.
*/
public UserCredentials obtainCredentials(String realm,
UserCredentials defaultValues,
int reasonCode)
{
return obtainCredentials(realm, defaultValues);
}
/**
* Returns a Credentials object associated with the specified realm.
* <p>
* @param realm The realm that the credentials are needed for.
* @param defaultValues the values to propose the user by default
* @return The credentials associated with the specified realm or null
* if none could be obtained.
*/
public UserCredentials obtainCredentials(String realm,
UserCredentials defaultValues)
{
defaultValues.setPassword(passwd);
return defaultValues;
}
/**
* Sets the userNameEditable property, which should indicate if the
* user name could be changed by user or not.
*
* @param isUserNameEditable indicates if the user name could be changed
*/
public void setUserNameEditable(boolean isUserNameEditable)
{
this.isUserNameEditable = isUserNameEditable;
}
/**
* Indicates if the user name is currently editable, i.e. could be
* changed by user or not.
*
* @return <code>true</code> if the user name could be changed,
* <code>false</code> - otherwise.
*/
public boolean isUserNameEditable()
{
return isUserNameEditable;
}
}
}

Loading…
Cancel
Save