daily pastebin goal
3%
SHARE
TWEET

Untitled

a guest Apr 21st, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.brain2.bosal.webservice.service.impl;
  2.  
  3. import static org.easymock.EasyMock.createMock;
  4. import static org.easymock.EasyMock.expect;
  5. import static org.easymock.EasyMock.replay;
  6. import static org.easymock.EasyMock.verify;
  7.  
  8. import org.junit.Assert;
  9. import org.junit.Test;
  10.  
  11. import com.brain2.bosal.domain.Language;
  12. import com.brain2.bosal.domain.User;
  13. import com.brain2.bosal.webservice.auth.RadiusAuthenticator;
  14. import com.brain2.bosal.webservice.dao.UserDao;
  15. import com.brain2.bosal.webservice.dao.impl.UserDaoImpl;
  16. import com.brain2.bosal.webservice.service.UserService;
  17.  
  18. public class UserServiceImplTests {
  19.     private RadiusAuthenticator radiusAuthenticator = createMock(RadiusAuthenticator.class);
  20.     private UserDao userDao = createMock(UserDaoImpl.class);
  21.     private UserService userService = new UserServiceImpl(userDao, radiusAuthenticator);
  22.    
  23.     @Test
  24.     public void validCredentials() {
  25.         try {
  26.             String username = "test";
  27.             String password = "test";
  28.            
  29.             User user = createUser(username);
  30.            
  31.             expect(radiusAuthenticator.authenticate(username, password)).andReturn(true);
  32.             replay(radiusAuthenticator);
  33.             expect(userDao.findUserByUsername(username)).andReturn(user);
  34.             replay(userDao);
  35.            
  36.             Assert.assertEquals("Authenticate did not return correct User object", user, userService.authenticate(username, password));
  37.            
  38.             verify(radiusAuthenticator);
  39.             verify(userDao);
  40.         } catch(Exception e) {
  41.             Assert.assertTrue(e.getMessage(), false);
  42.         }
  43.     }
  44.    
  45.     private User createUser(String username) {
  46.         User user = new User();
  47.         user.setId(1);
  48.         user.setUsername(username);
  49.         user.setCustomerNumber(1);
  50.         user.setSalesOrganization("TEST");
  51.         user.setLanguage(createLanguage());
  52.        
  53.         return user;
  54.     }
  55.    
  56.     private Language createLanguage() {
  57.         Language language = new Language();
  58.         language.setId(1);
  59.         language.setLanguageCode("NL");
  60.        
  61.         return language;
  62.     }
  63. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top