Hi, 
I'm trying to get DAO that is relying on the context object as per 
the example of http://tersesystems.com/post/9700064.jhtml
But I'm not getting. 
Kindly anybody tell me how to do this. 
Thanks in advance... 

My code goes like this..... 

--------------------------------- 

public class LoginServiceTest extends TestCase { 
private Log logger = LogFactory.getLog(this.getClass()); 
private UserServiceImpl userServiceImpl; 
private UserDao mockDao; 
User user; 

public void testLogin() throws UsernameNotExistException { 
try { 

user = new User(); 
mockDao = new UserDaoHibernateImpl(); 
userServiceImpl.setUserDao(mockDao); 

//org.springframework.context.ApplicationContext ctx = new 
// FileSystemXmlApplicationContext( "D:\\...\\Web 
// Content\\WEB-INF\\applicationContext.xml"); 

ApplicationContext mockContext = EasyMock.createMock 
(ApplicationContext.class); 

mockDao = createMock(UserDao.class); 
expect(mockContext.getBean("userDao")).andReturn(mockDao); 
mockDao.getUser("admin"); 
replay(mockContext); 
replay(mockDao); 

assertEquals(user, userServiceImpl.login("admin", "admin")); 
verify(mockDao); 

} catch (HibernateObjectRetrievalFailureException he) { 
throw new UsernameNotExistException(user.getUsername()); 
} catch (Exception e) { 
this.logger.error("Could not login", e); 
throw new UsernameNotExistException(user.getUsername()); 
} 
} 
} 


---------------------- 
applicationContext.xml 
---------------------- 
.... 
.... 
<!-- User DAO object: Hibernate implementation --> 
<bean id="userDao" 
class="com.....model.dao.hibernate.UserDaoHibernateImpl"> 
<property name="hibernateTemplate"><ref bean="hibernateTemplate"/> 
</property> 
</bean> 
.... 
.... 

-- 
View this message in context: 
http://n2.nabble.com/How-to-get-DAO-while-we%27re-relying-on-a-context-object-%28that-is-being-passed-in%29-tp1608974p1608974.html
Sent from the Tapestry Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to