Added base project for openldap tests.

This commit is contained in:
Mattias Arthursson
2008-08-14 15:10:17 +00:00
parent 2997844258
commit bdb2a4bfa6
5 changed files with 277 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-parent</artifactId>
<version>1.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-ldap-openldap-integration-tests</artifactId>
<packaging>jar</packaging>
<name>Spring LDAP Integration Tests</name>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core-tiger</artifactId>
</dependency>
<!-- Spring Dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>gsbase</groupId>
<artifactId>gsbase</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,181 @@
/*
* Copyright 2005-2007 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.core;
import static junit.framework.Assert.assertEquals;
import java.util.List;
import javax.naming.Name;
import javax.naming.directory.SearchControls;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.test.AttributeCheckAttributesMapper;
import org.springframework.ldap.test.AttributeCheckContextMapper;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
/**
* Verifies that LdapTemplate search methods work against OpenLDAP.
*
* @author Mattias Arthursson
*/
@ContextConfiguration(locations = { "/conf/ldapTemplateTestContext.xml" })
public class LdapTemplateSearchResultITest extends AbstractJUnit4SpringContextTests {
@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 = new DistinguishedName(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_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 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_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());
}
}

View File

@@ -0,0 +1,3 @@
userDn=cn=admin,dc=jayway,dc=se
password=secret
base=dc=jayway,dc=se

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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/conf/ldap.properties" />
</bean>
<bean id="contextSource"
class="org.springframework.ldap.core.support.LdapContextSource">
<property name="base" value="dc=jayway,dc=se" />
<property name="userDn" value="${userDn}" />
<property name="password" value="${password}" />
<property name="url" value="ldap://${serverAddress}:389" />
</bean>
<bean id="ldapTemplate"
class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
</beans>

View File

@@ -0,0 +1,6 @@
log4j.rootCategory=warn, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout.ConversionPattern=%r [%t] %-5p\: %-15c{2} - %m%n
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.logger.org.apache.directory.server.schema.registries.DefaultSyntaxRegistry=WARN