diff --git a/spring-ldap-odm/build.xml b/spring-ldap-odm/build.xml
index 43a43857..280ce466 100644
--- a/spring-ldap-odm/build.xml
+++ b/spring-ldap-odm/build.xml
@@ -19,7 +19,7 @@
-
+
@@ -29,10 +29,9 @@
-
+
-
-
@@ -43,7 +42,7 @@
we want to optionally run all tests and report on the whole
batch, then we need to set a failure property as in the server
tests. -->
-
+
@@ -65,7 +64,7 @@
-
+
diff --git a/spring-ldap-odm/src/itest/java/conf/apacheDsContext.xml b/spring-ldap-odm/src/itest/java/conf/apacheDsContext.xml
deleted file mode 100644
index 80910e7e..00000000
--- a/spring-ldap-odm/src/itest/java/conf/apacheDsContext.xml
+++ /dev/null
@@ -1,84 +0,0 @@
-
-
-
-
-
-
-
-
-
- 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/java/conf/beans.xml b/spring-ldap-odm/src/itest/java/conf/beans.xml
index f74961c4..8f84cd19 100644
--- a/spring-ldap-odm/src/itest/java/conf/beans.xml
+++ b/spring-ldap-odm/src/itest/java/conf/beans.xml
@@ -2,20 +2,12 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/spring-ldap-odm/src/itest/java/conf/ldap.properties b/spring-ldap-odm/src/itest/java/conf/ldap.properties
deleted file mode 100644
index a0bbef1a..00000000
--- a/spring-ldap-odm/src/itest/java/conf/ldap.properties
+++ /dev/null
@@ -1,4 +0,0 @@
-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/java/conf/log4j.xml b/spring-ldap-odm/src/itest/java/conf/log4j.xml
deleted file mode 100644
index 23d78f02..00000000
--- a/spring-ldap-odm/src/itest/java/conf/log4j.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/spring-ldap-odm/src/itest/java/conf/setup_data.ldif b/spring-ldap-odm/src/itest/java/conf/setup_data.ldif
deleted file mode 100644
index 560cffb9..00000000
--- a/spring-ldap-odm/src/itest/java/conf/setup_data.ldif
+++ /dev/null
@@ -1,19 +0,0 @@
-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/java/conf/teardown_data.ldif b/spring-ldap-odm/src/itest/java/conf/teardown_data.ldif
deleted file mode 100644
index 16f41052..00000000
--- a/spring-ldap-odm/src/itest/java/conf/teardown_data.ldif
+++ /dev/null
@@ -1,9 +0,0 @@
-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/itest/java/org/springframework/ldap/AbstractLdapTemplateIntegrationTest.java b/spring-ldap-odm/src/itest/java/org/springframework/ldap/AbstractLdapTemplateIntegrationTest.java
deleted file mode 100644
index 96b309b8..00000000
--- a/spring-ldap-odm/src/itest/java/org/springframework/ldap/AbstractLdapTemplateIntegrationTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2005-2007 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.ldap;
-
-import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
-
-public abstract class AbstractLdapTemplateIntegrationTest extends
- AbstractDependencyInjectionSpringContextTests {
-
- private LdapServerManager ldapServerManager;
-
- protected void onSetUp() throws Exception {
- super.onSetUp();
-
- ldapServerManager.cleanAndSetup("setup_data.ldif");
- }
-
- public void setLdapServerManager(LdapServerManager ldapServerManager) {
- this.ldapServerManager = ldapServerManager;
- }
-}
diff --git a/spring-ldap-odm/src/itest/java/org/springframework/ldap/ConfigEnvHelper.java b/spring-ldap-odm/src/itest/java/org/springframework/ldap/ConfigEnvHelper.java
deleted file mode 100644
index 9fd2034b..00000000
--- a/spring-ldap-odm/src/itest/java/org/springframework/ldap/ConfigEnvHelper.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright 2005-2007 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.ldap;
-
-import java.io.File;
-import java.util.Hashtable;
-
-import javax.naming.Context;
-
-import org.apache.directory.server.configuration.MutableServerStartupConfiguration;
-import org.apache.directory.server.jndi.ServerContextFactory;
-import org.springframework.beans.factory.InitializingBean;
-
-/**
- * Helper class to simplify Spring configuration of ApacheDS.
- *
- * @author Mattias Arthursson
- */
-public class ConfigEnvHelper implements InitializingBean {
- private final MutableServerStartupConfiguration configuration;
-
- private final Hashtable initialEnv;
-
- private final File workingDir = new File(System
- .getProperty("java.io.tmpdir")
- + File.separator + "ldaptemplate_apacheds");
-
- public ConfigEnvHelper(Hashtable initialEnv,
- MutableServerStartupConfiguration configuration) {
-
- this.initialEnv = initialEnv;
- this.configuration = configuration;
- }
-
- public Hashtable getEnv() {
- return initialEnv;
- }
-
- public void afterPropertiesSet() throws Exception {
- initialEnv.put(Context.INITIAL_CONTEXT_FACTORY, ServerContextFactory.class.getName());
- configuration.setWorkingDirectory(workingDir);
- initialEnv.putAll(configuration.toJndiEnvironment());
- }
-}
diff --git a/spring-ldap-odm/src/itest/java/org/springframework/ldap/LdapServerManager.java b/spring-ldap-odm/src/itest/java/org/springframework/ldap/LdapServerManager.java
deleted file mode 100644
index df62b00a..00000000
--- a/spring-ldap-odm/src/itest/java/org/springframework/ldap/LdapServerManager.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright 2005-2007 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.ldap;
-
-import java.util.Properties;
-
-import javax.naming.Binding;
-import javax.naming.Context;
-import javax.naming.ContextNotEmptyException;
-import javax.naming.InitialContext;
-import javax.naming.Name;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.directory.DirContext;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.directory.server.core.configuration.ShutdownConfiguration;
-import org.apache.directory.server.jndi.ServerContextFactory;
-import org.apache.directory.server.protocol.shared.store.LdifFileLoader;
-import org.springframework.beans.factory.DisposableBean;
-import org.springframework.ldap.core.ContextSource;
-import org.springframework.ldap.core.DistinguishedName;
-import org.springframework.ldap.core.support.DefaultDirObjectFactory;
-
-/**
- * Utility class to initialize the apache directory server for use in the
- * integration tests.
- *
- * @author Mattias Arthursson
- *
- */
-public class LdapServerManager implements DisposableBean {
- private static Log log = LogFactory.getLog(LdapServerManager.class);
-
- private ContextSource contextSource;
-
- public void setContextSource(ContextSource contextSource) {
- this.contextSource = contextSource;
- }
-
- public void destroy() throws Exception {
- Properties env = new Properties();
- env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
- ServerContextFactory.class.getName());
- env.setProperty(Context.SECURITY_AUTHENTICATION, "simple");
- env.setProperty(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");
- env.setProperty(Context.SECURITY_CREDENTIALS, "secret");
-
- ShutdownConfiguration configuration = new ShutdownConfiguration();
- env.putAll(configuration.toJndiEnvironment());
-
- new InitialContext(env);
- }
-
- public void cleanAndSetup(String ldifFile) throws Exception {
- DirContext ctx = contextSource.getReadWriteContext();
-
- // First of all, make sure the database is empty.
- Name startingPoint = null;
-
- // Different test cases have different base paths. This means that the
- // starting point will be different.
- if (ctx.getEnvironment().get(
- DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY) != null) {
- startingPoint = DistinguishedName.EMPTY_PATH;
- } else {
- startingPoint = new DistinguishedName("dc=jayway,dc=se");
- }
-
- try {
- log.info("Cleaning all present data.");
- clearSubContexts(ctx, startingPoint);
- // Load the ldif to the recently started server
- log.info("Loading setup data");
- LdifFileLoader loader = new LdifFileLoader(ctx, ldifFile);
- loader.execute();
- } finally {
- ctx.close();
- }
- }
-
- private void clearSubContexts(DirContext ctx, Name name)
- throws NamingException {
-
- NamingEnumeration enumeration = null;
- try {
- enumeration = ctx.listBindings(name);
- while (enumeration.hasMore()) {
- Binding element = (Binding) enumeration.next();
- DistinguishedName childName = new DistinguishedName(element
- .getName());
- childName.prepend((DistinguishedName) name);
-
- try {
- ctx.destroySubcontext(childName);
- } catch (ContextNotEmptyException e) {
- clearSubContexts(ctx, childName);
- ctx.destroySubcontext(childName);
- }
- }
- } catch (NamingException e) {
- e.printStackTrace();
- } finally {
- try {
- enumeration.close();
- } catch (Exception e) {
- // Never mind this
- }
- }
- }
-}
diff --git a/spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/contextmapping/AnnotatedClassContextMapperTest.java b/spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/contextmapping/AnnotatedClassContextMapperTest.java
index 678bbfd8..16932b56 100644
--- a/spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/contextmapping/AnnotatedClassContextMapperTest.java
+++ b/spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/contextmapping/AnnotatedClassContextMapperTest.java
@@ -5,8 +5,15 @@
*/
package org.springframework.ldap.odm.contextmapping;
+import java.util.Date;
+import java.util.Map;
+
+import javax.naming.Name;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.springframework.ldap.core.DirContextAdapter;
+import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.odm.annotations.DirAttribute;
import org.springframework.ldap.odm.annotations.NamingAttribute;
import org.springframework.ldap.odm.annotations.NamingSuffix;
@@ -15,380 +22,328 @@ import org.springframework.ldap.odm.attributetypes.LdapTypeConverter;
import org.springframework.ldap.odm.attributetypes.ReferencedEntryEditorFactory;
import org.springframework.ldap.odm.contextmapping.exception.ContextMapperException;
import org.springframework.ldap.odm.entity.MockEntity;
-import org.springframework.ldap.core.DirContextAdapter;
-import org.springframework.ldap.core.DistinguishedName;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
import org.testng.Assert;
import org.testng.annotations.Test;
-import javax.naming.Name;
-import java.util.Date;
-import java.util.Map;
-
public class AnnotatedClassContextMapperTest extends
- AbstractDependencyInjectionSpringContextTests
-{
- private static final Log LOGGER = LogFactory
- .getLog(AnnotatedClassContextMapperTest.class);
+ AbstractDependencyInjectionSpringContextTests {
+ private static final Log LOGGER = LogFactory
+ .getLog(AnnotatedClassContextMapperTest.class);
- private LdapTypeConverter typeConverter;
+ private LdapTypeConverter typeConverter;
- private ReferencedEntryEditorFactory refEditorFactory;
+ private ReferencedEntryEditorFactory refEditorFactory;
- public void setRefEditorFactory(
- ReferencedEntryEditorFactory refEditorFactory)
- {
- this.refEditorFactory = refEditorFactory;
- }
+ public void setRefEditorFactory(
+ ReferencedEntryEditorFactory refEditorFactory) {
+ this.refEditorFactory = refEditorFactory;
+ }
- public void setTypeConverter(LdapTypeConverter typeConverter)
- {
- this.typeConverter = typeConverter;
- }
+ public void setTypeConverter(LdapTypeConverter typeConverter) {
+ this.typeConverter = typeConverter;
+ }
- @Override
- protected String[] getConfigLocations()
- {
- return new String[]{"conf/beans.xml"};
- }
+ @Override
+ protected String[] getConfigLocations() {
+ return new String[] { "conf/beans.xml" };
+ }
- public void testMapsDirectoryAttributesToBeanProperties()
- {
- try
- {
- AnnotatedClassContextMapper contextMapper = new AnnotatedClassContextMapper(
- MockEntity.class, typeConverter, refEditorFactory);
- ContextMap contextMap = contextMapper.getContextMap();
- Assert.assertEquals("cn", contextMap.attributeNameFor("Name"),
- "Name mapping not as expected");
- Assert.assertEquals("mail", contextMap.attributeNameFor("Mail"),
- "Mail mapping not as expected");
- Assert.assertEquals("addr", contextMap.attributeNameFor("Address"),
- "Address mapping not as expected");
- Assert.assertEquals("userpassword", contextMap
- .attributeNameFor("Password"),
- "Password mapping not as expected");
- Assert.assertEquals("desc", contextMap
- .attributeNameFor("Description"),
- "Description mapping not as expected");
- }
- catch (ContextMapperException e)
- {
- LOGGER.debug(e.getMessage());
- Assert.fail(e.getMessage(), e);
- }
- }
+ public void testMapsDirectoryAttributesToBeanProperties() {
+ try {
+ AnnotatedClassContextMapper contextMapper = new AnnotatedClassContextMapper(
+ MockEntity.class, typeConverter, refEditorFactory);
+ ContextMap contextMap = contextMapper.getContextMap();
+ Assert.assertEquals("cn", contextMap.attributeNameFor("Name"),
+ "Name mapping not as expected");
+ Assert.assertEquals("mail", contextMap.attributeNameFor("Mail"),
+ "Mail mapping not as expected");
+ Assert.assertEquals("addr", contextMap.attributeNameFor("Address"),
+ "Address mapping not as expected");
+ Assert.assertEquals("userpassword", contextMap
+ .attributeNameFor("Password"),
+ "Password mapping not as expected");
+ Assert.assertEquals("desc", contextMap
+ .attributeNameFor("Description"),
+ "Description mapping not as expected");
+ } catch (ContextMapperException e) {
+ LOGGER.debug(e.getMessage());
+ Assert.fail(e.getMessage(), e);
+ }
+ }
- public void testReturnsCorrectNamingAttribute()
- {
- try
- {
- AnnotatedClassContextMapper contextMapper = new AnnotatedClassContextMapper(
- MockEntity.class, typeConverter, refEditorFactory);
- Assert.assertEquals("cn", contextMapper.getNamingAttribute(),
- "Context mapper naming attribute not as expected");
+ public void testReturnsCorrectNamingAttribute() {
+ try {
+ AnnotatedClassContextMapper contextMapper = new AnnotatedClassContextMapper(
+ MockEntity.class, typeConverter, refEditorFactory);
+ Assert.assertEquals("cn", contextMapper.getNamingAttribute(),
+ "Context mapper naming attribute not as expected");
- }
- catch (ContextMapperException e)
- {
- LOGGER.debug(e.getMessage());
- Assert.fail(e.getMessage(), e);
- }
- }
+ } catch (ContextMapperException e) {
+ LOGGER.debug(e.getMessage());
+ Assert.fail(e.getMessage(), e);
+ }
+ }
- public void testReturnsCorrectObjectClasses()
- {
- try
- {
- AnnotatedClassContextMapper contextMapper = new AnnotatedClassContextMapper(
- MockEntity.class, typeConverter, refEditorFactory);
- Assert.assertEquals(new String[]{"top", "person",
- "organizationalPerson", "inetorgperson"}, contextMapper
- .getObjectClasses(),
- "Context mapper naming attribute not as expected");
+ public void testReturnsCorrectObjectClasses() {
+ try {
+ AnnotatedClassContextMapper contextMapper = new AnnotatedClassContextMapper(
+ MockEntity.class, typeConverter, refEditorFactory);
+ Assert.assertEquals(new String[] { "top", "person",
+ "organizationalPerson", "inetorgperson" }, contextMapper
+ .getObjectClasses(),
+ "Context mapper naming attribute not as expected");
- }
- catch (ContextMapperException e)
- {
- LOGGER.debug(e.getMessage());
- Assert.fail(e.getMessage());
- }
- }
+ } catch (ContextMapperException e) {
+ LOGGER.debug(e.getMessage());
+ Assert.fail(e.getMessage());
+ }
+ }
- public void testBuildDn()
- {
- try
- {
- AnnotatedClassContextMapper contextMapper = new AnnotatedClassContextMapper(
- MockEntity.class, typeConverter, refEditorFactory);
- MockEntity entity = new MockEntity();
- entity.setName("Mr Bean");
- entity.setAddress("Somewhere in england");
- entity.setDescription(new String[]{"The quick brown fox jumped",
- "over the lazy dog"});
- Name dn = contextMapper.buildDn(entity);
- Assert.assertEquals("cn=Mr Bean, ou=people, dc=example, dc=com", dn
- .toString(), "dn not as expected");
+ public void testBuildDn() {
+ try {
+ AnnotatedClassContextMapper contextMapper = new AnnotatedClassContextMapper(
+ MockEntity.class, typeConverter, refEditorFactory);
+ MockEntity entity = new MockEntity();
+ entity.setName("Mr Bean");
+ entity.setAddress("Somewhere in england");
+ entity.setDescription(new String[] { "The quick brown fox jumped",
+ "over the lazy dog" });
+ Name dn = contextMapper.buildDn(entity);
+ Assert.assertEquals("cn=Mr Bean, ou=people, dc=example, dc=com", dn
+ .toString(), "dn not as expected");
- }
- catch (ContextMapperException e)
- {
- LOGGER.debug(e.getMessage());
- Assert.fail(e.getMessage());
- }
- }
+ } catch (ContextMapperException e) {
+ LOGGER.debug(e.getMessage());
+ Assert.fail(e.getMessage());
+ }
+ }
- public void testMapToContext()
- {
- try
- {
- AnnotatedClassContextMapper contextMapper = new AnnotatedClassContextMapper(
- MockEntity.class, typeConverter, refEditorFactory);
- MockEntity entity = new MockEntity();
- entity.setName("Mr Bean");
- entity.setMail("bean@bean.com");
- entity.setAddress("Somewhere in england");
- entity.setPassword("fred".getBytes());
- entity.setDescription(new String[]{"The quick brown fox jumped",
- "over the lazy dog"});
- entity.setAcceptEmails(false);
- entity.setResetLogin(new Date(1L));
- entity.setCreator(new DistinguishedName(
- "uid=amAdmin,ou=people,dc=myretsu,dc=com"));
- entity.setFailedLogins(3);
- DirContextAdapter ctxAdapter = new DirContextAdapter();
- contextMapper.mapToContext(entity, ctxAdapter);
+ public void testMapToContext() {
+ try {
+ AnnotatedClassContextMapper contextMapper = new AnnotatedClassContextMapper(
+ MockEntity.class, typeConverter, refEditorFactory);
+ MockEntity entity = new MockEntity();
+ entity.setName("Mr Bean");
+ entity.setMail("bean@bean.com");
+ entity.setAddress("Somewhere in england");
+ entity.setPassword("fred".getBytes());
+ entity.setDescription(new String[] { "The quick brown fox jumped",
+ "over the lazy dog" });
+ entity.setAcceptEmails(false);
+ entity.setResetLogin(new Date(1L));
+ entity.setCreator(new DistinguishedName(
+ "uid=amAdmin,ou=people,dc=myretsu,dc=com"));
+ entity.setFailedLogins(3);
+ DirContextAdapter ctxAdapter = new DirContextAdapter();
+ contextMapper.mapToContext(entity, ctxAdapter);
- Assert.assertEquals("Mr Bean", ctxAdapter.getStringAttribute("cn"),
- "Name mapping not as expected");
- Assert
- .assertEquals("bean@bean.com", ctxAdapter
- .getStringAttribute("mail"),
- "Mail mapping not as expected");
- Assert.assertEquals("Somewhere in england", ctxAdapter
- .getObjectAttribute("addr"),
- "Address mapping not as expected");
- Assert.assertEquals("fred", new String((byte[]) ctxAdapter
- .getObjectAttribute("userpassword")),
- "Password mapping not as expected");
- Assert.assertEquals("The quick brown fox jumped", ctxAdapter
- .getStringAttributes("desc")[0],
- "Description mapping not as expected");
- Assert.assertEquals("false", ctxAdapter
- .getStringAttribute("acceptemails"),
- "AcceptEmails mapping not as expected");
- Assert.assertEquals("19700101100000.1", ctxAdapter
- .getStringAttribute("loginresettime"),
- "ResetLogin mapping not as expected");
- Assert.assertEquals("3", ctxAdapter
- .getStringAttribute("failedlogins"),
- "FailedLogins mapping not as expected");
- Assert.assertEquals("uid=amAdmin, ou=people, dc=myretsu, dc=com",
- ctxAdapter.getStringAttribute("creatorname"),
- "Creator mapping not as expected");
- }
- catch (ContextMapperException e)
- {
- LOGGER.debug(e.getMessage());
- Assert.fail(e.getMessage(), e);
- }
- }
+ Assert.assertEquals("Mr Bean", ctxAdapter.getStringAttribute("cn"),
+ "Name mapping not as expected");
+ Assert
+ .assertEquals("bean@bean.com", ctxAdapter
+ .getStringAttribute("mail"),
+ "Mail mapping not as expected");
+ Assert.assertEquals("Somewhere in england", ctxAdapter
+ .getObjectAttribute("addr"),
+ "Address mapping not as expected");
+ Assert.assertEquals("fred", new String((byte[]) ctxAdapter
+ .getObjectAttribute("userpassword")),
+ "Password mapping not as expected");
+ Assert.assertEquals("The quick brown fox jumped", ctxAdapter
+ .getStringAttributes("desc")[0],
+ "Description mapping not as expected");
+ Assert.assertEquals("false", ctxAdapter
+ .getStringAttribute("acceptemails"),
+ "AcceptEmails mapping not as expected");
+ Assert.assertEquals("19700101100000.1", ctxAdapter
+ .getStringAttribute("loginresettime"),
+ "ResetLogin mapping not as expected");
+ Assert.assertEquals("3", ctxAdapter
+ .getStringAttribute("failedlogins"),
+ "FailedLogins mapping not as expected");
+ Assert.assertEquals("uid=amAdmin, ou=people, dc=myretsu, dc=com",
+ ctxAdapter.getStringAttribute("creatorname"),
+ "Creator mapping not as expected");
+ } catch (ContextMapperException e) {
+ LOGGER.debug(e.getMessage());
+ Assert.fail(e.getMessage(), e);
+ }
+ }
- public void testMapFromContext() throws ContextMapperException
- {
- AnnotatedClassContextMapper contextMapper = new AnnotatedClassContextMapper(
- MockEntity.class, typeConverter, refEditorFactory);
- DirContextAdapter ctxAdapter = new DirContextAdapter();
- ctxAdapter.setAttributeValue("cn", "Mr Bean");
- ctxAdapter.setAttributeValue("mail", "bean@bean.com");
- ctxAdapter.setAttributeValue("addr", "Somewhere in england");
- ctxAdapter.setAttributeValue("userpassword", "fred".getBytes());
- ctxAdapter
- .setAttributeValues("desc", new String[]{"elem1", "elem2"});
- ctxAdapter.setAttributeValue("userpassword", "fred".getBytes());
- ctxAdapter.setAttributeValue("acceptemails", "true");
- ctxAdapter.setAttributeValue("loginresettime", "19700101100000.1");
- ctxAdapter.setAttributeValue("failedlogins", "3");
- ctxAdapter.setAttributeValue("creatorname",
- "uid=amAdmin,ou=people,dc=myretsu,dc=com");
+ public void testMapFromContext() throws ContextMapperException {
+ AnnotatedClassContextMapper contextMapper = new AnnotatedClassContextMapper(
+ MockEntity.class, typeConverter, refEditorFactory);
+ DirContextAdapter ctxAdapter = new DirContextAdapter();
+ ctxAdapter.setAttributeValue("cn", "Mr Bean");
+ ctxAdapter.setAttributeValue("mail", "bean@bean.com");
+ ctxAdapter.setAttributeValue("addr", "Somewhere in england");
+ ctxAdapter.setAttributeValue("userpassword", "fred".getBytes());
+ ctxAdapter
+ .setAttributeValues("desc", new String[] { "elem1", "elem2" });
+ ctxAdapter.setAttributeValue("userpassword", "fred".getBytes());
+ ctxAdapter.setAttributeValue("acceptemails", "true");
+ ctxAdapter.setAttributeValue("loginresettime", "19700101100000.1");
+ ctxAdapter.setAttributeValue("failedlogins", "3");
+ ctxAdapter.setAttributeValue("creatorname",
+ "uid=amAdmin,ou=people,dc=myretsu,dc=com");
- MockEntity entity = (MockEntity) contextMapper
- .mapFromContext(ctxAdapter);
- Assert.assertEquals(entity.getMail(), "bean@bean.com",
- "The mocked entity should match what has been mapped");
- Assert.assertEquals("Mr Bean", entity.getName(),
- "Name mapping not as expected");
- Assert.assertEquals(entity.getMail(), "bean@bean.com",
- "Mail mapping not as expected");
- Assert.assertEquals(entity.getAddress(), "Somewhere in england",
- "Address mapping not as expected");
- Assert.assertEquals("fred", new String(entity.getPassword()),
- "Password mapping not as expected");
- Assert.assertEquals("elem1", entity.getDescription()[0],
- "Description mapping not as expected");
- Assert.assertEquals(Boolean.TRUE, entity.getAcceptEmails(),
- "AcceptEmails mapping not as expected");
- Assert.assertEquals(new Date(1L), entity.getResetLogin(),
- "ResetLogin mapping not as expected");
- Assert.assertEquals(new Integer(3), entity.getFailedLogins(),
- "FailedLogin mapping not as expected");
- Assert.assertEquals(new DistinguishedName(
- "uid=amAdmin,ou=people,dc=myretsu,dc=com"),
- entity.getCreator(), "Creator mapping not as expected");
+ MockEntity entity = (MockEntity) contextMapper
+ .mapFromContext(ctxAdapter);
+ Assert.assertEquals(entity.getMail(), "bean@bean.com",
+ "The mocked entity should match what has been mapped");
+ Assert.assertEquals("Mr Bean", entity.getName(),
+ "Name mapping not as expected");
+ Assert.assertEquals(entity.getMail(), "bean@bean.com",
+ "Mail mapping not as expected");
+ Assert.assertEquals(entity.getAddress(), "Somewhere in england",
+ "Address mapping not as expected");
+ Assert.assertEquals("fred", new String(entity.getPassword()),
+ "Password mapping not as expected");
+ Assert.assertEquals("elem1", entity.getDescription()[0],
+ "Description mapping not as expected");
+ Assert.assertEquals(Boolean.TRUE, entity.getAcceptEmails(),
+ "AcceptEmails mapping not as expected");
+ Assert.assertEquals(new Date(1L), entity.getResetLogin(),
+ "ResetLogin mapping not as expected");
+ Assert.assertEquals(new Integer(3), entity.getFailedLogins(),
+ "FailedLogin mapping not as expected");
+ Assert.assertEquals(new DistinguishedName(
+ "uid=amAdmin,ou=people,dc=myretsu,dc=com"),
+ entity.getCreator(), "Creator mapping not as expected");
- }
+ }
- @Test(groups = {"AnnotatedClassContextMapper"}, expectedExceptions = ContextMapperException.class)
- public void throwsExceptionWhenNamingSuffixHasSyntaxError()
- throws ContextMapperException
- {
- AnnotatedClassContextMapper contextMapper = new AnnotatedClassContextMapper(
- MockModelNamingSuffixSyntaxError.class, typeConverter,
- refEditorFactory);
- Assert
- .fail("AnnotatedClassContextMapper should throw an exception when naming path annotation syntax is "
- + "incorrect.");
- }
+ @Test(groups = { "AnnotatedClassContextMapper" }, expectedExceptions = ContextMapperException.class)
+ public void throwsExceptionWhenNamingSuffixHasSyntaxError()
+ throws ContextMapperException {
+ AnnotatedClassContextMapper contextMapper = new AnnotatedClassContextMapper(
+ MockModelNamingSuffixSyntaxError.class, typeConverter,
+ refEditorFactory);
+ Assert
+ .fail("AnnotatedClassContextMapper should throw an exception when naming path annotation syntax is "
+ + "incorrect.");
+ }
- @Test(groups = {"AnnotatedClassContextMapper"}, expectedExceptions = ContextMapperException.class)
- public void throwsExceptionWhenNamingSuffixNotInSeparateElements()
- throws ContextMapperException
- {
- AnnotatedClassContextMapper contextMapper = new AnnotatedClassContextMapper(
- MockModelNamingSuffixNotInSeparateElements.class,
- typeConverter, refEditorFactory);
- Assert
- .fail("AnnotatedClassContextMapper should throw an exception when naming path annotation syntax is "
- + "incorrect.");
- }
+ @Test(groups = { "AnnotatedClassContextMapper" }, expectedExceptions = ContextMapperException.class)
+ public void throwsExceptionWhenNamingSuffixNotInSeparateElements()
+ throws ContextMapperException {
+ AnnotatedClassContextMapper contextMapper = new AnnotatedClassContextMapper(
+ MockModelNamingSuffixNotInSeparateElements.class,
+ typeConverter, refEditorFactory);
+ Assert
+ .fail("AnnotatedClassContextMapper should throw an exception when naming path annotation syntax is "
+ + "incorrect.");
+ }
- @Test(groups = {"AnnotatedClassContextMapper"}, expectedExceptions = ContextMapperException.class)
- public void throwsExceptionWhenModelObjectMissingGetterOrSetter()
- throws ContextMapperException
- {
- AnnotatedClassContextMapper contextMapper = new AnnotatedClassContextMapper(
- MockModelMissingSetter.class, typeConverter, refEditorFactory);
- Assert.fail("Should've thrown exception due to missing getter/setter");
- }
+ @Test(groups = { "AnnotatedClassContextMapper" }, expectedExceptions = ContextMapperException.class)
+ public void throwsExceptionWhenModelObjectMissingGetterOrSetter()
+ throws ContextMapperException {
+ AnnotatedClassContextMapper contextMapper = new AnnotatedClassContextMapper(
+ MockModelMissingSetter.class, typeConverter, refEditorFactory);
+ Assert.fail("Should've thrown exception due to missing getter/setter");
+ }
- @Test(groups = {"AnnotatedClassContextMapper"})
- public void throwsExceptionWhenBeanPropertyNotAValidTranslationType()
- {
- try
- {
- AnnotatedClassContextMapper contextMapper = new AnnotatedClassContextMapper(
- MockModelInvalidTranslationType.class, typeConverter,
- refEditorFactory);
- Assert
- .fail("Should've thrown exception due to missing getter/setter");
- }
- catch (ContextMapperException e)
- {
- Assert
- .assertTrue(e
- .getMessage()
- .contains(
- "MockModelInvalidTranslationType.getMap() has invalid return type"));
- }
+ @Test(groups = { "AnnotatedClassContextMapper" })
+ public void throwsExceptionWhenBeanPropertyNotAValidTranslationType() {
+ try {
+ AnnotatedClassContextMapper contextMapper = new AnnotatedClassContextMapper(
+ MockModelInvalidTranslationType.class, typeConverter,
+ refEditorFactory);
+ Assert
+ .fail("Should've thrown exception due to missing getter/setter");
+ } catch (ContextMapperException e) {
+ Assert
+ .assertTrue(e
+ .getMessage()
+ .contains(
+ "MockModelInvalidTranslationType.getMap() has invalid return type"));
+ }
- }
+ }
- @NamingAttribute("cn")
- @NamingSuffix({"ou=people", "dc=example", "dc=com"})
- @ObjectClasses({"top", "person", "organizationalPerson", "inetorgperson"})
- public class MockModelMissingSetter
- {
- @DirAttribute("cn")
- private String name;
+ @NamingAttribute("cn")
+ @NamingSuffix( { "ou=people", "dc=example", "dc=com" })
+ @ObjectClasses( { "top", "person", "organizationalPerson", "inetorgperson" })
+ public class MockModelMissingSetter {
+ @DirAttribute("cn")
+ private String name;
- @DirAttribute("addr")
- private String address;
+ @DirAttribute("addr")
+ private String address;
- @DirAttribute("mail")
- private String mail;
+ @DirAttribute("mail")
+ private String mail;
- public String getName()
- {
- return name;
- }
+ public String getName() {
+ return name;
+ }
- public String getAddress()
- {
- return address;
- }
+ public String getAddress() {
+ return address;
+ }
- public String getMail()
- {
- return mail;
- }
+ public String getMail() {
+ return mail;
+ }
- public void setName(String name)
- {
- this.name = name;
- }
+ public void setName(String name) {
+ this.name = name;
+ }
- public void setAddress(String address)
- {
- this.address = address;
- }
- }
+ public void setAddress(String address) {
+ this.address = address;
+ }
+ }
- @NamingAttribute("cn")
- @NamingSuffix({"ou=people", "dc=example", "dc=com"})
- @ObjectClasses({"top", "person", "organizationalPerson", "inetorgperson"})
- public class MockModelBadMethodName
- {
+ @NamingAttribute("cn")
+ @NamingSuffix( { "ou=people", "dc=example", "dc=com" })
+ @ObjectClasses( { "top", "person", "organizationalPerson", "inetorgperson" })
+ public class MockModelBadMethodName {
- @DirAttribute("cn")
- private String name;
+ @DirAttribute("cn")
+ private String name;
- @DirAttribute("addr")
- private String address;
+ @DirAttribute("addr")
+ private String address;
- public String zzzName()
- {
- return name;
- }
+ public String zzzName() {
+ return name;
+ }
- public String getAddress()
- {
- return address;
- }
- }
+ public String getAddress() {
+ return address;
+ }
+ }
- @NamingAttribute("cn")
- @NamingSuffix({"ou=people,dc=example ,dc=com"})
- @ObjectClasses({"top", "person", "organizationalPerson", "inetorgperson"})
- public class MockModelNamingSuffixNotInSeparateElements
- {
- }
+ @NamingAttribute("cn")
+ @NamingSuffix( { "ou=people,dc=example ,dc=com" })
+ @ObjectClasses( { "top", "person", "organizationalPerson", "inetorgperson" })
+ public class MockModelNamingSuffixNotInSeparateElements {
+ }
- @NamingAttribute("cn")
- @NamingSuffix({"ou=people", "dc 0);
}
- public void testFilterByBeanProperty()
+ @Test(groups = "LdapDao")
+ public void filterByBeanProperty()
{
ldapDao.create(testPerson);
List results = ldapDao.filterByBeanProperty(testPerson.getEmailAddress(), "EmailAddress", TestPerson.class);
@@ -144,7 +156,9 @@ public class LdapDaoTest extends AbstractLdapTemplateIntegrationTest
Assert.assertTrue(results.size() > 0, "Filter should return collection containing more than one result. ");
}
- public void testUpdateEntity()
+
+ @Test(groups = "LdapDao")
+ public void updateEntity()
{
try
{
@@ -162,7 +176,9 @@ public class LdapDaoTest extends AbstractLdapTemplateIntegrationTest
}
}
- public void testUpdateEntityThrowsExceptionWhenNameNotBound()
+
+ @Test(groups = "LdapDao")
+ public void updateEntityThrowsExceptionWhenNameNotBound()
{
try
{
@@ -171,13 +187,15 @@ public class LdapDaoTest extends AbstractLdapTemplateIntegrationTest
ldapDao.update(testPerson);
Assert.fail("Should've failed since the entry doesn't exist");
}
- catch (Exception e)
+ catch (EntryNotFoundException e)
{
- Assert.assertTrue(e instanceof NameNotFoundException);
+ Assert.assertTrue(e instanceof EntryNotFoundException);
+ Assert.assertTrue(e.getMessage().contains("Entry not found"), "Error message not as expected.");
}
}
- public void testDeleteEntity()
+ @Test(groups = "LdapDao")
+ public void deleteEntity()
{
ldapDao.create(testPerson);
LOGGER.debug(testPerson);
diff --git a/spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/entity/MockEntity.java b/spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/entity/MockEntity.java
index 40b1025e..968b7039 100644
--- a/spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/entity/MockEntity.java
+++ b/spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/entity/MockEntity.java
@@ -5,14 +5,14 @@
*/
package org.springframework.ldap.odm.entity;
+import java.util.Date;
+
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.odm.annotations.DirAttribute;
import org.springframework.ldap.odm.annotations.NamingAttribute;
import org.springframework.ldap.odm.annotations.NamingSuffix;
import org.springframework.ldap.odm.annotations.ObjectClasses;
-import java.util.Date;
-
@NamingAttribute("cn")
@NamingSuffix({"ou = people", "dc = example", "dc=com"})
@ObjectClasses({"top", "person", "organizationalPerson", "inetorgperson"})
diff --git a/spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/entity/TestPerson.java b/spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/entity/TestPerson.java
index 80ce264b..bdc066ae 100644
--- a/spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/entity/TestPerson.java
+++ b/spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/entity/TestPerson.java
@@ -9,14 +9,13 @@ import org.springframework.ldap.odm.annotations.DirAttribute;
import org.springframework.ldap.odm.annotations.NamingAttribute;
import org.springframework.ldap.odm.annotations.NamingSuffix;
import org.springframework.ldap.odm.annotations.ObjectClasses;
-import org.apache.commons.lang.builder.EqualsBuilder;
import com.thoughtworks.xstream.XStream;
@NamingAttribute("uid")
@NamingSuffix({"ou=people"})
-@ObjectClasses({"person", "organizationalPerson", "inetorgperson"})
+@ObjectClasses({"top", "person", "organizationalPerson", "inetorgperson"})
public class TestPerson
{
/*********************************** Directory mapped fields ************************************/
@@ -107,10 +106,5 @@ public class TestPerson
return "\n" + xStream.toXML(this);
}
- public boolean equals(Object o)
- {
- return EqualsBuilder.reflectionEquals(this, o);
- }
-
}
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 c7fbb7df..4d9228e7 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
@@ -5,15 +5,15 @@
*/
package org.springframework.ldap.odm.attributetypes;
-import org.springframework.beans.SimpleTypeConverter;
-import org.springframework.beans.propertyeditors.CustomDateEditor;
-import org.springframework.ldap.core.DistinguishedName;
-
-import javax.naming.ldap.LdapName;
import java.beans.PropertyEditor;
import java.text.SimpleDateFormat;
import java.util.Date;
+import javax.naming.ldap.LdapName;
+
+import org.springframework.beans.SimpleTypeConverter;
+import org.springframework.beans.propertyeditors.CustomDateEditor;
+import org.springframework.ldap.core.DistinguishedName;
public class LdapTypeConverter extends SimpleTypeConverter
{
diff --git a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/attributetypes/NameEditor.java b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/attributetypes/NameEditor.java
index 36898738..ae17ecdb 100644
--- a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/attributetypes/NameEditor.java
+++ b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/attributetypes/NameEditor.java
@@ -5,11 +5,12 @@
*/
package org.springframework.ldap.odm.attributetypes;
-import org.springframework.ldap.core.DistinguishedName;
-
import java.beans.PropertyEditorSupport;
+
import javax.naming.ldap.LdapName;
+import org.springframework.ldap.core.DistinguishedName;
+
public class NameEditor extends PropertyEditorSupport
{
private Class conversionClass;
diff --git a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/attributetypes/ReferencedEntryEditor.java b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/attributetypes/ReferencedEntryEditor.java
index 641fc4f4..30996977 100644
--- a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/attributetypes/ReferencedEntryEditor.java
+++ b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/attributetypes/ReferencedEntryEditor.java
@@ -5,16 +5,17 @@
*/
package org.springframework.ldap.odm.attributetypes;
+import java.beans.PropertyEditorSupport;
+
+import javax.naming.InvalidNameException;
+import javax.naming.ldap.LdapName;
+
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.odm.contextmapping.AnnotatedClassContextMapper;
import org.springframework.ldap.odm.contextmapping.exception.ContextMapperException;
-import javax.naming.InvalidNameException;
-import javax.naming.ldap.LdapName;
-import java.beans.PropertyEditorSupport;
-
public class ReferencedEntryEditor extends PropertyEditorSupport
-{
+{
private LdapTemplate ldapTemplate;
private AnnotatedClassContextMapper contextMapper;
diff --git a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/attributetypes/ReferencedEntryEditorFactory.java b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/attributetypes/ReferencedEntryEditorFactory.java
index ec1444c4..50c3408a 100644
--- a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/attributetypes/ReferencedEntryEditorFactory.java
+++ b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/attributetypes/ReferencedEntryEditorFactory.java
@@ -10,12 +10,11 @@ import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
+import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.odm.attributetypes.exception.ReferencedEntryEditorCreationException;
import org.springframework.ldap.odm.contextmapping.AnnotatedClassContextMapper;
import org.springframework.ldap.odm.contextmapping.ContextMapperFactory;
import org.springframework.ldap.odm.contextmapping.exception.ContextMapperException;
-import org.springframework.ldap.core.LdapTemplate;
public class ReferencedEntryEditorFactory
{
diff --git a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/attributetypes/ValidConversionType.java b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/attributetypes/ValidConversionType.java
index 0c268b94..3b835892 100644
--- a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/attributetypes/ValidConversionType.java
+++ b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/attributetypes/ValidConversionType.java
@@ -5,11 +5,11 @@
*/
package org.springframework.ldap.odm.attributetypes;
-import org.springframework.ldap.core.DistinguishedName;
-
-import javax.naming.ldap.LdapName;
import java.util.Date;
+import javax.naming.ldap.LdapName;
+
+import org.springframework.ldap.core.DistinguishedName;
/* Should be able to support any of Spring's conversion types. Add a test case if you add one */
public enum ValidConversionType
diff --git a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/contextmapping/AnnotatedClassContextMapper.java b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/contextmapping/AnnotatedClassContextMapper.java
index ee026d03..6bd84457 100644
--- a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/contextmapping/AnnotatedClassContextMapper.java
+++ b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/contextmapping/AnnotatedClassContextMapper.java
@@ -5,6 +5,14 @@
*/
package org.springframework.ldap.odm.contextmapping;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.naming.Name;
+import javax.naming.directory.Attribute;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.TypeMismatchException;
@@ -23,13 +31,6 @@ import org.springframework.ldap.odm.attributetypes.exception.ReferencedEntryEdit
import org.springframework.ldap.odm.contextmapping.exception.ContextMapperException;
import org.springframework.util.StringUtils;
-import javax.naming.Name;
-import javax.naming.directory.Attribute;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Map;
-
public class AnnotatedClassContextMapper implements ContextMapper, ContextAssembler
{
private static final Log LOGGER = LogFactory.getLog(AnnotatedClassContextMapper.class);
diff --git a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/dao/LdapDaoImpl.java b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/dao/LdapDaoImpl.java
index c0b20b7c..fe478807 100644
--- a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/dao/LdapDaoImpl.java
+++ b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/dao/LdapDaoImpl.java
@@ -5,19 +5,21 @@
*/
package org.springframework.ldap.odm.dao;
+import java.util.List;
+
+import javax.naming.Name;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.ldap.core.DirContextAdapter;
-import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.DistinguishedName;
+import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.odm.contextmapping.AnnotatedClassContextMapper;
import org.springframework.ldap.odm.contextmapping.ContextMapperFactory;
import org.springframework.ldap.odm.contextmapping.exception.ContextMapperException;
import org.springframework.ldap.odm.dao.exception.DaoException;
import org.springframework.ldap.odm.dao.exception.DataIntegrityViolationException;
-
-import javax.naming.Name;
-import java.util.List;
+import org.springframework.ldap.odm.dao.exception.EntryNotFoundException;
public class LdapDaoImpl implements LdapDao
{
@@ -60,6 +62,12 @@ public class LdapDaoImpl implements LdapDao
ctxMapper.mapToContext(dirObject, contextAdapter);
ldapTemplate.modifyAttributes(dn, contextAdapter.getModificationItems());
}
+ catch (org.springframework.ldap.NameNotFoundException e)
+ {
+ //We need to rethrow a serializable exception if we are going to invoke
+ //this as a remote service.
+ throw new EntryNotFoundException(e.getMessage());
+ }
catch (ContextMapperException e)
{
throw new DaoException(e.getMessage(), e);
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 f9dc2eee..88966e2e 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
@@ -5,327 +5,260 @@
*/
package org.springframework.ldap.odm.attributetypes;
-import junit.framework.TestCase;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.beans.TypeMismatchException;
-import org.springframework.ldap.core.DistinguishedName;
-import org.testng.Assert;
-
-import javax.naming.InvalidNameException;
-import javax.naming.ldap.LdapName;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
-public class LdapTypeConverterTest extends TestCase
-{
- private static final Log LOGGER = LogFactory.getLog(LdapTypeConverterTest.class);
+import javax.naming.InvalidNameException;
+import javax.naming.ldap.LdapName;
- private LdapTypeConverter typeConverter;
+import junit.framework.TestCase;
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
- typeConverter = new LdapTypeConverter();
- }
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.TypeMismatchException;
+import org.springframework.ldap.core.DistinguishedName;
+import org.testng.Assert;
- public void testConvertToByteArray()
- {
- byte[] objectToTranslate = "fred".getBytes();
+public class LdapTypeConverterTest extends TestCase {
+ private static final Log LOGGER = LogFactory
+ .getLog(LdapTypeConverterTest.class);
- try
- {
- byte[] translated = (byte[]) typeConverter.convertIfNecessary(
- objectToTranslate, byte[].class);
- Assert.assertTrue(Arrays.equals(objectToTranslate, translated),
- "byte[] attributes should pass through unchanged.");
- }
- catch (TypeMismatchException e)
- {
- Assert
- .fail(
- "Unexpected exception: byte[] attributes should pass through unchanged.",
- e);
- }
- }
+ private LdapTypeConverter typeConverter;
- public void testConvertToBoolean()
- {
- String objectToTranslate = "true";
- try
- {
- Object translated = typeConverter.convertIfNecessary(
- objectToTranslate, Boolean.class);
- Assert
- .assertEquals(true, translated,
- "Unexpected translated value");
- }
- catch (TypeMismatchException e)
- {
- Assert.fail("Unexpected exception during translation", e);
- }
- }
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ typeConverter = new LdapTypeConverter();
+ }
- public void testConvertFromBoolean()
- {
- boolean objectToTranslate = false;
- try
- {
- Object translated = typeConverter.getAsText(objectToTranslate);
- Assert.assertEquals(translated, "false",
- "Unexpected translated value");
- }
- catch (TypeMismatchException e)
- {
- Assert.fail("Unexpected exception during translation", e);
- }
- }
+ public void testConvertToByteArray() {
+ byte[] objectToTranslate = "fred".getBytes();
- public void testConvertToString()
- {
- String objectToTranslate = "onetwothree";
- try
- {
- Object translated = typeConverter.convertIfNecessary(
- objectToTranslate, String.class);
- Assert.assertEquals("onetwothree", translated,
- "Unexpected translated value");
- }
- catch (TypeMismatchException e)
- {
- Assert.fail("Unexpected exception during translation", e);
- }
- }
+ try {
+ byte[] translated = (byte[]) typeConverter.convertIfNecessary(
+ objectToTranslate, byte[].class);
+ Assert.assertTrue(Arrays.equals(objectToTranslate, translated),
+ "byte[] attributes should pass through unchanged.");
+ } catch (TypeMismatchException e) {
+ Assert
+ .fail(
+ "Unexpected exception: byte[] attributes should pass through unchanged.",
+ e);
+ }
+ }
- public void testConvertToStringArray()
- {
- String object1 = "onetwothree";
- String object2 = "fourfivesix";
- String object3 = "seveneightnine";
- Object objectToTranslate = new String[]{object1, object2, object3};
+ public void testConvertToBoolean() {
+ String objectToTranslate = "true";
+ try {
+ Object translated = typeConverter.convertIfNecessary(
+ objectToTranslate, Boolean.class);
+ Assert
+ .assertEquals(true, translated,
+ "Unexpected translated value");
+ } catch (TypeMismatchException e) {
+ Assert.fail("Unexpected exception during translation", e);
+ }
+ }
- try
- {
- Object[] translated = (Object[]) typeConverter.convertIfNecessary(
- objectToTranslate, String[].class);
- Assert.assertEquals("fourfivesix", translated[1],
- "Unexpected translated value");
- }
- catch (TypeMismatchException e)
- {
- Assert.fail("Unexpected exception during translation", e);
- }
- }
+ public void testConvertFromBoolean() {
+ boolean objectToTranslate = false;
+ try {
+ Object translated = typeConverter.getAsText(objectToTranslate);
+ Assert.assertEquals(translated, "false",
+ "Unexpected translated value");
+ } catch (TypeMismatchException e) {
+ Assert.fail("Unexpected exception during translation", e);
+ }
+ }
- public void testConvertToGeneralizedTime() throws ParseException
- {
- String object1 = "20061005093637.44";
- DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss.S");
- Date expected = df.parse("20061005093637.44");
+ public void testConvertToString() {
+ String objectToTranslate = "onetwothree";
+ try {
+ Object translated = typeConverter.convertIfNecessary(
+ objectToTranslate, String.class);
+ Assert.assertEquals("onetwothree", translated,
+ "Unexpected translated value");
+ } catch (TypeMismatchException e) {
+ Assert.fail("Unexpected exception during translation", e);
+ }
+ }
- try
- {
- Object translated = typeConverter.convertIfNecessary(object1,
- Date.class);
- Assert.assertEquals(translated, expected,
- "Unexpected translated value");
- }
- catch (TypeMismatchException e)
- {
- Assert.fail("Unexpected exception during translation", e);
- }
- }
+ public void testConvertToStringArray() {
+ String object1 = "onetwothree";
+ String object2 = "fourfivesix";
+ String object3 = "seveneightnine";
+ Object objectToTranslate = new String[] { object1, object2, object3 };
- public void testConvertToGeneralizedTimeArray() throws ParseException
- {
- String object1 = "20071105093655.44";
- String object2 = "20061005093637.44";
- Object objectToTranslate = new String[]{object1, object2};
+ try {
+ Object[] translated = (Object[]) typeConverter.convertIfNecessary(
+ objectToTranslate, String[].class);
+ Assert.assertEquals("fourfivesix", translated[1],
+ "Unexpected translated value");
+ } catch (TypeMismatchException e) {
+ Assert.fail("Unexpected exception during translation", e);
+ }
+ }
- DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss.S");
- Date expected = df.parse("20061005093637.44");
+ public void testConvertToGeneralizedTime() throws ParseException {
+ String object1 = "20061005093637.44";
+ 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,
- "Unexpected translated value");
- }
- catch (TypeMismatchException e)
- {
- Assert.fail("Unexpected exception during translation");
- }
- }
+ try {
+ Object translated = typeConverter.convertIfNecessary(object1,
+ Date.class);
+ Assert.assertEquals(translated, expected,
+ "Unexpected translated value");
+ } catch (TypeMismatchException e) {
+ Assert.fail("Unexpected exception during translation", e);
+ }
+ }
- public void testConvertToLdapName()
- {
- String object1 = "uid=amAdmin, ou = people, dc = myretsu,dc=com";
- try
- {
- Object translated = typeConverter.convertIfNecessary(object1,
- LdapName.class);
- Assert.assertEquals(translated, new LdapName(object1),
- "Unexpected translated value");
- }
- catch (TypeMismatchException e)
- {
- Assert.fail("Unexpected exception during translation", e);
- }
- catch (InvalidNameException e)
- {
- Assert.fail("Problem with test: Ldap name can't be parsed.", e);
- }
- }
+ public void testConvertToGeneralizedTimeArray() throws ParseException {
+ String object1 = "20071105093655.44";
+ String object2 = "20061005093637.44";
+ Object objectToTranslate = new String[] { object1, object2 };
- public void testConvertToLdapNameArray()
- {
- String object1 = "uid=amAdmin, ou = people, dc = myretsu,dc=com";
- String object2 = "uid=fred, ou = people, dc = myretsu,dc=com";
- 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, LdapName[].class);
- Assert.assertEquals(new LdapName(object2), translated[1],
- "Unexpected translated value");
- }
- catch (TypeMismatchException e)
- {
- Assert.fail("Unexpected exception during translation", e);
- }
- catch (InvalidNameException e)
- {
- Assert.fail("Problem with test: Ldap name can't be parsed.", e);
- }
- }
+ try {
+ Object[] translated = (Object[]) typeConverter.convertIfNecessary(
+ objectToTranslate, Date[].class);
+ Assert.assertEquals(translated[1], expected,
+ "Unexpected translated value");
+ } catch (TypeMismatchException e) {
+ Assert.fail("Unexpected exception during translation");
+ }
+ }
- public void testConvertToDistinguishedName()
- {
- String object1 = "uid=amAdmin, ou = people, dc = myretsu,dc=com";
- try
- {
- Object translated = typeConverter.convertIfNecessary(object1,
- DistinguishedName.class);
- Assert.assertEquals(new DistinguishedName(object1), translated,
- "Unexpected translated value");
- }
- catch (TypeMismatchException e)
- {
- Assert.fail("Unexpected exception during translation", e);
- }
- }
+ public void testConvertToLdapName() {
+ String object1 = "uid=amAdmin, ou = people, dc = myretsu,dc=com";
+ try {
+ Object translated = typeConverter.convertIfNecessary(object1,
+ LdapName.class);
+ Assert.assertEquals(translated, new LdapName(object1),
+ "Unexpected translated value");
+ } catch (TypeMismatchException e) {
+ Assert.fail("Unexpected exception during translation", e);
+ } catch (InvalidNameException e) {
+ Assert.fail("Problem with test: Ldap name can't be parsed.", e);
+ }
+ }
- public void testConvertToDistinguishedNameArray()
- {
- String object1 = "uid=amAdmin, ou = people, dc = myretsu,dc=com";
- String object2 = "uid=fred, ou = people, dc = myretsu,dc=com";
- Object objectToTranslate = new String[]{object1, object2};
+ public void testConvertToLdapNameArray() {
+ String object1 = "uid=amAdmin, ou = people, dc = myretsu,dc=com";
+ String object2 = "uid=fred, ou = people, dc = myretsu,dc=com";
+ Object objectToTranslate = new String[] { object1, object2 };
- try
- {
- Object[] translated = (Object[]) typeConverter.convertIfNecessary(
- objectToTranslate, DistinguishedName[].class);
- Assert.assertEquals(new DistinguishedName(object2), translated[1],
- "Unexpected translated value");
- }
- catch (TypeMismatchException e)
- {
- Assert.fail("Unexpected exception during translation", e);
- }
- }
+ try {
+ Object[] translated = (Object[]) typeConverter.convertIfNecessary(
+ objectToTranslate, LdapName[].class);
+ Assert.assertEquals(new LdapName(object2), translated[1],
+ "Unexpected translated value");
+ } catch (TypeMismatchException e) {
+ Assert.fail("Unexpected exception during translation", e);
+ } catch (InvalidNameException e) {
+ Assert.fail("Problem with test: Ldap name can't be parsed.", e);
+ }
+ }
- public void testConvertToLong()
- {
- String object1 = "9887342";
- try
- {
- Object translated = typeConverter.convertIfNecessary(object1,
- Long.class);
- Assert.assertEquals(9887342L, translated,
- "Unexpected translated value");
- }
- catch (TypeMismatchException e)
- {
- Assert.fail("Unexpected exception during translation", e);
- }
- }
+ public void testConvertToDistinguishedName() {
+ String object1 = "uid=amAdmin, ou = people, dc = myretsu,dc=com";
+ try {
+ Object translated = typeConverter.convertIfNecessary(object1,
+ DistinguishedName.class);
+ Assert.assertEquals(new DistinguishedName(object1), translated,
+ "Unexpected translated value");
+ } catch (TypeMismatchException e) {
+ Assert.fail("Unexpected exception during translation", e);
+ }
+ }
- public void testConvertToLongArray()
- {
- String object1 = "878787";
- String object2 = "23948787";
- Object objectToTranslate = new String[]{object1, object2};
+ public void testConvertToDistinguishedNameArray() {
+ String object1 = "uid=amAdmin, ou = people, dc = myretsu,dc=com";
+ String object2 = "uid=fred, ou = people, dc = myretsu,dc=com";
+ Object objectToTranslate = new String[] { object1, object2 };
- try
- {
- Object[] translated = (Object[]) typeConverter.convertIfNecessary(
- objectToTranslate, Long[].class);
- Assert.assertEquals(23948787L, translated[1],
- "Unexpected translated value");
- }
- catch (TypeMismatchException e)
- {
- Assert.fail("Unexpected exception during translation", e);
- }
- }
+ try {
+ Object[] translated = (Object[]) typeConverter.convertIfNecessary(
+ objectToTranslate, DistinguishedName[].class);
+ Assert.assertEquals(new DistinguishedName(object2), translated[1],
+ "Unexpected translated value");
+ } catch (TypeMismatchException e) {
+ Assert.fail("Unexpected exception during translation", e);
+ }
+ }
- public void testConvertToInteger()
- {
- String object1 = "9887342";
+ public void testConvertToLong() {
+ String object1 = "9887342";
+ try {
+ Object translated = typeConverter.convertIfNecessary(object1,
+ Long.class);
+ Assert.assertEquals(9887342L, translated,
+ "Unexpected translated value");
+ } catch (TypeMismatchException e) {
+ Assert.fail("Unexpected exception during translation", e);
+ }
+ }
- try
- {
- Object translated = typeConverter.convertIfNecessary(object1,
- Integer.class);
- Assert.assertEquals(9887342, translated,
- "Unexpected translated value");
- }
- catch (TypeMismatchException e)
- {
- Assert.fail("Unexpected exception during translation", e);
- }
- }
+ public void testConvertToLongArray() {
+ String object1 = "878787";
+ String object2 = "23948787";
+ Object objectToTranslate = new String[] { object1, object2 };
- public void testConvertToIntegerArray()
- {
- String object1 = "878787";
- String object2 = "23948787";
- Object objectToTranslate = new String[]{object1, object2};
+ try {
+ Object[] translated = (Object[]) typeConverter.convertIfNecessary(
+ objectToTranslate, Long[].class);
+ Assert.assertEquals(23948787L, translated[1],
+ "Unexpected translated value");
+ } catch (TypeMismatchException e) {
+ Assert.fail("Unexpected exception during translation", e);
+ }
+ }
- try
- {
- Object[] translated = (Object[]) typeConverter.convertIfNecessary(
- objectToTranslate, Integer[].class);
- Assert.assertEquals(23948787, translated[1],
- "Unexpected translated value");
- }
- catch (TypeMismatchException e)
- {
- Assert.fail("Unexpected exception during translation", e);
- }
- }
+ public void testConvertToInteger() {
+ String object1 = "9887342";
- public void testThrowsTypeMismatchExceptionWhenTypeTranslationFails()
- {
- String object1 = "asdlkjkalkjl";
+ try {
+ Object translated = typeConverter.convertIfNecessary(object1,
+ Integer.class);
+ Assert.assertEquals(9887342, translated,
+ "Unexpected translated value");
+ } catch (TypeMismatchException e) {
+ Assert.fail("Unexpected exception during translation", e);
+ }
+ }
- Object[] translated;
- try
- {
- translated = (Object[]) typeConverter.convertIfNecessary(object1,
- LdapName.class);
- Assert.fail("Should've thrown exception");
- }
- catch (TypeMismatchException e)
- {
- // Pass
- }
- }
+ public void testConvertToIntegerArray() {
+ String object1 = "878787";
+ String object2 = "23948787";
+ Object objectToTranslate = new String[] { object1, object2 };
+
+ try {
+ Object[] translated = (Object[]) typeConverter.convertIfNecessary(
+ objectToTranslate, Integer[].class);
+ Assert.assertEquals(23948787, translated[1],
+ "Unexpected translated value");
+ } catch (TypeMismatchException e) {
+ Assert.fail("Unexpected exception during translation", e);
+ }
+ }
+
+ public void testThrowsTypeMismatchExceptionWhenTypeTranslationFails() {
+ String object1 = "asdlkjkalkjl";
+
+ Object[] translated;
+ try {
+ translated = (Object[]) typeConverter.convertIfNecessary(object1,
+ LdapName.class);
+ Assert.fail("Should've thrown exception");
+ } catch (TypeMismatchException e) {
+ // Pass
+ }
+ }
}