Fixed failing integration tests.

Added java.net repo to root pom to fix failing ldapbp reference.
This commit is contained in:
Mattias Arthursson
2008-06-12 08:57:59 +00:00
parent 03304a4649
commit f94014bf0e
4 changed files with 157 additions and 140 deletions

View File

@@ -21,158 +21,146 @@ import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
public class LdapAndJdbcDummyDaoImpl implements DummyDao {
private LdapTemplate ldapTemplate;
private LdapTemplate ldapTemplate;
private JdbcTemplate jdbcTemplate;
private JdbcTemplate jdbcTemplate;
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public void setLdapTemplate(LdapTemplate ldapTemplate) {
this.ldapTemplate = ldapTemplate;
}
public void setLdapTemplate(LdapTemplate ldapTemplate) {
this.ldapTemplate = ldapTemplate;
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#createWithException(java.lang.String,
* java.lang.String, java.lang.String, java.lang.String,
* java.lang.String)
*/
public void createWithException(String country, String company,
String fullname, String lastname, String description) {
create(country, company, fullname, lastname, description);
throw new DummyException("This method failed");
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#createWithException(java.lang.String,
* java.lang.String, java.lang.String, java.lang.String, java.lang.String)
*/
public void createWithException(String country, String company, String fullname, String lastname, String description) {
create(country, company, fullname, lastname, description);
throw new DummyException("This method failed");
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#create(java.lang.String,
* java.lang.String, java.lang.String, java.lang.String,
* java.lang.String)
*/
public void create(String country, String company, String fullname,
String lastname, String description) {
DistinguishedName dn = new DistinguishedName();
dn.add("c", country);
dn.add("ou", company);
dn.add("cn", fullname);
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#create(java.lang.String,
* java.lang.String, java.lang.String, java.lang.String, java.lang.String)
*/
public void create(String country, String company, String fullname, String lastname, String description) {
DistinguishedName dn = new DistinguishedName();
dn.add("c", country);
dn.add("ou", company);
dn.add("cn", fullname);
DirContextAdapter ctx = new DirContextAdapter();
ctx.setAttributeValues("objectclass", new String[] { "top", "person" });
ctx.setAttributeValue("cn", fullname);
ctx.setAttributeValue("sn", lastname);
ctx.setAttributeValue("description", description);
ldapTemplate.bind(dn, ctx, null);
jdbcTemplate.update("insert into PERSON values(?, ?, ?)", new Object[] {
fullname, lastname, description });
}
DirContextAdapter ctx = new DirContextAdapter();
ctx.setAttributeValues("objectclass", new String[] { "top", "person" });
ctx.setAttributeValue("cn", fullname);
ctx.setAttributeValue("sn", lastname);
ctx.setAttributeValue("description", description);
ldapTemplate.bind(dn, ctx, null);
jdbcTemplate.update("insert into PERSON values(?, ?, ?)", new Object[] { fullname, lastname, description });
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#update(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void update(String dn, String fullname, String lastname,
String description) {
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
ctx.setAttributeValue("sn", lastname);
ctx.setAttributeValue("description", description);
ctx.update();
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#update(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void update(String dn, String fullname, String lastname, String description) {
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
ctx.setAttributeValue("sn", lastname);
ctx.setAttributeValue("description", description);
ctx.update();
ldapTemplate.rebind(dn, ctx, null);
jdbcTemplate
.update(
"update PERSON set lastname=?, description = ? where fullname = ?",
new Object[] { lastname, description, fullname });
}
ldapTemplate.rebind(dn, ctx, null);
jdbcTemplate.update("update PERSON set lastname=?, description = ? where fullname = ?", new Object[] {
lastname, description, fullname });
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#updateWithException(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void updateWithException(String dn, String fullname,
String lastname, String description) {
update(dn, fullname, lastname, description);
throw new DummyException("This method failed.");
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#updateWithException(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void updateWithException(String dn, String fullname, String lastname, String description) {
update(dn, fullname, lastname, description);
throw new DummyException("This method failed.");
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#updateAndRename(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void updateAndRename(String dn, String newDn, String description) {
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
ctx.setAttributeValue("description", description);
ctx.update();
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#updateAndRename(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void updateAndRename(String dn, String newDn, String description) {
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
ctx.setAttributeValue("description", description);
ctx.update();
ldapTemplate.rebind(dn, ctx, null);
ldapTemplate.rename(dn, newDn);
}
ldapTemplate.rebind(dn, ctx, null);
ldapTemplate.rename(dn, newDn);
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#updateAndRenameWithException(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void updateAndRenameWithException(String dn, String newDn,
String description) {
updateAndRename(dn, newDn, description);
throw new DummyException("This method failed.");
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#updateAndRenameWithException(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void updateAndRenameWithException(String dn, String newDn, String description) {
updateAndRename(dn, newDn, description);
throw new DummyException("This method failed.");
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#modifyAttributes(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void modifyAttributes(String dn, String lastName, String description) {
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
ctx.setAttributeValue("sn", lastName);
ctx.setAttributeValue("description", description);
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#modifyAttributes(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void modifyAttributes(String dn, String lastName, String description) {
DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(dn);
ctx.setAttributeValue("sn", lastName);
ctx.setAttributeValue("description", description);
ldapTemplate.modifyAttributes(dn, ctx.getModificationItems());
}
ldapTemplate.modifyAttributes(dn, ctx.getModificationItems());
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#modifyAttributesWithException(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void modifyAttributesWithException(String dn, String lastName,
String description) {
modifyAttributes(dn, lastName, description);
throw new DummyException("This method failed.");
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#modifyAttributesWithException(java.lang.String,
* java.lang.String, java.lang.String)
*/
public void modifyAttributesWithException(String dn, String lastName, String description) {
modifyAttributes(dn, lastName, description);
throw new DummyException("This method failed.");
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#unbind(java.lang.String)
*/
public void unbind(String dn, String fullname) {
ldapTemplate.unbind(dn);
jdbcTemplate.update("delete from PERSON where fullname=?",
new Object[] { fullname });
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#unbind(java.lang.String)
*/
public void unbind(String dn, String fullname) {
ldapTemplate.unbind(dn);
jdbcTemplate.update("delete from PERSON where fullname=?", new Object[] { fullname });
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#unbindWithException(java.lang.String)
*/
public void unbindWithException(String dn, String fullname) {
unbind(dn, fullname);
throw new DummyException("This operation failed.");
}
/*
* (non-Javadoc)
*
* @see org.springframework.ldap.transaction.support.DummyDao#unbindWithException(java.lang.String)
*/
public void unbindWithException(String dn, String fullname) {
unbind(dn, fullname);
throw new DummyException("This operation failed.");
}
}

View File

@@ -33,13 +33,17 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.io.ClassPathResource;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.ldap.AbstractLdapTemplateIntegrationTest;
import org.springframework.ldap.NameNotFoundException;
import org.springframework.ldap.core.AttributesMapper;
import org.springframework.ldap.core.ContextSource;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.test.LdapTestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.transaction.support.TransactionSynchronizationManager;
@@ -63,9 +67,9 @@ public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends
@Autowired
private JdbcTemplate jdbcTemplate;
public void setDummyDao(DummyDao dummyDaoImpl) {
this.dummyDao = dummyDaoImpl;
}
@Autowired
@Qualifier("contextSourceTarget")
ContextSource contextSource;
@Before
public void prepareTestedInstance() throws Exception {
@@ -76,6 +80,9 @@ public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends
jdbcTemplate.execute("create table PERSON(fullname VARCHAR, lastname VARCHAR, description VARCHAR)");
jdbcTemplate.update("insert into PERSON values(?, ?, ?)", new Object[] { "Some Person", "Person",
"Sweden, Company1, Some Person" });
LdapTestUtils.clearSubContexts(contextSource, DistinguishedName.EMPTY_PATH);
LdapTestUtils.loadLdif(contextSource, new ClassPathResource("setup_data.ldif"));
}
@After
@@ -288,6 +295,7 @@ public class ContextSourceAndDataSourceTransactionManagerIntegrationTest extends
});
assertNotNull(result);
dummyDao.update(dn, "Some Person", "Person", "Sweden, Company1, Some Person");
}
@Test

