@Test public void testSignup() throws Exception { String name = "test_user"; String email = "test@staffjoy.xyz"; Instant memberSince = Instant.now().minus(100, ChronoUnit.DAYS); String userId = UUID.randomUUID().toString(); AccountDto accountDto = AccountDto.builder() .id(userId) .name(name) .email(email) .memberSince(memberSince) .phoneNumber("18001112222") .confirmedAndActive(false) .photoUrl("http: .build(); when(accountClient.createAccount(anyString(), any(CreateAccountRequest.class))) .thenReturn(new GenericAccountResponse(accountDto)); MvcResult mvcResult = mockMvc.perform(post("/confirm") .param("email", "")) .andExpect(status().is3xxRedirection()) .andExpect(view().name(SignupController.SIGN_UP_REDIRECT_PATH)) .andReturn(); mvcResult = mockMvc.perform(post("/confirm") .param("email", accountDto.getEmail()).param("name", accountDto.getName())) .andExpect(status().isOk()) .andExpect(view().name(Constant.VIEW_CONFIRM)) .andExpect(content().string(containsString(pageFactory.buildConfirmPage().getDescription()))) .andReturn(); }
@PostMapping(value="/confirm") public String signUp(@RequestParam(value = "name", required = false) String name, @RequestParam("email") String email, Model model) { if (!StringUtils.hasText(email)) { return SIGN_UP_REDIRECT_PATH; } CreateAccountRequest request = CreateAccountRequest.builder() .name(name) .email(email) .build(); GenericAccountResponse genericAccountResponse = null; try { genericAccountResponse = accountClient.createAccount(AuthConstant.AUTHORIZATION_WWW_SERVICE, request); } catch (Exception ex) { String errMsg = "Failed to create account"; helperService.logException(logger, ex, errMsg); return SIGN_UP_REDIRECT_PATH; } if (!genericAccountResponse.isSuccess()) { helperService.logError(logger, genericAccountResponse.getMessage()); return SIGN_UP_REDIRECT_PATH; } AccountDto account = genericAccountResponse.getAccount(); logger.info(String.format("New Account signup - %s", account)); model.addAttribute(Constant.ATTRIBUTE_NAME_PAGE, pageFactory.buildConfirmPage()); return Constant.VIEW_CONFIRM; }
SignupController { @PostMapping(value="/confirm") public String signUp(@RequestParam(value = "name", required = false) String name, @RequestParam("email") String email, Model model) { if (!StringUtils.hasText(email)) { return SIGN_UP_REDIRECT_PATH; } CreateAccountRequest request = CreateAccountRequest.builder() .name(name) .email(email) .build(); GenericAccountResponse genericAccountResponse = null; try { genericAccountResponse = accountClient.createAccount(AuthConstant.AUTHORIZATION_WWW_SERVICE, request); } catch (Exception ex) { String errMsg = "Failed to create account"; helperService.logException(logger, ex, errMsg); return SIGN_UP_REDIRECT_PATH; } if (!genericAccountResponse.isSuccess()) { helperService.logError(logger, genericAccountResponse.getMessage()); return SIGN_UP_REDIRECT_PATH; } AccountDto account = genericAccountResponse.getAccount(); logger.info(String.format("New Account signup - %s", account)); model.addAttribute(Constant.ATTRIBUTE_NAME_PAGE, pageFactory.buildConfirmPage()); return Constant.VIEW_CONFIRM; } }
SignupController { @PostMapping(value="/confirm") public String signUp(@RequestParam(value = "name", required = false) String name, @RequestParam("email") String email, Model model) { if (!StringUtils.hasText(email)) { return SIGN_UP_REDIRECT_PATH; } CreateAccountRequest request = CreateAccountRequest.builder() .name(name) .email(email) .build(); GenericAccountResponse genericAccountResponse = null; try { genericAccountResponse = accountClient.createAccount(AuthConstant.AUTHORIZATION_WWW_SERVICE, request); } catch (Exception ex) { String errMsg = "Failed to create account"; helperService.logException(logger, ex, errMsg); return SIGN_UP_REDIRECT_PATH; } if (!genericAccountResponse.isSuccess()) { helperService.logError(logger, genericAccountResponse.getMessage()); return SIGN_UP_REDIRECT_PATH; } AccountDto account = genericAccountResponse.getAccount(); logger.info(String.format("New Account signup - %s", account)); model.addAttribute(Constant.ATTRIBUTE_NAME_PAGE, pageFactory.buildConfirmPage()); return Constant.VIEW_CONFIRM; }  }
SignupController { @PostMapping(value="/confirm") public String signUp(@RequestParam(value = "name", required = false) String name, @RequestParam("email") String email, Model model) { if (!StringUtils.hasText(email)) { return SIGN_UP_REDIRECT_PATH; } CreateAccountRequest request = CreateAccountRequest.builder() .name(name) .email(email) .build(); GenericAccountResponse genericAccountResponse = null; try { genericAccountResponse = accountClient.createAccount(AuthConstant.AUTHORIZATION_WWW_SERVICE, request); } catch (Exception ex) { String errMsg = "Failed to create account"; helperService.logException(logger, ex, errMsg); return SIGN_UP_REDIRECT_PATH; } if (!genericAccountResponse.isSuccess()) { helperService.logError(logger, genericAccountResponse.getMessage()); return SIGN_UP_REDIRECT_PATH; } AccountDto account = genericAccountResponse.getAccount(); logger.info(String.format("New Account signup - %s", account)); model.addAttribute(Constant.ATTRIBUTE_NAME_PAGE, pageFactory.buildConfirmPage()); return Constant.VIEW_CONFIRM; }  @PostMapping(value="/confirm") String signUp(@RequestParam(value = "name", required = false) String name, @RequestParam("email") String email, Model model); }
SignupController { @PostMapping(value="/confirm") public String signUp(@RequestParam(value = "name", required = false) String name, @RequestParam("email") String email, Model model) { if (!StringUtils.hasText(email)) { return SIGN_UP_REDIRECT_PATH; } CreateAccountRequest request = CreateAccountRequest.builder() .name(name) .email(email) .build(); GenericAccountResponse genericAccountResponse = null; try { genericAccountResponse = accountClient.createAccount(AuthConstant.AUTHORIZATION_WWW_SERVICE, request); } catch (Exception ex) { String errMsg = "Failed to create account"; helperService.logException(logger, ex, errMsg); return SIGN_UP_REDIRECT_PATH; } if (!genericAccountResponse.isSuccess()) { helperService.logError(logger, genericAccountResponse.getMessage()); return SIGN_UP_REDIRECT_PATH; } AccountDto account = genericAccountResponse.getAccount(); logger.info(String.format("New Account signup - %s", account)); model.addAttribute(Constant.ATTRIBUTE_NAME_PAGE, pageFactory.buildConfirmPage()); return Constant.VIEW_CONFIRM; }  @PostMapping(value="/confirm") String signUp(@RequestParam(value = "name", required = false) String name, @RequestParam("email") String email, Model model);  }