@Test public void shouldCreateActiveUserByDefault() { motechUserService.register( "userName", "password", "1234", "", asList("IT_ADMIN", "DB_ADMIN"), Locale.ENGLISH); MotechUser motechUser = usersDataService.findByUserName("userName"); assertEquals(UserStatus.ACTIVE, motechUser.getUserStatus()); }
@Test public void shouldNotChangePasswordWithoutOldPassword() { motechUserService.register( "userName", "password", "1234", "", asList("IT_ADMIN", "DB_ADMIN"), Locale.ENGLISH); motechUserService.changePassword("userName", "foo", "newPassword"); MotechUser motechUser = usersDataService.findByUserName("userName"); assertTrue(passwordEncoder.isPasswordValid(motechUser.getPassword(), "password")); }
@Test public void testPasswordEncoding() { String plainTextPassword = "******"; motechUserService.register( "testuser", plainTextPassword, "entity1", "", asList("ADMIN"), Locale.ENGLISH); MotechUser motechUser = usersDataService.findByUserName("testuser"); assertTrue(passwordEncoder.isPasswordValid(motechUser.getPassword(), plainTextPassword)); }
@Test public void testRegister() { motechUserService.register( "userName", "password", "1234", "", asList("IT_ADMIN", "DB_ADMIN"), Locale.ENGLISH); MotechUser motechUser = usersDataService.findByUserName("userName"); assertNotNull(motechUser); assertTrue(motechUser.getRoles().contains("IT_ADMIN")); assertTrue(motechUser.getRoles().contains("DB_ADMIN")); }
@After public void tearDown() throws Exception { super.tearDown(); usersDataService.deleteAll(); rolesDataService.deleteAll(); clearSecurityContext(); }
@Test public void shouldCreateBlockedUser() { motechUserService.register( "userName", "password", "1234", "", asList("IT_ADMIN", "DB_ADMIN"), Locale.ENGLISH, UserStatus.BLOCKED, null); MotechUser motechUser = usersDataService.findByUserName("userName"); assertEquals(UserStatus.BLOCKED, motechUser.getUserStatus()); }
@Before @Override public void setUp() throws Exception { super.setUp(); passwordEncoder = getFromContext(MotechPasswordEncoder.class); usersDataService.deleteAll(); rolesDataService.deleteAll(); // authorize motechUserService.registerMotechAdmin("admin", "admin", "*****@*****.**", Locale.ENGLISH); setUpSecurityContext("admin", "admin", getPermissions()); }
@Test public void shouldNotActivateInvalidUser() { motechUserService.register( "userName", "password", "1234", "", asList("IT_ADMIN", "DB_ADMIN"), Locale.ENGLISH, UserStatus.BLOCKED, null); motechUserService.activateUser("userName1"); MotechUser motechUser = usersDataService.findByUserName("userName"); assertFalse(motechUser.isActive()); }