Fixed code and tests so that the integration tests now run via 'mvn test', provided that the LDAP server is running.

This commit is contained in:
Ulrik Sandberg
2008-10-26 19:59:45 +00:00
parent c495408e84
commit 3cc7d2476d
11 changed files with 21 additions and 41 deletions

View File

@@ -71,16 +71,4 @@
<scope>test</scope>
</dependency>
</dependencies>
<!--
Requires an ldap server to be up and running. Uncomment to enable
integration tests
<build>
<testSourceDirectory>src/itest/java</testSourceDirectory>
<testResources>
<testResource>
<directory>src/itest/java</directory>
</testResource>
</testResources>
</build>
-->
</project>

View File

@@ -1,4 +1,4 @@
Sample application demonstrating how to do the most basic stuff in Spring LDAP
Sample application demonstrating how to do the most basic stuff in Spring LDAP.
A very simple dao implementation is provided in
org.springframework.ldap.samples.article.dao.PersonDaoImpl
It demonstrates some basic operations using Spring LDAP. For reference purposes,
@@ -7,11 +7,14 @@ available in TraditionalPersonDaoImpl.
How to use:
-----------
The project is in a maven build structure. Make sure you have installed the samples-utils artifact, as this will be
The project is in a Maven build structure. Make sure you have installed the samples-utils artifact, as this will be
needed for this project to work.
mvn jetty:run will start up a web server demonstrating the capabilities. The web application will be available
'mvn jetty:run' will start up a web server demonstrating the capabilities. The web application will be available
under http://localhost:8080/spring-ldap-person-article/
mvn eclipse:eclipse will construct an eclipse project for you to use. Import that project into eclipse using
'mvn eclipse:eclipse' will construct an Eclipse project for you to use. Import that project into Eclipse using
File/Import/Existing Project, and select this directory.
'mvn test' will run some integration tests that require the LDAP server to be running. It's recommended to run
'mvn jetty:run' from another terminal window before 'mvn test'.

View File

@@ -14,6 +14,3 @@ log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
#Pattern to output : date priority [category] - <message>line_separator
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - <%m>%n
#Enable debug logging
#log4j.category.net.sf.ldaptemplate=DEBUG

View File

@@ -33,7 +33,6 @@ import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import org.apache.commons.lang.StringUtils;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.ldap.samples.article.domain.Person;
/**
@@ -90,6 +89,7 @@ public class TraditionalPersonDaoImpl implements
dn, null,
getAttributesToBind(person));
} catch (NamingException e) {
throw new RuntimeException(e);
} finally {
if (ctx != null) {
@@ -147,9 +147,6 @@ public class TraditionalPersonDaoImpl implements
String cn = (String) attr.get();
list.add(cn);
}
} catch (NameNotFoundException e) {
// The base context was not found.
// Just clean up and exit.
} catch (NamingException e) {
throw new RuntimeException(e);
} finally {
@@ -194,10 +191,6 @@ public class TraditionalPersonDaoImpl implements
.getAttributes();
list.add(mapToPerson(dn, attributes));
}
} catch (NameNotFoundException e) {
// The base context was not found, which basically means
// that the search did not return any results. Just clean up and
// exit.
} catch (NamingException e) {
throw new RuntimeException(e);
} finally {
@@ -234,7 +227,7 @@ public class TraditionalPersonDaoImpl implements
.getAttributes(dn);
return mapToPerson(dn, attributes);
} catch (NameNotFoundException e) {
throw new DataRetrievalFailureException(
throw new RuntimeException(
"Did not find entry with primary key '"
+ dn + "'", e);
} catch (NamingException e) {

View File

@@ -8,7 +8,6 @@
<property name="location" value="/WEB-INF/ldap.properties" />
</bean>
<bean id="contextSource"
class="org.springframework.ldap.test.TestContextSourceFactoryBean">
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />

View File

@@ -17,7 +17,7 @@ package org.springframework.ldap.samples.article.dao;
import java.util.List;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.ldap.NameNotFoundException;
import org.springframework.ldap.samples.article.dao.PersonDao;
import org.springframework.ldap.samples.article.domain.Person;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
@@ -90,23 +90,25 @@ public abstract class AbstractPersonDaoIntegrationTest
personDao.findByPrimaryKey(
"Sweden", "company1",
"Another Person");
fail("DataRetrievalFailureException expected");
} catch (DataRetrievalFailureException expected) {
// expected
fail("NameNotFoundException (when using Spring LDAP) or RuntimeException (when using traditional) expected");
} catch (NameNotFoundException expected) {
// expected
} catch (RuntimeException expected) {
// expected
}
}
}
public void testGetAllPersonNames() {
List result = personDao.getAllPersonNames();
assertEquals(5, result.size());
assertEquals(2, result.size());
String first = (String) result.get(0);
assertEquals("Some Person", first);
}
public void testFindAll() {
List result = personDao.findAll();
assertEquals(5, result.size());
assertEquals(2, result.size());
Person first = (Person) result.get(0);
assertEquals("Some Person", first
.getFullName());

View File

@@ -20,7 +20,7 @@ import org.springframework.ldap.samples.article.dao.PersonDaoImpl;
/**
* Integration tests for the PersonDaoImpl class.
*
* @author Mattias Hellborg Arthursson
* @author Mattias Hellborg Arthurssonrthursson
* @author Ulrik Sandberg
*/
public class PersonDaoImplIntegrationTest extends

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.ldap.samples.article.dao;
import org.springframework.ldap.samples.article.dao.TraditionalPersonDaoImpl;
/**
* Integration tests for the TraditionalPersonDaoImpl class.
*

View File

@@ -1,4 +1,4 @@
urls=ldap://127.0.0.1
userDn=cn=Manager,dc=jayway,dc=se
urls=ldap://127.0.0.1:3900
userDn=uid=admin,ou=system
password=secret
base=dc=jayway,dc=se

View File

@@ -26,7 +26,7 @@
<bean id="traditionalPersonDao"
class="org.springframework.ldap.samples.article.dao.TraditionalPersonDaoImpl">
<property name="url" value="ldap://localhost:389" />
<property name="url" value="ldap://localhost:3900" />
<property name="base" value="dc=jayway,dc=se" />
<property name="userDn" value="${userDn}" />
<property name="password" value="${password}" />