Announcement Announcement Module
Collapse
No announcement yet.
Testing Problems when moving to annotation-based config Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Testing Problems when moving to annotation-based config

    I just refactored my application to use annotation-based configuration. I'm having a problem getting my TestNG tests to run. I'm getting a no bean name error.

    FAILED CONFIGURATION: atBeforeClass setup
    org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'userService' is defined
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.getBeanDefinition(DefaultListab leBeanFactory.java:387)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getMergedLocalBeanDefinition(AbstractB eanFactory.java:968)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:246 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.context.support.AbstractApplic ationContext.getBean(AbstractApplicationContext.ja va:881)
    at com.mpower.test.UserTest.setup(UserTest.java:33)
    ... Removed 22 stack frames
    SKIPPED: insertUser

    Here is where I define and configure the bean:
    atService("userService")
    public class UserServiceImpl implements UserService {

    private UserDao userDao;

    atResource(name="userDao")
    public void setUserDao(UserDao userDao) {
    this.userDao = userDao;
    }

    atOverride
    public User authenticateUser(String userName, String password) {
    return userDao.readUserByUserNameAndPassword(userName, password);
    }

    atOverride
    public User maintainUser(User user) {
    return userDao.saveUser(user);
    }
    }

    And here is my test:
    public class UserTest extends BaseTest {

    private UserService userService;

    atTest(groups={"user"})
    public void insertUser() {
    User user = new User();
    user.setUserName("kelly");
    user.setPassword("password");
    userService.maintainUser(user);
    }

    atTest(groups={"user"}, dependsOnMethods={"insertUser"})
    public void readUser() {
    User user = userService.authenticateUser("kelly", "password");
    assert user != null;
    }

    public void setUserService(UserService userService) {
    this.userService = userService;
    }

    atBeforeClass
    public void setup() {
    userService = (UserService)super.applicationContext.getBean("use rService");
    }
    }

    And here is BaseTest:
    atContextConfiguration(locations={"classpath:/applicationContext.xml"})
    public abstract class BaseTest extends AbstractTestNGSpringContextTests {
    }


    Any ideas? I would assume that pulling the "userService" bean from the appCtx would be fine?

    Erik
    Last edited by eweibust; May 30th, 2008, 01:00 PM.

  • #2
    Can you post your applicationContext.xml file? For sure if you're missing the <context:component-scan /> element the UserServiceImpl class won't be registered as a bean.

    Cheers,
    GB

    Comment


    • #3
      GB,

      You nailed it. It was my appCtx. I got bit by the dang copy/paste bug. I copied my component-scan element from another appCtx I had and never updated the stinking base-package.

      Thanks...
      Erik

      Comment

      Working...
      X