LDAP-316 - Optional support for apache commons-pool2 added.

This commit is contained in:
Anindya Chatterjee
2015-10-10 17:03:59 +05:30
committed by Rob Winch
parent 05b89c3b45
commit 4cefc5b147
36 changed files with 4742 additions and 33 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2005-2013 the original author or authors.
* Copyright 2005-2015 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.
@@ -17,6 +17,7 @@
package org.springframework.ldap.config;
import org.apache.commons.pool.impl.GenericKeyedObjectPool;
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig;
import org.junit.Test;
import org.springframework.beans.BeansException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -27,6 +28,7 @@ import org.springframework.ldap.core.support.DirContextAuthenticationStrategy;
import org.springframework.ldap.core.support.LdapContextSource;
import org.springframework.ldap.pool.factory.PoolingContextSource;
import org.springframework.ldap.pool.validation.DefaultDirContextValidator;
import org.springframework.ldap.pool2.factory.PooledContextSource;
import org.springframework.ldap.support.LdapUtils;
import org.springframework.ldap.transaction.compensating.TempEntryRenamingStrategy;
import org.springframework.ldap.transaction.compensating.manager.ContextSourceAndDataSourceTransactionManager;
@@ -36,9 +38,12 @@ import org.springframework.ldap.transaction.compensating.support.DefaultTempEntr
import org.springframework.ldap.transaction.compensating.support.DifferentSubtreeTempEntryRenamingStrategy;
import org.springframework.transaction.PlatformTransactionManager;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.naming.CannotProceedException;
import javax.naming.CommunicationException;
import javax.naming.directory.SearchControls;
import java.lang.management.ManagementFactory;
import java.util.Set;
import static org.junit.Assert.assertArrayEquals;
@@ -124,6 +129,7 @@ public class LdapTemplateNamespaceHandlerTest {
assertSame(authenticationStrategy, getInternalState(contextSource, "authenticationStrategy"));
assertEquals(baseEnv, getInternalState(contextSource, "baseEnv"));
}
@Test
public void verifyParseWithCustomValues() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-values.xml");
@@ -360,4 +366,132 @@ public class LdapTemplateNamespaceHandlerTest {
assertNotNull(repository);
}
@Test
public void verifyParsePooling2Defaults() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling2-defaults.xml");
ContextSource outerContextSource = ctx.getBean(ContextSource.class);
assertNotNull(outerContextSource);
assertTrue(outerContextSource instanceof TransactionAwareContextSourceProxy);
ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
assertNotNull(pooledContextSource);
assertTrue(pooledContextSource instanceof PooledContextSource);
assertNotNull(getInternalState(pooledContextSource, "poolConfig"));
Object objectFactory = getInternalState(pooledContextSource, "dirContextPooledObjectFactory");
assertNotNull(getInternalState(objectFactory, "contextSource"));
assertNull(getInternalState(objectFactory, "dirContextValidator"));
Set<Class<? extends Throwable>> nonTransientExceptions =
(Set<Class<? extends Throwable>>) getInternalState(objectFactory, "nonTransientExceptions");
assertEquals(1, nonTransientExceptions.size());
assertTrue(nonTransientExceptions.contains(CommunicationException.class));
org.apache.commons.pool2.impl.GenericKeyedObjectPool objectPool =
(org.apache.commons.pool2.impl.GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool");
assertEquals(8, objectPool.getMaxIdlePerKey());
assertEquals(-1, objectPool.getMaxTotal());
assertEquals(8, objectPool.getMaxTotalPerKey());
assertEquals(0, objectPool.getMinIdlePerKey());
assertEquals(true, objectPool.getBlockWhenExhausted());
assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_EVICTION_POLICY_CLASS_NAME, objectPool.getEvictionPolicyClassName());
assertEquals(false, objectPool.getFairness());
// ensures the pool is registered
ObjectName oname = objectPool.getJmxName();
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> result = mbs.queryNames(oname, null);
assertEquals(1, result.size());
assertEquals(true, objectPool.getLifo());
assertEquals(-1L, objectPool.getMaxWaitMillis());
assertEquals(1000L*60L*30L, objectPool.getMinEvictableIdleTimeMillis());
assertEquals(3, objectPool.getNumTestsPerEvictionRun());
assertEquals(-1L, objectPool.getSoftMinEvictableIdleTimeMillis());
assertEquals(-1L, objectPool.getTimeBetweenEvictionRunsMillis());
assertEquals(false, objectPool.getTestOnBorrow());
assertEquals(false, objectPool.getTestOnCreate());
assertEquals(false, objectPool.getTestOnReturn());
assertEquals(false, objectPool.getTestWhileIdle());
}
@Test
public void verifyParsePool2SizeSet() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pool2-configured-poolsize.xml");
ContextSource outerContextSource = ctx.getBean(ContextSource.class);
assertNotNull(outerContextSource);
ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
assertNotNull(pooledContextSource);
org.apache.commons.pool2.impl.GenericKeyedObjectPool objectPool =
(org.apache.commons.pool2.impl.GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool");
assertEquals(12, objectPool.getMaxTotal());
assertEquals(20, objectPool.getMaxIdlePerKey());
assertEquals(10, objectPool.getMaxTotalPerKey());
assertEquals(13, objectPool.getMaxWaitMillis());
assertEquals(14, objectPool.getMinIdlePerKey());
assertEquals(true, objectPool.getBlockWhenExhausted());
assertEquals("org.springframework.ldap.pool2.DummyEvictionPolicy", objectPool.getEvictionPolicyClassName());
assertEquals(true, objectPool.getFairness());
assertEquals(false, objectPool.getLifo());
// ensures the pool is registered
ObjectName oname = objectPool.getJmxName();
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> result = mbs.queryNames(oname, null);
assertEquals(1, result.size());
assertEquals("org.springframework.ldap.pool2:type=ldap-pool,name=test-pool", oname.toString());
}
@Test
public void verifyParsePool2ValidationSet() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/ldap-namespace-config-pool2-test-specified.xml");
ContextSource outerContextSource = ctx.getBean(ContextSource.class);
assertNotNull(outerContextSource);
ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
assertNotNull(pooledContextSource);
org.apache.commons.pool2.impl.GenericKeyedObjectPool objectPool =
(org.apache.commons.pool2.impl.GenericKeyedObjectPool) getInternalState(pooledContextSource, "keyedObjectPool");
assertEquals(123, objectPool.getMinEvictableIdleTimeMillis());
assertEquals(321, objectPool.getTimeBetweenEvictionRunsMillis());
assertEquals(22, objectPool.getNumTestsPerEvictionRun());
assertEquals(12, objectPool.getSoftMinEvictableIdleTimeMillis());
assertEquals(true, objectPool.getTestOnBorrow());
assertEquals(true, objectPool.getTestOnReturn());
assertEquals(true, objectPool.getTestOnCreate());
assertEquals(true, objectPool.getTestWhileIdle());
Object objectFactory = getInternalState(pooledContextSource, "dirContextPooledObjectFactory");
org.springframework.ldap.pool2.validation.DefaultDirContextValidator validator =
(org.springframework.ldap.pool2.validation.DefaultDirContextValidator) getInternalState(objectFactory, "dirContextValidator");
assertEquals("ou=test", validator.getBase());
assertEquals("objectclass=person", validator.getFilter());
SearchControls searchControls = ctx.getBean(SearchControls.class);
assertEquals("objectclass=person", validator.getFilter());
assertSame(searchControls, validator.getSearchControls());
Set<Class<? extends Throwable>> nonTransientExceptions =
(Set<Class<? extends Throwable>>) getInternalState(objectFactory, "nonTransientExceptions");
assertEquals(2, nonTransientExceptions.size());
assertTrue(nonTransientExceptions.contains(CommunicationException.class));
assertTrue(nonTransientExceptions.contains(CannotProceedException.class));
}
@Test(expected = BeansException.class)
public void verifyParseWithPool2AndNativePoolingWillFail() {
new ClassPathXmlApplicationContext("/ldap-namespace-config-pool2-with-native.xml");
}
@Test(expected = BeansException.class)
public void verifyParseWithPool1AndPool2WillFail() {
new ClassPathXmlApplicationContext("/ldap-namespace-config-pool2-with-pool1.xml");
}
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright 2005-2015 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.pool2;
import org.apache.commons.pool2.KeyedObjectPool;
import org.junit.Before;
import org.springframework.ldap.core.ContextSource;
import org.springframework.ldap.pool2.validation.DirContextValidator;
import javax.naming.Context;
import javax.naming.directory.DirContext;
import javax.naming.ldap.LdapContext;
import static org.mockito.Mockito.mock;
/**
* Contains mocks common to many tests for the connection pool.
*
* @author Ulrik Sandberg
*/
public abstract class AbstractPoolTestCase {
protected Context contextMock;
protected DirContext dirContextMock;
protected LdapContext ldapContextMock;
protected KeyedObjectPool keyedObjectPoolMock;
protected ContextSource contextSourceMock;
protected DirContextValidator dirContextValidatorMock;
@Before
public void setUp() throws Exception {
contextMock = mock(Context.class);
dirContextMock = mock(DirContext.class);
ldapContextMock = mock(LdapContext.class);
keyedObjectPoolMock = mock(KeyedObjectPool.class);
contextSourceMock = mock(ContextSource.class);
dirContextValidatorMock = mock(DirContextValidator.class);
}
}

