Cleaned up usage of DistinguishedName from satellite modules, samples and tests.

This commit is contained in:
Mattias Hellborg Arthursson
2013-08-30 10:44:51 +02:00
parent ed605be49a
commit 66bc1968db
41 changed files with 623 additions and 366 deletions

View File

@@ -0,0 +1,37 @@
/*
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.itest.core.support;
import org.springframework.ldap.core.support.BaseLdapNameAware;
import javax.naming.ldap.LdapName;
/**
* @author Mattias Hellborg Arthursson
*/
public class DummyBaseLdapNameAware implements BaseLdapNameAware {
private LdapName baseLdapPath;
@Override
public void setBaseLdapPath(LdapName baseLdapPath) {
this.baseLdapPath = baseLdapPath;
}
public LdapName getBaseLdapPath() {
return baseLdapPath;
}
}

View File

@@ -22,11 +22,12 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.ldap.core.ContextSource;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.ldap.test.LdapTestUtils;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import javax.naming.Name;
import javax.naming.NamingException;
import java.io.IOException;
@@ -46,7 +47,7 @@ public abstract class AbstractLdapTemplateIntegrationTest extends AbstractJUnit4
return new ClassPathResource("/setup_data.ldif");
}
protected DistinguishedName getRoot() {
return DistinguishedName.EMPTY_PATH;
protected Name getRoot() {
return LdapUtils.emptyLdapName();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,20 +16,20 @@
package org.springframework.ldap;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.test.context.ContextConfiguration;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.test.context.ContextConfiguration;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
/**
* Tests the bind and unbind methods of LdapTemplate. The test methods in this
@@ -58,11 +58,11 @@ public class LdapTemplateBindUnbindITest extends
}
@Test
public void testBindAndUnbindWithAttributesUsingDistinguishedName() {
public void testBindAndUnbindWithAttributesUsingLdapName() {
Attributes attributes = setupAttributes();
tested.bind(new DistinguishedName(DN), null, attributes);
tested.bind(LdapUtils.newLdapName(DN), null, attributes);
verifyBoundCorrectData();
tested.unbind(new DistinguishedName(DN));
tested.unbind(LdapUtils.newLdapName(DN));
verifyCleanup();
}
@@ -81,23 +81,22 @@ public class LdapTemplateBindUnbindITest extends
}
@Test
public void testBindAndUnbindWithDirContextAdapterUsingDistinguishedName() {
public void testBindAndUnbindWithDirContextAdapterUsingLdapName() {
DirContextAdapter adapter = new DirContextAdapter();
adapter.setAttributeValues("objectclass", new String[] { "top",
"person" });
adapter.setAttributeValue("cn", "Some Person4");
adapter.setAttributeValue("sn", "Person4");
tested.bind(new DistinguishedName(DN), adapter, null);
tested.bind(LdapUtils.newLdapName(DN), adapter, null);
verifyBoundCorrectData();
tested.unbind(new DistinguishedName(DN));
tested.unbind(LdapUtils.newLdapName(DN));
verifyCleanup();
}
@Test
public void testBindAndUnbindWithDirContextAdapterOnly() {
DirContextAdapter adapter = new DirContextAdapter(
new DistinguishedName(DN));
DirContextAdapter adapter = new DirContextAdapter(LdapUtils.newLdapName(DN));
adapter.setAttributeValues("objectclass", new String[] { "top",
"person" });
adapter.setAttributeValue("cn", "Some Person4");
@@ -111,8 +110,7 @@ public class LdapTemplateBindUnbindITest extends
@Test
public void testBindAndRebindWithDirContextAdapterOnly() {
DirContextAdapter adapter = new DirContextAdapter(
new DistinguishedName(DN));
DirContextAdapter adapter = new DirContextAdapter(LdapUtils.newLdapName(DN));
adapter.setAttributeValues("objectclass", new String[] { "top",
"person" });
adapter.setAttributeValue("cn", "Some Person4");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,22 +15,23 @@
*/
package org.springframework.ldap;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.CountNameClassPairCallbackHandler;
import org.springframework.ldap.itest.PersonContextMapper;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.ldap.test.AttributeCheckContextMapper;
import org.springframework.test.context.ContextConfiguration;
import javax.naming.ldap.LdapName;
import java.util.List;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
/**
* Tests for LdapTemplate's list methods.
*
@@ -46,7 +47,7 @@ public class LdapTemplateListITest extends AbstractLdapTemplateIntegrationTest {
private static final String BASE_STRING = "";
private static final DistinguishedName BASE_NAME = new DistinguishedName(BASE_STRING);
private static final LdapName BASE_NAME = LdapUtils.newLdapName(BASE_STRING);
private static final String[] ALL_ATTRIBUTES = { "cn", "sn", "description", "telephoneNumber" };
@@ -75,16 +76,14 @@ public class LdapTemplateListITest extends AbstractLdapTemplateIntegrationTest {
public void testListBindings_ContextMapper_Name() {
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
contextMapper.setExpectedValues(ALL_VALUES);
DistinguishedName dn = new DistinguishedName("ou=company2,c=Sweden");
dn.append(BASE_NAME);
LdapName dn = LdapUtils.newLdapName("ou=company2,c=Sweden");
List list = tested.listBindings(dn, contextMapper);
assertEquals(1, list.size());
}
@Test
public void testListBindings_ContextMapper_MapToPersons() {
DistinguishedName dn = new DistinguishedName("ou=company1,c=Sweden");
dn.append(BASE_NAME);
LdapName dn = LdapUtils.newLdapName("ou=company1,c=Sweden");
List list = tested.listBindings(dn, new PersonContextMapper());
assertEquals(3, list.size());
String personClass = "org.springframework.ldap.itest.Person";

View File

@@ -21,7 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.AttributesMapper;
import org.springframework.ldap.core.ContextMapper;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.AbstractContextSource;
import org.springframework.ldap.itest.Person;
@@ -87,9 +86,9 @@ public class LdapTemplateLookupITest extends AbstractLdapTemplateIntegrationTest
}
@Test
public void testLookup_AttributesMapper_DistinguishedName() {
public void testLookup_AttributesMapper_LdapName() {
AttributesMapper mapper = new PersonAttributesMapper();
Person person = (Person) tested.lookup(new DistinguishedName("cn=Some Person2, ou=company1,c=Sweden"), mapper);
Person person = (Person) tested.lookup(LdapUtils.newLdapName("cn=Some Person2, ou=company1,c=Sweden"), mapper);
assertEquals("Some Person2", person.getFullname());
assertEquals("Person2", person.getLastname());
@@ -136,13 +135,13 @@ public class LdapTemplateLookupITest extends AbstractLdapTemplateIntegrationTest
/**
* Verifies that only the subset is used when specifying a subset of the
* available attributes as return attributes. Uses DistinguishedName instead
* available attributes as return attributes. Uses LdapName instead
* of plain string as name.
*/
@Test
public void testLookup_ReturnAttributes_AttributesMapper_DistinguishedName() {
public void testLookup_ReturnAttributes_AttributesMapper_LdapName() {
AttributesMapper mapper = new SubsetPersonAttributesMapper();
Person person = (Person) tested.lookup(new DistinguishedName("cn=Some Person2, ou=company1,c=Sweden"),
Person person = (Person) tested.lookup(LdapUtils.newLdapName("cn=Some Person2, ou=company1,c=Sweden"),
new String[] { "cn" }, mapper);
assertEquals("Some Person2", person.getFullname());

View File

@@ -24,6 +24,7 @@ import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DirContextOperations;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.test.context.ContextConfiguration;
import javax.naming.directory.Attributes;
@@ -95,10 +96,10 @@ public class LdapTemplateModifyITest extends AbstractLdapTemplateIntegrationTest
}
@Test
public void testRebind_Attributes_DistinguishedName() {
public void testRebind_Attributes_LdapName() {
Attributes attributes = setupAttributes();
tested.rebind(new DistinguishedName(PERSON4_DN), null, attributes);
tested.rebind(LdapUtils.newLdapName(PERSON4_DN), null, attributes);
verifyBoundCorrectData();
}
@@ -231,11 +232,11 @@ public class LdapTemplateModifyITest extends AbstractLdapTemplateIntegrationTest
}
@Test
public void testModifyAttributes_DistinguishedName() {
public void testModifyAttributes_LdapName() {
ModificationItem item = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("description",
"Some other description"));
tested.modifyAttributes(new DistinguishedName(PERSON4_DN), new ModificationItem[] { item });
tested.modifyAttributes(LdapUtils.newLdapName(PERSON4_DN), new ModificationItem[] { item });
verifyBoundCorrectData();
}

View File

@@ -19,12 +19,12 @@ package org.springframework.ldap;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.CountNameClassPairCallbackHandler;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.test.context.ContextConfiguration;
import javax.naming.Name;
import javax.naming.ldap.LdapName;
import static junit.framework.Assert.assertEquals;
@@ -46,8 +46,8 @@ public class LdapTemplateNoBaseSuffixITest extends AbstractLdapTemplateIntegrati
private LdapTemplate tested;
@Override
protected DistinguishedName getRoot() {
return new DistinguishedName("dc=jayway,dc=se");
protected Name getRoot() {
return LdapUtils.newLdapName("dc=jayway,dc=se");
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,19 +16,20 @@
package org.springframework.ldap;
import static junit.framework.Assert.fail;
import javax.naming.Name;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.test.context.ContextConfiguration;
import javax.naming.Name;
import javax.naming.ldap.LdapName;
import static junit.framework.Assert.fail;
/**
* Tests the recursive modification methods (unbind and the protected delete
* methods) of LdapTemplate.
@@ -42,13 +43,13 @@ public class LdapTemplateRecursiveDeleteITest extends AbstractLdapTemplateIntegr
@Autowired
private LdapTemplate tested;
private static DistinguishedName DN = new DistinguishedName("cn=Some Person5,ou=company1,c=Sweden");
private static LdapName DN = LdapUtils.newLdapName("cn=Some Person5,ou=company1,c=Sweden");
private DistinguishedName firstSubDn;
private LdapName firstSubDn;
private DistinguishedName secondSubDn;
private LdapName secondSubDn;
private DistinguishedName leafDn;
private LdapName leafDn;
@Before
public void prepareTestedInstance() throws Exception {
@@ -59,16 +60,18 @@ public class LdapTemplateRecursiveDeleteITest extends AbstractLdapTemplateIntegr
adapter.setAttributeValue("description", "Some description");
tested.bind(DN, adapter, null);
firstSubDn = new DistinguishedName("cn=subPerson");
firstSubDn.prepend(DN);
firstSubDn = LdapUtils.newLdapName("cn=subPerson");
firstSubDn = LdapUtils.prepend(firstSubDn, DN);
adapter = new DirContextAdapter();
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
adapter.setAttributeValue("cn", "subPerson");
adapter.setAttributeValue("sn", "subPerson");
adapter.setAttributeValue("description", "Should be recursively deleted");
tested.bind(firstSubDn, adapter, null);
secondSubDn = new DistinguishedName("cn=subPerson2");
secondSubDn.prepend(DN);
secondSubDn = LdapUtils.newLdapName("cn=subPerson2");
secondSubDn = LdapUtils.prepend(secondSubDn, DN);
adapter = new DirContextAdapter();
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
adapter.setAttributeValue("cn", "subPerson2");
@@ -76,8 +79,9 @@ public class LdapTemplateRecursiveDeleteITest extends AbstractLdapTemplateIntegr
adapter.setAttributeValue("description", "Should be recursively deleted");
tested.bind(secondSubDn, adapter, null);
leafDn = new DistinguishedName("cn=subSubPerson");
leafDn.prepend(firstSubDn);
leafDn = LdapUtils.newLdapName("cn=subSubPerson");
leafDn = LdapUtils.prepend(leafDn, DN);
adapter = new DirContextAdapter();
adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
adapter.setAttributeValue("cn", "subSubPerson");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,20 +16,20 @@
package org.springframework.ldap;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.fail;
import javax.naming.Name;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.test.context.ContextConfiguration;
import javax.naming.Name;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.fail;
/**
* Tests the rename methods of LdapTemplate.
*
@@ -69,14 +69,14 @@ public class LdapTemplateRenameITest extends AbstractLdapTemplateIntegrationTest
public void testRename() {
tested.rename(DN, NEWDN);
verifyDeleted(new DistinguishedName(DN));
verifyDeleted(LdapUtils.newLdapName(DN));
verifyBoundCorrectData();
}
@Test
public void testRename_DistinguishedName() throws Exception {
Name oldDn = new DistinguishedName(DN);
Name newDn = new DistinguishedName(NEWDN);
public void testRename_LdapName() throws Exception {
Name oldDn = LdapUtils.newLdapName(DN);
Name newDn = LdapUtils.newLdapName(NEWDN);
tested.rename(oldDn, newDn);
verifyDeleted(oldDn);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,16 +15,6 @@
*/
package org.springframework.ldap;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import java.util.List;
import javax.naming.Name;
import javax.naming.directory.SearchControls;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -33,13 +23,22 @@ import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DirContextOperations;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.AbstractContextMapper;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.ldap.test.AttributeCheckAttributesMapper;
import org.springframework.ldap.test.AttributeCheckContextMapper;
import org.springframework.test.context.ContextConfiguration;
import javax.naming.Name;
import javax.naming.directory.SearchControls;
import java.util.List;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
/**
* Tests for LdapTemplate's search methods. This test class tests all the
* different versions of the search methods except the generic ones covered in
@@ -72,7 +71,7 @@ public class LdapTemplateSearchResultITest extends AbstractLdapTemplateIntegrati
private static final String FILTER_STRING = "(&(objectclass=person)(sn=Person2))";
private static final Name BASE_NAME = new DistinguishedName(BASE_STRING);
private static final Name BASE_NAME = LdapUtils.newLdapName(BASE_STRING);
@Before
public void prepareTestedInstance() throws Exception {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,19 +16,20 @@
package org.springframework.ldap.control;
import static junit.framework.Assert.assertEquals;
import java.util.Arrays;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.AbstractLdapTemplateIntegrationTest;
import org.springframework.ldap.core.ContextMapper;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.test.context.ContextConfiguration;
import javax.naming.Name;
import java.util.Arrays;
import static junit.framework.Assert.assertEquals;
/**
* Provides tests that verify that the server supports certain controls.
*
@@ -43,8 +44,8 @@ public class SupportedControlsITest extends AbstractLdapTemplateIntegrationTest
private static final String SUPPORTED_CONTROL = "supportedcontrol";
@Override
protected DistinguishedName getRoot() {
return new DistinguishedName("dc=jayway,dc=se");
protected Name getRoot() {
return LdapUtils.newLdapName("dc=jayway,dc=se");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,16 +15,6 @@
*/
package org.springframework.ldap.core.simple;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import java.util.List;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchControls;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.AbstractLdapTemplateIntegrationTest;
@@ -32,16 +22,26 @@ import org.springframework.ldap.NameNotFoundException;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DirContextOperations;
import org.springframework.ldap.core.DirContextProcessor;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.filter.AndFilter;
import org.springframework.ldap.filter.EqualsFilter;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.test.context.ContextConfiguration;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchControls;
import javax.naming.ldap.LdapName;
import java.util.List;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
@ContextConfiguration(locations = { "/conf/simpleLdapTemplateTestContext.xml" })
public class SimpleLdapTemplateITest extends AbstractLdapTemplateIntegrationTest {
private static String DN_STRING = "cn=Some Person4,ou=company1,c=Sweden";
private static DistinguishedName DN = new DistinguishedName("cn=Some Person4,ou=company1,c=Sweden");
private static LdapName DN = LdapUtils.newLdapName("cn=Some Person4,ou=company1,c=Sweden");
@Autowired
private SimpleLdapTemplate ldapTemplate;
@@ -54,7 +54,7 @@ public class SimpleLdapTemplateITest extends AbstractLdapTemplateIntegrationTest
@Test
public void testLookupName() {
String result = ldapTemplate.lookup(new DistinguishedName("cn=Some Person,ou=company1,c=Sweden"),
String result = ldapTemplate.lookup(LdapUtils.newLdapName("cn=Some Person,ou=company1,c=Sweden"),
new CnContextMapper());
assertEquals("Some Person", result);
}
@@ -94,7 +94,7 @@ public class SimpleLdapTemplateITest extends AbstractLdapTemplateIntegrationTest
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
DummyDirContextProcessor processor = new DummyDirContextProcessor();
List<String> cns = ldapTemplate.search(DistinguishedName.EMPTY_PATH, "(&(objectclass=person)(sn=Person3))",
List<String> cns = ldapTemplate.search(LdapUtils.emptyLdapName(), "(&(objectclass=person)(sn=Person3))",
searchControls, new CnContextMapper(), processor);
assertEquals(1, cns.size());
@@ -105,7 +105,7 @@ public class SimpleLdapTemplateITest extends AbstractLdapTemplateIntegrationTest
@Test
public void testSearchName() {
List<String> cns = ldapTemplate.search(DistinguishedName.EMPTY_PATH, "(&(objectclass=person)(sn=Person3))",
List<String> cns = ldapTemplate.search(LdapUtils.emptyLdapName(), "(&(objectclass=person)(sn=Person3))",
new CnContextMapper());
assertEquals(1, cns.size());
@@ -134,7 +134,7 @@ public class SimpleLdapTemplateITest extends AbstractLdapTemplateIntegrationTest
@Test
public void testModifyAttributesName() {
DirContextOperations ctx = ldapTemplate.lookupContext(new DistinguishedName(
DirContextOperations ctx = ldapTemplate.lookupContext(LdapUtils.newLdapName(
"cn=Some Person,ou=company1,c=Sweden"));
ctx.setAttributeValue("description", "updated description");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,17 +15,19 @@
*/
package org.springframework.ldap.core.support;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.itest.core.support.DummyBaseLdapNameAware;
import org.springframework.ldap.itest.core.support.DummyBaseLdapPathAware;
import org.springframework.ldap.support.LdapUtils;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
/**
* Integration tests for {@link BaseLdapPathBeanPostProcessor}.
@@ -38,12 +40,15 @@ public class BaseLdapPathBeanPostprocessorITest {
public void testPostProcessBeforeInitialization() throws Exception {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
"/conf/baseLdapPathPostProcessorTestContext.xml");
DummyBaseLdapPathAware tested = (DummyBaseLdapPathAware) ctx.getBean("dummyBaseContextAware");
DummyBaseLdapPathAware tested = ctx.getBean(DummyBaseLdapPathAware.class);
DistinguishedName base = tested.getBase();
assertNotNull(base);
assertEquals(new DistinguishedName("dc=jayway,dc=se"), base);
}
DummyBaseLdapNameAware otherTested = ctx.getBean(DummyBaseLdapNameAware.class);
assertEquals(LdapUtils.newLdapName("dc=jayway,dc=se"), otherTested.getBaseLdapPath());
}
@Test
public void testPostProcessBeforeInitializationMultipleContextSources() throws Exception {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,18 +15,18 @@
*/
package org.springframework.ldap.filter;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.AbstractLdapTemplateIntegrationTest;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.CountNameClassPairCallbackHandler;
import org.springframework.ldap.itest.filter.DummyFilterConsumer;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.test.context.ContextConfiguration;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
/**
* @author Mattias Hellborg Arthursson
*/
@@ -50,7 +50,7 @@ public class HardcodedFilterIntegrationTest extends AbstractLdapTemplateIntegrat
public void verifyThatWildcardsAreUnescaped() {
HardcodedFilter filter = new HardcodedFilter("cn=Some*");
CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler();
ldapTemplate.search(DistinguishedName.EMPTY_PATH, filter.encode(), handler);
ldapTemplate.search(LdapUtils.emptyLdapName(), filter.encode(), handler);
int hits = handler.getNoOfRows();
assertTrue("expected more than one hit, got " + hits, hits > 1);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2010 the original author or authors.
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,17 +15,6 @@
*/
package org.springframework.ldap.transaction.compensating.manager;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.After;
@@ -39,13 +28,22 @@ import org.springframework.jdbc.core.RowMapper;
import org.springframework.ldap.AbstractLdapTemplateIntegrationTest;
import org.springframework.ldap.NameNotFoundException;
import org.springframework.ldap.core.AttributesMapper;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.itest.transaction.compensating.manager.DummyDao;
import org.springframework.ldap.itest.transaction.compensating.manager.DummyException;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import java.sql.ResultSet;
import java.sql.SQLException;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
/**
* Integration tests for {@link ContextSourceAndDataSourceTransactionManager}.
*

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<import resource="classpath:/conf/commonTestContext.xml"/>
@@ -20,9 +20,11 @@
<constructor-arg ref="contextSource" />
</bean>
<bean id="dummyBaseContextAware"
class="org.springframework.ldap.itest.core.support.DummyBaseLdapPathAware" />
<bean id="dummyBaseLdapPathAware"
class="org.springframework.ldap.itest.core.support.DummyBaseLdapPathAware" />
<bean class="org.springframework.ldap.itest.core.support.DummyBaseLdapNameAware" />
<bean
class="org.springframework.ldap.core.support.BaseLdapPathBeanPostProcessor" />
</beans>