From 6484f85c5bf21d4680fa2e81a611e90045e42f41 Mon Sep 17 00:00:00 2001
From: Ulrik Sandberg
Date: Wed, 25 Jul 2007 08:52:31 +0000
Subject: [PATCH] Patch from Jasper on July 25.
---
spring-ldap-odm/build.xml | 190 ++++++++---------
spring-ldap-odm/ivy.xml | 191 +++++++++---------
.../{LdapDaoTest.java => LdapDaoITest.java} | 23 ++-
.../src/itest/resources/apacheDsContext.xml | 84 ++++++++
spring-ldap-odm/src/itest/resources/beans.xml | 43 ++++
.../src/itest/resources/ldap.properties | 4 +
spring-ldap-odm/src/itest/resources/log4j.xml | 50 +++++
.../src/itest/resources/setup_data.ldif | 19 ++
.../src/itest/resources/teardown_data.ldif | 9 +
.../odm/attributetypes/LdapTypeConverter.java | 13 +-
.../springframework/ldap/odm/dao/package.html | 3 +-
.../ldap/odm/mapping/ObjectDirectoryMap.java | 4 +-
.../ldap/odm/util/package.html | 2 +-
.../attributetypes/LdapTypeConverterTest.java | 39 ++--
.../ObjectDirectoryMapperImplTest.java | 3 +-
15 files changed, 446 insertions(+), 231 deletions(-)
rename spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/dao/{LdapDaoTest.java => LdapDaoITest.java} (87%)
create mode 100644 spring-ldap-odm/src/itest/resources/apacheDsContext.xml
create mode 100644 spring-ldap-odm/src/itest/resources/beans.xml
create mode 100644 spring-ldap-odm/src/itest/resources/ldap.properties
create mode 100644 spring-ldap-odm/src/itest/resources/log4j.xml
create mode 100644 spring-ldap-odm/src/itest/resources/setup_data.ldif
create mode 100644 spring-ldap-odm/src/itest/resources/teardown_data.ldif
diff --git a/spring-ldap-odm/build.xml b/spring-ldap-odm/build.xml
index 3fcce091..41210221 100644
--- a/spring-ldap-odm/build.xml
+++ b/spring-ldap-odm/build.xml
@@ -1,95 +1,95 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-Unit test report has been generated.
-The HTML report is ${target.testresults.html.dir}/index.html
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Unit test report has been generated.
+The HTML report is ${target.testresults.html.dir}/index.html
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spring-ldap-odm/ivy.xml b/spring-ldap-odm/ivy.xml
index a580368f..af21f8b3 100644
--- a/spring-ldap-odm/ivy.xml
+++ b/spring-ldap-odm/ivy.xml
@@ -1,97 +1,96 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/dao/LdapDaoTest.java b/spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/dao/LdapDaoITest.java
similarity index 87%
rename from spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/dao/LdapDaoTest.java
rename to spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/dao/LdapDaoITest.java
index 68ed9ada..77438bbe 100644
--- a/spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/dao/LdapDaoTest.java
+++ b/spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/dao/LdapDaoITest.java
@@ -5,6 +5,7 @@
*/
package org.springframework.ldap.odm.dao;
+import junit.framework.Assert;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -14,14 +15,13 @@ import org.springframework.ldap.NameNotFoundException;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.odm.entity.ITestPerson;
import org.springframework.ldap.odm.entity.ITestRole;
-import org.testng.Assert;
import java.util.List;
-public class LdapDaoTest extends AbstractLdapTemplateIntegrationTest
+public class LdapDaoITest extends AbstractLdapTemplateIntegrationTest
{
- protected static final Log LOGGER = LogFactory.getLog(LdapDaoTest.class);
+ protected static final Log LOGGER = LogFactory.getLog(LdapDaoITest.class);
protected LdapDao ldapDao;
private ITestPerson testPerson;
@@ -87,7 +87,7 @@ public class LdapDaoTest extends AbstractLdapTemplateIntegrationTest
ldapDao.create(testPerson);
ITestPerson retrieved = (ITestPerson) ldapDao.findByNamingAttribute(testPerson.getIdentifier(), ITestPerson.class);
LOGGER.debug(retrieved);
- Assert.assertNotNull(retrieved, "Should've found the created entity.");
+ Assert.assertNotNull("Should've found the created entity.", retrieved);
}
@@ -109,7 +109,7 @@ public class LdapDaoTest extends AbstractLdapTemplateIntegrationTest
DistinguishedName dn = new DistinguishedName("uid=" + testPerson.getIdentifier() + ",ou=people");
ITestPerson retrieved = (ITestPerson) ldapDao.findByDn(dn, ITestPerson.class);
LOGGER.debug(retrieved);
- Assert.assertNotNull(retrieved, "Should've found the created entity.");
+ Assert.assertNotNull("Should've found the created entity.", retrieved);
}
@@ -123,9 +123,9 @@ public class LdapDaoTest extends AbstractLdapTemplateIntegrationTest
}
catch (Exception expected)
{
- Assert.assertTrue(expected instanceof NameAlreadyBoundException,
- "Exception type doesn't match expected. ( got: "
- + expected.getMessage());
+ Assert.assertTrue("Exception type doesn't match expected. ( got: "
+ + expected.getMessage(),
+ expected instanceof NameAlreadyBoundException);
}
}
@@ -141,7 +141,8 @@ public class LdapDaoTest extends AbstractLdapTemplateIntegrationTest
ldapDao.create(testPerson);
List results = ldapDao.filterByBeanProperty(testPerson.getEmailAddress(), "EmailAddress", ITestPerson.class);
LOGGER.debug("filterByBeanProperty returned: " + results.size() + " results.");
- Assert.assertTrue(results.size() > 0, "Filter should return collection containing more than one result. ");
+ Assert.assertTrue("Filter should return collection containing more than one result. ",
+ results.size() > 0);
}
public void testUpdateEntity()
@@ -154,7 +155,7 @@ public class LdapDaoTest extends AbstractLdapTemplateIntegrationTest
ldapDao.update(testPerson);
ITestPerson retrieved = (ITestPerson) ldapDao.findByNamingAttribute(testPerson.getIdentifier(),
ITestPerson.class);
- Assert.assertEquals(retrieved.getEmailAddress(), newEmail, "Email name not updated.");
+ Assert.assertEquals("Email name not updated.", retrieved.getEmailAddress(), newEmail);
}
catch (Exception unexpected)
{
@@ -183,7 +184,7 @@ public class LdapDaoTest extends AbstractLdapTemplateIntegrationTest
LOGGER.debug(testPerson);
ldapDao.delete(testPerson);
ITestPerson retrieved = (ITestPerson) ldapDao.findByNamingAttribute(testPerson.getIdentifier(), ITestPerson.class);
- Assert.assertNull(retrieved, "Entity should've been deleted.");
+ Assert.assertNull("Entity should've been deleted.", retrieved);
}
diff --git a/spring-ldap-odm/src/itest/resources/apacheDsContext.xml b/spring-ldap-odm/src/itest/resources/apacheDsContext.xml
new file mode 100644
index 00000000..80910e7e
--- /dev/null
+++ b/spring-ldap-odm/src/itest/resources/apacheDsContext.xml
@@ -0,0 +1,84 @@
+
+
+
+
+
+
+
+
+
+ simple
+
+
+ ${userDn}
+
+
+ ${password}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ objectClass: top
+ objectClass: domain
+ objectClass: extensibleObject
+ dc: example
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-ldap-odm/src/itest/resources/beans.xml b/spring-ldap-odm/src/itest/resources/beans.xml
new file mode 100644
index 00000000..2440c627
--- /dev/null
+++ b/spring-ldap-odm/src/itest/resources/beans.xml
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-ldap-odm/src/itest/resources/ldap.properties b/spring-ldap-odm/src/itest/resources/ldap.properties
new file mode 100644
index 00000000..a0bbef1a
--- /dev/null
+++ b/spring-ldap-odm/src/itest/resources/ldap.properties
@@ -0,0 +1,4 @@
+urls=ldap://127.0.0.1:3900
+userDn=uid=admin,ou=system
+password=secret
+base=dc=example,dc=com
diff --git a/spring-ldap-odm/src/itest/resources/log4j.xml b/spring-ldap-odm/src/itest/resources/log4j.xml
new file mode 100644
index 00000000..23d78f02
--- /dev/null
+++ b/spring-ldap-odm/src/itest/resources/log4j.xml
@@ -0,0 +1,50 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-ldap-odm/src/itest/resources/setup_data.ldif b/spring-ldap-odm/src/itest/resources/setup_data.ldif
new file mode 100644
index 00000000..560cffb9
--- /dev/null
+++ b/spring-ldap-odm/src/itest/resources/setup_data.ldif
@@ -0,0 +1,19 @@
+dn: ou=people,dc=example,dc=com
+objectclass: top
+objectclass: organizationalUnit
+ou: people
+
+dn: ou=roles,dc=example,dc=com
+objectclass: top
+objectclass: organizationalUnit
+ou: roles
+
+dn: cn=webUser,ou=roles,dc=example,dc=com
+objectclass: top
+objectclass: organizationalRole
+cn: webUser
+description: Everyday site visitor
+
+
+
+
diff --git a/spring-ldap-odm/src/itest/resources/teardown_data.ldif b/spring-ldap-odm/src/itest/resources/teardown_data.ldif
new file mode 100644
index 00000000..16f41052
--- /dev/null
+++ b/spring-ldap-odm/src/itest/resources/teardown_data.ldif
@@ -0,0 +1,9 @@
+dn: ou=people,dc=example,dc=com
+objectclass: top
+objectclass: organizationalUnit
+ou: people
+
+dn: ou=roles,dc=example,dc=com
+objectclass: top
+objectclass: organizationalUnit
+ou: roles
\ No newline at end of file
diff --git a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/attributetypes/LdapTypeConverter.java b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/attributetypes/LdapTypeConverter.java
index 55dacb41..a35737d4 100644
--- a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/attributetypes/LdapTypeConverter.java
+++ b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/attributetypes/LdapTypeConverter.java
@@ -16,9 +16,9 @@ import java.text.SimpleDateFormat;
import java.util.Date;
/**
- *
+ *
* LdapTypeConverter is responsible for the conversion of LDAP attributes returned in String form
- * to native java types and vice versa. It it leverages Spring's property editors, with
+ * to native java types and vice versa. It it leverages Spring's property editors, with
* some custom editors to:
*
* convert generalized time strings to java.util.Date.
@@ -26,17 +26,18 @@ import java.util.Date;
* org.springframework.ldap.core.DistinguishedName.
*
*
- *
+ *
* Additional custom editors may be created at runtime to if an Object Directory Map
* contains references to other mapped objects (eg. A role of type Role.class containing
* references to members of type Person.class)
- *
+ *
*
- *
*/
public class LdapTypeConverter extends SimpleTypeConverter
{
- private static final DateFormat GENERALIZED_TIME = new SimpleDateFormat("yyyyMMddHHmmss.S");
+
+ private static final DateFormat GENERALIZED_TIME
+ = new SimpleDateFormat("yyyyMMddHHmmss.SSSZ");
public LdapTypeConverter()
{
diff --git a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/dao/package.html b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/dao/package.html
index 47855aae..ee513d29 100644
--- a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/dao/package.html
+++ b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/dao/package.html
@@ -1,7 +1,8 @@
-Provides a realization of the Data Access Object (DAO) pattern using object directory mapping.
+Provides a realization of the Data Access Object (DAO) pattern using LDAP
+object directory mapping.
diff --git a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/mapping/ObjectDirectoryMap.java b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/mapping/ObjectDirectoryMap.java
index ef858c62..4607a118 100644
--- a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/mapping/ObjectDirectoryMap.java
+++ b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/mapping/ObjectDirectoryMap.java
@@ -30,7 +30,9 @@ public interface ObjectDirectoryMap
/** The set of bean property names in the Object Directory Map. */
Set beanPropertyNames();
- /** The Class that the Object Directory Map corresponds to. */
+ /** The Class that the Object Directory Map represents. That is,
+ * LDAP entries will be serialized to and from this class.
+ */
Class getClazz();
/** The name of the attribute corresponding to the first element in a distinguished
diff --git a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/util/package.html b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/util/package.html
index 2d452367..f2fc2b22 100644
--- a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/util/package.html
+++ b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/util/package.html
@@ -1,7 +1,7 @@
-Contains utility classes.
+Utility classes.
\ No newline at end of file
diff --git a/spring-ldap-odm/src/test/java/org/springframework/ldap/odm/attributetypes/LdapTypeConverterTest.java b/spring-ldap-odm/src/test/java/org/springframework/ldap/odm/attributetypes/LdapTypeConverterTest.java
index 0979e4a0..3600116b 100644
--- a/spring-ldap-odm/src/test/java/org/springframework/ldap/odm/attributetypes/LdapTypeConverterTest.java
+++ b/spring-ldap-odm/src/test/java/org/springframework/ldap/odm/attributetypes/LdapTypeConverterTest.java
@@ -19,8 +19,8 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
+import java.util.Calendar;
-//TODO: There's probably a lot of redundant tests in here
public class LdapTypeConverterTest extends TestCase
{
private static final Log LOGGER = LogFactory.getLog(LdapTypeConverterTest.class);
@@ -120,17 +120,15 @@ public class LdapTypeConverterTest extends TestCase
}
}
- public void testConvertToGeneralizedTime() throws ParseException
+ public void testConvertToDate() throws ParseException
{
- String object1 = "20061005093637.44";
- DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss.S");
- Date expected = df.parse("20061005093637.44");
+ String object1 = "19700101100000.000+1000";
try
{
Object translated = typeConverter.convertIfNecessary(object1,
Date.class);
- Assert.assertEquals(translated, expected,
+ Assert.assertEquals(translated, new Date(0L),
"Unexpected translated value");
}
catch (TypeMismatchException e)
@@ -141,41 +139,44 @@ public class LdapTypeConverterTest extends TestCase
public void testConvertFromDate()
{
- Date source = new Date(1184283822285L); //Friday July 13, 2007 9:43:42 AM
- Assert.assertEquals(typeConverter.getAsText(source), "20070713094342.285");
+ Date source = new Date(1184283822285L); //Friday July 13, 2007 9:43:42 AM GMT+1000
+ LOGGER.debug(typeConverter.getAsText(source));
+
+ Assert.assertTrue(typeConverter.getAsText(source)
+ .matches("20070713\\d\\d\\d\\d42.285\\+\\d\\d\\d\\d"));
}
- public void testConvertToGeneralizedTimeArray() throws ParseException
+ public void testConvertToDateArray() throws ParseException
{
- String object1 = "20071105093655.44";
- String object2 = "20061005093637.44";
+ String object1 = "20071105093655.0+1000";
+ String object2 = "19700101100000.0+1000";
Object objectToTranslate = new String[]{object1, object2};
- DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss.S");
- Date expected = df.parse("20061005093637.44");
-
try
{
Object[] translated = (Object[]) typeConverter.convertIfNecessary(
objectToTranslate, Date[].class);
- Assert.assertEquals(translated[1], expected,
+ Assert.assertEquals(translated[1], new Date(0L),
"Unexpected translated value");
}
catch (TypeMismatchException e)
{
+ e.printStackTrace();
Assert.fail("Unexpected exception during translation");
+
}
}
+
public void testConvertFromDateArray()
{
- Date date1 = new Date(1184283822285L); //Friday July 13, 2007 9:43:42 AM
- Date date2 = new Date(0); //epoch
+ Date date1 = new Date(1184283822285L); //Friday July 13, 2007 9:43:42 AM + GMT+1000
+ Date date2 = new Date(0); //epoch + GMT + 1000
Date[] dates = new Date[]{date1, date2};
String[] converted = typeConverter.getAllAsText(dates);
- Assert.assertEquals(converted[0], "20070713094342.285");
- Assert.assertEquals(converted[1], "19700101100000.0");
+ Assert.assertTrue(converted[0].matches("20070713\\d\\d\\d\\d42.285\\+\\d\\d\\d\\d"));
+ Assert.assertTrue(converted[1].matches("19700101\\d\\d\\d\\d00.000\\+\\d\\d\\d\\d"));
}
public void testConvertToLdapName()
diff --git a/spring-ldap-odm/src/test/java/org/springframework/ldap/odm/mapping/ObjectDirectoryMapperImplTest.java b/spring-ldap-odm/src/test/java/org/springframework/ldap/odm/mapping/ObjectDirectoryMapperImplTest.java
index 9a29cafd..9cf54399 100644
--- a/spring-ldap-odm/src/test/java/org/springframework/ldap/odm/mapping/ObjectDirectoryMapperImplTest.java
+++ b/spring-ldap-odm/src/test/java/org/springframework/ldap/odm/mapping/ObjectDirectoryMapperImplTest.java
@@ -150,7 +150,8 @@ public class ObjectDirectoryMapperImplTest extends TestCase
Assert.assertEquals("bean@bean.com", ctxAdapter.getStringAttribute("mail"));
Assert.assertEquals("fred", new String((byte[]) ctxAdapter.getObjectAttribute("userpassword")));
Assert.assertEquals("false", ctxAdapter.getStringAttribute("acceptemails"));
- Assert.assertEquals("19700101100000.1", ctxAdapter.getStringAttribute("loginresettime"));
+ Assert.assertTrue(ctxAdapter.getStringAttribute("loginresettime")
+ .matches("19700101\\d\\d\\d\\d00.001\\+\\d\\d\\d\\d"));
Assert.assertEquals("3", ctxAdapter.getStringAttribute("failedlogins"));
Assert.assertEquals("uid=amAdmin, ou=people, dc=myretsu, dc=com",
ctxAdapter.getStringAttribute("creatorname"));