LDAP-267: Added integration tests and modified samples to use new xml namespace.

This commit is contained in:
Mattias Hellborg Arthursson
2013-10-08 08:17:49 +02:00
parent 0606f37388
commit 795701fd58
21 changed files with 980 additions and 306 deletions

View File

@@ -231,14 +231,14 @@ public class DelegatingContext implements Context {
* @see javax.naming.Context#destroySubcontext(javax.naming.Name)
*/
public void destroySubcontext(Name name) throws NamingException {
throw new UnsupportedOperationException("Cannot call createSubcontext on a pooled context");
throw new UnsupportedOperationException("Cannot call destroySubcontext on a pooled context");
}
/**
* @see javax.naming.Context#destroySubcontext(java.lang.String)
*/
public void destroySubcontext(String name) throws NamingException {
throw new UnsupportedOperationException("Cannot call createSubcontext on a pooled context");
throw new UnsupportedOperationException("Cannot call destroySubcontext on a pooled context");
}
/**

View File

@@ -2,42 +2,33 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
xmlns:ldap="http://www.springframework.org/schema/ldap"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd">
<context:property-placeholder location="classpath:/ldap.properties" />
<ldap:context-source id="contextSource"
password="${password}"
url="ldap://localhost:18880"
username="${userDn}"
base="dc=jayway,dc=se" />
<ldap:ldap-template id="ldapTemplate" context-source-ref="contextSource"/>
<!--
This is for test and demo purposes only - the TestContextSourceFactoryBean starts an in-process
Apache Directory Server instance and populates it with data from the specified LDIF file.
A real-world application would use a DirContextSource instead.
-->
<bean id="contextSource"
class="org.springframework.ldap.test.TestContextSourceFactoryBean">
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
<property name="defaultPartitionName" value="jayway" />
<property name="principal" value="${userDn}" />
<property name="password" value="${password}" />
<property name="ldifFile" value="classpath:/setup_data.ldif" />
<property name="port" value="18880" />
</bean>
<!--
Below is an example of a ContextSource definition as it would look in a real application, connecting
against an external LDAP server.
<bean class="org.springframework.ldap.core.support.LdapContextSource" id="contextSource">
<property name="url" value="ldap://ldap.example.com" />
<property name="userDn" value="cn=admin,dc=261consulting,dc=com"/>
<property name="password" value="secret"/>
<property name="base" value="dc=261consulting,dc=com" />
<bean id="dummy" class="org.springframework.ldap.test.TestContextSourceFactoryBean">
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
<property name="defaultPartitionName" value="jayway" />
<property name="ldifFile" value="classpath:/setup_data.ldif" />
<property name="port" value="18880" />
<property name="contextSource" ref="contextSource" />
</bean>
-->
<bean id="ldapTemplate"
class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
<bean id="ldapTreeBuilder"
class="org.springframework.ldap.samples.utils.LdapTreeBuilder">

View File

@@ -2,42 +2,32 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
xmlns:ldap="http://www.springframework.org/schema/ldap"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd">
<context:property-placeholder location="classpath:/ldap.properties" />
<ldap:context-source id="contextSource"
password="${password}"
url="ldap://localhost:18880"
username="${userDn}"
base="dc=jayway,dc=se" />
<ldap:ldap-template id="ldapTemplate" context-source-ref="contextSource"/>
<!--
This is for test and demo purposes only - the TestContextSourceFactoryBean starts an in-process
Apache Directory Server instance and populates it with data from the specified LDIF file.
A real-world application would use a DirContextSource instead.
-->
<bean id="contextSource"
class="org.springframework.ldap.test.TestContextSourceFactoryBean">
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
<property name="defaultPartitionName" value="jayway" />
<property name="principal" value="${userDn}" />
<property name="password" value="${password}" />
<property name="ldifFile" value="classpath:/setup_data.ldif" />
<property name="port" value="18880" />
</bean>
<!--
Below is an example of a ContextSource definition as it would look in a real application, connecting
against an external LDAP server.
<bean class="org.springframework.ldap.core.support.LdapContextSource" id="contextSource">
<property name="url" value="ldap://ldap.example.com" />
<property name="userDn" value="cn=admin,dc=261consulting,dc=com"/>
<property name="password" value="secret"/>
<property name="base" value="dc=261consulting,dc=com" />
<bean id="dummy" class="org.springframework.ldap.test.TestContextSourceFactoryBean">
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
<property name="defaultPartitionName" value="jayway" />
<property name="ldifFile" value="classpath:/setup_data.ldif" />
<property name="port" value="18880" />
<property name="contextSource" ref="contextSource" />
</bean>
-->
<bean id="ldapTemplate"
class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
<bean id="ldapTreeBuilder"
class="org.springframework.ldap.samples.utils.LdapTreeBuilder">

View File

@@ -16,6 +16,8 @@
package org.springframework.ldap.test;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.directory.server.core.DefaultDirectoryService;
import org.apache.directory.server.core.DirectoryService;
import org.apache.directory.server.core.entry.ServerEntry;
@@ -33,6 +35,8 @@ import java.io.File;
* @since 1.3.2
*/
public class EmbeddedLdapServer {
private static final Log log = LogFactory.getLog(EmbeddedLdapServer.class);
private final DirectoryService directoryService;
private final LdapServer ldapServer;

View File

@@ -0,0 +1,34 @@
package org.springframework.ldap.test;
import org.springframework.beans.factory.config.AbstractFactoryBean;
/**
* @author Mattias Hellborg Arthursson
*/
public class EmbeddedLdapServerFactoryBean extends AbstractFactoryBean<EmbeddedLdapServer> {
private int port;
private String partitionName;
private String partitionSuffix;
@Override
public Class<?> getObjectType() {
return EmbeddedLdapServer.class;
}
public void setPartitionName(String partitionName) {
this.partitionName = partitionName;
}
public void setPartitionSuffix(String partitionSuffix) {
this.partitionSuffix = partitionSuffix;
}
public void setPort(int port) {
this.port = port;
}
@Override
protected EmbeddedLdapServer createInstance() throws Exception {
return EmbeddedLdapServer.newEmbeddedServer(partitionName, partitionSuffix, port);
}
}

View File

@@ -189,10 +189,10 @@ public class LdapTestUtils {
childName = LdapUtils.prepend(childName, name);
try {
ctx.destroySubcontext(childName);
ctx.unbind(childName);
} catch (ContextNotEmptyException e) {
clearSubContexts(ctx, childName);
ctx.destroySubcontext(childName);
ctx.unbind(childName);
}
}
} catch (NamingException e) {

View File

@@ -48,6 +48,8 @@ public class TestContextSourceFactoryBean extends AbstractFactoryBean {
private AuthenticationSource authenticationSource;
private ContextSource contextSource;
public void setAuthenticationSource(AuthenticationSource authenticationSource) {
this.authenticationSource = authenticationSource;
}
@@ -88,37 +90,48 @@ public class TestContextSourceFactoryBean extends AbstractFactoryBean {
this.port = port;
}
protected Object createInstance() throws Exception {
public void setContextSource(ContextSource contextSource) {
this.contextSource = contextSource;
}
protected Object createInstance() throws Exception {
LdapTestUtils.startEmbeddedServer(port, defaultPartitionSuffix, defaultPartitionName);
LdapContextSource targetContextSource = new LdapContextSource();
if (baseOnTarget) {
targetContextSource.setBase(defaultPartitionSuffix);
}
if (contextSource == null) {
// If not explicitly configured, create a new instance.
LdapContextSource targetContextSource = new LdapContextSource();
if (baseOnTarget) {
targetContextSource.setBase(defaultPartitionSuffix);
}
targetContextSource.setUrl("ldap://localhost:" + port);
targetContextSource.setUserDn(principal);
targetContextSource.setPassword(password);
targetContextSource.setDirObjectFactory(dirObjectFactory);
targetContextSource.setPooled(pooled);
targetContextSource.setUrl("ldap://localhost:" + port);
targetContextSource.setUserDn(principal);
targetContextSource.setPassword(password);
targetContextSource.setDirObjectFactory(dirObjectFactory);
targetContextSource.setPooled(pooled);
if (authenticationSource != null) {
targetContextSource.setAuthenticationSource(authenticationSource);
}
targetContextSource.afterPropertiesSet();
if (authenticationSource != null) {
targetContextSource.setAuthenticationSource(authenticationSource);
}
targetContextSource.afterPropertiesSet();
if (baseOnTarget) {
LdapTestUtils.clearSubContexts(targetContextSource, LdapUtils.emptyLdapName());
contextSource = targetContextSource;
}
Thread.sleep(1000);
if (baseOnTarget) {
LdapTestUtils.clearSubContexts(contextSource, LdapUtils.emptyLdapName());
}
else {
LdapTestUtils.clearSubContexts(targetContextSource, LdapUtils.newLdapName(defaultPartitionSuffix));
LdapTestUtils.clearSubContexts(contextSource, LdapUtils.newLdapName(defaultPartitionSuffix));
}
if (ldifFile != null) {
LdapTestUtils.loadLdif(targetContextSource, ldifFile);
LdapTestUtils.loadLdif(contextSource, ldifFile);
}
return targetContextSource;
return contextSource;
}
public Class getObjectType() {

View File

@@ -18,11 +18,9 @@ package org.springframework.ldap.itest25;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.ldap.core.DirContextOperations;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import static junit.framework.Assert.assertEquals;
@@ -31,12 +29,7 @@ import static junit.framework.Assert.assertEquals;
*
* @author Mattias Hellborg Arthursson
*/
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
public class LdapTemplateLookup25ITest extends AbstractJUnit4SpringContextTests {
@Autowired
private LdapTemplate tested;
public class LdapTemplateLookup25ITest {
/**
* This method depends on a DirObjectFactory (
* {@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
@@ -44,10 +37,29 @@ public class LdapTemplateLookup25ITest extends AbstractJUnit4SpringContextTests
*/
@Test
public void testThatPlainLookupWorksWithSpring25() {
DirContextOperations result = tested.lookupContext("cn=Some Person2, ou=company1,c=Sweden");
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/conf/ldapTemplateTestContext.xml");
LdapTemplate tested = (LdapTemplate) ctx.getBean("ldapTemplate");
assertEquals("Some Person2", result.getStringAttribute("cn"));
assertEquals("Person2", result.getStringAttribute("sn"));
assertEquals("Sweden, Company1, Some Person2", result.getStringAttribute("description"));
}
performTestAndShutdownContext(ctx, tested);
}
@Test
public void testThatNamespaceConfigurationWorksWithSpring25() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/conf/ldapTemplateNamespaceTestContext.xml");
LdapTemplate tested = (LdapTemplate) ctx.getBean("ldapTemplate");
performTestAndShutdownContext(ctx, tested);
}
private void performTestAndShutdownContext(ClassPathXmlApplicationContext ctx, LdapTemplate tested) {
try {
DirContextOperations result = tested.lookupContext("cn=Some Person2, ou=company1,c=Sweden");
assertEquals("Some Person2", result.getStringAttribute("cn"));
assertEquals("Person2", result.getStringAttribute("sn"));
assertEquals("Sweden, Company1, Some Person2", result.getStringAttribute("description"));
} finally {
ctx.close();
}
}
}

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ldap="http://www.springframework.org/schema/ldap"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd">
<import resource="classpath:/conf/commonTestContext.xml" />
<ldap:context-source
password="${password}"
url="ldap://localhost:1888"
username="${userDn}"
base="dc=jayway,dc=se" />
<ldap:ldap-template />
<bean id="dummy" class="org.springframework.ldap.test.TestContextSourceFactoryBean">
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
<property name="defaultPartitionName" value="jayway" />
<property name="ldifFile" value="classpath:/setup_data.ldif" />
<property name="port" value="1888" />
<property name="contextSource" ref="contextSource" />
</bean>
</beans>

View File

@@ -21,6 +21,7 @@ import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.DirContextOperations;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
@@ -32,6 +33,7 @@ import static junit.framework.Assert.assertEquals;
* @author Mattias Hellborg Arthursson
*/
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
@DirtiesContext
public class LdapTemplateLookup30ITest extends AbstractJUnit4SpringContextTests {
@Autowired

View File

@@ -0,0 +1,55 @@
/*
* 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.itest30;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.DirContextOperations;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import static junit.framework.Assert.assertEquals;
/**
* Tests the lookup methods of LdapTemplate together with Spring 3.0.
*
* @author Mattias Hellborg Arthursson
*/
@ContextConfiguration(locations = {"/conf/ldapTemplateNamespaceTestContext.xml"})
@DirtiesContext
public class LdapTemplateNamespaceLookup30ITest extends AbstractJUnit4SpringContextTests {
@Autowired
private LdapTemplate tested;
/**
* This method depends on a DirObjectFactory (
* {@link org.springframework.ldap.core.support.DefaultDirObjectFactory})
* being set in the ContextSource.
*/
@Test
public void testThatPlainLookupWorksWithSpring30() {
DirContextOperations result = tested.lookupContext("cn=Some Person2, ou=company1,c=Sweden");
assertEquals("Some Person2", result.getStringAttribute("cn"));
assertEquals("Person2", result.getStringAttribute("sn"));
assertEquals("Sweden, Company1, Some Person2", result.getStringAttribute("description"));
}
}

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ldap="http://www.springframework.org/schema/ldap"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd">
<import resource="classpath:/conf/commonTestContext.xml" />
<ldap:context-source
password="${password}"
url="ldap://localhost:1888"
username="${userDn}"
base="dc=jayway,dc=se" />
<ldap:ldap-template />
<bean id="dummy" class="org.springframework.ldap.test.TestContextSourceFactoryBean">
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
<property name="defaultPartitionName" value="jayway" />
<property name="ldifFile" value="classpath:/setup_data.ldif" />
<property name="port" value="1888" />
<property name="contextSource" ref="contextSource" />
</bean>
</beans>

View File

@@ -1,159 +0,0 @@
/*
* Copyright 2005-2010 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;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.fail;
import java.io.Serializable;
import java.util.Date;
import java.util.LinkedList;
import javax.naming.directory.DirContext;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.AbstractContextSource;
import org.springframework.test.context.ContextConfiguration;
/**
* Tests bind and lookup with Java objects where the ContextSource has a
* <code>null</code> DirObjectFactory configured.
*
* @author Ulrik Sandberg
*/
@ContextConfiguration(locations = {"/conf/ldapTemplateObjectBindTestContext.xml"})
public class LdapTemplateObjectBindIntegrationTest extends AbstractLdapTemplateIntegrationTest {
@Autowired
private LdapTemplate tested;
@Test
public void testBindJavaObjectDate() throws Exception {
String dn = "cn=myRandomDate";
Date now = new Date();
tested.bind(dn, now, null);
Date result = (Date) tested.lookup(dn);
assertEquals(now, result);
tested.unbind(dn);
}
@Test
public void testBindJavaObjectInteger() throws Exception {
String dn = "cn=myRandomInt";
int i = 54321;
tested.bind(dn, new Integer(i), null);
Integer result = (Integer) tested.lookup(dn);
assertEquals(i, result.intValue());
tested.unbind(dn);
}
@Test
public void testBindLinkedList() {
LinkedList list = new LinkedList();
list.add(new Integer(54321));
list.add(new Integer(67890));
String dn = "cn=myRandomList";
tested.bind(dn, list, null);
LinkedList result = (LinkedList) tested.lookup(dn);
assertEquals(2, result.size());
assertEquals(54321, ((Integer) result.get(0)).intValue());
assertEquals(67890, ((Integer) result.get(1)).intValue());
tested.unbind(dn);
}
@Test
public void testBindNonSerializableJavaObjectShouldFail() throws Exception {
NonSerializablePojo pojo = new NonSerializablePojo();
pojo.setName("A Name");
try {
tested.bind("cn=myRandomObject", pojo, null);
fail("IllegalArgumentException expected");
}
catch (IllegalArgumentException expected) {
assertEquals("can only bind Referenceable, Serializable, DirContext", expected.getMessage());
}
}
/**
* Custom non-serializable class used for demonstrating bind and lookup of
* Java objects.
*/
public static class NonSerializablePojo {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@Test
public void testBindSerializableJavaObjectShouldSucceed() throws Exception {
SerializablePojo pojo = new SerializablePojo();
pojo.setName("A Name");
tested.bind("cn=myRandomObject", pojo, null);
SerializablePojo result = (SerializablePojo) tested.lookup("cn=myRandomObject");
assertEquals("A Name", result.getName());
tested.unbind("cn=myRandomObject");
}
/**
* Custom serializable class used for demonstrating bind and lookup of Java
* objects.
*/
public static class SerializablePojo implements Serializable {
private static final long serialVersionUID = 3655768927093734908L;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
/**
* This test demonstrates that it's fully possible to perform plain JNDI
* operations from Spring LDAP.
*/
@Test
public void testPlainJndiBindJavaObject() throws Exception {
AbstractContextSource contextSource = (AbstractContextSource) tested.getContextSource();
DirContext ctx = contextSource.getReadWriteContext();
ctx.bind("cn=myRandomInt", new Integer(28420));
Integer result = (Integer) ctx.lookup("cn=myRandomInt");
assertEquals(28420, result.intValue());
tested.unbind("cn=myRandomInt");
}
}

View File

@@ -17,15 +17,17 @@
package org.springframework.ldap.itest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.io.ClassPathResource;
import org.springframework.ldap.core.ContextSource;
import org.springframework.ldap.core.DirContextOperations;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.pool.factory.PoolingContextSource;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.ldap.test.LdapTestUtils;
import org.springframework.ldap.transaction.compensating.manager.TransactionAwareContextSourceProxy;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
@@ -46,8 +48,7 @@ public class LdapTemplatePooledITest extends AbstractJUnit4SpringContextTests {
private LdapTemplate tested;
@Autowired
@Qualifier("contextSourceTarget")
protected ContextSource contextSource;
private ContextSource contextSource;
@After
public void cleanup() throws Exception {

View File

@@ -0,0 +1,391 @@
/*
* 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;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.ldap.NameNotFoundException;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DirContextOperations;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.AbstractContextMapper;
import org.springframework.ldap.query.SearchScope;
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;
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.
*
* @author Mattias Hellborg Arthursson
*/
@ContextConfiguration(locations = {"/conf/ldapTemplateNamespaceTestContext.xml"})
public class LdapTemplateSearchResultNamespaceConfigITest extends AbstractLdapTemplateIntegrationTest {
@Autowired
private LdapTemplate tested;
private AttributeCheckAttributesMapper attributesMapper;
private AttributeCheckContextMapper contextMapper;
private static final String[] ALL_ATTRIBUTES = { "cn", "sn", "description", "telephoneNumber" };
private static final String[] CN_SN_ATTRS = { "cn", "sn" };
private static final String[] ABSENT_ATTRIBUTES = { "description", "telephoneNumber" };
private static final String[] CN_SN_VALUES = { "Some Person2", "Person2" };
private static final String[] ALL_VALUES = { "Some Person2", "Person2", "Sweden, Company1, Some Person2",
"+46 555-654321" };
private static final String BASE_STRING = "";
private static final String FILTER_STRING = "(&(objectclass=person)(sn=Person2))";
private static final Name BASE_NAME = LdapUtils.newLdapName(BASE_STRING);
@Before
public void prepareTestedInstance() throws Exception {
attributesMapper = new AttributeCheckAttributesMapper();
contextMapper = new AttributeCheckContextMapper();
}
@After
public void cleanup() throws Exception {
attributesMapper = null;
contextMapper = null;
}
@Test
public void testSearch_AttributesMapper() {
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
attributesMapper.setExpectedValues(ALL_VALUES);
List list = tested.search(BASE_STRING, FILTER_STRING, attributesMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_LdapQuery_AttributesMapper() {
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);
assertEquals(1, list.size());
}
@Test
public void testSearch_LdapQuery_AttributesMapper_FewerAttributes() {
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"),
attributesMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_LdapQuery_AttributesMapper_SearchScope() {
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);
assertEquals(0, list.size());
}
@Test
public void testSearch_LdapQuery_AttributesMapper_SearchScope_CorrectBase() {
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
attributesMapper.setExpectedValues(ALL_VALUES);
List<Object> list = tested.search(query()
.base("ou=company1,c=Sweden")
.searchScope(SearchScope.ONELEVEL)
.where("objectclass").is("person").and("sn").is("Person2"),
attributesMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_LdapQuery_AttributesMapper_NoBase() {
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
attributesMapper.setExpectedValues(ALL_VALUES);
List<Object> list = tested.search(query()
.where("objectclass").is("person").and("sn").is("Person2"),
attributesMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_LdapQuery_AttributesMapper_DifferentBase() {
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
attributesMapper.setExpectedValues(ALL_VALUES);
List<Object> list = tested.search(query()
.base("c=Norway")
.where("objectclass").is("person").and("sn").is("Person2"),
attributesMapper);
assertEquals(0, list.size());
}
@Test
public void testSearch_SearchScope_AttributesMapper() {
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
attributesMapper.setExpectedValues(ALL_VALUES);
List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, attributesMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_SearchScope_LimitedAttrs_AttributesMapper() {
attributesMapper.setExpectedAttributes(CN_SN_ATTRS);
attributesMapper.setExpectedValues(CN_SN_VALUES);
attributesMapper.setAbsentAttributes(ABSENT_ATTRIBUTES);
List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS,
attributesMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_AttributesMapper_Name() {
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
attributesMapper.setExpectedValues(ALL_VALUES);
List list = tested.search(BASE_NAME, FILTER_STRING, attributesMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_SearchScope_AttributesMapper_Name() {
attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES);
attributesMapper.setExpectedValues(ALL_VALUES);
List list = tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, attributesMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_SearchScope_LimitedAttrs_AttributesMapper_Name() {
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);
assertEquals(1, list.size());
}
@Test
public void testSearch_ContextMapper() {
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
contextMapper.setExpectedValues(ALL_VALUES);
List list = tested.search(BASE_STRING, FILTER_STRING, contextMapper);
assertEquals(1, list.size());
}
@Test
public void testSearchForObject() {
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
contextMapper.setExpectedValues(ALL_VALUES);
DirContextAdapter result = (DirContextAdapter) tested
.searchForObject(BASE_STRING, FILTER_STRING, contextMapper);
assertNotNull(result);
}
@Test(expected = IncorrectResultSizeDataAccessException.class)
public void testSearchForObjectWithMultipleHits() {
tested.searchForObject(BASE_STRING, "(&(objectclass=person)(sn=*))", new AbstractContextMapper() {
@Override
protected Object doMapFromContext(DirContextOperations ctx) {
return ctx;
}
});
}
@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;
}
});
}
@Test
public void testSearch_SearchScope_ContextMapper() {
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
contextMapper.setExpectedValues(ALL_VALUES);
List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, contextMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_SearchScope_LimitedAttrs_ContextMapper() {
contextMapper.setExpectedAttributes(CN_SN_ATTRS);
contextMapper.setExpectedValues(CN_SN_VALUES);
contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES);
List list = tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, contextMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_ContextMapper_Name() {
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
contextMapper.setExpectedValues(ALL_VALUES);
List list = tested.search(BASE_NAME, FILTER_STRING, contextMapper);
assertEquals(1, list.size());
}
@Test
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);
assertEquals(1, list.size());
}
@Test
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"),
contextMapper);
assertEquals(1, list.size());
}
@Test
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);
assertEquals(0, list.size());
}
@Test
public void testSearch_ContextMapper_LdapQuery_SearchScope_CorrectBase() {
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
contextMapper.setExpectedValues(ALL_VALUES);
List<DirContextAdapter> list = tested.search(query()
.base("ou=company1,c=Sweden")
.searchScope(SearchScope.ONELEVEL)
.where("objectclass").is("person").and("sn").is("Person2"),
contextMapper);
assertEquals(1, list.size());
}
@Test
public void testSearchForContext_LdapQuery() {
DirContextOperations result = tested.searchForContext(query()
.where("objectclass").is("person").and("sn").is("Person2"));
assertNotNull(result);
assertEquals("Person2", result.getStringAttribute("sn"));
}
@Test(expected = EmptyResultDataAccessException.class)
public void testSearchForContext_LdapQuery_SearchScopeNotFound() {
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,c=Sweden")
.where("objectclass").is("person").and("sn").is("Person2"));
assertNotNull(result);
assertEquals("Person2", result.getStringAttribute("sn"));
}
@Test
public void testSearch_SearchScope_ContextMapper_Name() {
contextMapper.setExpectedAttributes(ALL_ATTRIBUTES);
contextMapper.setExpectedValues(ALL_VALUES);
List list = tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, contextMapper);
assertEquals(1, list.size());
}
@Test
public void testSearch_SearchScope_LimitedAttrs_ContextMapper_Name() {
contextMapper.setExpectedAttributes(CN_SN_ATTRS);
contextMapper.setExpectedValues(CN_SN_VALUES);
contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES);
List list = tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, contextMapper);
assertEquals(1, list.size());
}
@Test
public void testSearchWithInvalidSearchBaseShouldByDefaultThrowException() {
try {
tested.search(BASE_NAME + "ou=unknown", FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS,
contextMapper);
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertTrue(true);
}
}
@Test
public void testSearchWithInvalidSearchBaseCanBeConfiguredToSwallowException() {
tested.setIgnoreNameNotFoundException(true);
contextMapper.setExpectedAttributes(CN_SN_ATTRS);
contextMapper.setExpectedValues(CN_SN_VALUES);
contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES);
List list = tested.search(BASE_NAME + "ou=unknown", FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS,
contextMapper);
assertEquals(0, list.size());
}
}

View File

@@ -0,0 +1,275 @@
/*
* 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.manager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.ldap.NameNotFoundException;
import org.springframework.ldap.core.AttributesMapper;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTest;
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 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 org.springframework.ldap.transaction.compensating.manager.ContextSourceTransactionManager}
* that uses the spring ldap namespace for configuration.
*
* @author Mattias Hellborg Arthursson
*/
@ContextConfiguration(locations = {"/conf/ldapTemplateNamespaceTransactionTestContext.xml"})
public class ContextSourceTransactionManagerNamespaceIntegrationTest extends AbstractLdapTemplateIntegrationTest {
private static Log log = LogFactory.getLog(ContextSourceTransactionManagerNamespaceIntegrationTest.class);
@Autowired
@Qualifier("dummyDao")
private DummyDao dummyDao;
@Autowired
private LdapTemplate ldapTemplate;
@Before
public void prepareTestedInstance() throws Exception {
if (TransactionSynchronizationManager.isSynchronizationActive()) {
TransactionSynchronizationManager.clearSynchronization();
}
}
@Test
public void testCreateWithException() {
try {
dummyDao.createWithException("Sweden", "company1", "some testperson", "testperson", "some description");
fail("DummyException expected");
}
catch (DummyException expected) {
assertTrue(true);
}
log.debug("Verifying result");
// Verify that no entry was created
try {
ldapTemplate.lookup("cn=some testperson, ou=company1, c=Sweden");
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertTrue(true);
}
}
@Test
public void testCreate() {
dummyDao.create("Sweden", "company1", "some testperson", "testperson", "some description");
log.debug("Verifying result");
String expectedDn = "cn=some testperson, ou=company1, c=Sweden";
Object ldapResult = ldapTemplate.lookup(expectedDn);
assertNotNull(ldapResult);
ldapTemplate.unbind(expectedDn);
}
@Test
public void testUpdateWithException() {
String dn = "cn=Some Person,ou=company1,c=Sweden";
try {
dummyDao.updateWithException(dn, "Some Person", "Updated Person", "Updated description");
fail("DummyException expected");
}
catch (DummyException expected) {
assertTrue(true);
}
log.debug("Verifying result");
Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
assertEquals("Person", attributes.get("sn").get());
assertEquals("Sweden, Company1, Some Person", attributes.get("description").get());
return new Object();
}
});
assertNotNull(ldapResult);
}
@Test
public void testUpdate() {
String dn = "cn=Some Person,ou=company1,c=Sweden";
dummyDao.update(dn, "Some Person", "Updated Person", "Updated description");
log.debug("Verifying result");
Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
assertEquals("Updated Person", attributes.get("sn").get());
assertEquals("Updated description", attributes.get("description").get());
return new Object();
}
});
assertNotNull(ldapResult);
dummyDao.update(dn, "Some Person", "Person", "Sweden, Company1, Some Person");
}
@Test
public void testUpdateAndRenameWithException() {
String dn = "cn=Some Person2,ou=company1,c=Sweden";
String newDn = "cn=Some Person2,ou=company2,c=Sweden";
try {
// Perform test
dummyDao.updateAndRenameWithException(dn, newDn, "Updated description");
fail("DummyException expected");
}
catch (DummyException expected) {
assertTrue(true);
}
// Verify that entry was not moved.
try {
ldapTemplate.lookup(newDn);
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertTrue(true);
}
// Verify that original entry was not updated.
Object object = ldapTemplate.lookup(dn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
assertEquals("Sweden, Company1, Some Person2", attributes.get("description").get());
return new Object();
}
});
assertNotNull(object);
}
@Test
public void testUpdateAndRename() {
String dn = "cn=Some Person2,ou=company1,c=Sweden";
String newDn = "cn=Some Person2,ou=company2,c=Sweden";
// Perform test
dummyDao.updateAndRename(dn, newDn, "Updated description");
// Verify that entry was moved and updated.
Object object = ldapTemplate.lookup(newDn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
assertEquals("Updated description", attributes.get("description").get());
return new Object();
}
});
assertNotNull(object);
dummyDao.updateAndRename(newDn, dn, "Sweden, Company1, Some Person2");
}
@Test
public void testModifyAttributesWithException() {
String dn = "cn=Some Person,ou=company1,c=Sweden";
try {
// Perform test
dummyDao.modifyAttributesWithException(dn, "Updated lastname", "Updated description");
fail("DummyException expected");
}
catch (DummyException expected) {
assertTrue(true);
}
// Verify result - check that the operation was properly rolled back
Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
assertEquals("Person", attributes.get("sn").get());
assertEquals("Sweden, Company1, Some Person", attributes.get("description").get());
return new Object();
}
});
assertNotNull(result);
}
@Test
public void testModifyAttributes() {
String dn = "cn=Some Person,ou=company1,c=Sweden";
// Perform test
dummyDao.modifyAttributes(dn, "Updated lastname", "Updated description");
// Verify result - check that the operation was not rolled back
Object result = ldapTemplate.lookup(dn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
assertEquals("Updated lastname", attributes.get("sn").get());
assertEquals("Updated description", attributes.get("description").get());
return new Object();
}
});
assertNotNull(result);
}
@Test
public void testUnbindWithException() {
String dn = "cn=Some Person,ou=company1,c=Sweden";
try {
// Perform test
dummyDao.unbindWithException(dn, "Some Person");
fail("DummyException expected");
}
catch (DummyException expected) {
assertTrue(true);
}
// Verify result - check that the operation was properly rolled back
Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
public Object mapFromAttributes(Attributes attributes) throws NamingException {
// Just verify that the entry still exists.
return new Object();
}
});
assertNotNull(ldapResult);
}
@Test
public void testUnbind() {
String dn = "cn=Some Person,ou=company1,c=Sweden";
// Perform test
dummyDao.unbind(dn, "Some Person");
try {
// Verify result - check that the operation was not rolled back
ldapTemplate.lookup(dn);
fail("NameNotFoundException expected");
}
catch (NameNotFoundException expected) {
assertTrue(true);
}
}
}

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ldap="http://www.springframework.org/schema/ldap"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd">
<import resource="classpath:/conf/commonTestContext.xml" />
<ldap:context-source
password="${password}"
url="ldap://localhost:1888"
username="${userDn}"
base="dc=jayway,dc=se" />
<ldap:ldap-template />
<bean id="dummy" class="org.springframework.ldap.test.TestContextSourceFactoryBean">
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
<property name="defaultPartitionName" value="jayway" />
<property name="ldifFile" value="classpath:/setup_data.ldif" />
<property name="port" value="1888" />
<property name="contextSource" ref="contextSource" />
</bean>
</beans>

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:ldap="http://www.springframework.org/schema/ldap"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd">
<import resource="classpath:/conf/commonTestContext.xml"/>
<ldap:context-source
password="${password}"
url="ldap://localhost:1888"
username="${userDn}"
base="dc=jayway,dc=se" />
<bean id="dummy" class="org.springframework.ldap.test.TestContextSourceFactoryBean">
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
<property name="defaultPartitionName" value="jayway" />
<property name="ldifFile" value="classpath:/setup_data.ldif" />
<property name="port" value="1888" />
<property name="contextSource" ref="contextSource" />
</bean>
<ldap:ldap-template />
<ldap:transaction-manager>
<ldap:default-renaming-strategy />
</ldap:transaction-manager>
<bean name="dummyDao"
class="org.springframework.ldap.itest.transaction.compensating.manager.LdapDummyDaoImpl">
<property name="ldapTemplate" ref="ldapTemplate" />
</bean>
<tx:annotation-driven />
</beans>

