Ok, I answered my own question. After writing that post I dug a little
further and finally found an overridable method in BaseDaoTestCase that
solved my problem:
protected String[] getConfigLocations() {
return (String[]) ArrayUtils.add(super.getConfigLocations(),
"classpath:**/security.xml");
}
This could be considered a bit kludgy. Is there a way of configuring this
rather than coding it?
Thanks!
Donley
donleyp wrote:
>
> I am having trouble using Acegi inside my unit tests.
>
> The following is a unit test for my "AccountDao" class.
>
> public class AccountDaoTest extends BaseDaoTestCase {
>
> private AuthenticationManager authenticationManager;
> private AccountDao accountDao;
> private UserDao userDao;
>
> /**
> * @param authenticationManager the authenticationManager to set
> */
> public void setAuthenticationManager(AuthenticationManager
> authenticationManager) {
> this.authenticationManager = authenticationManager;
> }
>
> /**
> * @param userDao the userDao to set
> */
> public void setUserDao(UserDao userDao) {
> this.userDao = userDao;
> }
>
> public void setAccountDao(AccountDao accountDao) {
> this.accountDao = accountDao;
> }
>
> public void testGetByCurrentUser() {
> Authentication authentication = new
> UsernamePasswordAuthenticationToken("dpsimer", "tomcat");
> authentication =
> this.authenticationManager.authenticate(authentication);
> List<Account> accountList = this.accountDao.getByCurrentUser();
> assertNotNull("accountList is null.", accountList);
> assertTrue("accountList is empty.", accountList.size() > 0);
> }
>
> public void testGetByUser() {
> User user = userDao.get(new Long(-1));
> List<Account> accountList = this.accountDao.getAllByUser(user);
> assertNotNull("accountList is null.", accountList);
> assertTrue("accountList is empty.", accountList.size() > 0);
> }
> }
>
> When I run this test, I receive the following error:
> org.springframework.beans.factory.UnsatisfiedDependencyException: Error
> creating bean with name
> 'biz.firethorn.ftap.demo.domain.dao.AccountDaoTest': Unsatisfied
> dependency expressed through bean property 'authenticationManager': Set
> this property value or disable dependency checking for this bean.
>
> The log output from the test spits this out:
> [ftap-demo] INFO [main] AccountDaoTest.loadContextLocations(177) | Loading
> context for locations:
> classpath*:/applicationContext-resources.xml,classpath*:/applicationContext-dao.xml,classpath*:/applicationContext.xml,classpath:**/applicationContext*.xml
>
> I think if I could just get security.xml appended to that list of context
> files, this test would work. How do I add security.xml to the context path
> for the unit tests?
>
> When I run code that uses AccountDao.getByCurrentUser() in the container,
> everything works great. I get the accounts for the currently logged in
> user with no errors.
>
> Thanks,
>
> Donley
>
>
>
--
View this message in context:
http://www.nabble.com/Testing-security-during-unit-tests.-tf3476510s2369.html#a9704137
Sent from the AppFuse - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]