Add JavaFormat format Gradle Task
Closes gh-744
This commit is contained in:
@@ -22,11 +22,10 @@ import org.springframework.ldap.core.support.BaseLdapPathAware;
|
||||
import javax.naming.Name;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class LdapGroupDao implements BaseLdapPathAware
|
||||
{
|
||||
public class LdapGroupDao implements BaseLdapPathAware {
|
||||
|
||||
private Name basePath;
|
||||
|
||||
public LdapGroupDao() {
|
||||
@@ -40,4 +39,5 @@ public class LdapGroupDao implements BaseLdapPathAware
|
||||
public Name getBasePath() {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,4 +20,5 @@ package org.springframework.ldap.itest;
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public interface NoAdTest {
|
||||
|
||||
}
|
||||
|
||||
@@ -21,10 +21,11 @@ import org.apache.commons.lang.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* Dummy bean to be used in the LdapTemplate integration tests.
|
||||
*
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class Person {
|
||||
|
||||
private String fullname;
|
||||
|
||||
private String lastname;
|
||||
@@ -64,9 +65,10 @@ public class Person {
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,22 +21,20 @@ import javax.naming.directory.Attributes;
|
||||
|
||||
import org.springframework.ldap.core.AttributesMapper;
|
||||
|
||||
|
||||
/**
|
||||
* Dummy implementation of AttributesMapper for use in integration tests.
|
||||
*
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class PersonAttributesMapper implements AttributesMapper<Person> {
|
||||
|
||||
/**
|
||||
* Maps the given attributes into a {@link Person} object.
|
||||
*
|
||||
*
|
||||
* @see org.springframework.ldap.core.AttributesMapper#mapFromAttributes(javax.naming.directory.Attributes)
|
||||
*/
|
||||
public Person mapFromAttributes(Attributes attributes)
|
||||
throws NamingException {
|
||||
public Person mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
Person person = new Person();
|
||||
person.setFullname((String) attributes.get("cn").get());
|
||||
person.setLastname((String) attributes.get("sn").get());
|
||||
@@ -44,4 +42,5 @@ public class PersonAttributesMapper implements AttributesMapper<Person> {
|
||||
person.setDescription((String) attributes.get("description").get());
|
||||
return person;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.ldap.core.support.AbstractContextMapper;
|
||||
/**
|
||||
* Dummy implemention of ContextMapper for use in the integration tests and for
|
||||
* illustration purposes.
|
||||
*
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class PersonContextMapper extends AbstractContextMapper<Person> {
|
||||
@@ -36,4 +36,5 @@ public class PersonContextMapper extends AbstractContextMapper<Person> {
|
||||
|
||||
return person;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,12 +18,13 @@ package org.springframework.ldap.itest.core;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
|
||||
/**
|
||||
* Dummy implementation of a class that has a {@link DistinguishedName} setter,
|
||||
* used for testing purposes.
|
||||
*
|
||||
* Dummy implementation of a class that has a {@link DistinguishedName} setter, used for
|
||||
* testing purposes.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class DummyDistinguishedNameConsumer {
|
||||
|
||||
private DistinguishedName distinguishedName;
|
||||
|
||||
public DistinguishedName getDistinguishedName() {
|
||||
@@ -33,4 +34,5 @@ public class DummyDistinguishedNameConsumer {
|
||||
public void setDistinguishedName(DistinguishedName distinguishedName) {
|
||||
this.distinguishedName = distinguishedName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import javax.naming.ldap.LdapName;
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class DummyBaseLdapNameAware implements BaseLdapNameAware {
|
||||
|
||||
private LdapName baseLdapPath;
|
||||
|
||||
@Override
|
||||
@@ -34,4 +35,5 @@ public class DummyBaseLdapNameAware implements BaseLdapNameAware {
|
||||
public LdapName getBaseLdapPath() {
|
||||
return baseLdapPath;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.springframework.ldap.core.support.BaseLdapPathAware;
|
||||
|
||||
/**
|
||||
* Dummy implementation of {@link BaseLdapPathAware}.
|
||||
*
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class DummyBaseLdapPathAware implements BaseLdapPathAware {
|
||||
|
||||
@@ -19,7 +19,7 @@ import org.springframework.ldap.filter.Filter;
|
||||
|
||||
/**
|
||||
* Dummy class to test Filter property editor.
|
||||
*
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class DummyFilterConsumer {
|
||||
@@ -33,4 +33,5 @@ public class DummyFilterConsumer {
|
||||
public void setFilter(Filter filter) {
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,17 +27,17 @@ import java.util.Set;
|
||||
/**
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@Entry(objectClasses = {"top", "groupOfUniqueNames"}, base = "cn=groups")
|
||||
@Entry(objectClasses = { "top", "groupOfUniqueNames" }, base = "cn=groups")
|
||||
public class Group {
|
||||
|
||||
@Id
|
||||
private Name dn;
|
||||
|
||||
@Attribute(name="cn")
|
||||
@Attribute(name = "cn")
|
||||
@DnAttribute("cn")
|
||||
private String name;
|
||||
|
||||
@Attribute(name="uniqueMember")
|
||||
@Attribute(name = "uniqueMember")
|
||||
private Set<Name> members;
|
||||
|
||||
public Name getDn() {
|
||||
@@ -71,4 +71,5 @@ public class Group {
|
||||
public void removeMember(Name member) {
|
||||
members.remove(member);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.springframework.ldap.odm.annotations.Transient;
|
||||
*/
|
||||
@Entry(objectClasses = { "inetOrgPerson", "organizationalPerson", "person", "top" })
|
||||
public class Person implements Persistable<Name> {
|
||||
|
||||
@Id
|
||||
private Name dn;
|
||||
|
||||
@@ -105,4 +106,5 @@ public class Person implements Persistable<Name> {
|
||||
public String getEntryUuid() {
|
||||
return entryUuid;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,11 +15,12 @@ import org.springframework.ldap.odm.annotations.Transient;
|
||||
*/
|
||||
@Entry(objectClasses = { "inetOrgPerson", "organizationalPerson", "person", "top" })
|
||||
public class PersonWithDnAnnotations {
|
||||
|
||||
@Id
|
||||
private Name dn;
|
||||
|
||||
@Attribute(name = "cn")
|
||||
@DnAttribute(value="cn", index=2)
|
||||
@DnAttribute(value = "cn", index = 2)
|
||||
private String commonName;
|
||||
|
||||
@Attribute(name = "sn")
|
||||
@@ -34,11 +35,11 @@ public class PersonWithDnAnnotations {
|
||||
@Attribute(name = "telephoneNumber")
|
||||
private String telephoneNumber;
|
||||
|
||||
@DnAttribute(value="ou", index=1)
|
||||
@DnAttribute(value = "ou", index = 1)
|
||||
@Transient
|
||||
private String company;
|
||||
|
||||
@DnAttribute(value="ou", index=0)
|
||||
@DnAttribute(value = "ou", index = 0)
|
||||
@Transient
|
||||
private String country;
|
||||
|
||||
@@ -113,4 +114,5 @@ public class PersonWithDnAnnotations {
|
||||
public String getEntryUuid() {
|
||||
return entryUuid;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.springframework.security.access.expression.method.DefaultMethodSecuri
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class MethodSecurityExpressionHandler extends DefaultMethodSecurityExpressionHandler {
|
||||
|
||||
private LdapGroupDao groupDao;
|
||||
|
||||
public LdapGroupDao getGroupDao() {
|
||||
|
||||
@@ -17,26 +17,22 @@
|
||||
package org.springframework.ldap.itest.transaction.compensating.manager;
|
||||
|
||||
public interface DummyDao {
|
||||
void createWithException(String country, String company, String fullname,
|
||||
String lastname, String description);
|
||||
|
||||
void create(String country, String company, String fullname,
|
||||
String lastname, String description);
|
||||
void createWithException(String country, String company, String fullname, String lastname, String description);
|
||||
|
||||
void create(String country, String company, String fullname, String lastname, String description);
|
||||
|
||||
void update(String dn, String fullname, String lastname, String description);
|
||||
|
||||
void updateWithException(String dn, String fullname, String lastname,
|
||||
String description);
|
||||
void updateWithException(String dn, String fullname, String lastname, String description);
|
||||
|
||||
void updateAndRename(String dn, String newDn, String description);
|
||||
|
||||
void updateAndRenameWithException(String dn, String newDn,
|
||||
String description);
|
||||
void updateAndRenameWithException(String dn, String newDn, String description);
|
||||
|
||||
void modifyAttributes(String dn, String lastName, String description);
|
||||
|
||||
void modifyAttributesWithException(String dn, String lastName,
|
||||
String description);
|
||||
void modifyAttributesWithException(String dn, String lastName, String description);
|
||||
|
||||
void unbind(String dn, String fullname);
|
||||
|
||||
@@ -49,4 +45,5 @@ public interface DummyDao {
|
||||
void createRecursivelyAndUnbindSubnode();
|
||||
|
||||
void createRecursivelyAndUnbindSubnodeWithException();
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
package org.springframework.ldap.itest.transaction.compensating.manager;
|
||||
|
||||
public class DummyException extends RuntimeException {
|
||||
|
||||
public DummyException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,9 +16,11 @@
|
||||
package org.springframework.ldap.itest.transaction.compensating.manager;
|
||||
|
||||
public class DummyServiceImpl {
|
||||
|
||||
private DummyDao dummyDaoImpl;
|
||||
|
||||
public void setDummyDaoImpl(DummyDao dummyDaoImpl) {
|
||||
this.dummyDaoImpl = dummyDaoImpl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Transactional
|
||||
public class LdapAndJdbcDummyDaoImpl implements DummyDao {
|
||||
|
||||
private LdapTemplate ldapTemplate;
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
@@ -38,18 +39,20 @@ public class LdapAndJdbcDummyDaoImpl implements DummyDao {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#createWithException(java.lang.String,
|
||||
* java.lang.String, java.lang.String, java.lang.String, java.lang.String)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.ldap.transaction.support.DummyDao#createWithException(java.lang
|
||||
* .String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void createWithException(String country, String company, String fullname, String lastname, String description) {
|
||||
public void createWithException(String country, String company, String fullname, String lastname,
|
||||
String description) {
|
||||
create(country, company, fullname, lastname, description);
|
||||
throw new DummyException("This method failed");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#create(java.lang.String,
|
||||
* java.lang.String, java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
@@ -70,7 +73,7 @@ public class LdapAndJdbcDummyDaoImpl implements DummyDao {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#update(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
*/
|
||||
@@ -80,15 +83,16 @@ public class LdapAndJdbcDummyDaoImpl implements DummyDao {
|
||||
ctx.setAttributeValue("description", description);
|
||||
|
||||
ldapTemplate.modifyAttributes(ctx);
|
||||
jdbcTemplate.update("update PERSON set lastname=?, description = ? where fullname = ?", new Object[] {
|
||||
lastname, description, fullname });
|
||||
jdbcTemplate.update("update PERSON set lastname=?, description = ? where fullname = ?",
|
||||
new Object[] { lastname, description, fullname });
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#updateWithException(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.ldap.transaction.support.DummyDao#updateWithException(java.lang
|
||||
* .String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void updateWithException(String dn, String fullname, String lastname, String description) {
|
||||
update(dn, fullname, lastname, description);
|
||||
@@ -97,9 +101,10 @@ public class LdapAndJdbcDummyDaoImpl implements DummyDao {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#updateAndRename(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.ldap.transaction.support.DummyDao#updateAndRename(java.lang.
|
||||
* String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void updateAndRename(String dn, String newDn, String description) {
|
||||
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
|
||||
@@ -111,9 +116,10 @@ public class LdapAndJdbcDummyDaoImpl implements DummyDao {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#updateAndRenameWithException(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.ldap.transaction.support.DummyDao#updateAndRenameWithException(
|
||||
* java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void updateAndRenameWithException(String dn, String newDn, String description) {
|
||||
updateAndRename(dn, newDn, description);
|
||||
@@ -122,9 +128,10 @@ public class LdapAndJdbcDummyDaoImpl implements DummyDao {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#modifyAttributes(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.ldap.transaction.support.DummyDao#modifyAttributes(java.lang.
|
||||
* String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void modifyAttributes(String dn, String lastName, String description) {
|
||||
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
|
||||
@@ -136,9 +143,10 @@ public class LdapAndJdbcDummyDaoImpl implements DummyDao {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#modifyAttributesWithException(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.ldap.transaction.support.DummyDao#modifyAttributesWithException
|
||||
* (java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void modifyAttributesWithException(String dn, String lastName, String description) {
|
||||
modifyAttributes(dn, lastName, description);
|
||||
@@ -147,7 +155,7 @@ public class LdapAndJdbcDummyDaoImpl implements DummyDao {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#unbind(java.lang.String)
|
||||
*/
|
||||
public void unbind(String dn, String fullname) {
|
||||
@@ -157,8 +165,10 @@ public class LdapAndJdbcDummyDaoImpl implements DummyDao {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#unbindWithException(java.lang.String)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.ldap.transaction.support.DummyDao#unbindWithException(java.lang
|
||||
* .String)
|
||||
*/
|
||||
public void unbindWithException(String dn, String fullname) {
|
||||
unbind(dn, fullname);
|
||||
@@ -184,4 +194,5 @@ public class LdapAndJdbcDummyDaoImpl implements DummyDao {
|
||||
public void createRecursivelyAndUnbindSubnodeWithException() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,9 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Transactional
|
||||
public class LdapDummyDaoImpl implements DummyDao {
|
||||
|
||||
private static final boolean RECURSIVE = true;
|
||||
|
||||
private LdapTemplate ldapTemplate;
|
||||
|
||||
public void setLdapTemplate(LdapTemplate ldapTemplate) {
|
||||
@@ -32,26 +34,24 @@ public class LdapDummyDaoImpl implements DummyDao {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#createWithException(java.lang.String,
|
||||
* java.lang.String, java.lang.String, java.lang.String,
|
||||
* java.lang.String)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.ldap.transaction.support.DummyDao#createWithException(java.lang
|
||||
* .String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void createWithException(String country, String company,
|
||||
String fullname, String lastname, String description) {
|
||||
public void createWithException(String country, String company, String fullname, String lastname,
|
||||
String description) {
|
||||
create(country, company, fullname, lastname, description);
|
||||
throw new DummyException("This method failed");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#create(java.lang.String,
|
||||
* java.lang.String, java.lang.String, java.lang.String,
|
||||
* java.lang.String)
|
||||
* java.lang.String, java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void create(String country, String company, String fullname,
|
||||
String lastname, String description) {
|
||||
public void create(String country, String company, String fullname, String lastname, String description) {
|
||||
DistinguishedName dn = new DistinguishedName();
|
||||
dn.add("ou", country);
|
||||
dn.add("ou", company);
|
||||
@@ -67,12 +67,11 @@ public class LdapDummyDaoImpl implements DummyDao {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#update(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
* java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void update(String dn, String fullname, String lastname,
|
||||
String description) {
|
||||
public void update(String dn, String fullname, String lastname, String description) {
|
||||
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
|
||||
ctx.setAttributeValue("sn", lastname);
|
||||
ctx.setAttributeValue("description", description);
|
||||
@@ -82,21 +81,22 @@ public class LdapDummyDaoImpl implements DummyDao {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#updateWithException(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.ldap.transaction.support.DummyDao#updateWithException(java.lang
|
||||
* .String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void updateWithException(String dn, String fullname,
|
||||
String lastname, String description) {
|
||||
public void updateWithException(String dn, String fullname, String lastname, String description) {
|
||||
update(dn, fullname, lastname, description);
|
||||
throw new DummyException("This method failed.");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#updateAndRename(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.ldap.transaction.support.DummyDao#updateAndRename(java.lang.
|
||||
* String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void updateAndRename(String dn, String newDn, String description) {
|
||||
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
|
||||
@@ -108,21 +108,22 @@ public class LdapDummyDaoImpl implements DummyDao {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#updateAndRenameWithException(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.ldap.transaction.support.DummyDao#updateAndRenameWithException(
|
||||
* java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void updateAndRenameWithException(String dn, String newDn,
|
||||
String description) {
|
||||
public void updateAndRenameWithException(String dn, String newDn, String description) {
|
||||
updateAndRename(dn, newDn, description);
|
||||
throw new DummyException("This method failed.");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#modifyAttributes(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.ldap.transaction.support.DummyDao#modifyAttributes(java.lang.
|
||||
* String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void modifyAttributes(String dn, String lastName, String description) {
|
||||
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
|
||||
@@ -134,19 +135,19 @@ public class LdapDummyDaoImpl implements DummyDao {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#modifyAttributesWithException(java.lang.String,
|
||||
* java.lang.String, java.lang.String)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.ldap.transaction.support.DummyDao#modifyAttributesWithException
|
||||
* (java.lang.String, java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void modifyAttributesWithException(String dn, String lastName,
|
||||
String description) {
|
||||
public void modifyAttributesWithException(String dn, String lastName, String description) {
|
||||
modifyAttributes(dn, lastName, description);
|
||||
throw new DummyException("This method failed.");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#unbind(java.lang.String)
|
||||
*/
|
||||
public void unbind(String dn, String fullname) {
|
||||
@@ -155,8 +156,10 @@ public class LdapDummyDaoImpl implements DummyDao {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.ldap.transaction.support.DummyDao#unbindWithException(java.lang.String)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.ldap.transaction.support.DummyDao#unbindWithException(java.lang
|
||||
* .String)
|
||||
*/
|
||||
public void unbindWithException(String dn, String fullname) {
|
||||
unbind(dn, fullname);
|
||||
@@ -177,7 +180,7 @@ public class LdapDummyDaoImpl implements DummyDao {
|
||||
@Override
|
||||
public void createRecursivelyAndUnbindSubnode() {
|
||||
DirContextAdapter ctx = new DirContextAdapter();
|
||||
ctx.setAttributeValues("objectclass", new String[]{"top", "organizationalUnit"});
|
||||
ctx.setAttributeValues("objectclass", new String[] { "top", "organizationalUnit" });
|
||||
ctx.setAttributeValue("ou", "dummy");
|
||||
ctx.setAttributeValue("description", "dummy description");
|
||||
|
||||
@@ -192,4 +195,5 @@ public class LdapDummyDaoImpl implements DummyDao {
|
||||
createRecursivelyAndUnbindSubnode();
|
||||
throw new DummyException("This method failed");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ public class DummyDaoLdapAndHibernateImpl extends HibernateDaoSupport implements
|
||||
ldapTemplate.bind(dn, ctx, null);
|
||||
this.getHibernateTemplate().saveOrUpdate(person);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void createWithException(OrgPerson person) {
|
||||
@@ -46,8 +45,7 @@ public class DummyDaoLdapAndHibernateImpl extends HibernateDaoSupport implements
|
||||
ldapTemplate.modifyAttributes(dn, ctx.getModificationItems());
|
||||
}
|
||||
|
||||
public void modifyAttributesWithException(String dn, String lastName,
|
||||
String description) {
|
||||
public void modifyAttributesWithException(String dn, String lastName, String description) {
|
||||
modifyAttributes(dn, lastName, description);
|
||||
throw new DummyException("This method failed.");
|
||||
}
|
||||
@@ -95,13 +93,11 @@ public class DummyDaoLdapAndHibernateImpl extends HibernateDaoSupport implements
|
||||
throw new DummyException("This method failed");
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setLdapTemplate(LdapTemplate ldapTemplate) {
|
||||
this.ldapTemplate = ldapTemplate;
|
||||
}
|
||||
|
||||
private String prepareDn(OrgPerson person){
|
||||
private String prepareDn(OrgPerson person) {
|
||||
return "cn=" + person.getFullname() + ",ou=" + person.getCompany() + ",ou=" + person.getCountry();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,23 +2,24 @@ package org.springframework.ldap.itest.transaction.compensating.manager.hibernat
|
||||
|
||||
/**
|
||||
* Pojo for use with the ContextSourceAndHibernateTransactionManager integration tests
|
||||
*
|
||||
* @author Hans Westerbeek
|
||||
*
|
||||
*/
|
||||
public class OrgPerson{
|
||||
|
||||
public class OrgPerson {
|
||||
|
||||
private Integer id;
|
||||
|
||||
|
||||
private String fullname;
|
||||
|
||||
private String lastname;
|
||||
|
||||
private String company;
|
||||
|
||||
|
||||
private String country;
|
||||
|
||||
|
||||
private String description;
|
||||
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -43,7 +44,6 @@ public class OrgPerson{
|
||||
this.lastname = lastname;
|
||||
}
|
||||
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
@@ -119,5 +119,5 @@ public class OrgPerson{
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.springframework.ldap.itest.transaction.compensating.manager.hibernate;
|
||||
|
||||
public interface OrgPersonDao {
|
||||
|
||||
void createWithException(OrgPerson person);
|
||||
|
||||
void create(OrgPerson person);
|
||||
@@ -20,4 +21,5 @@ public interface OrgPersonDao {
|
||||
void unbind(OrgPerson person);
|
||||
|
||||
void unbindWithException(OrgPerson person);
|
||||
|
||||
}
|
||||
|
||||
@@ -26,11 +26,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class LdapConditionallyFilteredTestRunner extends SpringJUnit4ClassRunner {
|
||||
|
||||
/**
|
||||
* Constructs a new {@code SpringJUnit4ClassRunner} and initializes a
|
||||
* {@link org.springframework.test.context.TestContextManager} to provide Spring testing functionality to
|
||||
* standard JUnit tests.
|
||||
*
|
||||
* {@link org.springframework.test.context.TestContextManager} to provide Spring
|
||||
* testing functionality to standard JUnit tests.
|
||||
* @param clazz the test class to be run
|
||||
* @see #createTestContextManager(Class)
|
||||
*/
|
||||
@@ -41,9 +41,11 @@ public class LdapConditionallyFilteredTestRunner extends SpringJUnit4ClassRunner
|
||||
if (noadtest != null) {
|
||||
try {
|
||||
filter(Categories.CategoryFilter.exclude(NoAdTest.class));
|
||||
} catch (NoTestsRemainException e) {
|
||||
}
|
||||
catch (NoTestsRemainException e) {
|
||||
// Nothing to do here.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public abstract class AbstractLdapTemplateIntegrationTest {
|
||||
@Before
|
||||
public void cleanAndSetup() throws NamingException, IOException {
|
||||
Resource ldifResource = getLdifFileResource();
|
||||
if(!LdapUtils.newLdapName(base).equals(LdapUtils.newLdapName(DEFAULT_BASE))) {
|
||||
if (!LdapUtils.newLdapName(base).equals(LdapUtils.newLdapName(DEFAULT_BASE))) {
|
||||
List<String> lines = IOUtils.readLines(ldifResource.getInputStream());
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
@@ -82,4 +82,5 @@ public abstract class AbstractLdapTemplateIntegrationTest {
|
||||
protected Name getRoot() {
|
||||
return LdapUtils.emptyLdapName();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
*
|
||||
* @author Josh Cummings
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapClientTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapClientTestContext.xml" })
|
||||
public class DefaultLdapClientAuthenticationITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -65,9 +65,7 @@ public class DefaultLdapClientAuthenticationITest extends AbstractLdapTemplateIn
|
||||
public void testAuthenticateWithLdapQuery() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
|
||||
LdapQuery query = LdapQueryBuilder.query()
|
||||
.where("objectclass").is("person")
|
||||
.and("uid").is("some.person3");
|
||||
LdapQuery query = LdapQueryBuilder.query().where("objectclass").is("person").and("uid").is("some.person3");
|
||||
tested.authenticate().query(query).password("password").execute();
|
||||
}
|
||||
|
||||
@@ -77,8 +75,8 @@ public class DefaultLdapClientAuthenticationITest extends AbstractLdapTemplateIn
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
|
||||
LdapQuery query = LdapQueryBuilder.query().filter(filter);
|
||||
assertThatExceptionOfType(AuthenticationException.class).isThrownBy(() ->
|
||||
tested.authenticate().query(query).password("invalidpassword").execute());
|
||||
assertThatExceptionOfType(AuthenticationException.class)
|
||||
.isThrownBy(() -> tested.authenticate().query(query).password("invalidpassword").execute());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,11 +84,9 @@ public class DefaultLdapClientAuthenticationITest extends AbstractLdapTemplateIn
|
||||
public void testAuthenticateWithLdapQueryAndInvalidPassword() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
|
||||
LdapQuery query = LdapQueryBuilder.query()
|
||||
.where("objectclass").is("person")
|
||||
.and("uid").is("some.person3");
|
||||
assertThatExceptionOfType(AuthenticationException.class).isThrownBy(() ->
|
||||
tested.authenticate().query(query).password("invalidpassword").execute());
|
||||
LdapQuery query = LdapQueryBuilder.query().where("objectclass").is("person").and("uid").is("some.person3");
|
||||
assertThatExceptionOfType(AuthenticationException.class)
|
||||
.isThrownBy(() -> tested.authenticate().query(query).password("invalidpassword").execute());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -103,7 +99,8 @@ public class DefaultLdapClientAuthenticationITest extends AbstractLdapTemplateIn
|
||||
try {
|
||||
DirContextAdapter adapter = (DirContextAdapter) ctx.lookup(entry.getRelativeDn());
|
||||
assertThat(adapter.getStringAttribute("cn")).isEqualTo("Some Person3");
|
||||
} catch (NamingException e) {
|
||||
}
|
||||
catch (NamingException e) {
|
||||
throw new RuntimeException("Failed to lookup " + entry.getRelativeDn(), e);
|
||||
}
|
||||
};
|
||||
@@ -116,9 +113,7 @@ public class DefaultLdapClientAuthenticationITest extends AbstractLdapTemplateIn
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithLdapQueryAndMapper() {
|
||||
LdapQuery query = LdapQueryBuilder.query()
|
||||
.where("objectclass").is("person")
|
||||
.and("uid").is("some.person3");
|
||||
LdapQuery query = LdapQueryBuilder.query().where("objectclass").is("person").and("uid").is("some.person3");
|
||||
DirContextOperations ctx = tested.authenticate().query(query).password("password")
|
||||
.execute(new LookupAttemptingCallback());
|
||||
|
||||
@@ -129,11 +124,9 @@ public class DefaultLdapClientAuthenticationITest extends AbstractLdapTemplateIn
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithLdapQueryAndMapperAndInvalidPassword() {
|
||||
LdapQuery query = LdapQueryBuilder.query()
|
||||
.where("objectclass").is("person")
|
||||
.and("uid").is("some.person3");
|
||||
assertThatExceptionOfType(AuthenticationException.class).isThrownBy(() ->
|
||||
tested.authenticate().query(query).password("invalidpassword").execute(new LookupAttemptingCallback()));
|
||||
LdapQuery query = LdapQueryBuilder.query().where("objectclass").is("person").and("uid").is("some.person3");
|
||||
assertThatExceptionOfType(AuthenticationException.class).isThrownBy(() -> tested.authenticate().query(query)
|
||||
.password("invalidpassword").execute(new LookupAttemptingCallback()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -142,19 +135,19 @@ public class DefaultLdapClientAuthenticationITest extends AbstractLdapTemplateIn
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
|
||||
LdapQuery query = LdapQueryBuilder.query().filter(filter);
|
||||
assertThatExceptionOfType(AuthenticationException.class).isThrownBy(() ->
|
||||
tested.authenticate().query(query).password("invalidpassword").execute());
|
||||
assertThatExceptionOfType(AuthenticationException.class)
|
||||
.isThrownBy(() -> tested.authenticate().query(query).password("invalidpassword").execute());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithFilterThatDoesNotMatchAnything() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(
|
||||
new EqualsFilter("uid", "some.person.that.isnt.there"));
|
||||
filter.and(new EqualsFilter("objectclass", "person"))
|
||||
.and(new EqualsFilter("uid", "some.person.that.isnt.there"));
|
||||
LdapQuery query = LdapQueryBuilder.query().filter(filter);
|
||||
assertThatExceptionOfType(EmptyResultDataAccessException.class).isThrownBy(() ->
|
||||
tested.authenticate().query(query).password("password").execute());
|
||||
assertThatExceptionOfType(EmptyResultDataAccessException.class)
|
||||
.isThrownBy(() -> tested.authenticate().query(query).password("password").execute());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -163,8 +156,8 @@ public class DefaultLdapClientAuthenticationITest extends AbstractLdapTemplateIn
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("cn", "Some Person"));
|
||||
LdapQuery query = LdapQueryBuilder.query().filter(filter);
|
||||
assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class).isThrownBy(() ->
|
||||
tested.authenticate().query(query).password("password").execute());
|
||||
assertThatExceptionOfType(IncorrectResultSizeDataAccessException.class)
|
||||
.isThrownBy(() -> tested.authenticate().query(query).password("password").execute());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -176,4 +169,5 @@ public class DefaultLdapClientAuthenticationITest extends AbstractLdapTemplateIn
|
||||
LookupAttemptingCallback callback = new LookupAttemptingCallback();
|
||||
tested.authenticate().query(query).password("password").execute(callback);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,16 +34,17 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Tests the bind and unbind methods of LdapTemplate. The test methods in this
|
||||
* class tests a little too much, but we need to clean up after binding, so the
|
||||
* most efficient way to test is to do it all in one test method. Also, the
|
||||
* methods in this class relies on that the lookup method works as it should -
|
||||
* that should be ok, since that is verified in a separate test class.
|
||||
*
|
||||
* Tests the bind and unbind methods of LdapTemplate. The test methods in this class tests
|
||||
* a little too much, but we need to clean up after binding, so the most efficient way to
|
||||
* test is to do it all in one test method. Also, the methods in this class relies on that
|
||||
* the lookup method works as it should - that should be ok, since that is verified in a
|
||||
* separate test class.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapClientTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapClientTestContext.xml" })
|
||||
public class DefaultLdapClientBindUnbindITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapClient tested;
|
||||
|
||||
@@ -80,8 +81,7 @@ public class DefaultLdapClientBindUnbindITest extends AbstractLdapTemplateIntegr
|
||||
@Test
|
||||
public void testBindAndUnbindWithDirContextAdapter() {
|
||||
DirContextAdapter adapter = new DirContextAdapter();
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top",
|
||||
"person" });
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
|
||||
adapter.setAttributeValue("cn", "Some Person4");
|
||||
adapter.setAttributeValue("sn", "Person4");
|
||||
|
||||
@@ -94,8 +94,7 @@ public class DefaultLdapClientBindUnbindITest extends AbstractLdapTemplateIntegr
|
||||
@Test
|
||||
public void testBindAndUnbindWithDirContextAdapterUsingLdapName() {
|
||||
DirContextAdapter adapter = new DirContextAdapter();
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top",
|
||||
"person" });
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
|
||||
adapter.setAttributeValue("cn", "Some Person4");
|
||||
adapter.setAttributeValue("sn", "Person4");
|
||||
|
||||
@@ -108,8 +107,7 @@ public class DefaultLdapClientBindUnbindITest extends AbstractLdapTemplateIntegr
|
||||
@Test
|
||||
public void testBindAndUnbindWithDirContextAdapterOnly() {
|
||||
DirContextAdapter adapter = new DirContextAdapter(LdapUtils.newLdapName(DN));
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top",
|
||||
"person" });
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
|
||||
adapter.setAttributeValue("cn", "Some Person4");
|
||||
adapter.setAttributeValue("sn", "Person4");
|
||||
|
||||
@@ -122,8 +120,7 @@ public class DefaultLdapClientBindUnbindITest extends AbstractLdapTemplateIntegr
|
||||
@Test
|
||||
public void testBindAndRebindWithDirContextAdapterOnly() {
|
||||
DirContextAdapter adapter = new DirContextAdapter(LdapUtils.newLdapName(DN));
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top",
|
||||
"person" });
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
|
||||
adapter.setAttributeValue("cn", "Some Person4");
|
||||
adapter.setAttributeValue("sn", "Person4");
|
||||
|
||||
@@ -160,8 +157,8 @@ public class DefaultLdapClientBindUnbindITest extends AbstractLdapTemplateIntegr
|
||||
}
|
||||
|
||||
private void verifyCleanup() {
|
||||
assertThatExceptionOfType(NameNotFoundException.class)
|
||||
.describedAs("NameNotFoundException expected")
|
||||
assertThatExceptionOfType(NameNotFoundException.class).describedAs("NameNotFoundException expected")
|
||||
.isThrownBy(() -> tested.search().name(DN).toEntry());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,10 +37,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link LdapClient}'s list methods.
|
||||
*
|
||||
*
|
||||
* @author Josh Cummings
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapClientTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapClientTestContext.xml" })
|
||||
public class DefaultLdapClientListITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -173,4 +173,5 @@ public class DefaultLdapClientListITest extends AbstractLdapTemplateIntegrationT
|
||||
});
|
||||
assertThat(handler.getNoOfRows()).isEqualTo(3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Josh Cummings
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapClientTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapClientTestContext.xml" })
|
||||
public class DefaultLdapClientLookupITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -45,8 +45,8 @@ public class DefaultLdapClientLookupITest extends AbstractLdapTemplateIntegratio
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory (
|
||||
* {@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
* {@link org.springframework.ldap.core.support.DefaultDirObjectFactory}) being set in
|
||||
* the ContextSource.
|
||||
*/
|
||||
@Test
|
||||
public void testLookup_Plain() {
|
||||
@@ -59,8 +59,8 @@ public class DefaultLdapClientLookupITest extends AbstractLdapTemplateIntegratio
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory (
|
||||
* {@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
* {@link org.springframework.ldap.core.support.DefaultDirObjectFactory}) being set in
|
||||
* the ContextSource.
|
||||
*/
|
||||
@Test
|
||||
public void testLookupContextRoot() {
|
||||
@@ -82,7 +82,8 @@ public class DefaultLdapClientLookupITest extends AbstractLdapTemplateIntegratio
|
||||
@Test
|
||||
public void testLookup_AttributesMapper_LdapName() {
|
||||
AttributesMapper<Person> mapper = new PersonAttributesMapper();
|
||||
Person person = tested.search().name(LdapUtils.newLdapName("cn=Some Person2, ou=company1,ou=Sweden")).toObject(mapper);
|
||||
Person person = tested.search().name(LdapUtils.newLdapName("cn=Some Person2, ou=company1,ou=Sweden"))
|
||||
.toObject(mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).isEqualTo("Person2");
|
||||
@@ -90,17 +91,17 @@ public class DefaultLdapClientLookupITest extends AbstractLdapTemplateIntegratio
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@link AttributesMapper} that only maps a subset of the full
|
||||
* attributes list. Used in tests where the return attributes list has been
|
||||
* limited.
|
||||
*
|
||||
* An {@link AttributesMapper} that only maps a subset of the full attributes list.
|
||||
* Used in tests where the return attributes list has been limited.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
private static final class SubsetPersonAttributesMapper implements AttributesMapper<Person> {
|
||||
|
||||
/**
|
||||
* Maps the <code>cn</code> attribute into a {@link Person} object. Also
|
||||
* verifies that the other attributes haven't been set.
|
||||
*
|
||||
* Maps the <code>cn</code> attribute into a {@link Person} object. Also verifies
|
||||
* that the other attributes haven't been set.
|
||||
*
|
||||
* @see AttributesMapper#mapFromAttributes(Attributes)
|
||||
*/
|
||||
public Person mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
@@ -110,19 +111,20 @@ public class DefaultLdapClientLookupITest extends AbstractLdapTemplateIntegratio
|
||||
assertThat(attributes.get("description")).as("description should be null").isNull();
|
||||
return person;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that only the subset is used when specifying a subset of the
|
||||
* available attributes as return attributes.
|
||||
* Verifies that only the subset is used when specifying a subset of the available
|
||||
* attributes as return attributes.
|
||||
*/
|
||||
@Test
|
||||
public void testLookup_ReturnAttributes_AttributesMapper() {
|
||||
AttributesMapper<Person> mapper = new SubsetPersonAttributesMapper();
|
||||
|
||||
Person person = tested.search().query((builder) -> builder
|
||||
.base("cn=Some Person2, ou=company1,ou=Sweden")
|
||||
.attributes("cn")).toObject(mapper);
|
||||
Person person = tested.search()
|
||||
.query((builder) -> builder.base("cn=Some Person2, ou=company1,ou=Sweden").attributes("cn"))
|
||||
.toObject(mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).as("lastName should not be set").isNull();
|
||||
@@ -130,16 +132,16 @@ public class DefaultLdapClientLookupITest extends AbstractLdapTemplateIntegratio
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that only the subset is used when specifying a subset of the
|
||||
* available attributes as return attributes. Uses LdapName instead
|
||||
* of plain string as name.
|
||||
* Verifies that only the subset is used when specifying a subset of the available
|
||||
* attributes as return attributes. Uses LdapName instead of plain string as name.
|
||||
*/
|
||||
@Test
|
||||
public void testLookup_ReturnAttributes_AttributesMapper_LdapName() {
|
||||
AttributesMapper<Person> mapper = new SubsetPersonAttributesMapper();
|
||||
Person person = tested.search().query((builder) -> builder
|
||||
.base(LdapUtils.newLdapName("cn=Some Person2, ou=company1,ou=Sweden"))
|
||||
.attributes("cn")).toObject(mapper);
|
||||
Person person = tested
|
||||
.search().query((builder) -> builder
|
||||
.base(LdapUtils.newLdapName("cn=Some Person2, ou=company1,ou=Sweden")).attributes("cn"))
|
||||
.toObject(mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).as("lastName should not be set").isNull();
|
||||
@@ -148,8 +150,8 @@ public class DefaultLdapClientLookupITest extends AbstractLdapTemplateIntegratio
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory (
|
||||
* {@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
* {@link org.springframework.ldap.core.support.DefaultDirObjectFactory}) being set in
|
||||
* the ContextSource.
|
||||
*/
|
||||
@Test
|
||||
public void testLookup_ContextMapper() {
|
||||
@@ -162,15 +164,16 @@ public class DefaultLdapClientLookupITest extends AbstractLdapTemplateIntegratio
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that only the subset is used when specifying a subset of the
|
||||
* available attributes as return attributes.
|
||||
* Verifies that only the subset is used when specifying a subset of the available
|
||||
* attributes as return attributes.
|
||||
*/
|
||||
@Test
|
||||
public void testLookup_ReturnAttributes_ContextMapper() {
|
||||
ContextMapper<Person> mapper = new PersonContextMapper();
|
||||
|
||||
Person person = tested.search().query((builder) -> builder
|
||||
.base("cn=Some Person2, ou=company1,ou=Sweden").attributes("cn")).toObject(mapper);
|
||||
Person person = tested.search()
|
||||
.query((builder) -> builder.base("cn=Some Person2, ou=company1,ou=Sweden").attributes("cn"))
|
||||
.toObject(mapper);
|
||||
|
||||
assertThat(person.getFullname()).isEqualTo("Some Person2");
|
||||
assertThat(person.getLastname()).as("lastName should not be set").isNull();
|
||||
@@ -186,4 +189,5 @@ public class DefaultLdapClientLookupITest extends AbstractLdapTemplateIntegratio
|
||||
assertThat(result.getDn()).isEqualTo(expectedName);
|
||||
assertThat(result.getNameInNamespace()).isEqualTo("cn=Some Person2,ou=company1,ou=Sweden," + base);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,10 +32,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests {@link LdapClient}'s lookup methods.
|
||||
*
|
||||
*
|
||||
* @author Josh Cummings
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapClientTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapClientTestContext.xml" })
|
||||
public class DefaultLdapClientLookupMultiRdnITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -45,10 +45,9 @@ public class DefaultLdapClientLookupMultiRdnITest extends AbstractLdapTemplateIn
|
||||
return new ClassPathResource("/setup_data_multi_rdn.ldif");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Verifies that we can lookup an entry that has a multi-valued rdn, which
|
||||
* means more than one attribute is part of the relative DN for the entry.
|
||||
* Verifies that we can lookup an entry that has a multi-valued rdn, which means more
|
||||
* than one attribute is part of the relative DN for the entry.
|
||||
*/
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
@@ -61,9 +60,9 @@ public class DefaultLdapClientLookupMultiRdnITest extends AbstractLdapTemplateIn
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that we can lookup an entry that has a multi-valued rdn, which
|
||||
* means more than one attribute is part of the relative DN for the entry.
|
||||
*
|
||||
* Verifies that we can lookup an entry that has a multi-valued rdn, which means more
|
||||
* than one attribute is part of the relative DN for the entry.
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
@@ -81,4 +80,5 @@ public class DefaultLdapClientLookupMultiRdnITest extends AbstractLdapTemplateIn
|
||||
assertThat(result.getDn().toString()).isEqualTo("cn=Some Person+sn=Person,ou=company1,ou=Norway");
|
||||
assertThat(result.getNameInNamespace()).isEqualTo("cn=Some Person+sn=Person,ou=company1,ou=Norway," + base);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,13 +44,14 @@ import static org.assertj.core.api.Assertions.fail;
|
||||
/**
|
||||
* Tests {@link LdapClient}'s modification methods (rebind and modifyAttributes)
|
||||
*
|
||||
* <p>It also illustrates the use of DirContextAdapter as a means of getting
|
||||
* <p>
|
||||
* It also illustrates the use of DirContextAdapter as a means of getting
|
||||
* {@code ModificationItems}, in order to avoid doing a full rebind and use
|
||||
* {@code modify()} instead.
|
||||
*
|
||||
*
|
||||
* @author Josh Cummings
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapClientTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapClientTestContext.xml" })
|
||||
public class DefaultLdapClientModifyITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -158,8 +159,8 @@ public class DefaultLdapClientModifyITest extends AbstractLdapTemplateIntegratio
|
||||
|
||||
/**
|
||||
* Test written originally to verify that duplicates are allowed on ordered
|
||||
* attributes, but had to be changed since Apache DS seems to disallow
|
||||
* duplicates even for ordered attributes.
|
||||
* attributes, but had to be changed since Apache DS seems to disallow duplicates even
|
||||
* for ordered attributes.
|
||||
*/
|
||||
@Test
|
||||
public void testModifyAttributes_MultiValueAddDuplicateToOrdered() {
|
||||
@@ -180,16 +181,16 @@ public class DefaultLdapClientModifyITest extends AbstractLdapTemplateIntegratio
|
||||
|
||||
@Test
|
||||
public void testModifyAttributes_Plain() {
|
||||
ModificationItem item = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("description",
|
||||
"Some other description"));
|
||||
ModificationItem item = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
|
||||
new BasicAttribute("description", "Some other description"));
|
||||
tested.modify(PERSON4_DN).attributes(item).execute();
|
||||
verifyBoundCorrectData();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModifyAttributes_LdapName() {
|
||||
ModificationItem item = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("description",
|
||||
"Some other description"));
|
||||
ModificationItem item = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
|
||||
new BasicAttribute("description", "Some other description"));
|
||||
tested.modify(LdapUtils.newLdapName(PERSON4_DN)).attributes(item).execute();
|
||||
verifyBoundCorrectData();
|
||||
}
|
||||
@@ -211,9 +212,9 @@ public class DefaultLdapClientModifyITest extends AbstractLdapTemplateIntegratio
|
||||
}
|
||||
|
||||
/**
|
||||
* Demonstrates how the DirContextAdapter can be used to automatically keep
|
||||
* track of changes of the attributes and deliver ModificationItems to use
|
||||
* in moifyAttributes().
|
||||
* Demonstrates how the DirContextAdapter can be used to automatically keep track of
|
||||
* changes of the attributes and deliver ModificationItems to use in
|
||||
* moifyAttributes().
|
||||
*/
|
||||
@Test
|
||||
public void testModifyAttributes_DirContextAdapter() {
|
||||
@@ -248,4 +249,5 @@ public class DefaultLdapClientModifyITest extends AbstractLdapTemplateIntegratio
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person4");
|
||||
assertThat(result.getStringAttribute("description")).isEqualTo("Some other description");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,12 +35,12 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Tests {@code LdapClient}'s recursive modification methods (unbind and the protected delete
|
||||
* methods).
|
||||
*
|
||||
* Tests {@code LdapClient}'s recursive modification methods (unbind and the protected
|
||||
* delete methods).
|
||||
*
|
||||
* @author Josh Cummings
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapClientTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapClientTestContext.xml" })
|
||||
public class DefaultLdapClientRecursiveDeleteITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -126,4 +126,5 @@ public class DefaultLdapClientRecursiveDeleteITest extends AbstractLdapTemplateI
|
||||
.describedAs("Expected entry '" + dn + "' to be non-existent")
|
||||
.isThrownBy(() -> tested.list(dn).toList(NameClassPair::getName));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,10 +37,10 @@ import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Tests {@link LdapClient}'s rename methods.
|
||||
*
|
||||
*
|
||||
* @author Josh Cummings
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapClientTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapClientTestContext.xml" })
|
||||
public class DefaultLdapClientRenameITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -99,4 +99,5 @@ public class DefaultLdapClientRenameITest extends AbstractLdapTemplateIntegratio
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person6");
|
||||
assertThat(result.getStringAttribute("description")).isEqualTo("Some description");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,10 +49,10 @@ import static org.springframework.ldap.query.LdapQueryBuilder.query;
|
||||
|
||||
/**
|
||||
* Tests for {@link LdapClient}'s search methods.
|
||||
*
|
||||
*
|
||||
* @author Josh Cummings
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapClientTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapClientTestContext.xml" })
|
||||
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@@ -106,9 +106,8 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search().query(query()
|
||||
.base(BASE_STRING)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"))
|
||||
List<Object> list = tested.search()
|
||||
.query(query().base(BASE_STRING).where("objectclass").is("person").and("sn").is("Person2"))
|
||||
.toList(attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
@@ -118,35 +117,30 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search().query(query()
|
||||
.base(BASE_STRING)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"))
|
||||
List<Object> list = tested.search()
|
||||
.query(query().base(BASE_STRING).where("objectclass").is("person").and("sn").is("Person2"))
|
||||
.toStream(attributesMapper).collect(Collectors.toList());
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper_FewerAttributes() {
|
||||
attributesMapper.setExpectedAttributes(new String[] {"cn"});
|
||||
attributesMapper.setExpectedValues(new String[]{"Some Person2"});
|
||||
attributesMapper.setExpectedAttributes(new String[] { "cn" });
|
||||
attributesMapper.setExpectedValues(new String[] { "Some Person2" });
|
||||
|
||||
List<Object> list = tested.search().query(query()
|
||||
.base(BASE_STRING)
|
||||
.attributes("cn")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"))
|
||||
List<Object> list = tested.search().query(
|
||||
query().base(BASE_STRING).attributes("cn").where("objectclass").is("person").and("sn").is("Person2"))
|
||||
.toList(attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchForStream_LdapQuery_AttributesMapper_FewerAttributes() {
|
||||
attributesMapper.setExpectedAttributes(new String[] {"cn"});
|
||||
attributesMapper.setExpectedValues(new String[]{"Some Person2"});
|
||||
attributesMapper.setExpectedAttributes(new String[] { "cn" });
|
||||
attributesMapper.setExpectedValues(new String[] { "Some Person2" });
|
||||
|
||||
List<Object> list = tested.search().query(query()
|
||||
.base(BASE_STRING)
|
||||
.attributes("cn")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"))
|
||||
List<Object> list = tested.search().query(
|
||||
query().base(BASE_STRING).attributes("cn").where("objectclass").is("person").and("sn").is("Person2"))
|
||||
.toStream(attributesMapper).collect(Collectors.toList());
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
@@ -156,11 +150,8 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search().query(query()
|
||||
.base(BASE_STRING)
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"))
|
||||
.toList(attributesMapper);
|
||||
List<Object> list = tested.search().query(query().base(BASE_STRING).searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2")).toList(attributesMapper);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@@ -169,11 +160,9 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search().query(query()
|
||||
.base(BASE_STRING)
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"))
|
||||
.toStream(attributesMapper).collect(Collectors.toList());
|
||||
List<Object> list = tested.search().query(query().base(BASE_STRING).searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2")).toStream(attributesMapper)
|
||||
.collect(Collectors.toList());
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@@ -182,10 +171,8 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search().query(query()
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"))
|
||||
List<Object> list = tested.search().query(query().base("ou=company1,ou=Sweden")
|
||||
.searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2"))
|
||||
.toList(attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
@@ -195,9 +182,8 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search().query(query()
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
List<Object> list = tested
|
||||
.search().query(query().base("ou=company1,ou=Sweden").searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"))
|
||||
.toStream(attributesMapper).collect(Collectors.toList());
|
||||
assertThat(list).hasSize(1);
|
||||
@@ -208,8 +194,7 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search().query(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"))
|
||||
List<Object> list = tested.search().query(query().where("objectclass").is("person").and("sn").is("Person2"))
|
||||
.toList(attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
@@ -219,8 +204,7 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search().query(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"))
|
||||
List<Object> list = tested.search().query(query().where("objectclass").is("person").and("sn").is("Person2"))
|
||||
.toStream(attributesMapper).collect(Collectors.toList());
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
@@ -230,9 +214,8 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search().query(query()
|
||||
.base("ou=Norway")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"))
|
||||
List<Object> list = tested.search()
|
||||
.query(query().base("ou=Norway").where("objectclass").is("person").and("sn").is("Person2"))
|
||||
.toList(attributesMapper);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
@@ -242,9 +225,8 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search().query(query()
|
||||
.base("ou=Norway")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"))
|
||||
List<Object> list = tested.search()
|
||||
.query(query().base("ou=Norway").where("objectclass").is("person").and("sn").is("Person2"))
|
||||
.toStream(attributesMapper).collect(Collectors.toList());
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
@@ -253,8 +235,8 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
public void testSearch_SearchScope_AttributesMapper() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
List<Object> list = tested.search().query(query().base(BASE_STRING)
|
||||
.searchScope(SearchScope.SUBTREE).filter(FILTER_STRING))
|
||||
List<Object> list = tested.search()
|
||||
.query(query().base(BASE_STRING).searchScope(SearchScope.SUBTREE).filter(FILTER_STRING))
|
||||
.toList(attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
@@ -264,11 +246,8 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
attributesMapper.setExpectedAttributes(CN_SN_ATTRS);
|
||||
attributesMapper.setExpectedValues(CN_SN_VALUES);
|
||||
attributesMapper.setAbsentAttributes(ABSENT_ATTRIBUTES);
|
||||
List<Object> list = tested.search().query(query().base(BASE_STRING)
|
||||
.searchScope(SearchScope.SUBTREE)
|
||||
.attributes(CN_SN_ATTRS)
|
||||
.filter(FILTER_STRING))
|
||||
.toList(attributesMapper);
|
||||
List<Object> list = tested.search().query(query().base(BASE_STRING).searchScope(SearchScope.SUBTREE)
|
||||
.attributes(CN_SN_ATTRS).filter(FILTER_STRING)).toList(attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -285,8 +264,9 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
public void testSearch_SearchScope_AttributesMapper_Name() {
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
List<Object> list = tested.search().query(query().base(BASE_NAME).searchScope(SearchScope.SUBTREE)
|
||||
.filter(FILTER_STRING)).toList(attributesMapper);
|
||||
List<Object> list = tested.search()
|
||||
.query(query().base(BASE_NAME).searchScope(SearchScope.SUBTREE).filter(FILTER_STRING))
|
||||
.toList(attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -295,8 +275,9 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
attributesMapper.setExpectedAttributes(CN_SN_ATTRS);
|
||||
attributesMapper.setExpectedValues(CN_SN_VALUES);
|
||||
attributesMapper.setAbsentAttributes(ABSENT_ATTRIBUTES);
|
||||
List<Object> list = tested.search().query(query().base(BASE_NAME).searchScope(SearchScope.SUBTREE)
|
||||
.attributes(CN_SN_ATTRS).filter(FILTER_STRING)).toList(attributesMapper);
|
||||
List<Object> list = tested.search().query(
|
||||
query().base(BASE_NAME).searchScope(SearchScope.SUBTREE).attributes(CN_SN_ATTRS).filter(FILTER_STRING))
|
||||
.toList(attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -324,10 +305,10 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
.toObject((Object ctx) -> ctx);
|
||||
}
|
||||
|
||||
@Test//(expected = EmptyResultDataAccessException.class)
|
||||
@Test // (expected = EmptyResultDataAccessException.class)
|
||||
public void testSearchForObjectNoHits() {
|
||||
Object result = tested.search().query(query().base(BASE_STRING)
|
||||
.filter("(&(objectclass=person)(sn=Person does not exist))"))
|
||||
Object result = tested.search()
|
||||
.query(query().base(BASE_STRING).filter("(&(objectclass=person)(sn=Person does not exist))"))
|
||||
.toObject((Object ctx) -> ctx);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
@@ -336,8 +317,9 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
public void testSearch_SearchScope_ContextMapper() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search().query(query().base(BASE_STRING).searchScope(SearchScope.SUBTREE)
|
||||
.filter(FILTER_STRING)).toList(contextMapper);
|
||||
List<DirContextAdapter> list = tested.search()
|
||||
.query(query().base(BASE_STRING).searchScope(SearchScope.SUBTREE).filter(FILTER_STRING))
|
||||
.toList(contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -364,9 +346,8 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
public void testSearch_ContextMapper_LdapQuery() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search().query(query()
|
||||
.base(BASE_NAME)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"))
|
||||
List<DirContextAdapter> list = tested.search()
|
||||
.query(query().base(BASE_NAME).where("objectclass").is("person").and("sn").is("Person2"))
|
||||
.toList(contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
@@ -375,9 +356,8 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
public void testSearchForStream_ContextMapper_LdapQuery() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search().query(query()
|
||||
.base(BASE_NAME)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"))
|
||||
List<DirContextAdapter> list = tested.search()
|
||||
.query(query().base(BASE_NAME).where("objectclass").is("person").and("sn").is("Person2"))
|
||||
.toStream(contextMapper).collect(Collectors.toList());
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
@@ -386,9 +366,8 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
public void testSearch_ContextMapper_LdapQuery_NoBase() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search().query(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"))
|
||||
.toList(contextMapper);
|
||||
List<DirContextAdapter> list = tested.search()
|
||||
.query(query().where("objectclass").is("person").and("sn").is("Person2")).toList(contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -396,9 +375,9 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
public void testSearchForStream_ContextMapper_LdapQuery_NoBase() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search().query(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"))
|
||||
.toStream(contextMapper).collect(Collectors.toList());
|
||||
List<DirContextAdapter> list = tested.search()
|
||||
.query(query().where("objectclass").is("person").and("sn").is("Person2")).toStream(contextMapper)
|
||||
.collect(Collectors.toList());
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -406,11 +385,8 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
public void testSearch_ContextMapper_LdapQuery_SearchScope() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search().query(query()
|
||||
.base(BASE_NAME)
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"))
|
||||
.toList(contextMapper);
|
||||
List<DirContextAdapter> list = tested.search().query(query().base(BASE_NAME).searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2")).toList(contextMapper);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@@ -418,11 +394,9 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
public void testSearchForStream_ContextMapper_LdapQuery_SearchScope() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search().query(query()
|
||||
.base(BASE_NAME)
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"))
|
||||
.toStream(contextMapper).collect(Collectors.toList());
|
||||
List<DirContextAdapter> list = tested.search().query(query().base(BASE_NAME).searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2")).toStream(contextMapper)
|
||||
.collect(Collectors.toList());
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@@ -430,10 +404,8 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
public void testSearch_ContextMapper_LdapQuery_SearchScope_CorrectBase() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search().query(query()
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"))
|
||||
List<DirContextAdapter> list = tested.search().query(query().base("ou=company1,ou=Sweden")
|
||||
.searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2"))
|
||||
.toList(contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
@@ -442,9 +414,8 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
public void testSearchForStream_ContextMapper_LdapQuery_SearchScope_CorrectBase() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search().query(query()
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
List<DirContextAdapter> list = tested
|
||||
.search().query(query().base("ou=company1,ou=Sweden").searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"))
|
||||
.toStream(contextMapper).collect(Collectors.toList());
|
||||
assertThat(list).hasSize(1);
|
||||
@@ -453,28 +424,26 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
@Test
|
||||
public void testSearchForContext_LdapQuery() {
|
||||
ContextMapper<DirContextOperations> mapper = (result) -> (DirContextOperations) result;
|
||||
DirContextOperations result = tested.search().query(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2")).toObject(mapper);
|
||||
DirContextOperations result = tested.search()
|
||||
.query(query().where("objectclass").is("person").and("sn").is("Person2")).toObject(mapper);
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person2");
|
||||
}
|
||||
|
||||
@Test//(expected = EmptyResultDataAccessException.class)
|
||||
@Test // (expected = EmptyResultDataAccessException.class)
|
||||
public void testSearchForContext_LdapQuery_SearchScopeNotFound() {
|
||||
Object result = tested.search().query(query()
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2")).toObject(attributesMapper);
|
||||
Object result = tested.search().query(
|
||||
query().searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2"))
|
||||
.toObject(attributesMapper);
|
||||
assertThat(result).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchForContext_LdapQuery_SearchScope_CorrectBase() {
|
||||
ContextMapper<DirContextOperations> mapper = (result) -> (DirContextOperations) result;
|
||||
DirContextOperations result =
|
||||
tested.search().query(query()
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.where("objectclass").is("person").and("sn").is("Person2")).toObject(mapper);
|
||||
DirContextOperations result = tested.search().query(query().searchScope(SearchScope.ONELEVEL)
|
||||
.base("ou=company1,ou=Sweden").where("objectclass").is("person").and("sn").is("Person2"))
|
||||
.toObject(mapper);
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person2");
|
||||
@@ -484,8 +453,9 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
public void testSearch_SearchScope_ContextMapper_Name() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search().query(query().base(BASE_NAME).searchScope(SearchScope.SUBTREE)
|
||||
.filter(FILTER_STRING)).toList(contextMapper);
|
||||
List<DirContextAdapter> list = tested.search()
|
||||
.query(query().base(BASE_NAME).searchScope(SearchScope.SUBTREE).filter(FILTER_STRING))
|
||||
.toList(contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -494,8 +464,9 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
contextMapper.setExpectedAttributes(CN_SN_ATTRS);
|
||||
contextMapper.setExpectedValues(CN_SN_VALUES);
|
||||
contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES);
|
||||
List<DirContextAdapter> list = tested.search().query(query().base(BASE_NAME).searchScope(SearchScope.SUBTREE)
|
||||
.attributes(CN_SN_ATTRS).filter(FILTER_STRING)).toList(contextMapper);
|
||||
List<DirContextAdapter> list = tested.search().query(
|
||||
query().base(BASE_NAME).searchScope(SearchScope.SUBTREE).attributes(CN_SN_ATTRS).filter(FILTER_STRING))
|
||||
.toList(contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -503,8 +474,7 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
public void testSearchWithInvalidSearchBaseShouldByDefaultThrowException() {
|
||||
try {
|
||||
tested.search().query(query().base(BASE_NAME + "ou=unknown").searchScope(SearchScope.SUBTREE)
|
||||
.attributes(CN_SN_ATTRS).filter(FILTER_STRING))
|
||||
.toObject(contextMapper);
|
||||
.attributes(CN_SN_ATTRS).filter(FILTER_STRING)).toObject(contextMapper);
|
||||
fail("NameNotFoundException expected");
|
||||
}
|
||||
catch (NameNotFoundException expected) {
|
||||
@@ -519,16 +489,14 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
contextMapper.setExpectedValues(CN_SN_VALUES);
|
||||
contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES);
|
||||
List<DirContextAdapter> list = tested.search().query(query().base(BASE_NAME + "ou=unknown")
|
||||
.searchScope(SearchScope.SUBTREE).attributes(CN_SN_ATTRS).filter(FILTER_STRING))
|
||||
.toList(contextMapper);
|
||||
.searchScope(SearchScope.SUBTREE).attributes(CN_SN_ATTRS).filter(FILTER_STRING)).toList(contextMapper);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyThatSearchWithCountLimitReturnsTheEntriesFoundSoFar() {
|
||||
List<Object> result = tested.search().query(query()
|
||||
.countLimit(3)
|
||||
.where("objectclass").is("person")).toList((Object ctx) -> new Object());
|
||||
List<Object> result = tested.search().query(query().countLimit(3).where("objectclass").is("person"))
|
||||
.toList((Object ctx) -> new Object());
|
||||
|
||||
assertThat(result).hasSize(3);
|
||||
}
|
||||
@@ -536,8 +504,7 @@ public class DefaultLdapClientSearchResultITest extends AbstractLdapTemplateInte
|
||||
@Test(expected = SizeLimitExceededException.class)
|
||||
public void verifyThatSearchWithCountLimitWithFlagToFalseThrowsException() {
|
||||
ReflectionTestUtils.setField(tested, "ignoreSizeLimitExceededException", false);
|
||||
tested.search().query(query()
|
||||
.countLimit(3)
|
||||
.where("objectclass").is("person")).toList((Object ctx) -> ctx);
|
||||
tested.search().query(query().countLimit(3).where("objectclass").is("person")).toList((Object ctx) -> ctx);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,10 +37,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for verifying that issues LDAP-50 and LDAP-109 are solved.
|
||||
*
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class InvalidBackslashITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -66,28 +66,25 @@ public class InvalidBackslashITest extends AbstractLdapTemplateIntegrationTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for LDAP-109, LDAP-50. When an entry has a distinguished name
|
||||
* including a backslach ('\') the Name supplied to DefaultDirObjectFactory
|
||||
* will be invalid.
|
||||
* Test for LDAP-109, LDAP-50. When an entry has a distinguished name including a
|
||||
* backslach ('\') the Name supplied to DefaultDirObjectFactory will be invalid.
|
||||
* <p>
|
||||
* E.g. the distinguished name "cn=Some\\Person6,ou=company1,ou=Sweden"
|
||||
* (indicating that the cn value is 'Some\Person'), will be represented by a
|
||||
* E.g. the distinguished name "cn=Some\\Person6,ou=company1,ou=Sweden" (indicating
|
||||
* that the cn value is 'Some\Person'), will be represented by a
|
||||
* <code>CompositeName</code> with the string representation
|
||||
* "cn=Some\\\Person6,ou=company1,ou=Sweden", which is in fact an invalid DN.
|
||||
* This will be supplied to <code>DistinguishedName</code> for parsing,
|
||||
* causing it to fail. This test makes sure that Spring LDAP properly works
|
||||
* around this bug.
|
||||
* "cn=Some\\\Person6,ou=company1,ou=Sweden", which is in fact an invalid DN. This
|
||||
* will be supplied to <code>DistinguishedName</code> for parsing, causing it to fail.
|
||||
* This test makes sure that Spring LDAP properly works around this bug.
|
||||
* </p>
|
||||
* <p>
|
||||
* What happens under the covers is (in the Java LDAP Provider code):
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* LdapName ldapname = new LdapName("cn=Some\\\\Person6,ou=company1,ou=Sweden");
|
||||
* CompositeName compositeName = new CompositeName();
|
||||
* compositeName.add(ldapname.get(ldapname.size() - 1)); // for some odd reason
|
||||
* </pre>
|
||||
* <code>CompositeName#add()</code> cannot handle this and the result is
|
||||
* the spoiled DN.
|
||||
* </pre> <code>CompositeName#add()</code> cannot handle this and the result is the
|
||||
* spoiled DN.
|
||||
* </p>
|
||||
* @throws InvalidNameException
|
||||
*/
|
||||
@@ -107,4 +104,5 @@ public class InvalidBackslashITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
assertThat(result).hasSize(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,11 +32,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests the attributes mapper search method.
|
||||
*
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapTemplateAttributesMapperITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
@@ -54,7 +55,7 @@ public class LdapTemplateAttributesMapperITest extends AbstractLdapTemplateInteg
|
||||
|
||||
/**
|
||||
* Demonstrates how to retrieve all values of a multi-value attribute.
|
||||
*
|
||||
*
|
||||
* @see LdapTemplateContextMapperITest#testSearch_ContextMapper_MultiValue()
|
||||
*/
|
||||
@Test
|
||||
@@ -77,4 +78,5 @@ public class LdapTemplateAttributesMapperITest extends AbstractLdapTemplateInteg
|
||||
|
||||
assertThat(((String[]) result.get(0)).length).isEqualTo(4);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,11 +40,11 @@ import static org.springframework.ldap.query.LdapQueryBuilder.query;
|
||||
|
||||
/**
|
||||
* Tests the authenticate methods of LdapTemplate.
|
||||
*
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapTemplateAuthenticationITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -63,10 +63,7 @@ public class LdapTemplateAuthenticationITest extends AbstractLdapTemplateIntegra
|
||||
public void testAuthenticateWithLdapQuery() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
|
||||
tested.authenticate(query()
|
||||
.where("objectclass").is("person")
|
||||
.and("uid").is("some.person3"),
|
||||
"password");
|
||||
tested.authenticate(query().where("objectclass").is("person").and("uid").is("some.person3"), "password");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,10 +79,7 @@ public class LdapTemplateAuthenticationITest extends AbstractLdapTemplateIntegra
|
||||
public void testAuthenticateWithLdapQueryAndInvalidPassword() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
|
||||
tested.authenticate(query()
|
||||
.where("objectclass").is("person")
|
||||
.and("uid").is("some.person3"),
|
||||
"invalidpassword");
|
||||
tested.authenticate(query().where("objectclass").is("person").and("uid").is("some.person3"), "invalidpassword");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -110,10 +104,8 @@ public class LdapTemplateAuthenticationITest extends AbstractLdapTemplateIntegra
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithLdapQueryAndMapper() {
|
||||
DirContextOperations ctx = tested.authenticate(query()
|
||||
.where("objectclass").is("person")
|
||||
.and("uid").is("some.person3"),
|
||||
"password",
|
||||
DirContextOperations ctx = tested.authenticate(
|
||||
query().where("objectclass").is("person").and("uid").is("some.person3"), "password",
|
||||
new LookupAttemptingCallback());
|
||||
|
||||
assertThat(ctx).isNotNull();
|
||||
@@ -123,10 +115,8 @@ public class LdapTemplateAuthenticationITest extends AbstractLdapTemplateIntegra
|
||||
@Test(expected = AuthenticationException.class)
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithLdapQueryAndMapperAndInvalidPassword() {
|
||||
DirContextOperations ctx = tested.authenticate(query()
|
||||
.where("objectclass").is("person")
|
||||
.and("uid").is("some.person3"),
|
||||
"invalidpassword",
|
||||
DirContextOperations ctx = tested.authenticate(
|
||||
query().where("objectclass").is("person").and("uid").is("some.person3"), "invalidpassword",
|
||||
new LookupAttemptingCallback());
|
||||
}
|
||||
|
||||
@@ -139,20 +129,22 @@ public class LdapTemplateAuthenticationITest extends AbstractLdapTemplateIntegra
|
||||
assertThat(tested.authenticate("", filter.toString(), "invalidpassword", errorCallback)).isFalse();
|
||||
final Exception error = errorCallback.getError();
|
||||
assertThat(error).as("collected error should not be null").isNotNull();
|
||||
assertThat(error instanceof AuthenticationException).as("expected org.springframework.ldap.AuthenticationException").isTrue();
|
||||
assertThat(error.getCause() instanceof javax.naming.AuthenticationException).as("expected javax.naming.AuthenticationException").isTrue();
|
||||
assertThat(error instanceof AuthenticationException)
|
||||
.as("expected org.springframework.ldap.AuthenticationException").isTrue();
|
||||
assertThat(error.getCause() instanceof javax.naming.AuthenticationException)
|
||||
.as("expected javax.naming.AuthenticationException").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithFilterThatDoesNotMatchAnything() {
|
||||
AndFilter filter = new AndFilter();
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(
|
||||
new EqualsFilter("uid", "some.person.that.isnt.there"));
|
||||
filter.and(new EqualsFilter("objectclass", "person"))
|
||||
.and(new EqualsFilter("uid", "some.person.that.isnt.there"));
|
||||
assertThat(tested.authenticate("", filter.toString(), "password")).isFalse();
|
||||
}
|
||||
|
||||
@Test(expected=IncorrectResultSizeDataAccessException.class)
|
||||
@Test(expected = IncorrectResultSizeDataAccessException.class)
|
||||
@Category(NoAdTest.class)
|
||||
public void testAuthenticateWithFilterThatMatchesSeveralEntries() {
|
||||
AndFilter filter = new AndFilter();
|
||||
@@ -168,4 +160,5 @@ public class LdapTemplateAuthenticationITest extends AbstractLdapTemplateIntegra
|
||||
LookupAttemptingCallback callback = new LookupAttemptingCallback();
|
||||
assertThat(tested.authenticate("", filter.encode(), "password", callback)).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,17 +32,17 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Tests the bind and unbind methods of LdapTemplate. The test methods in this
|
||||
* class tests a little too much, but we need to clean up after binding, so the
|
||||
* most efficient way to test is to do it all in one test method. Also, the
|
||||
* methods in this class relies on that the lookup method works as it should -
|
||||
* that should be ok, since that is verified in a separate test class.
|
||||
*
|
||||
* Tests the bind and unbind methods of LdapTemplate. The test methods in this class tests
|
||||
* a little too much, but we need to clean up after binding, so the most efficient way to
|
||||
* test is to do it all in one test method. Also, the methods in this class relies on that
|
||||
* the lookup method works as it should - that should be ok, since that is verified in a
|
||||
* separate test class.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
public class LdapTemplateBindUnbindITest extends
|
||||
AbstractLdapTemplateIntegrationTest {
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapTemplateBindUnbindITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
@@ -79,8 +79,7 @@ public class LdapTemplateBindUnbindITest extends
|
||||
@Test
|
||||
public void testBindAndUnbindWithDirContextAdapter() {
|
||||
DirContextAdapter adapter = new DirContextAdapter();
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top",
|
||||
"person" });
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
|
||||
adapter.setAttributeValue("cn", "Some Person4");
|
||||
adapter.setAttributeValue("sn", "Person4");
|
||||
|
||||
@@ -93,8 +92,7 @@ public class LdapTemplateBindUnbindITest extends
|
||||
@Test
|
||||
public void testBindAndUnbindWithDirContextAdapterUsingLdapName() {
|
||||
DirContextAdapter adapter = new DirContextAdapter();
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top",
|
||||
"person" });
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
|
||||
adapter.setAttributeValue("cn", "Some Person4");
|
||||
adapter.setAttributeValue("sn", "Person4");
|
||||
|
||||
@@ -107,8 +105,7 @@ public class LdapTemplateBindUnbindITest extends
|
||||
@Test
|
||||
public void testBindAndUnbindWithDirContextAdapterOnly() {
|
||||
DirContextAdapter adapter = new DirContextAdapter(LdapUtils.newLdapName(DN));
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top",
|
||||
"person" });
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
|
||||
adapter.setAttributeValue("cn", "Some Person4");
|
||||
adapter.setAttributeValue("sn", "Person4");
|
||||
|
||||
@@ -121,8 +118,7 @@ public class LdapTemplateBindUnbindITest extends
|
||||
@Test
|
||||
public void testBindAndRebindWithDirContextAdapterOnly() {
|
||||
DirContextAdapter adapter = new DirContextAdapter(LdapUtils.newLdapName(DN));
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top",
|
||||
"person" });
|
||||
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
|
||||
adapter.setAttributeValue("cn", "Some Person4");
|
||||
adapter.setAttributeValue("sn", "Person4");
|
||||
|
||||
@@ -167,4 +163,5 @@ public class LdapTemplateBindUnbindITest extends
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,10 +29,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for LdapTemplate's context executor methods.
|
||||
*
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapTemplateContextExecutorTest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -49,4 +49,5 @@ public class LdapTemplateContextExecutorTest extends AbstractLdapTemplateIntegra
|
||||
Object object = tested.executeReadOnly(executor);
|
||||
assertThat(object instanceof DirContextAdapter).as("Should be a DirContextAdapter").isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,20 +28,21 @@ import java.util.List;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests the ContextMapper search method. In its way this method also
|
||||
* demonstrates the use of DirContextAdapter and the DirObjectFactory.
|
||||
*
|
||||
* Tests the ContextMapper search method. In its way this method also demonstrates the use
|
||||
* of DirContextAdapter and the DirObjectFactory.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapTemplateContextMapperITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory ({@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
* This method depends on a DirObjectFactory
|
||||
* ({@link org.springframework.ldap.core.support.DefaultDirObjectFactory}) being set
|
||||
* in the ContextSource.
|
||||
*/
|
||||
@Test
|
||||
public void testSearch_ContextMapper() {
|
||||
@@ -57,7 +58,7 @@ public class LdapTemplateContextMapperITest extends AbstractLdapTemplateIntegrat
|
||||
|
||||
/**
|
||||
* Demonstrates how to retrieve all values of a multi-value attribute.
|
||||
*
|
||||
*
|
||||
* @see LdapTemplateAttributesMapperITest#testSearch_AttributesMapper_MultiValue()
|
||||
*/
|
||||
@Test
|
||||
@@ -74,4 +75,5 @@ public class LdapTemplateContextMapperITest extends AbstractLdapTemplateIntegrat
|
||||
assertThat(result).hasSize(1);
|
||||
assertThat(((String[]) result.get(0)).length).isEqualTo(4);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,10 +33,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for LdapTemplate's list methods.
|
||||
*
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapTemplateListITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -157,4 +157,5 @@ public class LdapTemplateListITest extends AbstractLdapTemplateIntegrationTest {
|
||||
tested.listBindings(BASE_NAME, handler);
|
||||
assertThat(handler.getNoOfRows()).isEqualTo(3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,11 +33,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests the lookup methods of LdapTemplate.
|
||||
*
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapTemplateLookupITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -45,8 +45,8 @@ public class LdapTemplateLookupITest extends AbstractLdapTemplateIntegrationTest
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory (
|
||||
* {@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
* {@link org.springframework.ldap.core.support.DefaultDirObjectFactory}) being set in
|
||||
* the ContextSource.
|
||||
*/
|
||||
@Test
|
||||
public void testLookup_Plain() {
|
||||
@@ -59,8 +59,8 @@ public class LdapTemplateLookupITest extends AbstractLdapTemplateIntegrationTest
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory (
|
||||
* {@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
* {@link org.springframework.ldap.core.support.DefaultDirObjectFactory}) being set in
|
||||
* the ContextSource.
|
||||
*/
|
||||
@Test
|
||||
public void testLookupContextRoot() {
|
||||
@@ -91,17 +91,17 @@ public class LdapTemplateLookupITest extends AbstractLdapTemplateIntegrationTest
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@link AttributesMapper} that only maps a subset of the full
|
||||
* attributes list. Used in tests where the return attributes list has been
|
||||
* limited.
|
||||
*
|
||||
* An {@link AttributesMapper} that only maps a subset of the full attributes list.
|
||||
* Used in tests where the return attributes list has been limited.
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
private final class SubsetPersonAttributesMapper implements AttributesMapper {
|
||||
|
||||
/**
|
||||
* Maps the <code>cn</code> attribute into a {@link Person} object. Also
|
||||
* verifies that the other attributes haven't been set.
|
||||
*
|
||||
* Maps the <code>cn</code> attribute into a {@link Person} object. Also verifies
|
||||
* that the other attributes haven't been set.
|
||||
*
|
||||
* @see org.springframework.ldap.core.AttributesMapper#mapFromAttributes(javax.naming.directory.Attributes)
|
||||
*/
|
||||
public Object mapFromAttributes(Attributes attributes) throws NamingException {
|
||||
@@ -111,11 +111,12 @@ public class LdapTemplateLookupITest extends AbstractLdapTemplateIntegrationTest
|
||||
assertThat(attributes.get("description")).as("description should be null").isNull();
|
||||
return person;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that only the subset is used when specifying a subset of the
|
||||
* available attributes as return attributes.
|
||||
* Verifies that only the subset is used when specifying a subset of the available
|
||||
* attributes as return attributes.
|
||||
*/
|
||||
@Test
|
||||
public void testLookup_ReturnAttributes_AttributesMapper() {
|
||||
@@ -129,9 +130,8 @@ public class LdapTemplateLookupITest extends AbstractLdapTemplateIntegrationTest
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that only the subset is used when specifying a subset of the
|
||||
* available attributes as return attributes. Uses LdapName instead
|
||||
* of plain string as name.
|
||||
* Verifies that only the subset is used when specifying a subset of the available
|
||||
* attributes as return attributes. Uses LdapName instead of plain string as name.
|
||||
*/
|
||||
@Test
|
||||
public void testLookup_ReturnAttributes_AttributesMapper_LdapName() {
|
||||
@@ -146,8 +146,8 @@ public class LdapTemplateLookupITest extends AbstractLdapTemplateIntegrationTest
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory (
|
||||
* {@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
* {@link org.springframework.ldap.core.support.DefaultDirObjectFactory}) being set in
|
||||
* the ContextSource.
|
||||
*/
|
||||
@Test
|
||||
public void testLookup_ContextMapper() {
|
||||
@@ -160,8 +160,8 @@ public class LdapTemplateLookupITest extends AbstractLdapTemplateIntegrationTest
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that only the subset is used when specifying a subset of the
|
||||
* available attributes as return attributes.
|
||||
* Verifies that only the subset is used when specifying a subset of the available
|
||||
* attributes as return attributes.
|
||||
*/
|
||||
@Test
|
||||
public void testLookup_ReturnAttributes_ContextMapper() {
|
||||
@@ -183,4 +183,5 @@ public class LdapTemplateLookupITest extends AbstractLdapTemplateIntegrationTest
|
||||
assertThat(result.getDn()).isEqualTo(expectedName);
|
||||
assertThat(result.getNameInNamespace()).isEqualTo("cn=Some Person2,ou=company1,ou=Sweden," + base);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,11 +30,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests the lookup methods of LdapTemplate.
|
||||
*
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapTemplateLookupMultiRdnITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -44,10 +44,9 @@ public class LdapTemplateLookupMultiRdnITest extends AbstractLdapTemplateIntegra
|
||||
return new ClassPathResource("/setup_data_multi_rdn.ldif");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Verifies that we can lookup an entry that has a multi-valued rdn, which
|
||||
* means more than one attribute is part of the relative DN for the entry.
|
||||
* Verifies that we can lookup an entry that has a multi-valued rdn, which means more
|
||||
* than one attribute is part of the relative DN for the entry.
|
||||
*/
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
@@ -61,9 +60,9 @@ public class LdapTemplateLookupMultiRdnITest extends AbstractLdapTemplateIntegra
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that we can lookup an entry that has a multi-valued rdn, which
|
||||
* means more than one attribute is part of the relative DN for the entry.
|
||||
*
|
||||
* Verifies that we can lookup an entry that has a multi-valued rdn, which means more
|
||||
* than one attribute is part of the relative DN for the entry.
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
@@ -83,4 +82,5 @@ public class LdapTemplateLookupMultiRdnITest extends AbstractLdapTemplateIntegra
|
||||
assertThat(result.getDn().toString()).isEqualTo("cn=Some Person+sn=Person,ou=company1,ou=Norway");
|
||||
assertThat(result.getNameInNamespace()).isEqualTo("cn=Some Person+sn=Person,ou=company1,ou=Norway," + base);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,19 +39,18 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Tests the modification methods (rebind and modifyAttributes) of LdapTemplate.
|
||||
* It also illustrates the use of DirContextAdapter as a means of getting
|
||||
* ModificationItems, in order to avoid doing a full rebind and use
|
||||
* modifyAttributes() instead. We rely on that the bind, unbind and lookup
|
||||
* methods work as they should - that should be ok, since that is verified in a
|
||||
* separate test class. NOTE: if any of the tests in this class fails, it may be
|
||||
* necessary to run the cleanup script as described in README.txt under
|
||||
* Tests the modification methods (rebind and modifyAttributes) of LdapTemplate. It also
|
||||
* illustrates the use of DirContextAdapter as a means of getting ModificationItems, in
|
||||
* order to avoid doing a full rebind and use modifyAttributes() instead. We rely on that
|
||||
* the bind, unbind and lookup methods work as they should - that should be ok, since that
|
||||
* is verified in a separate test class. NOTE: if any of the tests in this class fails, it
|
||||
* may be necessary to run the cleanup script as described in README.txt under
|
||||
* /src/iutest/.
|
||||
*
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapTemplateModifyITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -163,8 +162,8 @@ public class LdapTemplateModifyITest extends AbstractLdapTemplateIntegrationTest
|
||||
|
||||
/**
|
||||
* Test written originally to verify that duplicates are allowed on ordered
|
||||
* attributes, but had to be changed since Apache DS seems to disallow
|
||||
* duplicates even for ordered attributes.
|
||||
* attributes, but had to be changed since Apache DS seems to disallow duplicates even
|
||||
* for ordered attributes.
|
||||
*/
|
||||
@Test
|
||||
public void testModifyAttributes_MultiValueAddDuplicateToOrdered() {
|
||||
@@ -187,8 +186,8 @@ public class LdapTemplateModifyITest extends AbstractLdapTemplateIntegrationTest
|
||||
|
||||
@Test
|
||||
public void testModifyAttributes_Plain() {
|
||||
ModificationItem item = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("description",
|
||||
"Some other description"));
|
||||
ModificationItem item = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
|
||||
new BasicAttribute("description", "Some other description"));
|
||||
|
||||
tested.modifyAttributes(PERSON4_DN, new ModificationItem[] { item });
|
||||
|
||||
@@ -197,8 +196,8 @@ public class LdapTemplateModifyITest extends AbstractLdapTemplateIntegrationTest
|
||||
|
||||
@Test
|
||||
public void testModifyAttributes_LdapName() {
|
||||
ModificationItem item = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("description",
|
||||
"Some other description"));
|
||||
ModificationItem item = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
|
||||
new BasicAttribute("description", "Some other description"));
|
||||
|
||||
tested.modifyAttributes(LdapUtils.newLdapName(PERSON4_DN), new ModificationItem[] { item });
|
||||
|
||||
@@ -223,9 +222,9 @@ public class LdapTemplateModifyITest extends AbstractLdapTemplateIntegrationTest
|
||||
}
|
||||
|
||||
/**
|
||||
* Demonstrates how the DirContextAdapter can be used to automatically keep
|
||||
* track of changes of the attributes and deliver ModificationItems to use
|
||||
* in moifyAttributes().
|
||||
* Demonstrates how the DirContextAdapter can be used to automatically keep track of
|
||||
* changes of the attributes and deliver ModificationItems to use in
|
||||
* moifyAttributes().
|
||||
*/
|
||||
@Test
|
||||
public void testModifyAttributes_DirContextAdapter() throws Exception {
|
||||
@@ -242,9 +241,7 @@ public class LdapTemplateModifyITest extends AbstractLdapTemplateIntegrationTest
|
||||
@Test
|
||||
public void verifyCompleteReplacementOfUniqueMemberAttribute_Ldap119Workaround() {
|
||||
DirContextOperations ctx = tested.lookupContext("cn=ROLE_USER,ou=groups");
|
||||
ctx.setAttributeValues("uniqueMember",
|
||||
new String[]{"cn=Some Person,ou=company1,ou=Norway," + base},
|
||||
true);
|
||||
ctx.setAttributeValues("uniqueMember", new String[] { "cn=Some Person,ou=company1,ou=Norway," + base }, true);
|
||||
ctx.getModificationItems();
|
||||
|
||||
tested.modifyAttributes(ctx);
|
||||
@@ -257,12 +254,12 @@ public class LdapTemplateModifyITest extends AbstractLdapTemplateIntegrationTest
|
||||
@Test
|
||||
public void verifyCompleteReplacementOfUniqueMemberAttribute_Ldap119() {
|
||||
DirContextOperations ctx = tested.lookupContext("cn=ROLE_USER,ou=groups");
|
||||
ctx.setAttributeValues("uniqueMember",
|
||||
new String[]{"cn=Some Person,ou=company1,ou=Norway," + base});
|
||||
ctx.setAttributeValues("uniqueMember", new String[] { "cn=Some Person,ou=company1,ou=Norway," + base });
|
||||
ctx.getModificationItems();
|
||||
|
||||
tested.modifyAttributes(ctx);
|
||||
}
|
||||
|
||||
private Attributes setupAttributes() {
|
||||
Attributes attributes = new BasicAttributes();
|
||||
BasicAttribute ocattr = new BasicAttribute("objectclass");
|
||||
@@ -281,4 +278,5 @@ public class LdapTemplateModifyITest extends AbstractLdapTemplateIntegrationTest
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person4");
|
||||
assertThat(result.getStringAttribute("description")).isEqualTo("Some other description");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,14 +32,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Tests to verify that not setting a base suffix on the ContextSource (as
|
||||
* defined in ldapTemplateNoBaseSuffixTestContext.xml) works as expected.
|
||||
*
|
||||
* Tests to verify that not setting a base suffix on the ContextSource (as defined in
|
||||
* ldapTemplateNoBaseSuffixTestContext.xml) works as expected.
|
||||
*
|
||||
* NOTE: This test will not work under Java 1.4.1 or earlier.
|
||||
*
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateNoBaseSuffixTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateNoBaseSuffixTestContext.xml" })
|
||||
public class LdapTemplateNoBaseSuffixITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -51,8 +51,9 @@ public class LdapTemplateNoBaseSuffixITest extends AbstractLdapTemplateIntegrati
|
||||
}
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory ({@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
* This method depends on a DirObjectFactory
|
||||
* ({@link org.springframework.ldap.core.support.DefaultDirObjectFactory}) being set
|
||||
* in the ContextSource.
|
||||
*/
|
||||
@Test
|
||||
public void testLookup_Plain() {
|
||||
@@ -84,8 +85,7 @@ public class LdapTemplateNoBaseSuffixITest extends AbstractLdapTemplateIntegrati
|
||||
adapter.setAttributeValue("sn", "Person4");
|
||||
tested.bind("cn=Some Person4, ou=company1, ou=Sweden," + base, adapter, null);
|
||||
|
||||
DirContextAdapter result = (DirContextAdapter) tested
|
||||
.lookup("cn=Some Person4, ou=company1, ou=Sweden," + base);
|
||||
DirContextAdapter result = (DirContextAdapter) tested.lookup("cn=Some Person4, ou=company1, ou=Sweden," + base);
|
||||
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person4");
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person4");
|
||||
@@ -100,4 +100,5 @@ public class LdapTemplateNoBaseSuffixITest extends AbstractLdapTemplateIntegrati
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,9 +33,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* This test only works against in-process Apache DS server, regardless of configured profile.
|
||||
* This test only works against in-process Apache DS server, regardless of configured
|
||||
* profile.
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplatePooledTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplatePooledTestContext.xml" })
|
||||
public class LdapTemplatePooledITest extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
@Autowired
|
||||
@@ -54,13 +55,14 @@ public class LdapTemplatePooledITest extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
/**
|
||||
* This method depends on a DirObjectFactory (
|
||||
* {@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
|
||||
* being set in the ContextSource.
|
||||
* {@link org.springframework.ldap.core.support.DefaultDirObjectFactory}) being set in
|
||||
* the ContextSource.
|
||||
*/
|
||||
@Test
|
||||
public void verifyThatInvalidConnectionIsAutomaticallyPurged() throws Exception {
|
||||
LdapTestUtils.startEmbeddedServer(1888, "dc=261consulting,dc=com", "jayway");
|
||||
LdapTestUtils.cleanAndSetup(contextSource, LdapUtils.emptyLdapName(), new ClassPathResource("/setup_data.ldif"));
|
||||
LdapTestUtils.cleanAndSetup(contextSource, LdapUtils.emptyLdapName(),
|
||||
new ClassPathResource("/setup_data.ldif"));
|
||||
|
||||
DirContextOperations result = tested.lookupContext("cn=Some Person2, ou=company1,ou=Sweden");
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person2");
|
||||
@@ -74,13 +76,17 @@ public class LdapTemplatePooledITest extends AbstractJUnit4SpringContextTests {
|
||||
try {
|
||||
tested.lookup("cn=Some Person2, ou=company1,ou=Sweden");
|
||||
fail("Exception expected");
|
||||
} catch (Exception expected) {
|
||||
}
|
||||
catch (Exception expected) {
|
||||
// This should fail because the target connection was closed
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
|
||||
LdapTestUtils.cleanAndSetup(contextSource, LdapUtils.emptyLdapName(), new ClassPathResource("/setup_data.ldif"));
|
||||
// But this should be OK, because the dirty connection should have been automatically purged.
|
||||
LdapTestUtils.cleanAndSetup(contextSource, LdapUtils.emptyLdapName(),
|
||||
new ClassPathResource("/setup_data.ldif"));
|
||||
// But this should be OK, because the dirty connection should have been
|
||||
// automatically purged.
|
||||
tested.lookup("cn=Some Person2, ou=company1,ou=Sweden");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,13 +33,13 @@ import javax.naming.ldap.LdapName;
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
/**
|
||||
* Tests the recursive modification methods (unbind and the protected delete
|
||||
* methods) of LdapTemplate.
|
||||
*
|
||||
* Tests the recursive modification methods (unbind and the protected delete methods) of
|
||||
* LdapTemplate.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapTemplateRecursiveDeleteITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -129,4 +129,5 @@ public class LdapTemplateRecursiveDeleteITest extends AbstractLdapTemplateIntegr
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,13 +33,13 @@ import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Tests the rename methods of LdapTemplate.
|
||||
*
|
||||
* We rely on that the bind, unbind and lookup methods work as they should -
|
||||
* that should be ok, since that is verified in a separate test class. *
|
||||
*
|
||||
*
|
||||
* We rely on that the bind, unbind and lookup methods work as they should - that should
|
||||
* be ok, since that is verified in a separate test class. *
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapTemplateRenameITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -100,4 +100,5 @@ public class LdapTemplateRenameITest extends AbstractLdapTemplateIntegrationTest
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person6");
|
||||
assertThat(result.getStringAttribute("description")).isEqualTo("Some description");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -47,13 +47,12 @@ import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.springframework.ldap.query.LdapQueryBuilder.query;
|
||||
|
||||
/**
|
||||
* Tests for LdapTemplate's search methods. This test class tests all the
|
||||
* different versions of the search methods except the generic ones covered in
|
||||
* other tests.
|
||||
*
|
||||
* Tests for LdapTemplate's search methods. This test class tests all the different
|
||||
* versions of the search methods except the generic ones covered in other tests.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@@ -106,10 +105,8 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base(BASE_STRING)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
List<Object> list = tested.search(
|
||||
query().base(BASE_STRING).where("objectclass").is("person").and("sn").is("Person2"), attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -118,35 +115,31 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.searchForStream(query()
|
||||
.base(BASE_STRING)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper).collect(Collectors.toList());
|
||||
List<Object> list = tested
|
||||
.searchForStream(query().base(BASE_STRING).where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper)
|
||||
.collect(Collectors.toList());
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper_FewerAttributes() {
|
||||
attributesMapper.setExpectedAttributes(new String[] {"cn"});
|
||||
attributesMapper.setExpectedValues(new String[]{"Some Person2"});
|
||||
attributesMapper.setExpectedAttributes(new String[] { "cn" });
|
||||
attributesMapper.setExpectedValues(new String[] { "Some Person2" });
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base(BASE_STRING)
|
||||
.attributes("cn")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
List<Object> list = tested.search(
|
||||
query().base(BASE_STRING).attributes("cn").where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchForStream_LdapQuery_AttributesMapper_FewerAttributes() {
|
||||
attributesMapper.setExpectedAttributes(new String[] {"cn"});
|
||||
attributesMapper.setExpectedValues(new String[]{"Some Person2"});
|
||||
attributesMapper.setExpectedAttributes(new String[] { "cn" });
|
||||
attributesMapper.setExpectedValues(new String[] { "Some Person2" });
|
||||
|
||||
List<Object> list = tested.searchForStream(query()
|
||||
.base(BASE_STRING)
|
||||
.attributes("cn")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
List<Object> list = tested.searchForStream(
|
||||
query().base(BASE_STRING).attributes("cn").where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper).collect(Collectors.toList());
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
@@ -156,11 +149,8 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base(BASE_STRING)
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
List<Object> list = tested.search(query().base(BASE_STRING).searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"), attributesMapper);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@@ -169,11 +159,9 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.searchForStream(query()
|
||||
.base(BASE_STRING)
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper).collect(Collectors.toList());
|
||||
List<Object> list = tested.searchForStream(query().base(BASE_STRING).searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"), attributesMapper)
|
||||
.collect(Collectors.toList());
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@@ -182,11 +170,8 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
List<Object> list = tested.search(query().base("ou=company1,ou=Sweden").searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"), attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -195,11 +180,10 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.searchForStream(query()
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper).collect(Collectors.toList());
|
||||
List<Object> list = tested
|
||||
.searchForStream(query().base("ou=company1,ou=Sweden").searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"), attributesMapper)
|
||||
.collect(Collectors.toList());
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -208,8 +192,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
List<Object> list = tested.search(query().where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
@@ -219,9 +202,9 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.searchForStream(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper).collect(Collectors.toList());
|
||||
List<Object> list = tested
|
||||
.searchForStream(query().where("objectclass").is("person").and("sn").is("Person2"), attributesMapper)
|
||||
.collect(Collectors.toList());
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -230,10 +213,8 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base("ou=Norway")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
List<Object> list = tested.search(
|
||||
query().base("ou=Norway").where("objectclass").is("person").and("sn").is("Person2"), attributesMapper);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@@ -242,10 +223,10 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.searchForStream(query()
|
||||
.base("ou=Norway")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper).collect(Collectors.toList());
|
||||
List<Object> list = tested
|
||||
.searchForStream(query().base("ou=Norway").where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper)
|
||||
.collect(Collectors.toList());
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@@ -288,8 +269,8 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
|
||||
attributesMapper.setExpectedAttributes(CN_SN_ATTRS);
|
||||
attributesMapper.setExpectedValues(CN_SN_VALUES);
|
||||
attributesMapper.setAbsentAttributes(ABSENT_ATTRIBUTES);
|
||||
List list = tested
|
||||
.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, attributesMapper);
|
||||
List list = tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS,
|
||||
attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -305,8 +286,8 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
|
||||
public void testSearchForObject() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
DirContextAdapter result = (DirContextAdapter) tested
|
||||
.searchForObject(BASE_STRING, FILTER_STRING, contextMapper);
|
||||
DirContextAdapter result = (DirContextAdapter) tested.searchForObject(BASE_STRING, FILTER_STRING,
|
||||
contextMapper);
|
||||
assertThat(result).isNotNull();
|
||||
}
|
||||
|
||||
@@ -322,12 +303,13 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
|
||||
|
||||
@Test(expected = EmptyResultDataAccessException.class)
|
||||
public void testSearchForObjectNoHits() {
|
||||
tested.searchForObject(BASE_STRING, "(&(objectclass=person)(sn=Person does not exist))", new AbstractContextMapper() {
|
||||
@Override
|
||||
protected Object doMapFromContext(DirContextOperations ctx) {
|
||||
return ctx;
|
||||
}
|
||||
});
|
||||
tested.searchForObject(BASE_STRING, "(&(objectclass=person)(sn=Person does not exist))",
|
||||
new AbstractContextMapper() {
|
||||
@Override
|
||||
protected Object doMapFromContext(DirContextOperations ctx) {
|
||||
return ctx;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -359,10 +341,8 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
|
||||
public void testSearch_ContextMapper_LdapQuery() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search(query()
|
||||
.base(BASE_NAME)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper);
|
||||
List<DirContextAdapter> list = tested.search(
|
||||
query().base(BASE_NAME).where("objectclass").is("person").and("sn").is("Person2"), contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -370,10 +350,10 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
|
||||
public void testSearchForStream_ContextMapper_LdapQuery() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.searchForStream(query()
|
||||
.base(BASE_NAME)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper).collect(Collectors.toList());
|
||||
List<DirContextAdapter> list = tested
|
||||
.searchForStream(query().base(BASE_NAME).where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper)
|
||||
.collect(Collectors.toList());
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -381,8 +361,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
|
||||
public void testSearch_ContextMapper_LdapQuery_NoBase() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
List<DirContextAdapter> list = tested.search(query().where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
@@ -391,9 +370,9 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
|
||||
public void testSearchForStream_ContextMapper_LdapQuery_NoBase() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.searchForStream(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper).collect(Collectors.toList());
|
||||
List<DirContextAdapter> list = tested
|
||||
.searchForStream(query().where("objectclass").is("person").and("sn").is("Person2"), contextMapper)
|
||||
.collect(Collectors.toList());
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -401,11 +380,8 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
|
||||
public void testSearch_ContextMapper_LdapQuery_SearchScope() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search(query()
|
||||
.base(BASE_NAME)
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper);
|
||||
List<DirContextAdapter> list = tested.search(query().base(BASE_NAME).searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"), contextMapper);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@@ -413,11 +389,8 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
|
||||
public void testSearchForStream_ContextMapper_LdapQuery_SearchScope() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.searchForStream(query()
|
||||
.base(BASE_NAME)
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper).collect(Collectors.toList());
|
||||
List<DirContextAdapter> list = tested.searchForStream(query().base(BASE_NAME).searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"), contextMapper).collect(Collectors.toList());
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@@ -425,10 +398,8 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
|
||||
public void testSearch_ContextMapper_LdapQuery_SearchScope_CorrectBase() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search(query()
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
List<DirContextAdapter> list = tested.search(query().base("ou=company1,ou=Sweden")
|
||||
.searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
@@ -437,18 +408,17 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
|
||||
public void testSearchForStream_ContextMapper_LdapQuery_SearchScope_CorrectBase() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.searchForStream(query()
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper).collect(Collectors.toList());
|
||||
List<DirContextAdapter> list = tested
|
||||
.searchForStream(query().base("ou=company1,ou=Sweden").searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"), contextMapper)
|
||||
.collect(Collectors.toList());
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchForContext_LdapQuery() {
|
||||
DirContextOperations result = tested.searchForContext(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"));
|
||||
DirContextOperations result = tested
|
||||
.searchForContext(query().where("objectclass").is("person").and("sn").is("Person2"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person2");
|
||||
@@ -456,18 +426,14 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
|
||||
|
||||
@Test(expected = EmptyResultDataAccessException.class)
|
||||
public void testSearchForContext_LdapQuery_SearchScopeNotFound() {
|
||||
tested.searchForContext(query()
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"));
|
||||
tested.searchForContext(
|
||||
query().searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchForContext_LdapQuery_SearchScope_CorrectBase() {
|
||||
DirContextOperations result =
|
||||
tested.searchForContext(query()
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"));
|
||||
DirContextOperations result = tested.searchForContext(query().searchScope(SearchScope.ONELEVEL)
|
||||
.base("ou=company1,ou=Sweden").where("objectclass").is("person").and("sn").is("Person2"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person2");
|
||||
@@ -515,14 +481,13 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
|
||||
|
||||
@Test
|
||||
public void verifyThatSearchWithCountLimitReturnsTheEntriesFoundSoFar() {
|
||||
List<Object> result = tested.search(query()
|
||||
.countLimit(3)
|
||||
.where("objectclass").is("person"), new ContextMapper<Object>() {
|
||||
@Override
|
||||
public Object mapFromContext(Object ctx) throws NamingException {
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
List<Object> result = tested.search(query().countLimit(3).where("objectclass").is("person"),
|
||||
new ContextMapper<Object>() {
|
||||
@Override
|
||||
public Object mapFromContext(Object ctx) throws NamingException {
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
|
||||
assertThat(result).hasSize(3);
|
||||
}
|
||||
@@ -530,13 +495,12 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
|
||||
@Test(expected = SizeLimitExceededException.class)
|
||||
public void verifyThatSearchWithCountLimitWithFlagToFalseThrowsException() {
|
||||
tested.setIgnoreSizeLimitExceededException(false);
|
||||
tested.search(query()
|
||||
.countLimit(3)
|
||||
.where("objectclass").is("person"), new ContextMapper<Object>() {
|
||||
tested.search(query().countLimit(3).where("objectclass").is("person"), new ContextMapper<Object>() {
|
||||
@Override
|
||||
public Object mapFromContext(Object ctx) throws NamingException {
|
||||
return new Object();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,13 +44,12 @@ import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.springframework.ldap.query.LdapQueryBuilder.query;
|
||||
|
||||
/**
|
||||
* Tests for LdapTemplate's search methods. This test class tests all the
|
||||
* different versions of the search methods except the generic ones covered in
|
||||
* other tests.
|
||||
*
|
||||
* Tests for LdapTemplate's search methods. This test class tests all the different
|
||||
* versions of the search methods except the generic ones covered in other tests.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateNamespaceTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateNamespaceTestContext.xml" })
|
||||
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@@ -103,10 +102,8 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base(BASE_STRING)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
List<Object> list = tested.search(
|
||||
query().base(BASE_STRING).where("objectclass").is("person").and("sn").is("Person2"), attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -115,35 +112,31 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.searchForStream(query()
|
||||
.base(BASE_STRING)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper).collect(Collectors.toList());
|
||||
List<Object> list = tested
|
||||
.searchForStream(query().base(BASE_STRING).where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper)
|
||||
.collect(Collectors.toList());
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch_LdapQuery_AttributesMapper_FewerAttributes() {
|
||||
attributesMapper.setExpectedAttributes(new String[] {"cn"});
|
||||
attributesMapper.setExpectedValues(new String[]{"Some Person2"});
|
||||
attributesMapper.setExpectedAttributes(new String[] { "cn" });
|
||||
attributesMapper.setExpectedValues(new String[] { "Some Person2" });
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base(BASE_STRING)
|
||||
.attributes("cn")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
List<Object> list = tested.search(
|
||||
query().base(BASE_STRING).attributes("cn").where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchForStream_LdapQuery_AttributesMapper_FewerAttributes() {
|
||||
attributesMapper.setExpectedAttributes(new String[] {"cn"});
|
||||
attributesMapper.setExpectedValues(new String[]{"Some Person2"});
|
||||
attributesMapper.setExpectedAttributes(new String[] { "cn" });
|
||||
attributesMapper.setExpectedValues(new String[] { "Some Person2" });
|
||||
|
||||
List<Object> list = tested.searchForStream(query()
|
||||
.base(BASE_STRING)
|
||||
.attributes("cn")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
List<Object> list = tested.searchForStream(
|
||||
query().base(BASE_STRING).attributes("cn").where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper).collect(Collectors.toList());
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
@@ -153,11 +146,8 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base(BASE_STRING)
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
List<Object> list = tested.search(query().base(BASE_STRING).searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"), attributesMapper);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@@ -166,11 +156,9 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.searchForStream(query()
|
||||
.base(BASE_STRING)
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper).collect(Collectors.toList());
|
||||
List<Object> list = tested.searchForStream(query().base(BASE_STRING).searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"), attributesMapper)
|
||||
.collect(Collectors.toList());
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@@ -179,11 +167,8 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
List<Object> list = tested.search(query().base("ou=company1,ou=Sweden").searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"), attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -192,11 +177,10 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.searchForStream(query()
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper).collect(Collectors.toList());
|
||||
List<Object> list = tested
|
||||
.searchForStream(query().base("ou=company1,ou=Sweden").searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"), attributesMapper)
|
||||
.collect(Collectors.toList());
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -205,8 +189,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
List<Object> list = tested.search(query().where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
@@ -216,9 +199,9 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.searchForStream(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper).collect(Collectors.toList());
|
||||
List<Object> list = tested
|
||||
.searchForStream(query().where("objectclass").is("person").and("sn").is("Person2"), attributesMapper)
|
||||
.collect(Collectors.toList());
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -227,10 +210,8 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.search(query()
|
||||
.base("ou=Norway")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper);
|
||||
List<Object> list = tested.search(
|
||||
query().base("ou=Norway").where("objectclass").is("person").and("sn").is("Person2"), attributesMapper);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@@ -239,10 +220,10 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe
|
||||
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
attributesMapper.setExpectedValues(ALL_VALUES);
|
||||
|
||||
List<Object> list = tested.searchForStream(query()
|
||||
.base("ou=Norway")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper).collect(Collectors.toList());
|
||||
List<Object> list = tested
|
||||
.searchForStream(query().base("ou=Norway").where("objectclass").is("person").and("sn").is("Person2"),
|
||||
attributesMapper)
|
||||
.collect(Collectors.toList());
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@@ -285,8 +266,8 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe
|
||||
attributesMapper.setExpectedAttributes(CN_SN_ATTRS);
|
||||
attributesMapper.setExpectedValues(CN_SN_VALUES);
|
||||
attributesMapper.setAbsentAttributes(ABSENT_ATTRIBUTES);
|
||||
List list = tested
|
||||
.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, attributesMapper);
|
||||
List list = tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS,
|
||||
attributesMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -302,8 +283,8 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe
|
||||
public void testSearchForObject() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
DirContextAdapter result = (DirContextAdapter) tested
|
||||
.searchForObject(BASE_STRING, FILTER_STRING, contextMapper);
|
||||
DirContextAdapter result = (DirContextAdapter) tested.searchForObject(BASE_STRING, FILTER_STRING,
|
||||
contextMapper);
|
||||
assertThat(result).isNotNull();
|
||||
}
|
||||
|
||||
@@ -319,12 +300,13 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe
|
||||
|
||||
@Test(expected = EmptyResultDataAccessException.class)
|
||||
public void testSearchForObjectNoHits() {
|
||||
tested.searchForObject(BASE_STRING, "(&(objectclass=person)(sn=Person does not exist))", new AbstractContextMapper() {
|
||||
@Override
|
||||
protected Object doMapFromContext(DirContextOperations ctx) {
|
||||
return ctx;
|
||||
}
|
||||
});
|
||||
tested.searchForObject(BASE_STRING, "(&(objectclass=person)(sn=Person does not exist))",
|
||||
new AbstractContextMapper() {
|
||||
@Override
|
||||
protected Object doMapFromContext(DirContextOperations ctx) {
|
||||
return ctx;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -356,10 +338,8 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe
|
||||
public void testSearch_ContextMapper_LdapQuery() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search(query()
|
||||
.base(BASE_NAME)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper);
|
||||
List<DirContextAdapter> list = tested.search(
|
||||
query().base(BASE_NAME).where("objectclass").is("person").and("sn").is("Person2"), contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -367,10 +347,10 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe
|
||||
public void testSearchForStream_ContextMapper_LdapQuery() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.searchForStream(query()
|
||||
.base(BASE_NAME)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper).collect(Collectors.toList());
|
||||
List<DirContextAdapter> list = tested
|
||||
.searchForStream(query().base(BASE_NAME).where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper)
|
||||
.collect(Collectors.toList());
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -378,8 +358,7 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe
|
||||
public void testSearch_ContextMapper_LdapQuery_NoBase() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
List<DirContextAdapter> list = tested.search(query().where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
@@ -388,9 +367,9 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe
|
||||
public void testSearchForStream_ContextMapper_LdapQuery_NoBase() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.searchForStream(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper).collect(Collectors.toList());
|
||||
List<DirContextAdapter> list = tested
|
||||
.searchForStream(query().where("objectclass").is("person").and("sn").is("Person2"), contextMapper)
|
||||
.collect(Collectors.toList());
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -398,11 +377,8 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe
|
||||
public void testSearch_ContextMapper_LdapQuery_SearchScope() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search(query()
|
||||
.base(BASE_NAME)
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper);
|
||||
List<DirContextAdapter> list = tested.search(query().base(BASE_NAME).searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"), contextMapper);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@@ -410,11 +386,8 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe
|
||||
public void testSearchForStream_ContextMapper_LdapQuery_SearchScope() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.searchForStream(query()
|
||||
.base(BASE_NAME)
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper).collect(Collectors.toList());
|
||||
List<DirContextAdapter> list = tested.searchForStream(query().base(BASE_NAME).searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"), contextMapper).collect(Collectors.toList());
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
@@ -422,10 +395,8 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe
|
||||
public void testSearch_ContextMapper_LdapQuery_SearchScope_CorrectBase() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.search(query()
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
List<DirContextAdapter> list = tested.search(query().base("ou=company1,ou=Sweden")
|
||||
.searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper);
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
@@ -434,18 +405,17 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe
|
||||
public void testSearchForStream_ContextMapper_LdapQuery_SearchScope_CorrectBase() {
|
||||
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
|
||||
contextMapper.setExpectedValues(ALL_VALUES);
|
||||
List<DirContextAdapter> list = tested.searchForStream(query()
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"),
|
||||
contextMapper).collect(Collectors.toList());
|
||||
List<DirContextAdapter> list = tested
|
||||
.searchForStream(query().base("ou=company1,ou=Sweden").searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"), contextMapper)
|
||||
.collect(Collectors.toList());
|
||||
assertThat(list).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchForContext_LdapQuery() {
|
||||
DirContextOperations result = tested.searchForContext(query()
|
||||
.where("objectclass").is("person").and("sn").is("Person2"));
|
||||
DirContextOperations result = tested
|
||||
.searchForContext(query().where("objectclass").is("person").and("sn").is("Person2"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person2");
|
||||
@@ -453,18 +423,14 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe
|
||||
|
||||
@Test(expected = EmptyResultDataAccessException.class)
|
||||
public void testSearchForContext_LdapQuery_SearchScopeNotFound() {
|
||||
tested.searchForContext(query()
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectclass").is("person").and("sn").is("Person2"));
|
||||
tested.searchForContext(
|
||||
query().searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchForContext_LdapQuery_SearchScope_CorrectBase() {
|
||||
DirContextOperations result =
|
||||
tested.searchForContext(query()
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.base("ou=company1,ou=Sweden")
|
||||
.where("objectclass").is("person").and("sn").is("Person2"));
|
||||
DirContextOperations result = tested.searchForContext(query().searchScope(SearchScope.ONELEVEL)
|
||||
.base("ou=company1,ou=Sweden").where("objectclass").is("person").and("sn").is("Person2"));
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getStringAttribute("sn")).isEqualTo("Person2");
|
||||
@@ -509,4 +475,5 @@ public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTe
|
||||
contextMapper);
|
||||
assertThat(list).isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,11 +35,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Provides tests that verify that the server supports certain controls.
|
||||
*
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/rootContextSourceTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/rootContextSourceTestContext.xml" })
|
||||
public class SupportedControlsITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
/** must use a context source that has no base set */
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
@@ -50,7 +51,7 @@ public class SupportedControlsITest extends AbstractLdapTemplateIntegrationTest
|
||||
protected Name getRoot() {
|
||||
return LdapUtils.newLdapName(base);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Category(NoAdTest.class)
|
||||
public void testExpectedControlsSupported() throws Exception {
|
||||
@@ -71,8 +72,10 @@ public class SupportedControlsITest extends AbstractLdapTemplateIntegrationTest
|
||||
|
||||
HashSet<String> controlsSet = new HashSet<String>(Arrays.asList(controls));
|
||||
|
||||
assertThat(controlsSet.contains("1.3.6.1.4.1.4203.1.10.1")).as("Entry Change Notification LDAPv3 control,").isTrue();
|
||||
assertThat(controlsSet.contains("1.3.6.1.4.1.4203.1.10.1")).as("Entry Change Notification LDAPv3 control,")
|
||||
.isTrue();
|
||||
assertThat(controlsSet.contains("1.3.6.1.4.1.4203.1.10.1")).as("Subentries Control,").isTrue();
|
||||
assertThat(controlsSet.contains("2.16.840.1.113730.3.4.2")).as("Manage DSA IT LDAPv3 control,").isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,10 +25,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link org.springframework.ldap.core.DistinguishedNameEditor}.
|
||||
*
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/distinguishedNameEditorTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/distinguishedNameEditorTestContext.xml" })
|
||||
public class DistinguishedNameEditorITest extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
@Autowired
|
||||
@@ -40,4 +40,5 @@ public class DistinguishedNameEditorITest extends AbstractJUnit4SpringContextTes
|
||||
DistinguishedName name = distinguishedNameConsumer.getDistinguishedName();
|
||||
assertThat(name).isEqualTo(new DistinguishedName("dc=jayway, dc=se"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.util.StopWatch;
|
||||
|
||||
/**
|
||||
* Performance test for the {@link DistinguishedName} class.
|
||||
*
|
||||
*
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class DnParsePerformanceITest {
|
||||
@@ -60,7 +60,7 @@ public class DnParsePerformanceITest {
|
||||
|
||||
StopWatch stopWatch = new StopWatch("Create from DistinguishedName");
|
||||
stopWatch.start();
|
||||
|
||||
|
||||
for (int i = 0; i < 2000; i++) {
|
||||
migpath = new DistinguishedName(migpath);
|
||||
path1 = new DistinguishedName(path1);
|
||||
@@ -75,4 +75,5 @@ public class DnParsePerformanceITest {
|
||||
stopWatch.stop();
|
||||
System.out.println(stopWatch.prettyPrint());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -42,8 +42,9 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
@ContextConfiguration(locations = {"/conf/simpleLdapTemplateTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/simpleLdapTemplateTestContext.xml" })
|
||||
public class SimpleLdapTemplateITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
private static String DN_STRING = "cn=Some Person4,ou=company1,ou=Sweden";
|
||||
|
||||
private static LdapName DN = LdapUtils.newLdapName("cn=Some Person4,ou=company1,ou=Sweden");
|
||||
@@ -139,8 +140,8 @@ public class SimpleLdapTemplateITest extends AbstractLdapTemplateIntegrationTest
|
||||
|
||||
@Test
|
||||
public void testModifyAttributesName() {
|
||||
DirContextOperations ctx = ldapTemplate.lookupContext(LdapUtils.newLdapName(
|
||||
"cn=Some Person,ou=company1,ou=Sweden"));
|
||||
DirContextOperations ctx = ldapTemplate
|
||||
.lookupContext(LdapUtils.newLdapName("cn=Some Person,ou=company1,ou=Sweden"));
|
||||
|
||||
ctx.setAttributeValue("description", "updated description");
|
||||
ctx.setAttributeValue("telephoneNumber", "0000001");
|
||||
@@ -204,7 +205,7 @@ public class SimpleLdapTemplateITest extends AbstractLdapTemplateIntegrationTest
|
||||
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
|
||||
assertThat(ldapTemplate.authenticate("", filter.toString(), "password")).isTrue();
|
||||
}
|
||||
|
||||
|
||||
private void verifyBoundCorrectData() {
|
||||
DirContextOperations result = ldapTemplate.lookupContext(DN_STRING);
|
||||
assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person4");
|
||||
@@ -228,6 +229,7 @@ public class SimpleLdapTemplateITest extends AbstractLdapTemplateIntegrationTest
|
||||
|
||||
return adapter.getStringAttribute("cn");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class DummyDirContextProcessor implements DirContextProcessor {
|
||||
@@ -253,4 +255,5 @@ public class SimpleLdapTemplateITest extends AbstractLdapTemplateIntegrationTest
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,8 +27,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor}.
|
||||
*
|
||||
* Integration tests for
|
||||
* {@link org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor}.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class BaseLdapPathBeanPostprocessorITest {
|
||||
@@ -103,4 +104,5 @@ public class BaseLdapPathBeanPostprocessorITest {
|
||||
assertThat(base).isNotNull();
|
||||
assertThat(base).isEqualTo(new DistinguishedName("dc=261consulting,dc=com"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,8 +24,9 @@ import org.springframework.ldap.support.LdapUtils;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor}.
|
||||
*
|
||||
* Integration tests for
|
||||
* {@link org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor}.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public class BaseLdapPathBeanPostprocessorNamespaceConfigITest {
|
||||
@@ -58,5 +59,4 @@ public class BaseLdapPathBeanPostprocessorNamespaceConfigITest {
|
||||
assertThat(otherTested.getBaseLdapPath()).isEqualTo(LdapUtils.newLdapName("dc=jayway,dc=se"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -43,10 +43,10 @@ import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Integration tests for LdapContextSource.
|
||||
*
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapContextSourceIntegrationTest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -160,9 +160,12 @@ public class LdapContextSourceIntegrationTest extends AbstractLdapTemplateIntegr
|
||||
}
|
||||
|
||||
private final static class DnContextMapper extends AbstractContextMapper<String> {
|
||||
|
||||
@Override
|
||||
protected String doMapFromContext(DirContextOperations ctx) {
|
||||
return ctx.getNameInNamespace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,10 +27,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Advanced integration tests for LdapContextSource.
|
||||
*
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapContextSourceTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapContextSourceTestContext.xml" })
|
||||
public class LdapContextSourceMultiServerIntegrationTest extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
@Autowired
|
||||
@@ -43,4 +43,5 @@ public class LdapContextSourceMultiServerIntegrationTest extends AbstractJUnit4S
|
||||
|
||||
assertThat(string).isEqualTo("ldap://127.0.0.1:389 ldap://127.0.0.2:389");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/hardcodedFilterTestContext.xml", "/conf/ldapTemplateTestContext.xml" })
|
||||
@ContextConfiguration(locations = { "/conf/hardcodedFilterTestContext.xml", "/conf/ldapTemplateTestContext.xml" })
|
||||
public class HardcodedFilterIntegrationTest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -45,7 +45,7 @@ public class HardcodedFilterIntegrationTest extends AbstractLdapTemplateIntegrat
|
||||
assertThat(filter instanceof HardcodedFilter).isTrue();
|
||||
assertThat(filter.toString()).isEqualTo("(&(objectclass=person)(!(objectclass=computer))");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void verifyThatWildcardsAreUnescaped() {
|
||||
HardcodedFilter filter = new HardcodedFilter("cn=Some*");
|
||||
@@ -54,4 +54,5 @@ public class HardcodedFilterIntegrationTest extends AbstractLdapTemplateIntegrat
|
||||
int hits = handler.getNoOfRows();
|
||||
assertThat(hits > 1).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,12 +25,12 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for https://jira.springsource.org/browse/LDAP-247.
|
||||
* Thanks to Jürgen Failenschmid for spotting the problem and providing the code for testing this.
|
||||
*
|
||||
* Tests for https://jira.springsource.org/browse/LDAP-247. Thanks to Jürgen Failenschmid
|
||||
* for spotting the problem and providing the code for testing this.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldap-247-testContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldap-247-testContext.xml" })
|
||||
public class JiraLdap247ITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -40,8 +40,11 @@ public class JiraLdap247ITest extends AbstractLdapTemplateIntegrationTest {
|
||||
public void verifyThatBasePathIsProperlyPopulated() {
|
||||
assertThat(ldapGroupDao).isNotNull();
|
||||
|
||||
// The base path should be automatically populated by BaseLdapPathBeanPostProcessor,
|
||||
// but it doesn't unless it implements Ordered, which caused the assertion below to fail.
|
||||
// The base path should be automatically populated by
|
||||
// BaseLdapPathBeanPostProcessor,
|
||||
// but it doesn't unless it implements Ordered, which caused the assertion below
|
||||
// to fail.
|
||||
assertThat(ldapGroupDao.getBasePath()).isNotNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,17 +34,19 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@ContextConfiguration("classpath:ldap321.xml")
|
||||
@Transactional
|
||||
@Rollback
|
||||
public class Ldap321Test{
|
||||
public class Ldap321Test {
|
||||
|
||||
@Autowired
|
||||
private RoleRepo roleRepo;
|
||||
|
||||
@Test
|
||||
public void testQueryRoleMap() throws Exception {
|
||||
Map<String,String> roleMap=roleRepo.queryRoleMap();
|
||||
Map<String, String> roleMap = roleRepo.queryRoleMap();
|
||||
assertThat(roleMap).isNotNull();
|
||||
|
||||
for(String roleName:roleMap.keySet()){
|
||||
System.out.println(roleName+":"+ roleMap.get(roleName));
|
||||
for (String roleName : roleMap.keySet()) {
|
||||
System.out.println(roleName + ":" + roleMap.get(roleName));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
public class RoleRepo {
|
||||
|
||||
@Transactional
|
||||
public Map<String,String> queryRoleMap() {
|
||||
return new HashMap<String,String>();
|
||||
public Map<String, String> queryRoleMap() {
|
||||
return new HashMap<String, String>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,14 +43,16 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceAndDataSourceTransactionManager}.
|
||||
*
|
||||
* Integration tests for
|
||||
* {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceAndDataSourceTransactionManager}.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapAndJdbcTransactionTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapAndJdbcTransactionTestContext.xml" })
|
||||
public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(ContextSourceAndDataSourceTransactionManagerIntegrationTest.class);
|
||||
private static Logger log = LoggerFactory
|
||||
.getLogger(ContextSourceAndDataSourceTransactionManagerIntegrationTest.class);
|
||||
|
||||
@Autowired
|
||||
@Qualifier("dummyDao")
|
||||
@@ -69,9 +71,10 @@ public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends
|
||||
}
|
||||
|
||||
jdbcTemplate.execute("drop table PERSON if exists");
|
||||
jdbcTemplate.execute("create table PERSON(fullname VARCHAR(256), lastname VARCHAR(256), description VARCHAR(256))");
|
||||
jdbcTemplate.update("insert into PERSON values(?, ?, ?)", new Object[] { "Some Person", "Person",
|
||||
"Sweden, Company1, Some Person" });
|
||||
jdbcTemplate
|
||||
.execute("create table PERSON(fullname VARCHAR(256), lastname VARCHAR(256), description VARCHAR(256))");
|
||||
jdbcTemplate.update("insert into PERSON values(?, ?, ?)",
|
||||
new Object[] { "Some Person", "Person", "Sweden, Company1, Some Person" });
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -347,4 +350,5 @@ public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,14 +36,17 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceAndDataSourceTransactionManager}.
|
||||
* Integration tests for
|
||||
* {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceAndDataSourceTransactionManager}.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/missingLdapAndJdbcTransactionTestContext.xml"})
|
||||
public class ContextSourceAndDataSourceTransactionManagerLdap179IntegrationTest extends AbstractJUnit4SpringContextTests {
|
||||
@ContextConfiguration(locations = { "/conf/missingLdapAndJdbcTransactionTestContext.xml" })
|
||||
public class ContextSourceAndDataSourceTransactionManagerLdap179IntegrationTest
|
||||
extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(ContextSourceAndDataSourceTransactionManagerLdap179IntegrationTest.class);
|
||||
private static Logger log = LoggerFactory
|
||||
.getLogger(ContextSourceAndDataSourceTransactionManagerLdap179IntegrationTest.class);
|
||||
|
||||
@Autowired
|
||||
@Qualifier("dummyDao")
|
||||
@@ -67,13 +70,13 @@ public class ContextSourceAndDataSourceTransactionManagerLdap179IntegrationTest
|
||||
jdbcTemplate.execute("drop table PERSON if exists");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void verifyThatJdbcTransactionIsClosedIfLdapServerUnavailable_ldap179() {
|
||||
try {
|
||||
dummyDao.create("Sweden", "company1", "some testperson", "testperson", "some description");
|
||||
fail("CannotCreateTransactionException expected");
|
||||
} catch (CannotCreateTransactionException expected) {
|
||||
}
|
||||
catch (CannotCreateTransactionException expected) {
|
||||
assertThat(expected.getCause() instanceof CommunicationException).isTrue();
|
||||
}
|
||||
|
||||
@@ -83,8 +86,10 @@ public class ContextSourceAndDataSourceTransactionManagerLdap179IntegrationTest
|
||||
try {
|
||||
dummyDao.create("Sweden", "company1", "some testperson", "testperson", "some description");
|
||||
fail("CannotCreateTransactionException expected");
|
||||
} catch (CannotCreateTransactionException expected) {
|
||||
}
|
||||
catch (CannotCreateTransactionException expected) {
|
||||
assertThat(expected.getCause() instanceof CommunicationException).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,15 +44,17 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceAndDataSourceTransactionManager}
|
||||
* Integration tests for
|
||||
* {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceAndDataSourceTransactionManager}
|
||||
* with namespace configuration.
|
||||
*
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapAndJdbcTransactionNamespaceTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapAndJdbcTransactionNamespaceTestContext.xml" })
|
||||
public class ContextSourceAndDataSourceTransactionManagerNamespaceITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(ContextSourceAndDataSourceTransactionManagerNamespaceITest.class);
|
||||
private static Logger log = LoggerFactory
|
||||
.getLogger(ContextSourceAndDataSourceTransactionManagerNamespaceITest.class);
|
||||
|
||||
@Autowired
|
||||
@Qualifier("dummyDao")
|
||||
@@ -71,9 +73,10 @@ public class ContextSourceAndDataSourceTransactionManagerNamespaceITest extends
|
||||
}
|
||||
|
||||
jdbcTemplate.execute("drop table PERSON if exists");
|
||||
jdbcTemplate.execute("create table PERSON(fullname VARCHAR(256), lastname VARCHAR(256), description VARCHAR(256))");
|
||||
jdbcTemplate.update("insert into PERSON values(?, ?, ?)", new Object[] { "Some Person", "Person",
|
||||
"Sweden, Company1, Some Person" });
|
||||
jdbcTemplate
|
||||
.execute("create table PERSON(fullname VARCHAR(256), lastname VARCHAR(256), description VARCHAR(256))");
|
||||
jdbcTemplate.update("insert into PERSON values(?, ?, ?)",
|
||||
new Object[] { "Some Person", "Person", "Sweden, Company1, Some Person" });
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -349,4 +352,5 @@ public class ContextSourceAndDataSourceTransactionManagerNamespaceITest extends
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,11 +37,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceTransactionManager}.
|
||||
*
|
||||
* Integration tests for
|
||||
* {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceTransactionManager}.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTransactionTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTransactionTestContext.xml" })
|
||||
public class ContextSourceTransactionManagerIntegrationTest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(ContextSourceTransactionManagerIntegrationTest.class);
|
||||
@@ -269,4 +270,5 @@ public class ContextSourceTransactionManagerIntegrationTest extends AbstractLdap
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,12 +37,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceTransactionManager}
|
||||
* Integration tests for
|
||||
* {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceTransactionManager}
|
||||
* that uses the spring ldap namespace for configuration.
|
||||
*
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateNamespaceTransactionTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateNamespaceTransactionTestContext.xml" })
|
||||
public class ContextSourceTransactionManagerNamespaceIntegrationTest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(ContextSourceTransactionManagerNamespaceIntegrationTest.class);
|
||||
@@ -270,4 +271,5 @@ public class ContextSourceTransactionManagerNamespaceIntegrationTest extends Abs
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,12 +34,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceAndDataSourceTransactionManager}
|
||||
* Integration tests for
|
||||
* {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceAndDataSourceTransactionManager}
|
||||
* that tests unbind/rebind of recursive entries.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTransactionSubtreeTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTransactionSubtreeTestContext.xml" })
|
||||
public class ContextSourceTransactionManagerSubtreeIntegrationTest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -67,7 +68,8 @@ public class ContextSourceTransactionManagerSubtreeIntegrationTest extends Abstr
|
||||
try {
|
||||
ldapTemplate.lookup("ou=company1,ou=Sweden");
|
||||
fail("NameNotFoundException expected");
|
||||
} catch (NameNotFoundException expected) {
|
||||
}
|
||||
catch (NameNotFoundException expected) {
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
}
|
||||
@@ -77,7 +79,8 @@ public class ContextSourceTransactionManagerSubtreeIntegrationTest extends Abstr
|
||||
try {
|
||||
dummyDao.deleteRecursivelyWithException("ou=company1,ou=Sweden");
|
||||
fail("DummyException expected");
|
||||
} catch (DummyException expected) {
|
||||
}
|
||||
catch (DummyException expected) {
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
|
||||
@@ -95,8 +98,10 @@ public class ContextSourceTransactionManagerSubtreeIntegrationTest extends Abstr
|
||||
try {
|
||||
dummyDao.createRecursivelyAndUnbindSubnodeWithException();
|
||||
fail("DummyException expected");
|
||||
} catch (DummyException expected) {
|
||||
}
|
||||
catch (DummyException expected) {
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,10 +50,11 @@ import static org.assertj.core.api.Assertions.fail;
|
||||
*
|
||||
* @author Hans Westerbeek
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapAndHibernateTransactionTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapAndHibernateTransactionTestContext.xml" })
|
||||
public class ContextSourceAndHibernateTransactionManagerIntegrationTest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(ContextSourceAndHibernateTransactionManagerIntegrationTest.class);
|
||||
private static Logger log = LoggerFactory
|
||||
.getLogger(ContextSourceAndHibernateTransactionManagerIntegrationTest.class);
|
||||
|
||||
@Autowired
|
||||
@Qualifier("dummyDao")
|
||||
@@ -367,4 +368,5 @@ public class ContextSourceAndHibernateTransactionManagerIntegrationTest extends
|
||||
person = (OrgPerson) this.hibernateTemplate.get(OrgPerson.class, new Integer(1));
|
||||
assertThat(person).isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,14 +33,17 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceAndHibernateTransactionManager}.
|
||||
* Integration tests for
|
||||
* {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceAndHibernateTransactionManager}.
|
||||
*
|
||||
* @author Hans Westerbeek
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/missingLdapAndHibernateTransactionTestContext.xml"})
|
||||
public class ContextSourceAndHibernateTransactionManagerLdap179IntegrationTest extends AbstractJUnit4SpringContextTests {
|
||||
@ContextConfiguration(locations = { "/conf/missingLdapAndHibernateTransactionTestContext.xml" })
|
||||
public class ContextSourceAndHibernateTransactionManagerLdap179IntegrationTest
|
||||
extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(ContextSourceAndHibernateTransactionManagerLdap179IntegrationTest.class);
|
||||
private static Logger log = LoggerFactory
|
||||
.getLogger(ContextSourceAndHibernateTransactionManagerLdap179IntegrationTest.class);
|
||||
|
||||
@Autowired
|
||||
@Qualifier("dummyDao")
|
||||
@@ -66,7 +69,8 @@ public class ContextSourceAndHibernateTransactionManagerLdap179IntegrationTest e
|
||||
|
||||
try {
|
||||
this.dummyDao.create(person);
|
||||
} catch (CannotCreateTransactionException expected) {
|
||||
}
|
||||
catch (CannotCreateTransactionException expected) {
|
||||
assertThat(expected.getCause() instanceof CommunicationException).isTrue();
|
||||
}
|
||||
|
||||
@@ -75,8 +79,10 @@ public class ContextSourceAndHibernateTransactionManagerLdap179IntegrationTest e
|
||||
|
||||
try {
|
||||
this.dummyDao.create(person);
|
||||
} catch (CannotCreateTransactionException expected) {
|
||||
}
|
||||
catch (CannotCreateTransactionException expected) {
|
||||
assertThat(expected.getCause() instanceof CommunicationException).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,15 +45,17 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceAndHibernateTransactionManager}
|
||||
* Integration tests for
|
||||
* {@link org.springframework.ldap.transaction.compensating.manager.ContextSourceAndHibernateTransactionManager}
|
||||
* with namespace configuration.
|
||||
*
|
||||
* @author Hans Westerbeek
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapAndHibernateTransactionNamespaceTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapAndHibernateTransactionNamespaceTestContext.xml" })
|
||||
public class ContextSourceAndHibernateTransactionManagerNamespaceITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(ContextSourceAndHibernateTransactionManagerNamespaceITest.class);
|
||||
private static Logger log = LoggerFactory
|
||||
.getLogger(ContextSourceAndHibernateTransactionManagerNamespaceITest.class);
|
||||
|
||||
@Autowired
|
||||
@Qualifier("dummyDao")
|
||||
@@ -367,4 +369,5 @@ public class ContextSourceAndHibernateTransactionManagerNamespaceITest extends A
|
||||
person = (OrgPerson) this.hibernateTemplate.get(OrgPerson.class, new Integer(1));
|
||||
assertThat(person).isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,8 +33,9 @@ import static org.springframework.ldap.query.LdapQueryBuilder.query;
|
||||
/**
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapTemplateOdmGroupManipulationITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
@@ -127,10 +128,12 @@ public class LdapTemplateOdmGroupManipulationITest extends AbstractLdapTemplateI
|
||||
public void testSetMembersSyntacticallyEqual() {
|
||||
Group group = tested.findOne(query().where("cn").is("ROLE_USER"), Group.class);
|
||||
|
||||
group.setMembers(new HashSet<Name>(){{
|
||||
add(LdapUtils.newLdapName("CN=Some Person,OU=company1, ou=Sweden, " + base));
|
||||
add(LdapUtils.newLdapName("CN=Some Person2, OU=company1,ou=Sweden," + base));
|
||||
}});
|
||||
group.setMembers(new HashSet<Name>() {
|
||||
{
|
||||
add(LdapUtils.newLdapName("CN=Some Person,OU=company1, ou=Sweden, " + base));
|
||||
add(LdapUtils.newLdapName("CN=Some Person2, OU=company1,ou=Sweden," + base));
|
||||
}
|
||||
});
|
||||
tested.update(group);
|
||||
|
||||
Group verification = tested.findOne(query().where("cn").is("ROLE_USER"), Group.class);
|
||||
@@ -141,4 +144,5 @@ public class LdapTemplateOdmGroupManipulationITest extends AbstractLdapTemplateI
|
||||
assertThat(members.contains(LdapUtils.newLdapName("cn=Some Person,ou=company1,ou=Sweden," + base))).isTrue();
|
||||
assertThat(members.contains(LdapUtils.newLdapName("cn=Some Person2,ou=company1,ou=Sweden," + base))).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,15 +34,16 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
/**
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapTemplateOdmWithDnAnnotationsITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
@Test
|
||||
public void testFindOne() {
|
||||
PersonWithDnAnnotations person = tested.findOne(query()
|
||||
.where("cn").is("Some Person3"), PersonWithDnAnnotations.class);
|
||||
PersonWithDnAnnotations person = tested.findOne(query().where("cn").is("Some Person3"),
|
||||
PersonWithDnAnnotations.class);
|
||||
|
||||
assertThat(person).isNotNull();
|
||||
assertThat(person.getCommonName()).isEqualTo("Some Person3");
|
||||
@@ -75,9 +76,8 @@ public class LdapTemplateOdmWithDnAnnotationsITest extends AbstractLdapTemplateI
|
||||
|
||||
@Test
|
||||
public void testFindInCountry() {
|
||||
List<PersonWithDnAnnotations> persons = tested.find(query()
|
||||
.base("ou=Sweden")
|
||||
.where("cn").isPresent(), PersonWithDnAnnotations.class);
|
||||
List<PersonWithDnAnnotations> persons = tested.find(query().base("ou=Sweden").where("cn").isPresent(),
|
||||
PersonWithDnAnnotations.class);
|
||||
|
||||
assertThat(persons).hasSize(4);
|
||||
|
||||
@@ -91,9 +91,8 @@ public class LdapTemplateOdmWithDnAnnotationsITest extends AbstractLdapTemplateI
|
||||
|
||||
@Test
|
||||
public void testFindForStreamInCountry() {
|
||||
List<PersonWithDnAnnotations> persons = tested.findForStream(query()
|
||||
.base("ou=Sweden")
|
||||
.where("cn").isPresent(), PersonWithDnAnnotations.class)
|
||||
List<PersonWithDnAnnotations> persons = tested
|
||||
.findForStream(query().base("ou=Sweden").where("cn").isPresent(), PersonWithDnAnnotations.class)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertThat(persons).hasSize(4);
|
||||
@@ -108,7 +107,7 @@ public class LdapTemplateOdmWithDnAnnotationsITest extends AbstractLdapTemplateI
|
||||
|
||||
private PersonWithDnAnnotations findPerson(List<PersonWithDnAnnotations> persons, String cn) {
|
||||
for (PersonWithDnAnnotations person : persons) {
|
||||
if(person.getCommonName().equals(cn)) {
|
||||
if (person.getCommonName().equals(cn)) {
|
||||
return person;
|
||||
}
|
||||
}
|
||||
@@ -150,16 +149,15 @@ public class LdapTemplateOdmWithDnAnnotationsITest extends AbstractLdapTemplateI
|
||||
|
||||
@Test
|
||||
public void testUpdate() {
|
||||
PersonWithDnAnnotations person = tested.findOne(query()
|
||||
.where("cn").is("Some Person3"), PersonWithDnAnnotations.class);
|
||||
PersonWithDnAnnotations person = tested.findOne(query().where("cn").is("Some Person3"),
|
||||
PersonWithDnAnnotations.class);
|
||||
|
||||
person.setDesc(Arrays.asList("New Description"));
|
||||
String entryUuid = person.getEntryUuid();
|
||||
assertThat(entryUuid).describedAs("The operational attribute 'entryUUID' was not set").isNotEmpty();
|
||||
tested.update(person);
|
||||
|
||||
person = tested.findByDn(
|
||||
LdapUtils.newLdapName("cn=Some Person3, ou=company1, ou=Sweden"),
|
||||
person = tested.findByDn(LdapUtils.newLdapName("cn=Some Person3, ou=company1, ou=Sweden"),
|
||||
PersonWithDnAnnotations.class);
|
||||
|
||||
assertThat(person.getCommonName()).isEqualTo("Some Person3");
|
||||
@@ -171,8 +169,8 @@ public class LdapTemplateOdmWithDnAnnotationsITest extends AbstractLdapTemplateI
|
||||
|
||||
@Test
|
||||
public void testUpdateWithChangedDn() {
|
||||
PersonWithDnAnnotations person = tested.findOne(query()
|
||||
.where("cn").is("Some Person3"), PersonWithDnAnnotations.class);
|
||||
PersonWithDnAnnotations person = tested.findOne(query().where("cn").is("Some Person3"),
|
||||
PersonWithDnAnnotations.class);
|
||||
|
||||
// This should make the entry move
|
||||
person.setCountry("Norway");
|
||||
@@ -180,8 +178,7 @@ public class LdapTemplateOdmWithDnAnnotationsITest extends AbstractLdapTemplateI
|
||||
assertThat(entryUuid).describedAs("The operational attribute 'entryUUID' was not set").isNotEmpty();
|
||||
tested.update(person);
|
||||
|
||||
person = tested.findByDn(
|
||||
LdapUtils.newLdapName("cn=Some Person3, ou=company1, ou=Norway"),
|
||||
person = tested.findByDn(LdapUtils.newLdapName("cn=Some Person3, ou=company1, ou=Norway"),
|
||||
PersonWithDnAnnotations.class);
|
||||
|
||||
assertThat(person.getCommonName()).isEqualTo("Some Person3");
|
||||
@@ -192,4 +189,5 @@ public class LdapTemplateOdmWithDnAnnotationsITest extends AbstractLdapTemplateI
|
||||
assertThat(person.getEntryUuid()).describedAs("The operational attribute 'entryUUID' was not set").isNotEmpty();
|
||||
assertThat(person.getEntryUuid()).isNotEqualTo(entryUuid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,15 +37,15 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
/**
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
|
||||
public class LdapTemplateOdmWithNoDnAnnotationsITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
|
||||
@Test
|
||||
public void testFindOne() {
|
||||
Person person = tested.findOne(query()
|
||||
.where("cn").is("Some Person3"), Person.class);
|
||||
Person person = tested.findOne(query().where("cn").is("Some Person3"), Person.class);
|
||||
|
||||
assertThat(person).isNotNull();
|
||||
assertThat(person.getCommonName()).isEqualTo("Some Person3");
|
||||
@@ -74,14 +74,12 @@ public class LdapTemplateOdmWithNoDnAnnotationsITest extends AbstractLdapTemplat
|
||||
|
||||
@Test(expected = EmptyResultDataAccessException.class)
|
||||
public void testFindOneThrowsEmptyResultIfNotFound() {
|
||||
tested.findOne(query()
|
||||
.where("cn").is("This cn does not exist"), Person.class);
|
||||
tested.findOne(query().where("cn").is("This cn does not exist"), Person.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFind() {
|
||||
List<Person> persons = tested.find(query()
|
||||
.where("cn").is("Some Person3"), Person.class);
|
||||
List<Person> persons = tested.find(query().where("cn").is("Some Person3"), Person.class);
|
||||
|
||||
assertThat(persons).hasSize(1);
|
||||
Person person = persons.get(0);
|
||||
@@ -96,8 +94,7 @@ public class LdapTemplateOdmWithNoDnAnnotationsITest extends AbstractLdapTemplat
|
||||
|
||||
@Test
|
||||
public void testFindForStream() {
|
||||
List<Person> persons = tested.findForStream(query()
|
||||
.where("cn").is("Some Person3"), Person.class)
|
||||
List<Person> persons = tested.findForStream(query().where("cn").is("Some Person3"), Person.class)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertThat(persons).hasSize(1);
|
||||
@@ -113,9 +110,7 @@ public class LdapTemplateOdmWithNoDnAnnotationsITest extends AbstractLdapTemplat
|
||||
|
||||
@Test
|
||||
public void testFindInCountry() {
|
||||
List<Person> persons = tested.find(query()
|
||||
.base("ou=Sweden")
|
||||
.where("cn").isPresent(), Person.class);
|
||||
List<Person> persons = tested.find(query().base("ou=Sweden").where("cn").isPresent(), Person.class);
|
||||
|
||||
assertThat(persons).hasSize(4);
|
||||
Person person = persons.get(0);
|
||||
@@ -125,9 +120,7 @@ public class LdapTemplateOdmWithNoDnAnnotationsITest extends AbstractLdapTemplat
|
||||
|
||||
@Test
|
||||
public void testFindForStreamInCountry() {
|
||||
List<Person> persons = tested.findForStream(query()
|
||||
.base("ou=Sweden")
|
||||
.where("cn").isPresent(), Person.class)
|
||||
List<Person> persons = tested.findForStream(query().base("ou=Sweden").where("cn").isPresent(), Person.class)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertThat(persons).hasSize(4);
|
||||
@@ -145,8 +138,7 @@ public class LdapTemplateOdmWithNoDnAnnotationsITest extends AbstractLdapTemplat
|
||||
@Test
|
||||
public void testCreate() {
|
||||
Person person = new Person();
|
||||
person.setDn(LdapNameBuilder.newInstance("ou=company1,ou=Sweden")
|
||||
.add("cn", "New Person").build());
|
||||
person.setDn(LdapNameBuilder.newInstance("ou=company1,ou=Sweden").add("cn", "New Person").build());
|
||||
person.setCommonName("New Person");
|
||||
person.setSurname("Person");
|
||||
person.setDesc(Arrays.asList("This is the description"));
|
||||
@@ -156,8 +148,7 @@ public class LdapTemplateOdmWithNoDnAnnotationsITest extends AbstractLdapTemplat
|
||||
|
||||
assertThat(tested.findAll(Person.class)).hasSize(6);
|
||||
|
||||
person = tested.findOne(query()
|
||||
.where("cn").is("New Person"), Person.class);
|
||||
person = tested.findOne(query().where("cn").is("New Person"), Person.class);
|
||||
|
||||
assertThat(person.getCommonName()).isEqualTo("New Person");
|
||||
assertThat(person.getSurname()).isEqualTo("Person");
|
||||
@@ -168,16 +159,14 @@ public class LdapTemplateOdmWithNoDnAnnotationsITest extends AbstractLdapTemplat
|
||||
|
||||
@Test
|
||||
public void testUpdate() {
|
||||
Person person = tested.findOne(query()
|
||||
.where("cn").is("Some Person3"), Person.class);
|
||||
Person person = tested.findOne(query().where("cn").is("Some Person3"), Person.class);
|
||||
|
||||
person.setDesc(Arrays.asList("New Description"));
|
||||
String entryUuid = person.getEntryUuid();
|
||||
assertThat(entryUuid).describedAs("The operational attribute 'entryUUID' was not set").isNotEmpty();
|
||||
tested.update(person);
|
||||
|
||||
person = tested.findOne(query()
|
||||
.where("cn").is("Some Person3"), Person.class);
|
||||
person = tested.findOne(query().where("cn").is("Some Person3"), Person.class);
|
||||
|
||||
assertThat(person.getCommonName()).isEqualTo("Some Person3");
|
||||
assertThat(person.getSurname()).isEqualTo("Person3");
|
||||
@@ -188,15 +177,15 @@ public class LdapTemplateOdmWithNoDnAnnotationsITest extends AbstractLdapTemplat
|
||||
|
||||
@Test
|
||||
public void testDelete() {
|
||||
Person person = tested.findOne(query()
|
||||
.where("cn").is("Some Person3"), Person.class);
|
||||
Person person = tested.findOne(query().where("cn").is("Some Person3"), Person.class);
|
||||
|
||||
tested.delete(person);
|
||||
|
||||
try {
|
||||
tested.findOne(query().where("cn").is("Some Person3"), Person.class);
|
||||
fail("EmptyResultDataAccessException e");
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
}
|
||||
catch (EmptyResultDataAccessException e) {
|
||||
assertThat(true).isTrue();
|
||||
}
|
||||
}
|
||||
@@ -206,15 +195,14 @@ public class LdapTemplateOdmWithNoDnAnnotationsITest extends AbstractLdapTemplat
|
||||
*/
|
||||
@Test
|
||||
public void testLdap271() {
|
||||
Person person = tested.findOne(query()
|
||||
.where("cn").is("Some Person3"), Person.class);
|
||||
Person person = tested.findOne(query().where("cn").is("Some Person3"), Person.class);
|
||||
|
||||
// Perform test
|
||||
person.setTelephoneNumber(null);
|
||||
tested.update(person);
|
||||
|
||||
person = tested.findOne(query()
|
||||
.where("cn").is("Some Person3"), Person.class);
|
||||
person = tested.findOne(query().where("cn").is("Some Person3"), Person.class);
|
||||
assertThat(person.getTelephoneNumber()).as("TelephoneNumber should be null").isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user