View File

@@ -1,24 +0,0 @@
<?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
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<import resource="classpath:/conf/commonTestContext.xml"/>
<bean id="contextSource"
class="org.springframework.ldap.test.TestContextSourceFactoryBean">
<property name="defaultPartitionSuffix" value="dc=jayway,dc=se" />
<property name="defaultPartitionName" value="jayway" />
<property name="principal" value="${userDn}" />
<property name="password" value="${password}" />
<property name="ldifFile" value="classpath:/setup_data.ldif" />
<property name="port" value="1888" />
<property name="dirObjectFactory"><null/></property>
</bean>
<bean id="ldapTemplate"
class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
</beans>

View File

@@ -16,35 +16,23 @@
-->
<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
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ldap="http://www.springframework.org/schema/ldap"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd">
<import resource="classpath:/conf/commonTestContext.xml" />
<bean id="contextSourceTarget"
class="org.springframework.ldap.core.support.LdapContextSource">
<property name="userDn" value="${userDn}" />
<property name="password" value="${password}" />
<property name="url" value="ldap://localhost:1888" />
<property name="base" value="dc=jayway,dc=se" />
</bean>
<ldap:context-source
password="${password}"
url="ldap://localhost:1888"
username="${userDn}"
base="dc=jayway,dc=se">
<bean id="contextSource" class="org.springframework.ldap.pool.factory.PoolingContextSource">
<property name="contextSource" ref="contextSourceTarget" />
<property name="maxActive" value="1" />
<property name="maxTotal" value="1" />
<property name="maxIdle" value="1" />
<property name="minIdle" value="1" />
<property name="testOnBorrow" value="false" />
<property name="testWhileIdle" value="false" />
</bean>
<ldap:pooling
max-active="1"
max-total="1"
max-idle="1"
min-idle="1" />
</ldap:context-source>
<bean id="ldapTemplate"
class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
<!--
<bean id="dataLoader" class="org.ddsteps.data.excel.CachingExcelDataLoader" />
-->
<ldap:ldap-template />
</beans>

View File

@@ -19,8 +19,4 @@
class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
<!--
<bean id="dataLoader" class="org.ddsteps.data.excel.CachingExcelDataLoader" />
-->
</beans>