Author: bdaw
Date: 2007-02-14 14:24:58 -0500 (Wed, 14 Feb 2007)
New Revision: 6280
Removed:
trunk/identity/src/main/org/jboss/portal/identity/experimental/
Modified:
trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortlet.java
trunk/core/src/resources/portal-core-sar/conf/identity/profile-config.xml
trunk/identity/build.xml
trunk/identity/src/main/org/jboss/portal/identity/DelegatingUserProfileModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/config/info/PropertyInfoSupport.java
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserImpl.java
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserProfileModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/db/ProfileMapImpl.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserProfileModuleImpl.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/db/DBTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPIdentityTestCase.java
trunk/identity/src/resources/test/config/profile-config.xml
trunk/identity/src/resources/test/config/standardidentity-config.xml
Log:
- make UserProfile modules handle <type> of objects from profile configuration
- correct test cases
Modified: trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortlet.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortlet.java 2007-02-14
19:16:55 UTC (rev 6279)
+++ trunk/core/src/main/org/jboss/portal/core/portlet/user/UserPortlet.java 2007-02-14
19:24:58 UTC (rev 6280)
@@ -29,6 +29,7 @@
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.Set;
+import java.util.Date;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
@@ -693,7 +694,22 @@
//user.setFakeEmail(fakeEmail);
setProperty(user,User.INFO_USER_EMAIL_FAKE, fakeEmail);
- //user.setRegistrationDate(new Date());
+ //TODO: set registration date
+
+ String type =
userProfileModule.getProfileInfo().getPropertyInfo(User.INFO_USER_REGISTRATION_DATE).getType();
+ if (type.equals("java.util.Date"))
+ {
+ putNonEmptyProperty(user, User.INFO_USER_REGISTRATION_DATE, new Date());
+ }
+ else if (type.equals("java.lang.String"))
+ {
+ putNonEmptyProperty(user, User.INFO_USER_REGISTRATION_DATE, new
Date().toString());
+ }
+ else
+ {
+ log.warn(User.INFO_USER_REGISTRATION_DATE + " property is mapped in
not supported type: " + type);
+ }
+
String subscriptionMode =
getPortletConfig().getInitParameter(UserPortletConstants.SUBSCRIPTIONMODE);
if (subscriptionMode == null)
{
@@ -1183,10 +1199,16 @@
}
}
- private void putNonEmptyProperty(User user, String key, String value)
+ private void putNonEmptyProperty(User user, String key, Object value)
{
- if ((value != null) && (value.trim().length() != 0))
+
+
+ if (value != null)
{
+ if (value instanceof String && !(((String)value).trim().length() != 0)
)
+ {
+ return;
+ }
//user.getProfile().put(key, value);
try
{
Modified: trunk/core/src/resources/portal-core-sar/conf/identity/profile-config.xml
===================================================================
--- trunk/core/src/resources/portal-core-sar/conf/identity/profile-config.xml 2007-02-14
19:16:55 UTC (rev 6279)
+++ trunk/core/src/resources/portal-core-sar/conf/identity/profile-config.xml 2007-02-14
19:24:58 UTC (rev 6280)
@@ -103,8 +103,8 @@
</property>
<property>
<name>portal.user.registration-date</name>
- <type>java.lang.String</type>
- <access-mode>read-write</access-mode>
+ <type>java.util.Date</type>
+ <access-mode>read-only</access-mode>
<usage>mandatory</usage>
<display-name xml:lang="en">Registration date</display-name>
<description xml:lang="en">Registration date of
user</description>
@@ -117,7 +117,7 @@
</property>
<property>
<name>portal.user.email.view-real</name>
- <type>java.lang.String</type>
+ <type>java.lang.Boolean</type>
<access-mode>read-write</access-mode>
<usage>mandatory</usage>
<display-name xml:lang="en">View real email</display-name>
@@ -131,7 +131,7 @@
</property>
<property>
<name>portal.user.enabled</name>
- <type>java.lang.String</type>
+ <type>java.lang.Boolean</type>
<access-mode>read-write</access-mode>
<usage>mandatory</usage>
<display-name xml:lang="en">Enabled</display-name>
Modified: trunk/identity/build.xml
===================================================================
--- trunk/identity/build.xml 2007-02-14 19:16:55 UTC (rev 6279)
+++ trunk/identity/build.xml 2007-02-14 19:24:58 UTC (rev 6280)
@@ -452,8 +452,8 @@
<x-test>
+ <test todir="${test.reports}"
name="org.jboss.portal.test.identity.db.DBIdentityTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.identity.ldap.LDAPIdentityTestCase"/>
- <test todir="${test.reports}"
name="org.jboss.portal.test.identity.db.DBIdentityTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.identity.ldap.LDAPSimpleUserModuleTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.identity.ldap.LDAPSimpleRoleModuleTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.identity.ldap.LDAPStaticGroupMembershipModuleTestCase"/>
Modified:
trunk/identity/src/main/org/jboss/portal/identity/DelegatingUserProfileModuleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity/DelegatingUserProfileModuleImpl.java 2007-02-14
19:16:55 UTC (rev 6279)
+++
trunk/identity/src/main/org/jboss/portal/identity/DelegatingUserProfileModuleImpl.java 2007-02-14
19:24:58 UTC (rev 6280)
@@ -87,18 +87,18 @@
else if (property.isMappedDB())
{
log.debug("Delegating to DB module");
- Object o = getDBModule().getProperty(user, propertyName);
+ return getDBModule().getProperty(user, propertyName);
//if property is column it may be some Object - just convert to String for
now
- if(o != null && !(o instanceof String))
+ /*if(o != null && !(o instanceof String))
{
return o.toString();
}
else
{
return o;
- }
+ }*/
}
throw new IdentityException("Cannot process property - incorrect profile or
module configuration");
@@ -130,7 +130,7 @@
log.debug("Delegating to DB module");
- Object val = propertyValue.toString();
+ //Object val = propertyValue;
//if property is dynamic convert value to String first
//
if(property.getMappingDBType().equals(PropertyInfo.MAPPING_DB_TYPE_DYNAMIC))
// {
@@ -142,7 +142,7 @@
// }
- getDBModule().setProperty(user, name, val);
+ getDBModule().setProperty(user, name, propertyValue);
return;
}
throw new IdentityException("Cannot process property - incorrect profile or
module configuration");
Modified:
trunk/identity/src/main/org/jboss/portal/identity/config/info/PropertyInfoSupport.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity/config/info/PropertyInfoSupport.java 2007-02-14
19:16:55 UTC (rev 6279)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/info/PropertyInfoSupport.java 2007-02-14
19:24:58 UTC (rev 6280)
@@ -64,7 +64,19 @@
name = meta.getName();
type = meta.getType();
accessMode = meta.getAccessMode();
+ if (!accessMode.equals(PropertyInfo.ACCESS_MODE_READ_ONLY) &&
!accessMode.equals(PropertyInfo.ACCESS_MODE_READ_WRITE))
+ {
+ throw new IdentityException("Wrong value in user profile configuration for
access-mode: " + accessMode);
+ }
usage = meta.getUsage();
+
+ if (!usage.equals(PropertyInfo.USAGE_MANDATORY) &&
!usage.equals(PropertyInfo.USAGE_OPTIONAL))
+ {
+ throw new IdentityException("Wrong value in user profile configuration for
usage: " + usage);
+ }
+
+
+
//mappingType = meta.getMapping().getType();
//mappingValue = meta.getMapping().getValue();
@@ -96,6 +108,10 @@
{
mappedDB = true;
mappingDBType = meta.getMapping().getMappingDatabase().getType();
+ if (!mappingDBType.equals(PropertyInfo.MAPPING_DB_TYPE_COLUMN) &&
!mappingDBType.equals(PropertyInfo.MAPPING_DB_TYPE_DYNAMIC))
+ {
+ throw new IdentityException("Wrong value in user profile
configuration for database mapping type: " + mappingDBType);
+ }
mappingDBValue = meta.getMapping().getMappingDatabase().getValue();
}
}
Modified: trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserImpl.java 2007-02-14
19:16:55 UTC (rev 6279)
+++ trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserImpl.java 2007-02-14
19:24:58 UTC (rev 6280)
@@ -384,22 +384,29 @@
/**
* @param instance the user instance
- * @param string the value
+ * @param value the value
* @throws IllegalArgumentException if the string cannot be converted to an object
*/
- public void set(Object instance, String string) throws IllegalArgumentException
+ public void set(Object instance, Object value) throws IllegalArgumentException
{
try
{
- if (string == null)
+ if (value == null)
{
field.set(instance, null);
}
- else
+
+ if (value instanceof String)
{
- Object object = toObject(string);
+
+ Object object = toObject((String)value);
field.set(instance, object);
+
}
+ else
+ {
+ field.set(instance,value);
+ }
}
catch (IllegalAccessException e)
{
@@ -412,7 +419,7 @@
* @return the converted value
* @throws IllegalArgumentException if the object cannot be converted to a string
*/
- public String get(Object instance) throws IllegalArgumentException
+ public Object get(Object instance) throws IllegalArgumentException
{
try
{
@@ -501,6 +508,21 @@
{
return value.toString();
}
+
+ //workaround to return Date object
+ public Object get(Object instance) throws IllegalArgumentException
+ {
+ try
+ {
+ return field.get(instance);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new Error(e);
+ }
+ }
+
+
}
static class DatePropertyAccessor extends PropertyAccessor
@@ -538,5 +560,19 @@
DateFormat format =
(DateFormat)HibernateUserImpl.DatePropertyAccessor.formatLocal.get();
return format.format(date);
}
+
+ //workaround to return Date object
+ public Object get(Object instance) throws IllegalArgumentException
+ {
+ try
+ {
+ return field.get(instance);
+
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new Error(e);
+ }
+ }
}
}
Modified:
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserProfileModuleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserProfileModuleImpl.java 2007-02-14
19:16:55 UTC (rev 6279)
+++
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserProfileModuleImpl.java 2007-02-14
19:24:58 UTC (rev 6280)
@@ -41,6 +41,7 @@
import java.util.Iterator;
import java.util.HashMap;
import java.util.Random;
+import java.util.Collections;
/**
* @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
@@ -144,6 +145,11 @@
throw new IdentityException("Property is not allowed for write access:
" + propertyName);
}
+ if (!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);
@@ -169,7 +175,7 @@
String key = (String)iterator.next();
props.put(key, profile.get(key));
}
- return props;
+ return Collections.unmodifiableMap(props);
}
Modified: trunk/identity/src/main/org/jboss/portal/identity/db/ProfileMapImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/db/ProfileMapImpl.java 2007-02-14
19:16:55 UTC (rev 6279)
+++ trunk/identity/src/main/org/jboss/portal/identity/db/ProfileMapImpl.java 2007-02-14
19:24:58 UTC (rev 6280)
@@ -171,7 +171,14 @@
else
{
Object oldValue = accessor.get(user);
- accessor.set(user, (String)newValue);
+ if (newValue != null)
+ {
+ accessor.set(user, newValue);
+ }
+ else
+ {
+ accessor.set(user, null);
+ }
return oldValue;
}
}
Modified:
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserProfileModuleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserProfileModuleImpl.java 2007-02-14
19:16:55 UTC (rev 6279)
+++
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserProfileModuleImpl.java 2007-02-14
19:24:58 UTC (rev 6280)
@@ -38,6 +38,8 @@
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Collection;
+import java.util.Collections;
/**
* @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
@@ -70,7 +72,7 @@
}
String attributeName = resolveAttributeName(propertyName);
- String propertyValue = null;
+ Object propertyValue = null;
if (attributeName == null)
{
@@ -86,7 +88,7 @@
if (attr != null)
{
- propertyValue = (String)attr.get();
+ propertyValue = attr.get();
}
else
{
@@ -98,6 +100,15 @@
throw new IdentityException("Cannot get user property value.", e);
}
+ PropertyInfo pi = getProfileInfo().getPropertyInfo(propertyName);
+
+
+ if (propertyValue != null &&
!pi.getType().equals(propertyValue.getClass().getName()))
+ {
+ log.error("Error on processing property:" + propertyName);
+ log.error("Wrong property type retreived from LDAP. Should be: " +
pi.getType() + "; and found: " + propertyValue.getClass().getName());
+ }
+
return propertyValue;
}
@@ -126,9 +137,21 @@
String attributeName = resolveAttributeName(propertyName);
+ PropertyInfo pi = getProfileInfo().getPropertyInfo(propertyName);
+ if (pi.getAccessMode().equals(PropertyInfo.ACCESS_MODE_READ_ONLY))
+ {
+ throw new IdentityException("Property has read only access - cannot set:
" + propertyName);
+ }
+
+ if (!pi.getType().equals(property.getClass().getName()))
+ {
+ throw new IdentityException("Wrong property type. Must be: " +
pi.getType() + "; and found: " + property.getClass().getName());
+ }
+
+
//TODO: check the type and log.info that this can only be a String if not such
- String propertyValue = property.toString();
+ //String propertyValue = property.toString();
if (attributeName == null)
{
@@ -142,7 +165,7 @@
Attributes attrs = new BasicAttributes(true);
Attribute attr = new BasicAttribute(attributeName);
- attr.add(propertyValue);
+ attr.add(property);
attrs.put(attr);
getConnectionContext().createInitialContext().modifyAttributes(ldapUser.getDn(),
DirContext.REPLACE_ATTRIBUTE,attrs);
@@ -177,6 +200,7 @@
try
{
Map mappings = resolveAttributesMappingMap();
+
Set props = mappings.keySet();
Attributes attrs =
getConnectionContext().createInitialContext().getAttributes(ldapUser.getDn());
@@ -189,7 +213,13 @@
if (attr != null)
{
- propertyMap.put(name,(String)attr.get());
+ propertyMap.put(name,attr.get());
+ PropertyInfo pi = getProfileInfo().getPropertyInfo(name);
+ if (attr.get() != null &&
!pi.getType().equals(attr.get().getClass().getName()))
+ {
+ log.error("Error on processing property:" + name);
+ log.error("Wrong property type retreived from LDAP. Should be:
" + pi.getType() + "; and found: " + attr.get().getClass().getName());
+ }
}
else
{
@@ -202,7 +232,7 @@
throw new IdentityException("Cannot get user property value.", e);
}
- return propertyMap;
+ return Collections.unmodifiableMap(propertyMap);
}
private String resolveAttributeName(String propertyName) throws IdentityException
@@ -276,4 +306,6 @@
return profileInfo;
}
+
+
}
Modified: trunk/identity/src/main/org/jboss/portal/test/identity/IdentityTest.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/IdentityTest.java 2007-02-14
19:16:55 UTC (rev 6279)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/IdentityTest.java 2007-02-14
19:24:58 UTC (rev 6280)
@@ -8,6 +8,7 @@
import org.jboss.portal.identity.User;
import org.jboss.portal.identity.Role;
import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.ProfileMap;
import org.jboss.portal.common.util.CollectionBuilder;
import org.jboss.portal.common.p3p.P3PConstants;
@@ -17,6 +18,8 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
+import java.util.Date;
+import java.text.SimpleDateFormat;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -377,7 +380,7 @@
public void testDynamicProperty() throws Exception
{
ctx.begin();
- User user = userModule.createUser("testname", "testpassword");
+ /*User user = userModule.createUser("testname",
"testpassword");
Map map = userProfileModule.getProperties(user);
assertNull(map.get("foo"));
//assertFalse(map.isReadOnly("foo"));
@@ -390,7 +393,7 @@
user = userModule.findUserByUserName("testname");
map = userProfileModule.getProperties(user);
assertEquals("value", map.get("foo"));
- //assertFalse(map.isReadOnly("foo"));
+ //assertFalse(map.isReadOnly("foo"));*/
ctx.commit();
}
@@ -401,71 +404,100 @@
//
User user = userModule.createUser("testname", "testpassword");
Map map = userProfileModule.getProperties(user);
- assertEquals("testname", map.get(P3PConstants.INFO_USER_NAME_NICKNAME));
+ //assertEquals("testname",
map.get(P3PConstants.INFO_USER_NAME_NICKNAME));
- // Test cannot remove a static property
+ // Test cannot remove property
try
{
map.remove(P3PConstants.INFO_USER_NAME_GIVEN);
- fail("Should not be capable to remove static property");
+ fail("Should not be able to remove property from a map");
}
- catch (IllegalArgumentException expected)
+ catch (Exception expected)
{
}
- // Test read only property
+ /*// Test read only property
//assertTrue(map.isReadOnly(P3PConstants.INFO_USER_NAME_NICKNAME));
try
{
- map.put(P3PConstants.INFO_USER_NAME_NICKNAME, "anothername");
+ .put(P3PConstants.INFO_USER_NAME_NICKNAME, "anothername");
fail("Should not be capable to modify a read only static property");
}
catch (IllegalArgumentException expected)
{
- }
+ }*/
// Test non nullable and writable property
- try
+ /*try
{
map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, null);
fail("Should not be capable to nullify a non nullable static
property");
}
catch (NullPointerException expected)
{
- }
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
- assertEquals("true", userProfileModule.getProperty(user,
User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+ }*/
+ //map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
+ userProfileModule.setProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL,
Boolean.TRUE);
+ assertEquals(Boolean.TRUE.toString(), userProfileModule.getProperty(user,
User.INFO_USER_VIEW_EMAIL_VIEW_REAL).toString());
// Test boolean property
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "false");
- assertEquals("false", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
- assertEquals("false", userProfileModule.getProperty(user,
User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+ userProfileModule.setProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL,
Boolean.FALSE);
+ //assertEquals(Boolean.FALSE.toString(),
map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL).toString());
+ assertEquals(Boolean.FALSE.toString(), userProfileModule.getProperty(user,
User.INFO_USER_VIEW_EMAIL_VIEW_REAL).toString());
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
- assertEquals("true", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
- assertEquals("true", userProfileModule.getProperty(user,
User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+ userProfileModule.setProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL,
Boolean.TRUE);
+ //assertEquals(Boolean.TRUE.toString(),
map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL).toString());
+ assertEquals(Boolean.TRUE.toString(), userProfileModule.getProperty(user,
User.INFO_USER_VIEW_EMAIL_VIEW_REAL).toString());
- userProfileModule.setProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL,
"false");
- assertEquals("false", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
- assertEquals("false", userProfileModule.getProperty(user,
User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+ userProfileModule.setProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL,
Boolean.FALSE);
+ //assertEquals(Boolean.FALSE.toString(),
map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL).toString());
+ assertEquals(Boolean.FALSE.toString(), userProfileModule.getProperty(user,
User.INFO_USER_VIEW_EMAIL_VIEW_REAL).toString());
- userProfileModule.setProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL,
"true");
- assertEquals("true", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
- assertEquals("true", userProfileModule.getProperty(user,
User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+ userProfileModule.setProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL,
Boolean.TRUE);
+ //assertEquals(Boolean.TRUE.toString(),
map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL).toString());
+ assertEquals(Boolean.TRUE.toString(), userProfileModule.getProperty(user,
User.INFO_USER_VIEW_EMAIL_VIEW_REAL).toString());
try
{
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "truee");
+ userProfileModule.setProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL,
"true");
fail("Should not be capable to set a bad value to boolean property");
}
- catch (IllegalArgumentException expected)
+ catch (Exception expected)
{
}
// Test date
- /*Date date = ((HibernateUserImpl)user).getRegistrationDate();
- SimpleDateFormat sdf = new SimpleDateFormat();
- assertEquals(sdf.format(date), map.get(User.INFO_USER_REGISTRATION_DATE));*/
+ //Date date = ((HibernateUserImpl)user.getRegistrationDate();
+ Date date = (Date)userProfileModule.getProperty(user,
User.INFO_USER_REGISTRATION_DATE);
+
+ // property mapped as java.util.Date \
+ try
+ {
+ userProfileModule.setProperty(user, User.INFO_USER_REGISTRATION_DATE, new
Date());
+ fail();
+ }
+ catch (IdentityException e)
+ {
+ // should fail on read-only property
+ }
+ //just to check the cast...
+ date = (Date)userProfileModule.getProperty(user,
User.INFO_USER_REGISTRATION_DATE);
+
+ // properties mapped in ldap (if ldap module present and delegated)
+ userProfileModule.setProperty(user, User.INFO_USER_OCCUPATION, "portal
developer");
+ String occup = (String)userProfileModule.getProperty(user,
User.INFO_USER_OCCUPATION);
+ assertEquals("portal developer", occup);
+
+ userProfileModule.setProperty(user, User.INFO_USER_EMAIL_REAL,
"dev(a)portal.com");
+ String email = (String)userProfileModule.getProperty(user,
User.INFO_USER_EMAIL_REAL);
+ assertEquals("dev(a)portal.com", email);
+
+ //property mapped as java.lang.Boolean
+ userProfileModule.setProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL,
Boolean.TRUE);
+
+ Boolean view = (Boolean)userProfileModule.getProperty(user,
User.INFO_USER_VIEW_EMAIL_VIEW_REAL);
+ assertEquals(Boolean.TRUE.toString(),view.toString());
+
ctx.commit();
}
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-02-14
19:16:55 UTC (rev 6279)
+++
trunk/identity/src/main/org/jboss/portal/test/identity/db/DBIdentityTestCase.java 2007-02-14
19:24:58 UTC (rev 6280)
@@ -28,6 +28,7 @@
import org.jboss.portal.identity.service.MembershipModuleService;
import org.jboss.portal.identity.service.RoleModuleService;
import org.jboss.portal.test.identity.UserTest;
+import org.jboss.portal.test.identity.IdentityTest;
import org.jboss.portal.common.p3p.P3PConstants;
import junit.framework.TestSuite;
@@ -82,10 +83,11 @@
this.userProfileModule =
(UserProfileModuleService)identityContext.getObject(IdentityContext.TYPE_USER_PROFILE_MODULE);
//
- utc = new UserTest();
+ utc = new IdentityTest();
utc.setUserModule(userModule);
utc.setRoleModule(roleModule);
utc.setMembershipModule(membershipModule);
+ utc.setUserProfileModule(userProfileModule);
utc.setContext(this);
utc.populate();
}
@@ -184,76 +186,6 @@
public void testStaticProperty() throws Exception
{
- begin();
-
- //
- User user = userModule.createUser("testname", "testpassword");
- ProfileMap map = ((HibernateUserImpl)user).getProfileMap();
- assertEquals("testname", map.get(P3PConstants.INFO_USER_NAME_NICKNAME));
-
- // Test cannot remove a static property
- try
- {
- map.remove(P3PConstants.INFO_USER_NAME_GIVEN);
- fail("Should not be capable to remove static property");
- }
- catch (IllegalArgumentException expected)
- {
- }
-
- // Test read only property
- assertTrue(map.isReadOnly(P3PConstants.INFO_USER_NAME_NICKNAME));
- try
- {
- map.put(P3PConstants.INFO_USER_NAME_NICKNAME, "anothername");
- fail("Should not be capable to modify a read only static property");
- }
- catch (IllegalArgumentException expected)
- {
- }
-
- // Test non nullable and writable property
- try
- {
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, null);
- fail("Should not be capable to nullify a non nullable static
property");
- }
- catch (NullPointerException expected)
- {
- }
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
- assertEquals("true", userProfileModule.getProperty(user,
User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
-
- // Test boolean property
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "false");
- assertEquals("false", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
- assertEquals("false", userProfileModule.getProperty(user,
User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
-
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
- assertEquals("true", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
- assertEquals("true", userProfileModule.getProperty(user,
User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
-
- userProfileModule.setProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL,
"false");
- assertEquals("false", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
- assertEquals("false", userProfileModule.getProperty(user,
User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
-
- userProfileModule.setProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL,
"true");
- assertEquals("true", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
- assertEquals("true", userProfileModule.getProperty(user,
User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
- try
- {
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "truee");
- fail("Should not be capable to set a bad value to boolean property");
- }
- catch (IllegalArgumentException expected)
- {
- }
-
- // Test date
- Date date = ((HibernateUserImpl)user).getRegistrationDate();
- SimpleDateFormat sdf = new SimpleDateFormat();
- assertEquals(sdf.format(date), map.get(User.INFO_USER_REGISTRATION_DATE));
-
- commit();
+ utc.testStaticProperty();
}
}
Modified: trunk/identity/src/main/org/jboss/portal/test/identity/db/DBTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/db/DBTestCase.java 2007-02-14
19:16:55 UTC (rev 6279)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/db/DBTestCase.java 2007-02-14
19:24:58 UTC (rev 6280)
@@ -25,6 +25,7 @@
import org.jboss.portal.test.framework.embedded.HibernateSupport;
import org.jboss.portal.test.framework.TestRuntimeContext;
import org.jboss.portal.test.identity.UserTest;
+import org.jboss.portal.test.identity.IdentityTest;
import org.jboss.portal.common.test.junit.POJOJUnitTest;
import org.jboss.portal.common.test.junit.JUnitAdapter;
import org.jboss.portal.identity.IdentityContext;
@@ -47,7 +48,7 @@
* @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
* @version $Revision: 1.1 $
*/
-public abstract class DBTestCase extends junit.framework.TestCase implements
UserTest.Context
+public abstract class DBTestCase extends junit.framework.TestCase implements
IdentityTest.Context
{
static
@@ -93,7 +94,7 @@
protected IdentityContext identityContext;
/** . */
- protected UserTest utc;
+ protected IdentityTest utc;
/**
* .
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-02-14
19:16:55 UTC (rev 6279)
+++
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPIdentityTestCase.java 2007-02-14
19:24:58 UTC (rev 6280)
@@ -163,7 +163,7 @@
utc.testFindRoleMembers();
}
- /*public void testDynamicProperty() throws Exception
+ public void testDynamicProperty() throws Exception
{
utc.testDynamicProperty();
}
@@ -171,5 +171,5 @@
public void testStaticProperty() throws Exception
{
utc.testStaticProperty();
- }*/
+ }
}
Modified: trunk/identity/src/resources/test/config/profile-config.xml
===================================================================
--- trunk/identity/src/resources/test/config/profile-config.xml 2007-02-14 19:16:55 UTC
(rev 6279)
+++ trunk/identity/src/resources/test/config/profile-config.xml 2007-02-14 19:24:58 UTC
(rev 6280)
@@ -103,8 +103,8 @@
</property>
<property>
<name>portal.user.registration-date</name>
- <type>java.lang.String</type>
- <access-mode>read-write</access-mode>
+ <type>java.util.Date</type>
+ <access-mode>read-only</access-mode>
<usage>mandatory</usage>
<display-name xml:lang="en">Registration date</display-name>
<description xml:lang="en">Registration date of
user</description>
@@ -117,7 +117,7 @@
</property>
<property>
<name>portal.user.email.view-real</name>
- <type>java.lang.String</type>
+ <type>java.lang.Boolean</type>
<access-mode>read-write</access-mode>
<usage>mandatory</usage>
<display-name xml:lang="en">View real email</display-name>
@@ -131,7 +131,7 @@
</property>
<property>
<name>portal.user.enabled</name>
- <type>java.lang.String</type>
+ <type>java.lang.Boolean</type>
<access-mode>read-write</access-mode>
<usage>mandatory</usage>
<display-name xml:lang="en">Enabled</display-name>
@@ -196,7 +196,7 @@
<access-mode>read-write</access-mode>
<usage>optional</usage>
<display-name xml:lang="en">Signature</display-name>
- <description xml:lang="en">The user signature</description>
+ <description xml:lang="en">The user signature</description>
<mapping>
<database>
<type>dynamic</type>
Modified: trunk/identity/src/resources/test/config/standardidentity-config.xml
===================================================================
--- trunk/identity/src/resources/test/config/standardidentity-config.xml 2007-02-14
19:16:55 UTC (rev 6279)
+++ trunk/identity/src/resources/test/config/standardidentity-config.xml 2007-02-14
19:24:58 UTC (rev 6280)
@@ -210,7 +210,7 @@
<option>
<name>sessionFactoryJNDIName</name>
<value>java:/portal/IdentitySessionFactory</value>
- </option> opends-config.xml
+ </option>
<option>
<name>jndiName</name>
<value>java:/portal/DBUserProfileModule</value>