View File

@@ -29,10 +29,14 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.io.ClassPathResource;
import org.springframework.ldap.AbstractLdapTemplateIntegrationTest;
import org.springframework.ldap.NameNotFoundException;
import org.springframework.ldap.core.AttributesMapper;
import org.springframework.ldap.core.ContextSource;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.test.LdapTestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.transaction.support.TransactionSynchronizationManager;
@@ -53,11 +57,18 @@ public class ContextSourceTransactionManagerIntegrationTest extends AbstractLdap
@Autowired
private LdapTemplate ldapTemplate;
@Autowired
@Qualifier("contextSourceTarget")
ContextSource contextSource;
@Before
public void prepareTestedInstance() throws Exception {
if (TransactionSynchronizationManager.isSynchronizationActive()) {
TransactionSynchronizationManager.clearSynchronization();
}
LdapTestUtils.clearSubContexts(contextSource, DistinguishedName.EMPTY_PATH);
LdapTestUtils.loadLdif(contextSource, new ClassPathResource("setup_data.ldif"));
}
@Test

View File

@@ -45,6 +45,16 @@
<inceptionYear>2006</inceptionYear>
<repositories>
<repository>
<id>maven central repo</id>
<url>http://repo1.maven.org/maven2/</url>
</repository>
<repository>
<id>java.net repo</id>
<url>http://download.java.net/maven/2/</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>