Author: bdaw
Date: 2007-06-20 17:11:01 -0400 (Wed, 20 Jun 2007)
New Revision: 7487
Modified:
trunk/identity/src/main/org/jboss/portal/identity/UserProfileModule.java
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserProfileModuleImpl.java
trunk/identity/src/main/org/jboss/portal/test/identity/IdentityTest.java
trunk/identity/src/main/org/jboss/portal/test/identity/db/DBIdentityTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPIdentityTestCase.java
Log:
make UserProfileModule remove property when provided value is null + tests
Modified: trunk/identity/src/main/org/jboss/portal/identity/UserProfileModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/UserProfileModule.java 2007-06-20
20:59:29 UTC (rev 7486)
+++ trunk/identity/src/main/org/jboss/portal/identity/UserProfileModule.java 2007-06-20
21:11:01 UTC (rev 7487)
@@ -48,10 +48,10 @@
public Object getProperty(User user, String propertyName) throws IdentityException,
IllegalArgumentException;
/**
- * Sets user property
+ * Sets user property. If the property value is null the property will be removed.
* @param user
* @param name
- * @param property
+ * @param property value
* @throws IdentityException
* @throws IllegalArgumentException
*/
Modified:
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserProfileModuleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserProfileModuleImpl.java 2007-06-20
20:59:29 UTC (rev 7486)
+++
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserProfileModuleImpl.java 2007-06-20
21:11:01 UTC (rev 7487)
@@ -142,14 +142,21 @@
throw new IdentityException("Property is not allowed for write access:
" + propertyName);
}
- if (!pi.getType().equals(propertyValue.getClass().getName()))
+ if (propertyValue != null &&
!pi.getType().equals(propertyValue.getClass().getName()))
{
throw new IdentityException("Wrong property type. Must be: " +
pi.getType() + "; and found: " + propertyValue.getClass().getName());
}
//if value is null reset property
- dbUser.getProfileMap().put(propertyName, propertyValue);
+ if (propertyValue != null)
+ {
+ dbUser.getProfileMap().put(propertyName, propertyValue);
+ }
+ else
+ {
+ dbUser.getProfileMap().remove(propertyName);
+ }
}
public Map getProperties(User user) throws IdentityException
Modified: trunk/identity/src/main/org/jboss/portal/test/identity/IdentityTest.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/IdentityTest.java 2007-06-20
20:59:29 UTC (rev 7486)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/IdentityTest.java 2007-06-20
21:11:01 UTC (rev 7487)
@@ -501,6 +501,29 @@
ctx.commit();
}
+ public void testNullProperty() throws Exception
+ {
+ ctx.begin();
+
+ User user = userModule.createUser("testname", "testpassword");
+
+ userProfileModule.setProperty(user, User.INFO_USER_THEME, "some theme
value");
+
+ Object o = userProfileModule.getProperty(user, User.INFO_USER_THEME);
+
+ assertNotNull(o);
+ assertEquals(o.toString(), "some theme value");
+
+ userProfileModule.setProperty(user, User.INFO_USER_THEME, null);
+
+ o = userProfileModule.getProperty(user, User.INFO_USER_THEME);
+
+ assertNull(o);
+
+ ctx.commit();
+
+ }
+
public void testGetProperties() throws Exception
{
ctx.begin();
Modified:
trunk/identity/src/main/org/jboss/portal/test/identity/db/DBIdentityTestCase.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/test/identity/db/DBIdentityTestCase.java 2007-06-20
20:59:29 UTC (rev 7486)
+++
trunk/identity/src/main/org/jboss/portal/test/identity/db/DBIdentityTestCase.java 2007-06-20
21:11:01 UTC (rev 7487)
@@ -187,6 +187,11 @@
commit();
}
+ public void testNullProperty() throws Exception
+ {
+ utc.testNullProperty();
+ }
+
public void testGetProperties() throws Exception
{
utc.testGetProperties();
Modified:
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPIdentityTestCase.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPIdentityTestCase.java 2007-06-20
20:59:29 UTC (rev 7486)
+++
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPIdentityTestCase.java 2007-06-20
21:11:01 UTC (rev 7487)
@@ -176,4 +176,10 @@
{
utc.testStaticProperty();
}
+
+ public void testNullProperty() throws Exception
+ {
+ utc.testNullProperty();
+ }
+
}
Show replies by date