@Test public void testAccountService() throws Exception { // 1. Get captcha String captchaKey = accountService.generateCaptchaKey(); accountService.generateCaptchaImage(captchaKey); String captchaValue = "12345"; // 2. Submit sign up Request SignUpRequest signUpRequest = new SignUpRequest(); signUpRequest.setCaptchaKey(captchaKey); signUpRequest.setCaptchaValue(captchaValue); signUpRequest.setId("juven"); signUpRequest.setEmail("*****@*****.**"); signUpRequest.setName("Juven Xu"); signUpRequest.setPassword("admin123"); signUpRequest.setConfirmPassword("admin123"); signUpRequest.setActivateServiceUrl("http://localhost:8080/account/activate"); accountService.signUp(signUpRequest); // 3. Read activation link greenMail.waitForIncomingEmail(2000, 1); Message[] msgs = greenMail.getReceivedMessages(); assertEquals(1, msgs.length); assertEquals("Please Activate Your Account", msgs[0].getSubject()); String activationLink = GreenMailUtil.getBody(msgs[0]).trim(); // 3a. Try login but not activated try { accountService.login("juven", "admin123"); fail("Disabled account shouldn't be able to log in."); } catch (AccountServiceException e) { } // 4. Activate account String activationCode = activationLink.substring(activationLink.lastIndexOf("=") + 1); accountService.activate(activationCode); // 5. Login with correct id and password accountService.login("juven", "admin123"); // 5a. Login with incorrect password try { accountService.login("juven", "admin456"); fail("Password is incorrect, shouldn't be able to login."); } catch (AccountServiceException e) { } }