View File

@@ -0,0 +1,409 @@
/*
* Copyright 2005-2015 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.pool2;
import org.apache.commons.pool2.KeyedObjectPool;
import org.junit.Test;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NamingException;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
/**
* @author Eric Dalquist <a
* href="mailto:eric.dalquist@doit.wisc.edu">eric.dalquist@doit.wisc.edu</a>
*/
public class DelegatingContextTest extends AbstractPoolTestCase {
@Test
public void testConstructorAssertions() {
try {
new DelegatingContext(null, contextMock, DirContextType.READ_ONLY);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
}
try {
new DelegatingContext(keyedObjectPoolMock, null,
DirContextType.READ_ONLY);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
}
try {
new DelegatingContext(keyedObjectPoolMock, contextMock, null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
}
}
@Test
public void testHelperMethods() throws Exception {
// Wrap the Context once
final DelegatingContext delegatingContext = new DelegatingContext(
keyedObjectPoolMock, contextMock, DirContextType.READ_ONLY);
final Context delegateContext = delegatingContext.getDelegateContext();
assertEquals(contextMock, delegateContext);
final Context innerDelegateContext = delegatingContext
.getInnermostDelegateContext();
assertEquals(contextMock, innerDelegateContext);
delegatingContext.assertOpen();
// Wrap the wrapper
KeyedObjectPool secondKeyedObjectPoolMock = mock(KeyedObjectPool.class);
final DelegatingContext delegatingContext2 = new DelegatingContext(
secondKeyedObjectPoolMock, delegatingContext,
DirContextType.READ_ONLY);
final Context delegateContext2 = delegatingContext2
.getDelegateContext();
assertEquals(delegatingContext, delegateContext2);
final Context innerDelegateContext2 = delegatingContext2
.getInnermostDelegateContext();
assertEquals(contextMock, innerDelegateContext2);
delegatingContext2.assertOpen();
// Close the outer wrapper
delegatingContext2.close();
final Context delegateContext2closed = delegatingContext2
.getDelegateContext();
assertNull(delegateContext2closed);
final Context innerDelegateContext2closed = delegatingContext2
.getInnermostDelegateContext();
assertNull(innerDelegateContext2closed);
try {
delegatingContext2.assertOpen();
fail("delegatingContext2.assertOpen() should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
// Close the outer wrapper
delegatingContext.close();
final Context delegateContextclosed = delegatingContext
.getDelegateContext();
assertNull(delegateContextclosed);
final Context innerDelegateContextclosed = delegatingContext
.getInnermostDelegateContext();
assertNull(innerDelegateContextclosed);
try {
delegatingContext.assertOpen();
fail("delegatingContext.assertOpen() should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
verify(keyedObjectPoolMock).returnObject(DirContextType.READ_ONLY, contextMock);
verify(secondKeyedObjectPoolMock)
.returnObject(DirContextType.READ_ONLY, contextMock);
}
@Test
public void testObjectMethods() throws Exception {
// Wrap the Context once
final DelegatingContext delegatingContext = new DelegatingContext(
keyedObjectPoolMock, contextMock, DirContextType.READ_ONLY);
assertEquals(contextMock.toString(), delegatingContext.toString());
delegatingContext.hashCode(); // Run it to make sure it doesn't fail
assertTrue(delegatingContext.equals(delegatingContext));
assertFalse(delegatingContext.equals(new Object()));
final DelegatingContext delegatingContext2 = new DelegatingContext(
keyedObjectPoolMock, contextMock, DirContextType.READ_ONLY);
assertTrue(delegatingContext.equals(delegatingContext2));
assertTrue(delegatingContext2.equals(delegatingContext));
assertTrue(delegatingContext.equals(contextMock));
// Close the contextMock and try again
delegatingContext.close();
assertEquals("Context is closed", delegatingContext.toString());
assertEquals(0, delegatingContext.hashCode()); // Run it to make sure
// it doesn't fail
assertTrue(delegatingContext.equals(delegatingContext));
assertFalse(delegatingContext.equals(new Object()));
assertFalse(delegatingContext.equals(delegatingContext2));
assertFalse(delegatingContext2.equals(delegatingContext));
assertFalse(delegatingContext.equals(contextMock));
verify(keyedObjectPoolMock).returnObject(DirContextType.READ_ONLY, contextMock);
}
@Test
public void testUnsupportedMethods() throws Exception {
final DelegatingContext delegatingContext = new DelegatingContext(
keyedObjectPoolMock, contextMock, DirContextType.READ_ONLY);
try {
delegatingContext.addToEnvironment(null, null);
fail("DelegatingContext.addToEnvironment Should have thrown an UnsupportedOperationException");
} catch (UnsupportedOperationException uoe) {
// Expected
}
try {
delegatingContext.createSubcontext((Name) null);
fail("DelegatingContext.createSubcontext Should have thrown an UnsupportedOperationException");
} catch (UnsupportedOperationException uoe) {
// Expected
}
try {
delegatingContext.createSubcontext((String) null);
fail("DelegatingContext.createSubcontext Should have thrown an UnsupportedOperationException");
} catch (UnsupportedOperationException uoe) {
// Expected
}
try {
delegatingContext.destroySubcontext((Name) null);
fail("DelegatingContext.destroySubcontext Should have thrown an UnsupportedOperationException");
} catch (UnsupportedOperationException uoe) {
// Expected
}
try {
delegatingContext.destroySubcontext((String) null);
fail("DelegatingContext.destroySubcontext Should have thrown an UnsupportedOperationException");
} catch (UnsupportedOperationException uoe) {
// Expected
}
try {
delegatingContext.removeFromEnvironment(null);
fail("DelegatingContext.removeFromEnvironment Should have thrown an UnsupportedOperationException");
} catch (UnsupportedOperationException uoe) {
// Expected
}
}
@Test
public void testAllMethodsOpened() throws Exception {
final DelegatingContext delegatingContext = new DelegatingContext(
keyedObjectPoolMock, contextMock, DirContextType.READ_ONLY);
delegatingContext.bind((Name) null, null);
delegatingContext.bind((String) null, null);
delegatingContext.composeName((Name) null, (Name) null);
delegatingContext.composeName((String) null, (String) null);
delegatingContext.getEnvironment();
delegatingContext.getNameInNamespace();
delegatingContext.getNameParser((Name) null);
delegatingContext.getNameParser((String) null);
delegatingContext.list((Name) null);
delegatingContext.list((String) null);
delegatingContext.listBindings((Name) null);
delegatingContext.listBindings((String) null);
delegatingContext.lookup((Name) null);
delegatingContext.lookup((String) null);
delegatingContext.lookupLink((Name) null);
delegatingContext.lookupLink((String) null);
delegatingContext.rebind((Name) null, null);
delegatingContext.rebind((String) null, null);
delegatingContext.rename((Name) null, (Name) null);
delegatingContext.rename((String) null, (String) null);
delegatingContext.unbind((Name) null);
delegatingContext.unbind((String) null);
}
@Test
public void testAllMethodsClosed() throws Exception {
final DelegatingContext delegatingContext = new DelegatingContext(
keyedObjectPoolMock, contextMock, DirContextType.READ_ONLY);
delegatingContext.close();
try {
delegatingContext.bind((Name) null, null);
fail("DelegatingContext.bind should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingContext.bind((String) null, null);
fail("DelegatingContext.bind should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingContext.composeName((Name) null, (Name) null);
fail("DelegatingContext.composeName should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingContext.composeName((String) null, (String) null);
fail("DelegatingContext.composeName should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingContext.getEnvironment();
fail("DelegatingContext.getEnvironment should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingContext.getNameInNamespace();
fail("DelegatingContext.getNameInNamespace should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingContext.getNameParser((Name) null);
fail("DelegatingContext.getNameParser should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingContext.getNameParser((String) null);
fail("DelegatingContext.getNameParser should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingContext.list((Name) null);
fail("DelegatingContext.list should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingContext.list((String) null);
fail("DelegatingContext.list should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingContext.listBindings((Name) null);
fail("DelegatingContext.listBindings should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingContext.listBindings((String) null);
fail("DelegatingContext.listBindings should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingContext.lookup((Name) null);
fail("DelegatingContext.lookup should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingContext.lookup((String) null);
fail("DelegatingContext.lookup should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingContext.lookupLink((Name) null);
fail("DelegatingContext.lookupLink should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingContext.lookupLink((String) null);
fail("DelegatingContext.lookupLink should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingContext.rebind((Name) null, null);
fail("DelegatingContext.rebind should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingContext.rebind((String) null, null);
fail("DelegatingContext.rebind should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingContext.rename((Name) null, (Name) null);
fail("DelegatingContext.rename should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingContext.rename((String) null, (String) null);
fail("DelegatingContext.rename should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingContext.unbind((Name) null);
fail("DelegatingContext.unbind should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingContext.unbind((String) null);
fail("DelegatingContext.unbind should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
verify(keyedObjectPoolMock).returnObject(DirContextType.READ_ONLY, contextMock);
}
@Test
public void testDoubleClose() throws Exception {
final DelegatingContext delegatingContext = new DelegatingContext(
keyedObjectPoolMock, contextMock, DirContextType.READ_ONLY);
delegatingContext.close();
// noop close
delegatingContext.close();
verify(keyedObjectPoolMock, times(1)).returnObject(DirContextType.READ_ONLY, contextMock);
}
@Test
public void testPoolExceptionOnClose() throws Exception {
doThrow(new Exception("Fake Pool returnObject Exception"))
.when(keyedObjectPoolMock).returnObject(DirContextType.READ_ONLY, contextMock);
final DelegatingContext delegatingContext = new DelegatingContext(
keyedObjectPoolMock, contextMock, DirContextType.READ_ONLY);
try {
delegatingContext.close();
fail("DelegatingContext.close should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
}
}

View File

@@ -0,0 +1,381 @@
/*
* Copyright 2005-2015 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.pool2;
import org.apache.commons.pool2.KeyedObjectPool;
import org.junit.Test;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
/**
* @author Eric Dalquist <a
* href="mailto:eric.dalquist@doit.wisc.edu">eric.dalquist@doit.wisc.edu</a>
*/
public class DelegatingDirContextTest extends AbstractPoolTestCase {
@Test
public void testConstructorAssertions() {
try {
new DelegatingDirContext(keyedObjectPoolMock, null,
DirContextType.READ_ONLY);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
}
try {
new DelegatingDirContext(keyedObjectPoolMock, dirContextMock, null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
}
}
@Test
public void testHelperMethods() throws Exception {
// Wrap the DirContext once
final DelegatingDirContext delegatingDirContext = new DelegatingDirContext(
keyedObjectPoolMock, dirContextMock, DirContextType.READ_ONLY);
final Context delegateContext = delegatingDirContext
.getDelegateContext();
assertEquals(dirContextMock, delegateContext);
final DirContext delegateDirContext = delegatingDirContext
.getDelegateDirContext();
assertEquals(dirContextMock, delegateDirContext);
final DirContext innerDelegateDirContext = delegatingDirContext
.getInnermostDelegateDirContext();
assertEquals(dirContextMock, innerDelegateDirContext);
delegatingDirContext.assertOpen();
// Wrap the wrapper
KeyedObjectPool secondKeyedObjectPoolMock = mock(KeyedObjectPool.class);
final DelegatingDirContext delegatingDirContext2 = new DelegatingDirContext(
secondKeyedObjectPoolMock, delegatingDirContext,
DirContextType.READ_ONLY);
final DirContext delegateDirContext2 = delegatingDirContext2
.getDelegateDirContext();
assertEquals(delegatingDirContext, delegateDirContext2);
final DirContext innerDelegateDirContext2 = delegatingDirContext2
.getInnermostDelegateDirContext();
assertEquals(dirContextMock, innerDelegateDirContext2);
delegatingDirContext2.assertOpen();
// Close the outer wrapper
delegatingDirContext2.close();
final DirContext delegateContext2closed = delegatingDirContext2
.getDelegateDirContext();
assertNull(delegateContext2closed);
final DirContext innerDelegateContext2closed = delegatingDirContext2
.getInnermostDelegateDirContext();
assertNull(innerDelegateContext2closed);
try {
delegatingDirContext2.assertOpen();
fail("delegatingDirContext2.assertOpen() should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
// Close the outer wrapper
delegatingDirContext.close();
final DirContext delegateDirContextClosed = delegatingDirContext
.getDelegateDirContext();
assertNull(delegateDirContextClosed);
final DirContext innerDelegateDirContextClosed = delegatingDirContext
.getInnermostDelegateDirContext();
assertNull(innerDelegateDirContextClosed);
try {
delegatingDirContext.assertOpen();
fail("delegatingDirContext.assertOpen() should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
verify(secondKeyedObjectPoolMock)
.returnObject(DirContextType.READ_ONLY, dirContextMock);
verify(keyedObjectPoolMock).returnObject(DirContextType.READ_ONLY, dirContextMock);
}
@Test
public void testObjectMethods() throws Exception {
// Wrap the DirContext once
final DelegatingDirContext delegatingDirContext = new DelegatingDirContext(
keyedObjectPoolMock, dirContextMock, DirContextType.READ_ONLY);
assertEquals(dirContextMock.toString(), delegatingDirContext.toString());
delegatingDirContext.hashCode(); // Run it to make sure it doesn't
// fail
assertTrue(delegatingDirContext.equals(delegatingDirContext));
assertFalse(delegatingDirContext.equals(new Object()));
final DelegatingDirContext delegatingDirContext2 = new DelegatingDirContext(
keyedObjectPoolMock, dirContextMock, DirContextType.READ_ONLY);
assertTrue(delegatingDirContext.equals(delegatingDirContext2));
assertTrue(delegatingDirContext2.equals(delegatingDirContext));
assertTrue(delegatingDirContext.equals(dirContextMock));
// Close the context and try again
delegatingDirContext.close();
assertEquals("DirContext is closed", delegatingDirContext.toString());
assertEquals(0, delegatingDirContext.hashCode()); // Run it to make
// sure it doesn't
// fail
assertTrue(delegatingDirContext.equals(delegatingDirContext));
assertFalse(delegatingDirContext.equals(new Object()));
assertFalse(delegatingDirContext.equals(delegatingDirContext2));
assertFalse(delegatingDirContext2.equals(delegatingDirContext));
assertFalse(delegatingDirContext.equals(dirContextMock));
verify(keyedObjectPoolMock).returnObject(DirContextType.READ_ONLY, dirContextMock);
}
@Test
public void testUnsupportedMethods() throws Exception {
final DelegatingDirContext delegatingDirContext = new DelegatingDirContext(
keyedObjectPoolMock, dirContextMock, DirContextType.READ_ONLY);
try {
delegatingDirContext.createSubcontext((Name) null, null);
fail("DelegatingDirContext.createSubcontext Should have thrown an UnsupportedOperationException");
} catch (UnsupportedOperationException uoe) {
// Expected
}
try {
delegatingDirContext.createSubcontext((String) null, null);
fail("DelegatingDirContext.createSubcontext Should have thrown an UnsupportedOperationException");
} catch (UnsupportedOperationException uoe) {
// Expected
}
try {
delegatingDirContext.getSchema((Name) null);
fail("DelegatingDirContext.getSchema Should have thrown an UnsupportedOperationException");
} catch (UnsupportedOperationException uoe) {
// Expected
}
try {
delegatingDirContext.getSchema((String) null);
fail("DelegatingDirContext.getSchema Should have thrown an UnsupportedOperationException");
} catch (UnsupportedOperationException uoe) {
// Expected
}
try {
delegatingDirContext.getSchemaClassDefinition((Name) null);
fail("DelegatingDirContext.getSchemaClassDefinition Should have thrown an UnsupportedOperationException");
} catch (UnsupportedOperationException uoe) {
// Expected
}
try {
delegatingDirContext.getSchemaClassDefinition((String) null);
fail("DelegatingDirContext.getSchemaClassDefinition Should have thrown an UnsupportedOperationException");
} catch (UnsupportedOperationException uoe) {
// Expected
}
}
@Test
public void testAllMethodsOpened() throws Exception {
final DelegatingDirContext delegatingDirContext = new DelegatingDirContext(
keyedObjectPoolMock, dirContextMock, DirContextType.READ_ONLY);
delegatingDirContext.bind((Name) null, null, null);
delegatingDirContext.bind((String) null, null, null);
delegatingDirContext.getAttributes((Name) null, null);
delegatingDirContext.getAttributes((Name) null);
delegatingDirContext.getAttributes((String) null, null);
delegatingDirContext.getAttributes((String) null);
delegatingDirContext.modifyAttributes((Name) null, 0, null);
delegatingDirContext.modifyAttributes((Name) null, null);
delegatingDirContext.modifyAttributes((String) null, 0, null);
delegatingDirContext.modifyAttributes((String) null, null);
delegatingDirContext.rebind((Name) null, null, null);
delegatingDirContext.rebind((String) null, null, null);
delegatingDirContext.search((Name) null, (Attributes) null, null);
delegatingDirContext.search((Name) null, null);
delegatingDirContext.search((Name) null, null, null, null);
delegatingDirContext.search((Name) null, (String) null, null);
delegatingDirContext.search((String) null, (Attributes) null, null);
delegatingDirContext.search((String) null, null);
delegatingDirContext.search((String) null, null, null, null);
delegatingDirContext.search((String) null, (String) null, null);
}
@Test
public void testAllMethodsClosed() throws Exception {
final DelegatingDirContext delegatingDirContext = new DelegatingDirContext(
keyedObjectPoolMock, dirContextMock, DirContextType.READ_ONLY);
delegatingDirContext.close();
try {
delegatingDirContext.bind((Name) null, null, null);
fail("DelegatingDirContext.bind should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingDirContext.bind((String) null, null, null);
fail("DelegatingDirContext.bind should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingDirContext.getAttributes((Name) null, null);
fail("DelegatingDirContext.getAttributes should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingDirContext.getAttributes((Name) null);
fail("DelegatingDirContext.getAttributes should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingDirContext.getAttributes((String) null, null);
fail("DelegatingDirContext.getAttributes should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingDirContext.getAttributes((String) null);
fail("DelegatingDirContext.getAttributes should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingDirContext.modifyAttributes((Name) null, 0, null);
fail("DelegatingDirContext.modifyAttributes should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingDirContext.modifyAttributes((Name) null, null);
fail("DelegatingDirContext.modifyAttributes should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingDirContext.modifyAttributes((String) null, 0, null);
fail("DelegatingDirContext.modifyAttributes should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingDirContext.modifyAttributes((String) null, null);
fail("DelegatingDirContext.modifyAttributes should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingDirContext.rebind((Name) null, null, null);
fail("DelegatingDirContext.rebind should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingDirContext.rebind((String) null, null, null);
fail("DelegatingDirContext.rebind should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingDirContext.search((Name) null, (Attributes) null, null);
fail("DelegatingDirContext.search should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingDirContext.search((Name) null, null);
fail("DelegatingDirContext.search should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingDirContext.search((Name) null, null, null, null);
fail("DelegatingDirContext.search should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingDirContext.search((Name) null, (String) null, null);
fail("DelegatingDirContext.search should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingDirContext.search((String) null, (Attributes) null, null);
fail("DelegatingDirContext.search should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingDirContext.search((String) null, null);
fail("DelegatingDirContext.search should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingDirContext.search((String) null, null, null, null);
fail("DelegatingDirContext.search should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingDirContext.search((String) null, (String) null, null);
fail("DelegatingDirContext.search should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
verify(keyedObjectPoolMock).returnObject(DirContextType.READ_ONLY, dirContextMock);
}
@Test
public void testDoubleClose() throws Exception {
final DelegatingDirContext delegatingDirContext = new DelegatingDirContext(
keyedObjectPoolMock, dirContextMock, DirContextType.READ_ONLY);
delegatingDirContext.close();
// noop close
delegatingDirContext.close();
verify(keyedObjectPoolMock, times(1)).returnObject(DirContextType.READ_ONLY, dirContextMock);
}
}

View File

@@ -0,0 +1,250 @@
/*
* Copyright 2005-2015 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.pool2;
import org.apache.commons.pool2.KeyedObjectPool;
import org.junit.Test;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.ldap.LdapContext;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
/**
* @author Eric Dalquist <a
* href="mailto:eric.dalquist@doit.wisc.edu">eric.dalquist@doit.wisc.edu</a>
*/
public class DelegatingLdapContextTest extends AbstractPoolTestCase {
@Test
public void testConstructorAssertions() {
try {
new DelegatingLdapContext(keyedObjectPoolMock, null,
DirContextType.READ_ONLY);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
}
try {
new DelegatingLdapContext(keyedObjectPoolMock, ldapContextMock,
null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
}
}
@Test
public void testHelperMethods() throws Exception {
// Wrap the LdapContext once
final DelegatingLdapContext delegatingLdapContext = new DelegatingLdapContext(
keyedObjectPoolMock, ldapContextMock, DirContextType.READ_ONLY);
final DirContext delegateDirContext = delegatingLdapContext
.getDelegateDirContext();
assertEquals(ldapContextMock, delegateDirContext);
final LdapContext delegateLdapContext = delegatingLdapContext
.getDelegateLdapContext();
assertEquals(ldapContextMock, delegateLdapContext);
final LdapContext innerDelegateLdapContext = delegatingLdapContext
.getInnermostDelegateLdapContext();
assertEquals(ldapContextMock, innerDelegateLdapContext);
delegatingLdapContext.assertOpen();
// Wrap the wrapper
KeyedObjectPool secondKeyedObjectPoolMock = mock(KeyedObjectPool.class);
final DelegatingLdapContext delegatingLdapContext2 = new DelegatingLdapContext(
secondKeyedObjectPoolMock, delegatingLdapContext,
DirContextType.READ_ONLY);
final LdapContext delegateLdapContext2 = delegatingLdapContext2
.getDelegateLdapContext();
assertEquals(delegatingLdapContext, delegateLdapContext2);
final LdapContext innerDelegateLdapContext2 = delegatingLdapContext2
.getInnermostDelegateLdapContext();
assertEquals(ldapContextMock, innerDelegateLdapContext2);
delegatingLdapContext2.assertOpen();
// Close the outer wrapper
delegatingLdapContext2.close();
final LdapContext delegateContext2closed = delegatingLdapContext2
.getDelegateLdapContext();
assertNull(delegateContext2closed);
final LdapContext innerDelegateContext2closed = delegatingLdapContext2
.getInnermostDelegateLdapContext();
assertNull(innerDelegateContext2closed);
try {
delegatingLdapContext2.assertOpen();
fail("delegatingLdapContext2.assertOpen() should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
// Close the outer wrapper
delegatingLdapContext.close();
final LdapContext delegateLdapContextClosed = delegatingLdapContext
.getDelegateLdapContext();
assertNull(delegateLdapContextClosed);
final LdapContext innerDelegateLdapContextClosed = delegatingLdapContext
.getInnermostDelegateLdapContext();
assertNull(innerDelegateLdapContextClosed);
try {
delegatingLdapContext.assertOpen();
fail("delegatingLdapContext.assertOpen() should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
verify(secondKeyedObjectPoolMock)
.returnObject(DirContextType.READ_ONLY, ldapContextMock);
verify(keyedObjectPoolMock).returnObject(DirContextType.READ_ONLY, ldapContextMock);
}
@Test
public void testObjectMethods() throws Exception {
// Wrap the LdapContext once
final DelegatingLdapContext delegatingLdapContext = new DelegatingLdapContext(
keyedObjectPoolMock, ldapContextMock, DirContextType.READ_ONLY);
assertEquals(ldapContextMock.toString(),
delegatingLdapContext.toString());
delegatingLdapContext.hashCode(); // Run it to make sure it doesn't fail
assertTrue(delegatingLdapContext.equals(delegatingLdapContext));
assertFalse(delegatingLdapContext.equals(new Object()));
final DelegatingLdapContext delegatingLdapContext2 = new DelegatingLdapContext(
keyedObjectPoolMock, ldapContextMock, DirContextType.READ_ONLY);
assertTrue(delegatingLdapContext.equals(delegatingLdapContext2));
assertTrue(delegatingLdapContext2.equals(delegatingLdapContext));
assertTrue(delegatingLdapContext.equals(ldapContextMock));
// Close the context and try again
delegatingLdapContext.close();
assertEquals("LdapContext is closed", delegatingLdapContext.toString());
assertEquals(0, delegatingLdapContext.hashCode()); // Run it to make
// sure it doesn't
// fail
assertTrue(delegatingLdapContext.equals(delegatingLdapContext));
assertFalse(delegatingLdapContext.equals(new Object()));
assertFalse(delegatingLdapContext.equals(delegatingLdapContext2));
assertFalse(delegatingLdapContext2.equals(delegatingLdapContext));
assertFalse(delegatingLdapContext.equals(ldapContextMock));
verify(keyedObjectPoolMock).returnObject(DirContextType.READ_ONLY, ldapContextMock);
}
@Test
public void testUnsupportedMethods() throws Exception {
final DelegatingLdapContext delegatingLdapContext = new DelegatingLdapContext(
keyedObjectPoolMock, ldapContextMock, DirContextType.READ_ONLY);
try {
delegatingLdapContext.newInstance(null);
fail("DelegatingLdapContext.newInstance Should have thrown an UnsupportedOperationException");
} catch (UnsupportedOperationException uoe) {
// Expected
}
try {
delegatingLdapContext.reconnect(null);
fail("DelegatingLdapContext.reconnect Should have thrown an UnsupportedOperationException");
} catch (UnsupportedOperationException uoe) {
// Expected
}
try {
delegatingLdapContext.setRequestControls(null);
fail("DelegatingLdapContext.setRequestControls Should have thrown an UnsupportedOperationException");
} catch (UnsupportedOperationException uoe) {
// Expected
}
}
// nice
@Test
public void testAllMethodsOpened() throws Exception {
final DelegatingLdapContext delegatingLdapContext = new DelegatingLdapContext(
keyedObjectPoolMock, ldapContextMock, DirContextType.READ_ONLY);
delegatingLdapContext.extendedOperation(null);
delegatingLdapContext.getConnectControls();
delegatingLdapContext.getRequestControls();
delegatingLdapContext.getResponseControls();
}
@Test
public void testAllMethodsClosed() throws Exception {
final DelegatingLdapContext delegatingLdapContext = new DelegatingLdapContext(
keyedObjectPoolMock, ldapContextMock, DirContextType.READ_ONLY);
delegatingLdapContext.close();
try {
delegatingLdapContext.extendedOperation(null);
fail("DelegatingLdapContext.extendedOperation should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingLdapContext.getConnectControls();
fail("DelegatingLdapContext.getConnectControls should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingLdapContext.getRequestControls();
fail("DelegatingLdapContext.getRequestControls should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
try {
delegatingLdapContext.getResponseControls();
fail("DelegatingLdapContext.getResponseControls should have thrown a NamingException");
} catch (NamingException ne) {
// Expected
}
verify(keyedObjectPoolMock).returnObject(DirContextType.READ_ONLY, ldapContextMock);
}
@Test
public void testDoubleClose() throws Exception {
final DelegatingLdapContext delegatingLdapContext = new DelegatingLdapContext(
keyedObjectPoolMock, ldapContextMock, DirContextType.READ_ONLY);
delegatingLdapContext.close();
// noop close
delegatingLdapContext.close();
verify(keyedObjectPoolMock, times(1)).returnObject(DirContextType.READ_ONLY, ldapContextMock);
}
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright 2005-2015 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.pool2;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.EvictionConfig;
import org.apache.commons.pool2.impl.EvictionPolicy;
/**
* A dummy {@link EvictionPolicy} implementation to test pool2 config.
*
* @author Anindya Chatterjee
* */
public class DummyEvictionPolicy implements EvictionPolicy {
/**
* @see EvictionPolicy#evict(EvictionConfig, PooledObject, int)
*
* */
@Override
public boolean evict(EvictionConfig config, PooledObject underTest, int idleCount) {
return false;
}
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright 2005-2015 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.pool2;
import org.junit.Test;
import static org.mockito.Mockito.verify;
/**
* Unit tests for the MutableDelegatingLdapContext class.
*
* @author Ulrik Sandberg
*/
public class MutableDelegatingLdapContextTest extends AbstractPoolTestCase {
@Test
public void testSupportedMethodsAllowedToCall() throws Exception {
final MutableDelegatingLdapContext delegatingLdapContext = new MutableDelegatingLdapContext(
keyedObjectPoolMock, ldapContextMock, DirContextType.READ_ONLY);
delegatingLdapContext.setRequestControls(null);
verify(ldapContextMock).setRequestControls(null);
}
}

View File

@@ -0,0 +1,227 @@
/*
* Copyright 2005-2015 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.pool2.factory;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.internal.util.reflection.Whitebox;
import org.springframework.ldap.core.ContextSource;
import org.springframework.ldap.pool2.DirContextType;
import org.springframework.ldap.pool2.validation.DirContextValidator;
import org.springframework.ldap.pool2.AbstractPoolTestCase;
import javax.naming.directory.DirContext;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
/**
* @author Eric Dalquist
* @author Anindya Chatterjee
*/
public class DirContextPooledObjectFactoryTest extends AbstractPoolTestCase {
@Test
public void testProperties() throws Exception {
final DirContextPooledObjectFactory objectFactory = new DirContextPooledObjectFactory();
try {
objectFactory.setContextSource(null);
fail("DirContextPooledObjectFactory.setContextSource should have thrown an IllegalArgumentException");
}
catch (IllegalArgumentException iae) {
// Expected
}
objectFactory.setContextSource(contextSourceMock);
final ContextSource contextSource2 = objectFactory.getContextSource();
assertEquals(contextSourceMock, contextSource2);
try {
objectFactory.setDirContextValidator(null);
fail("DirContextPooledObjectFactory.setDirContextValidator should have thrown an IllegalArgumentException");
}
catch (IllegalArgumentException iae) {
// Expected
}
objectFactory.setDirContextValidator(dirContextValidatorMock);
final DirContextValidator dirContextValidator2 = objectFactory.getDirContextValidator();
assertEquals(dirContextValidatorMock, dirContextValidator2);
}
@Test
public void testMakeObjectAssertions() throws Exception {
final DirContextPooledObjectFactory objectFactory = new DirContextPooledObjectFactory();
try {
objectFactory.makeObject(DirContextType.READ_ONLY);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
}
objectFactory.setContextSource(contextSourceMock);
try {
objectFactory.makeObject(null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
}
}
@Test
public void testMakeObjectReadOnly() throws Exception {
final DirContextPooledObjectFactory objectFactory = new DirContextPooledObjectFactory();
DirContext readOnlyContextMock = mock(DirContext.class);
when(contextSourceMock.getReadOnlyContext()).thenReturn(readOnlyContextMock);
objectFactory.setContextSource(contextSourceMock);
final PooledObject createdDirContext = objectFactory.makeObject(DirContextType.READ_ONLY);
InvocationHandler invocationHandler = Proxy.getInvocationHandler(createdDirContext.getObject());
assertEquals(readOnlyContextMock, Whitebox.getInternalState(invocationHandler, "target"));
}
@Test
public void testMakeObjectReadWrite() throws Exception {
final DirContextPooledObjectFactory objectFactory = new DirContextPooledObjectFactory();
DirContext readWriteContextMock = mock(DirContext.class);
when(contextSourceMock.getReadWriteContext()).thenReturn(readWriteContextMock);
objectFactory.setContextSource(contextSourceMock);
final PooledObject createdDirContext = objectFactory.makeObject(DirContextType.READ_WRITE);
InvocationHandler invocationHandler = Proxy.getInvocationHandler(createdDirContext.getObject());
assertEquals(readWriteContextMock, Whitebox.getInternalState(invocationHandler, "target"));
}
@Test
public void testValidateObjectAssertions() throws Exception {
final DirContextPooledObjectFactory objectFactory = new DirContextPooledObjectFactory();
try {
PooledObject pooledObject = new DefaultPooledObject(dirContextMock);
objectFactory.validateObject(DirContextType.READ_ONLY, pooledObject);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
}
objectFactory.setDirContextValidator(dirContextValidatorMock);
try {
PooledObject pooledObject = new DefaultPooledObject(dirContextMock);
objectFactory.validateObject(null, pooledObject);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
}
try {
PooledObject pooledObject = new DefaultPooledObject(dirContextMock);
objectFactory.validateObject(new Object(), pooledObject);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
}
try {
objectFactory.validateObject(DirContextType.READ_ONLY, null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
}
try {
PooledObject pooledObject = new DefaultPooledObject(new Object());
objectFactory.validateObject(DirContextType.READ_ONLY, pooledObject);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
}
}
@Test
public void testValidateObject() throws Exception {
when(dirContextValidatorMock
.validateDirContext(DirContextType.READ_ONLY, dirContextMock))
.thenReturn(true);
final DirContextPooledObjectFactory objectFactory = new DirContextPooledObjectFactory();
objectFactory.setDirContextValidator(dirContextValidatorMock);
PooledObject pooledObject = new DefaultPooledObject(dirContextMock);
final boolean valid = objectFactory.validateObject(DirContextType.READ_ONLY, pooledObject);
assertTrue(valid);
//Check exception in validator
DirContextValidator secondDirContextValidatorMock = mock(DirContextValidator.class);
when(secondDirContextValidatorMock.validateDirContext(DirContextType.READ_ONLY, dirContextMock))
.thenThrow(new RuntimeException("Failed to validate"));
objectFactory.setDirContextValidator(secondDirContextValidatorMock);
final boolean valid2 = objectFactory.validateObject(DirContextType.READ_ONLY, pooledObject);
assertFalse(valid2);
}
@Test
public void testDestroyObjectAssertions() throws Exception {
final DirContextPooledObjectFactory objectFactory = new DirContextPooledObjectFactory();
try {
objectFactory.destroyObject(DirContextType.READ_ONLY, null);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
}
try {
PooledObject pooledObject = new DefaultPooledObject(new Object());
objectFactory.validateObject(DirContextType.READ_ONLY, pooledObject);
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException expected) {
assertTrue(true);
}
}
@Test
public void testDestroyObject() throws Exception {
final DirContextPooledObjectFactory objectFactory = new DirContextPooledObjectFactory();
PooledObject pooledObject = new DefaultPooledObject(dirContextMock);
objectFactory.destroyObject(DirContextType.READ_ONLY, pooledObject);
DirContext throwingDirContextMock = Mockito.mock(DirContext.class);
doThrow(new RuntimeException("Failed to close"))
.when(throwingDirContextMock).close();
pooledObject = new DefaultPooledObject(throwingDirContextMock);
objectFactory.destroyObject(DirContextType.READ_ONLY, pooledObject);
verify(dirContextMock).close();
}
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2005-2015 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.pool2.factory;
import org.junit.Test;
import org.springframework.ldap.pool2.AbstractPoolTestCase;
import org.springframework.ldap.pool2.MutableDelegatingLdapContext;
import javax.naming.directory.DirContext;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
/**
* Unit tests for the MutablePoolingContextSource class.
*
* @author Ulrik Sandberg
* @author Anindya Chatterjee
*/
public class MutablePooledContextSourceTest extends AbstractPoolTestCase {
@Test
public void testGetReadOnlyLdapContext() throws Exception {
when(contextSourceMock.getReadOnlyContext()).thenReturn(ldapContextMock);
final MutablePooledContextSource poolingContextSource = new MutablePooledContextSource(null);
poolingContextSource.setContextSource(contextSourceMock);
// Get a context
final DirContext result = poolingContextSource.getReadOnlyContext();
assertEquals(MutableDelegatingLdapContext.class, result.getClass());
}
}

View File

@@ -0,0 +1,113 @@
/*
* Copyright 2005-2015 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.pool2.factory;
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig;
import org.junit.Test;
import org.springframework.ldap.pool2.AbstractPoolTestCase;
import static org.junit.Assert.assertEquals;
/**
* @author Anindya Chatterjee
* */
public class PoolConfigTest extends AbstractPoolTestCase {
@Test
public void testProperties() {
final PoolConfig poolConfig = new PoolConfig();
poolConfig.setMaxTotalPerKey(5);
final int maxTotalPerKey = poolConfig.getMaxTotalPerKey();
assertEquals(5, maxTotalPerKey);
poolConfig.setMaxIdlePerKey(500);
final int maxIdle = poolConfig.getMaxIdlePerKey();
assertEquals(500, maxIdle);
poolConfig.setMaxTotal(5000);
final int maxTotal = poolConfig.getMaxTotal();
assertEquals(5000, maxTotal);
poolConfig.setMaxWaitMillis(2000L);
final long maxWait = poolConfig.getMaxWaitMillis();
assertEquals(2000L, maxWait);
poolConfig.setMinEvictableIdleTimeMillis(60000L);
final long minEvictableIdleTimeMillis = poolConfig.getMinEvictableIdleTimeMillis();
assertEquals(60000L, minEvictableIdleTimeMillis);
poolConfig.setMinIdlePerKey(100);
final int minIdle = poolConfig.getMinIdlePerKey();
assertEquals(100, minIdle);
poolConfig.setNumTestsPerEvictionRun(5);
final int numTestsPerEvictionRun = poolConfig.getNumTestsPerEvictionRun();
assertEquals(5, numTestsPerEvictionRun);
poolConfig.setTestOnBorrow(true);
final boolean testOnBorrow = poolConfig.isTestOnBorrow();
assertEquals(true, testOnBorrow);
poolConfig.setTestOnReturn(true);
final boolean testOnReturn = poolConfig.isTestOnReturn();
assertEquals(true, testOnReturn);
poolConfig.setTestWhileIdle(true);
final boolean testWhileIdle = poolConfig.isTestWhileIdle();
assertEquals(true, testWhileIdle);
poolConfig.setTestOnCreate(true);
final boolean testOnCreate = poolConfig.isTestOnCreate();
assertEquals(true, testOnCreate);
poolConfig.setTimeBetweenEvictionRunsMillis(120000L);
final long timeBetweenEvictionRunsMillis = poolConfig.getTimeBetweenEvictionRunsMillis();
assertEquals(120000L, timeBetweenEvictionRunsMillis);
poolConfig.setSoftMinEvictableIdleTimeMillis(120000L);
final long softMinEvictableIdleTimeMillis = poolConfig.getSoftMinEvictableIdleTimeMillis();
assertEquals(120000L, softMinEvictableIdleTimeMillis);
poolConfig.setBlockWhenExhausted(true);
final boolean whenExhaustedAction = poolConfig.isBlockWhenExhausted();
assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_BLOCK_WHEN_EXHAUSTED, whenExhaustedAction);
poolConfig.setEvictionPolicyClassName(GenericKeyedObjectPoolConfig.DEFAULT_EVICTION_POLICY_CLASS_NAME);
final String evictionPolicyClassName = poolConfig.getEvictionPolicyClassName();
assertEquals(GenericKeyedObjectPoolConfig.DEFAULT_EVICTION_POLICY_CLASS_NAME, evictionPolicyClassName);
poolConfig.setFairness(true);
final boolean fairness = poolConfig.isFairness();
assertEquals(true, fairness);
poolConfig.setJmxEnabled(true);
final boolean jmxEnabled = poolConfig.isJmxEnabled();
assertEquals(true, jmxEnabled);
poolConfig.setJmxNameBase("test");
final String jmxBaseName = poolConfig.getJmxNameBase();
assertEquals("test", jmxBaseName);
poolConfig.setJmxNamePrefix("pool");
final String prefix = poolConfig.getJmxNamePrefix();
assertEquals("pool", prefix);
poolConfig.setLifo(true);
final boolean lifo = poolConfig.isLifo();
assertEquals(true, lifo);
}
}

View File

@@ -0,0 +1,237 @@
/*
* Copyright 2005-2015 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.pool2.factory;
import org.junit.Test;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.ldap.core.ContextSource;
import org.springframework.ldap.pool2.validation.DirContextValidator;
import org.springframework.ldap.pool2.AbstractPoolTestCase;
import javax.naming.directory.DirContext;
import javax.naming.ldap.LdapContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* @author Eric Dalquist
* @author Anindya Chatterjee
*/
public class PooledContextSourceTest extends AbstractPoolTestCase {
@Test
public void testProperties() throws Exception {
final PoolConfig poolConfig = new PoolConfig();
poolConfig.setMaxIdlePerKey(500);
poolConfig.setMinIdlePerKey(100);
poolConfig.setMaxTotal(5000);
poolConfig.setMaxTotalPerKey(5);
poolConfig.setMaxWaitMillis(2000L);
poolConfig.setMinEvictableIdleTimeMillis(60000L);
poolConfig.setNumTestsPerEvictionRun(5);
poolConfig.setTestOnBorrow(true);
poolConfig.setTestOnReturn(true);
poolConfig.setTestWhileIdle(true);
poolConfig.setTestOnCreate(true);
poolConfig.setTimeBetweenEvictionRunsMillis(120000L);
poolConfig.setSoftMinEvictableIdleTimeMillis(120000L);
poolConfig.setBlockWhenExhausted(true);
poolConfig.setFairness(true);
poolConfig.setJmxEnabled(true);
poolConfig.setJmxNameBase("test");
poolConfig.setJmxNamePrefix("pool");
poolConfig.setLifo(true);
final PooledContextSource PooledContextSource = new PooledContextSource(poolConfig);
try {
PooledContextSource.setContextSource(null);
fail("PooledContextSource.setBaseName should have thrown an IllegalArgumentException");
}
catch (IllegalArgumentException iae) {
// Expected
}
PooledContextSource.setContextSource(contextSourceMock);
final ContextSource contextSource2 = PooledContextSource.getContextSource();
assertEquals(contextSourceMock, contextSource2);
try {
PooledContextSource.setDirContextValidator(null);
fail("PooledContextSource.setDirContextValidator should have thrown an IllegalArgumentException");
}
catch (IllegalArgumentException iae) {
// Expected
}
PooledContextSource.setDirContextValidator(dirContextValidatorMock);
final DirContextValidator dirContextValidator2 = PooledContextSource.getDirContextValidator();
assertEquals(dirContextValidatorMock, dirContextValidator2);
final int numActive = PooledContextSource.getNumActive();
assertEquals(0, numActive);
final int numIdle = PooledContextSource.getNumIdle();
assertEquals(0, numIdle);
}
@Test
public void testGetReadOnlyContextPool() throws Exception {
DirContext secondDirContextMock = mock(DirContext.class);
when(contextSourceMock.getReadOnlyContext()).thenReturn(dirContextMock, secondDirContextMock);
final PooledContextSource PooledContextSource = new PooledContextSource(null);
PooledContextSource.setContextSource(contextSourceMock);
//Get a context
final DirContext readOnlyContext1 = PooledContextSource.getReadOnlyContext();
assertEquals(readOnlyContext1, dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(1, PooledContextSource.getNumActive());
assertEquals(0, PooledContextSource.getNumIdle());
//Close the context
readOnlyContext1.close();
assertEquals(0, PooledContextSource.getNumActive());
assertEquals(1, PooledContextSource.getNumIdle());
//Get the context again
final DirContext readOnlyContext2 = PooledContextSource.getReadOnlyContext();
assertEquals(readOnlyContext2, dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(1, PooledContextSource.getNumActive());
assertEquals(0, PooledContextSource.getNumIdle());
//Get a new context
final DirContext readOnlyContext3 = PooledContextSource.getReadOnlyContext();
assertEquals(readOnlyContext3, secondDirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(2, PooledContextSource.getNumActive());
assertEquals(0, PooledContextSource.getNumIdle());
//Close context
readOnlyContext2.close();
assertEquals(1, PooledContextSource.getNumActive());
assertEquals(1, PooledContextSource.getNumIdle());
//Close context
readOnlyContext3.close();
assertEquals(0, PooledContextSource.getNumActive());
assertEquals(2, PooledContextSource.getNumIdle());
}
@Test
public void testGetReadWriteContextPool() throws Exception {
DirContext secondDirContextMock = mock(DirContext.class);
when(contextSourceMock.getReadWriteContext()).thenReturn(dirContextMock, secondDirContextMock);
final PooledContextSource PooledContextSource = new PooledContextSource(null);
PooledContextSource.setContextSource(contextSourceMock);
//Get a context
final DirContext readOnlyContext1 = PooledContextSource.getReadWriteContext();
assertEquals(readOnlyContext1, dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(1, PooledContextSource.getNumActive());
assertEquals(0, PooledContextSource.getNumIdle());
//Close the context
readOnlyContext1.close();
assertEquals(0, PooledContextSource.getNumActive());
assertEquals(1, PooledContextSource.getNumIdle());
//Get the context again
final DirContext readOnlyContext2 = PooledContextSource.getReadWriteContext();
assertEquals(readOnlyContext2, dirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(1, PooledContextSource.getNumActive());
assertEquals(0, PooledContextSource.getNumIdle());
//Get a new context
final DirContext readOnlyContext3 = PooledContextSource.getReadWriteContext();
assertEquals(readOnlyContext3, secondDirContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(2, PooledContextSource.getNumActive());
assertEquals(0, PooledContextSource.getNumIdle());
//Close context
readOnlyContext2.close();
assertEquals(1, PooledContextSource.getNumActive());
assertEquals(1, PooledContextSource.getNumIdle());
//Close context
readOnlyContext3.close();
assertEquals(0, PooledContextSource.getNumActive());
assertEquals(2, PooledContextSource.getNumIdle());
}
@Test
public void testGetContextException() throws Exception {
when(contextSourceMock.getReadWriteContext())
.thenThrow(new RuntimeException("Problem getting context"));
final PooledContextSource PooledContextSource = new PooledContextSource(null);
PooledContextSource.setContextSource(contextSourceMock);
try {
PooledContextSource.getReadWriteContext();
fail("PooledContextSource.getReadWriteContext should have thrown DataAccessResourceFailureException");
}
catch (DataAccessResourceFailureException darfe) {
// Expected
}
}
@Test
public void testGetReadOnlyLdapContext() throws Exception {
LdapContext secondLdapContextMock = mock(LdapContext.class);
when(contextSourceMock.getReadOnlyContext()).thenReturn(ldapContextMock, secondLdapContextMock);
final PooledContextSource pooledContextSource = new PooledContextSource(null);
pooledContextSource.setContextSource(contextSourceMock);
//Get a context
final DirContext readOnlyContext1 = pooledContextSource.getReadOnlyContext();
assertEquals(readOnlyContext1, ldapContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(1, pooledContextSource.getNumActive());
assertEquals(0, pooledContextSource.getNumIdle());
//Close the context
readOnlyContext1.close();
assertEquals(0, pooledContextSource.getNumActive());
assertEquals(1, pooledContextSource.getNumIdle());
//Get the context again
final DirContext readOnlyContext2 = pooledContextSource.getReadOnlyContext();
assertEquals(readOnlyContext2, ldapContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(1, pooledContextSource.getNumActive());
assertEquals(0, pooledContextSource.getNumIdle());
//Get a new context
final DirContext readOnlyContext3 = pooledContextSource.getReadOnlyContext();
assertEquals(readOnlyContext3, secondLdapContextMock); //Order reversed because the 'wrapper' has the needed equals logic
assertEquals(2, pooledContextSource.getNumActive());
assertEquals(0, pooledContextSource.getNumIdle());
//Close context
readOnlyContext2.close();
assertEquals(1, pooledContextSource.getNumActive());
assertEquals(1, pooledContextSource.getNumIdle());
//Close context
readOnlyContext3.close();
assertEquals(0, pooledContextSource.getNumActive());
assertEquals(2, pooledContextSource.getNumIdle());
}
}

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.xsd http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd">
<ldap:context-source password="apassword" url="ldap://localhost:389" username="uid=admin">
<ldap:pooling2
max-total-per-key="10"
max-idle-per-key="20"
max-total="12"
max-wait="13"
min-idle-per-key="14"
block-when-exhausted="true"
eviction-policy-class="org.springframework.ldap.pool2.DummyEvictionPolicy"
fairness="true"
jmx-enable="true"
jmx-name-base="org.springframework.ldap.pool2:type=ldap-pool,name="
jmx-name-prefix="test-pool"
lifo="false" />
</ldap:context-source>
<ldap:ldap-template />
</beans>

View File

@@ -0,0 +1,25 @@
<?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.xsd http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd">
<ldap:context-source password="apassword" url="ldap://localhost:389" username="uid=admin">
<ldap:pooling2
test-on-borrow="true"
test-on-return="true"
test-while-idle="true"
test-on-create="true"
min-evictable-time-millis="123"
eviction-run-interval-millis="321"
tests-per-eviction-run="22"
soft-min-evictable-idle-time-millis="12"
validation-query-base="ou=test"
validation-query-filter="objectclass=person"
validation-query-search-controls-ref="searchControls"
non-transient-exceptions="javax.naming.CannotProceedException,javax.naming.CommunicationException" />
</ldap:context-source>
<bean class="javax.naming.directory.SearchControls" id="searchControls" />
<ldap:ldap-template />
</beans>

View File

@@ -0,0 +1,16 @@
<?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.xsd http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd">
<!--
The below is invalid, since native pooling is not supported together with Spring LDAP pooling.
-->
<ldap:context-source
password="apassword" url="ldap://localhost:389" username="uid=admin"
native-pooling="true">
<ldap:pooling2 />
</ldap:context-source>
<ldap:ldap-template />
</beans>

View File

@@ -0,0 +1,14 @@
<?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.xsd http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd">
<!-- Invalid pool configuration. Only one of them can be used at the same time. -->
<ldap:context-source
password="apassword" url="ldap://localhost:389" username="uid=admin">
<ldap:pooling />
<ldap:pooling2 />
</ldap:context-source>
<ldap:ldap-template />
</beans>

View File

@@ -0,0 +1,11 @@
<?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.xsd http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd">
<ldap:context-source password="apassword" url="ldap://localhost:389" username="uid=admin">
<ldap:pooling2 />
</ldap:context-source>
<ldap:ldap-template />
</beans>