@Test void activateUser() { @SuppressWarnings("unchecked") Query<User> q = mock(Query.class); when(q.eq(ACTIVE, false)).thenReturn(q); when(q.and()).thenReturn(q); when(q.eq(ACTIVATIONCODE, "123")).thenReturn(q); when(q.findOne()).thenReturn(user); when(dataService.query(USER, User.class)).thenReturn(q); accountService.activateUser("123"); ArgumentCaptor<User> argument = ArgumentCaptor.forClass(User.class); verify(dataService).update(eq(USER), argument.capture()); verify(user).setActive(true); SimpleMailMessage expected = new SimpleMailMessage(); expected.setTo("jan.jansen@activation.nl"); expected.setText( "Dear Jan Jansen,\n\nYour registration request for Molgenis title was approved.\n" + "Your account is now active.\n\n" + "Kind regards,\n\n" + "Server administrator"); expected.setSubject("Your registration request for Molgenis title"); verify(mailSender).send(expected); }
@Override @RunAsSystem public void activateUser(String activationCode) { User user = dataService .query(USER, User.class) .eq(ACTIVE, false) .and() .eq(ACTIVATIONCODE, activationCode) .findOne(); if (user != null) { user.setActive(true); dataService.update(USER, user); SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setTo(user.getEmail()); mailMessage.setSubject("Your registration request for " + appSettings.getTitle()); mailMessage.setText(createActivatedEmailText(user, appSettings.getTitle())); mailSender.send(mailMessage); } else { throw new MolgenisUserException("Invalid activation code or account already activated."); } }
AccountServiceImpl implements AccountService { @Override @RunAsSystem public void activateUser(String activationCode) { User user = dataService .query(USER, User.class) .eq(ACTIVE, false) .and() .eq(ACTIVATIONCODE, activationCode) .findOne(); if (user != null) { user.setActive(true); dataService.update(USER, user); SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setTo(user.getEmail()); mailMessage.setSubject("Your registration request for " + appSettings.getTitle()); mailMessage.setText(createActivatedEmailText(user, appSettings.getTitle())); mailSender.send(mailMessage); } else { throw new MolgenisUserException("Invalid activation code or account already activated."); } } }
AccountServiceImpl implements AccountService { @Override @RunAsSystem public void activateUser(String activationCode) { User user = dataService .query(USER, User.class) .eq(ACTIVE, false) .and() .eq(ACTIVATIONCODE, activationCode) .findOne(); if (user != null) { user.setActive(true); dataService.update(USER, user); SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setTo(user.getEmail()); mailMessage.setSubject("Your registration request for " + appSettings.getTitle()); mailMessage.setText(createActivatedEmailText(user, appSettings.getTitle())); mailSender.send(mailMessage); } else { throw new MolgenisUserException("Invalid activation code or account already activated."); } } AccountServiceImpl(
      DataService dataService,
      MailSender mailSender,
      UserService userService,
      AppSettings appSettings,
      AuthenticationSettings authenticationSettings,
      IdGenerator idGenerator); }
AccountServiceImpl implements AccountService { @Override @RunAsSystem public void activateUser(String activationCode) { User user = dataService .query(USER, User.class) .eq(ACTIVE, false) .and() .eq(ACTIVATIONCODE, activationCode) .findOne(); if (user != null) { user.setActive(true); dataService.update(USER, user); SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setTo(user.getEmail()); mailMessage.setSubject("Your registration request for " + appSettings.getTitle()); mailMessage.setText(createActivatedEmailText(user, appSettings.getTitle())); mailSender.send(mailMessage); } else { throw new MolgenisUserException("Invalid activation code or account already activated."); } } AccountServiceImpl(
      DataService dataService,
      MailSender mailSender,
      UserService userService,
      AppSettings appSettings,
      AuthenticationSettings authenticationSettings,
      IdGenerator idGenerator); @Override @RunAsSystem @Transactional void createUser(User user, String baseActivationUri); @Override @RunAsSystem void activateUser(String activationCode); }
AccountServiceImpl implements AccountService { @Override @RunAsSystem public void activateUser(String activationCode) { User user = dataService .query(USER, User.class) .eq(ACTIVE, false) .and() .eq(ACTIVATIONCODE, activationCode) .findOne(); if (user != null) { user.setActive(true); dataService.update(USER, user); SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setTo(user.getEmail()); mailMessage.setSubject("Your registration request for " + appSettings.getTitle()); mailMessage.setText(createActivatedEmailText(user, appSettings.getTitle())); mailSender.send(mailMessage); } else { throw new MolgenisUserException("Invalid activation code or account already activated."); } } AccountServiceImpl(
      DataService dataService,
      MailSender mailSender,
      UserService userService,
      AppSettings appSettings,
      AuthenticationSettings authenticationSettings,
      IdGenerator idGenerator); @Override @RunAsSystem @Transactional void createUser(User user, String baseActivationUri); @Override @RunAsSystem void activateUser(String activationCode);  }