LDAP-262: Cleaned up and consolidated the samples.

This commit is contained in:
Mattias Hellborg Arthursson
2013-09-12 07:34:11 +02:00
parent 742ce2b2fe
commit 9458b80fa1
115 changed files with 244 additions and 5866 deletions

View File

@@ -0,0 +1,122 @@
/*
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.samples.plain.dao;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.NameNotFoundException;
import org.springframework.ldap.samples.plain.domain.Person;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
/**
* Abstract base class for PersonDao integration tests.
*
* @author Mattias Hellborg Arthursson
* @author Ulrik Sandberg
*/
@ContextConfiguration("/config/testContext.xml")
public class PersonDaoSampleIntegrationTest extends
AbstractJUnit4SpringContextTests {
protected Person person;
@Autowired
private PersonDao personDao;
@Before
public void preparePerson() throws Exception {
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");
}
/**
* 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.
*/
@Test
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
}
}
}
@Test
public void testGetAllPersonNames() {
List result = personDao.getAllPersonNames();
assertEquals(2, result.size());
String first = (String) result.get(0);
assertEquals("Some Person", first);
}
@Test
public void testFindAll() {
List result = personDao.findAll();
assertEquals(2, result.size());
Person first = (Person) result.get(0);
assertEquals("Some Person", first
.getFullName());
}
@Test
public void testFindByPrimaryKey() {
Person result = personDao.findByPrimaryKey(
"Sweden", "company1", "Some Person");
assertEquals(person, result);
}
}

View File

@@ -0,0 +1,4 @@
urls=ldap://127.0.0.1:18880
userDn=uid=admin,ou=system
password=secret
base=dc=jayway,dc=se

View File

@@ -0,0 +1,29 @@
<?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="18880" />
</bean>
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
<bean id="personDao"
class="org.springframework.ldap.samples.plain.dao.PersonDaoImpl">
<property name="ldapTemplate" ref="ldapTemplate" />
</bean>
</beans>

View 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