Added samples project for testing with Spring 3.0 artifacts.
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright 2005-2008 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.samples.article.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.ldap.NameNotFoundException;
|
||||
import org.springframework.ldap.samples.article.dao.PersonDao;
|
||||
import org.springframework.ldap.samples.article.domain.Person;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
|
||||
/**
|
||||
* Abstract base class for PersonDao integration tests.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public abstract class AbstractPersonDaoIntegrationTest
|
||||
extends
|
||||
AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
protected Person person;
|
||||
|
||||
protected PersonDao personDao;
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { "config/testContext.xml" };
|
||||
}
|
||||
|
||||
protected void onSetUp() throws Exception {
|
||||
super.onSetUp();
|
||||
person = new Person();
|
||||
person.setCountry("Sweden");
|
||||
person.setCompany("company1");
|
||||
person.setFullName("Some Person");
|
||||
person.setLastName("Person");
|
||||
person
|
||||
.setDescription("Sweden, Company1, Some Person");
|
||||
person.setPhone("+46 555-123456");
|
||||
}
|
||||
|
||||
protected void onTearDown() throws Exception {
|
||||
super.onTearDown();
|
||||
person = null;
|
||||
personDao = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Having a single test method test create, update and delete is not exactly
|
||||
* the ideal way of testing, since they depend on each other. A better way
|
||||
* would be to separate the tests and load a test fixture before each
|
||||
* operation, in order to guarantee the expected state every time. See the
|
||||
* ldaptemplate-person sample for the correct way to do this.
|
||||
*/
|
||||
public void testCreateUpdateDelete() {
|
||||
try {
|
||||
person.setFullName("Another Person");
|
||||
personDao.create(person);
|
||||
personDao.findByPrimaryKey(
|
||||
"Sweden", "company1",
|
||||
"Another Person");
|
||||
// if we got here, create succeeded
|
||||
|
||||
person
|
||||
.setDescription("Another description");
|
||||
personDao.update(person);
|
||||
Person result = personDao
|
||||
.findByPrimaryKey(
|
||||
"Sweden", "company1",
|
||||
"Another Person");
|
||||
assertEquals(
|
||||
"Another description", result
|
||||
.getDescription());
|
||||
} finally {
|
||||
personDao.delete(person);
|
||||
try {
|
||||
personDao.findByPrimaryKey(
|
||||
"Sweden", "company1",
|
||||
"Another Person");
|
||||
fail("NameNotFoundException (when using Spring LDAP) or RuntimeException (when using traditional) expected");
|
||||
} catch (NameNotFoundException expected) {
|
||||
// expected
|
||||
} catch (RuntimeException expected) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetAllPersonNames() {
|
||||
List result = personDao.getAllPersonNames();
|
||||
assertEquals(2, result.size());
|
||||
String first = (String) result.get(0);
|
||||
assertEquals("Some Person", first);
|
||||
}
|
||||
|
||||
public void testFindAll() {
|
||||
List result = personDao.findAll();
|
||||
assertEquals(2, result.size());
|
||||
Person first = (Person) result.get(0);
|
||||
assertEquals("Some Person", first
|
||||
.getFullName());
|
||||
}
|
||||
|
||||
public void testFindByPrimaryKey() {
|
||||
Person result = personDao.findByPrimaryKey(
|
||||
"Sweden", "company1", "Some Person");
|
||||
assertEquals(person, result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2005-2008 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.samples.article.dao;
|
||||
|
||||
import org.springframework.ldap.samples.article.dao.PersonDaoImpl;
|
||||
|
||||
/**
|
||||
* Integration tests for the PersonDaoImpl class.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class PersonDaoImplIntegrationTest extends
|
||||
AbstractPersonDaoIntegrationTest {
|
||||
|
||||
public void setPersonDao(
|
||||
PersonDaoImpl personDao) {
|
||||
this.personDao = personDao;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2005-2008 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.samples.article.dao;
|
||||
|
||||
/**
|
||||
* Integration tests for the TraditionalPersonDaoImpl class.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
* @author Ulrik Sandberg
|
||||
*/
|
||||
public class TraditionalPersonDaoImplIntegrationTest
|
||||
extends AbstractPersonDaoIntegrationTest {
|
||||
|
||||
public void setPersonDao(
|
||||
TraditionalPersonDaoImpl personDao) {
|
||||
this.personDao = personDao;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
urls=ldap://127.0.0.1:3900
|
||||
userDn=uid=admin,ou=system
|
||||
password=secret
|
||||
base=dc=jayway,dc=se
|
||||
@@ -0,0 +1,37 @@
|
||||
<?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 id="placeholderConfig"
|
||||
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<property name="location" value="classpath:/config/ldap.properties" />
|
||||
</bean>
|
||||
|
||||
<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="/setup_data.ldif" />
|
||||
<property name="port" value="3901" />
|
||||
</bean>
|
||||
|
||||
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
|
||||
<constructor-arg ref="contextSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="personDao"
|
||||
class="org.springframework.ldap.samples.article.dao.PersonDaoImpl">
|
||||
<property name="ldapTemplate" ref="ldapTemplate" />
|
||||
</bean>
|
||||
|
||||
<bean id="traditionalPersonDao"
|
||||
class="org.springframework.ldap.samples.article.dao.TraditionalPersonDaoImpl">
|
||||
<property name="url" value="ldap://localhost:3901" />
|
||||
<property name="base" value="dc=jayway,dc=se" />
|
||||
<property name="userDn" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
</bean>
|
||||
</beans>
|
||||
35
samples/article-spring30/src/test/resources/setup_data.ldif
Normal file
35
samples/article-spring30/src/test/resources/setup_data.ldif
Normal file
@@ -0,0 +1,35 @@
|
||||
dn: c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: country
|
||||
c: Sweden
|
||||
description: The country of Sweden
|
||||
|
||||
dn: ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: organizationalUnit
|
||||
ou: company1
|
||||
description: First company in Sweden
|
||||
|
||||
dn: cn=Some Person,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: person
|
||||
objectclass: organizationalPerson
|
||||
objectclass: inetOrgPerson
|
||||
uid: some.person
|
||||
userPassword: password
|
||||
cn: Some Person
|
||||
sn: Person
|
||||
description: Sweden, Company1, Some Person
|
||||
telephoneNumber: +46 555-123456
|
||||
|
||||
dn: cn=Some Person2,ou=company1,c=Sweden,dc=jayway,dc=se
|
||||
objectclass: top
|
||||
objectclass: person
|
||||
objectclass: organizationalPerson
|
||||
objectclass: inetOrgPerson
|
||||
uid: some.person2
|
||||
userPassword: password
|
||||
cn: Some Person2
|
||||
sn: Person2
|
||||
description: Sweden, Company1, Some Person2
|
||||
telephoneNumber: +46 555-654321
|
||||
Reference in New Issue
Block a user