Fixes removing properties with partial match, and adds tests for it.

ice4sip
Damian Minkov 12 years ago
parent 02aa358e4f
commit 994e8bfe99

@ -354,7 +354,7 @@ public synchronized void removeProperty(String propertyName)
//remove all properties
for (String child : this.getPropertyNamesByPrefix(propertyName, false))
{
removeProperty(child);
this.setProperty(child, null, false);
}
this.setProperty(propertyName, null, false);
@ -411,15 +411,17 @@ public List<String> getPropertyNamesByPrefix(String prefix,
while (q.next())
{
String key = q.getString(1);
int ix = key.lastIndexOf('.');
if(ix == -1)
{
continue;
}
String keyPrefix = key.substring(0, ix);
if(exactPrefixMatch)
{
int ix = key.lastIndexOf('.');
if(ix == -1)
{
continue;
}
String keyPrefix = key.substring(0, ix);
if(prefix.equals(keyPrefix))
{
resultSet.add(key);
@ -427,7 +429,7 @@ public List<String> getPropertyNamesByPrefix(String prefix,
}
else
{
if(keyPrefix.startsWith(prefix))
if(key.startsWith(prefix))
{
resultSet.add(key);
}
@ -772,7 +774,6 @@ public String getConfigurationFilename()
{
return "props.hsql.script";
}
/**
* Loads the specified default properties maps from the Jitsi installation

@ -536,9 +536,13 @@ private int getLastCustomStatusMessageIndex()
DesktopUtilActivator.getConfigurationService()
.getPropertyNamesByPrefix(CUSTOM_MESSAGES_PREFIX, false);
int prefixLen = CUSTOM_MESSAGES_PREFIX.length() + 1;
for(String p : customMessagesProps)
{
String s = p.substring(CUSTOM_MESSAGES_PREFIX.length() + 1);
if(prefixLen > p.length())
continue;
String s = p.substring(prefixLen);
try
{

@ -485,7 +485,7 @@ private void initContent()
protocol,
accID.getUserID()));
}
for(Map.Entry<String, String> entry :
SecurityConfigActivator.getChatRoomsWithSavedPasswords()
.entrySet())
@ -498,7 +498,7 @@ private void initContent()
resources.getI18NString("service.gui.CHAT_ROOM"),
description));
}
// load provisioning passwords
String PROVISIONING_PROPERTIES_PREFIX =
"net.java.sip.communicator.plugin.provisioning.auth";
@ -523,17 +523,18 @@ private void initContent()
configurationService.getPropertyNamesByPrefix(
HTTP_PROPERTIES_PREFIX, false);
int prefLen = HTTP_PROPERTIES_PREFIX.length() + 1;
for(String prop: httpPasses)
{
// we skip the entry containing the encoded password
if(prop.contains("PASSWORD"))
if(prop.contains("PASSWORD")
|| prefLen > prop.length())
continue;
model.savedPasswords.add(
new PasswordsTableRow(
prop,
"http://" + prop.substring(
HTTP_PROPERTIES_PREFIX.length() + 1),
"http://" + prop.substring(prefLen),
configurationService.getString(prop)));
}
}

@ -151,6 +151,7 @@ private void doLoadStoredAccounts(ProtocolProviderFactory factory)
bundleContext,
CredentialsStorageService.class);
int prefLen = storedAccount.length() + 1;
for (Iterator<String> storedAccountPropertyIter
= storedAccountProperties.iterator();
storedAccountPropertyIter.hasNext();)
@ -159,7 +160,10 @@ private void doLoadStoredAccounts(ProtocolProviderFactory factory)
String value = configService.getString(property);
//strip the package prefix
property = property.substring(storedAccount.length() + 1);
if(prefLen > property.length())
continue;
property = property.substring(prefLen);
if (ProtocolProviderFactory.IS_ACCOUNT_DISABLED.equals(property))
disabled = Boolean.parseBoolean(value);

@ -153,6 +153,57 @@ public void testSetGetProperty() throws PropertyVetoException
property, actualReturn);
}
/**
* Tests whether removing and getting properties works correctly.
* @throws PropertyVetoException in case someone wrongfully vetoes the
* property change.
*/
public void testRemoveProperty() throws PropertyVetoException
{
String propertyName = "my.test.property.acc1234";
Object property = new String("my.test.property's value");
configurationService.setProperty(propertyName, property);
Object actualReturn = configurationService.getProperty(propertyName);
assertEquals("a property was not properly stored",
property, actualReturn);
configurationService.removeProperty(propertyName);
Object actualReturn2 = configurationService.getProperty(propertyName);
assertNull("a property was not properly removed",
actualReturn2);
}
/**
* Tests whether removing and getting properties works correctly.
* @throws PropertyVetoException in case someone wrongfully vetoes the
* property change.
*/
public void testRemovePrefixedProperty() throws PropertyVetoException
{
// this one is used in provisioning, if we have account info like:
// net.java.sip.communicator.impl.protocol.sip.acc1sip1322067404000=acc1sip1322067404000
// we need to remove it by provisioning this:
// net.java.sip.communicator.impl.protocol.sip.acc1sip=${null}
String propertyName = "my.test.property.acc1234";
String propertyPrefixName = "my.test.property.acc";
Object property = new String("my.test.property's value");
configurationService.setProperty(propertyName, property);
Object actualReturn = configurationService.getProperty(propertyName);
assertEquals("a property was not properly stored",
property, actualReturn);
configurationService.removeProperty(propertyPrefixName);
Object actualReturn2 = configurationService.getProperty(propertyName);
assertNull("a property was not properly removed by prefix",
actualReturn2);
}
/**
* Tests whether setting and getting works alright for properties declared
* as system and whether resolving and retrieving from the system property

Loading…
Cancel
Save