UserCreationController { @RequestMapping(value = "/activations", method = RequestMethod.POST) public UserActivationResponseDto activateUser(@Valid @RequestBody UserActivationRequestDto userActivationRequest, @RequestHeader(X_FORWARDED_PROTO) String xForwardedProto, @RequestHeader(X_FORWARDED_HOST) String xForwardedHost, @RequestHeader(X_FORWARDED_PORT) int xForwardedPort) { return userCreationService.activateUser(userActivationRequest, xForwardedProto, xForwardedHost, xForwardedPort); }  @RequestMapping(value = "/creations", method = RequestMethod.POST) UserCreationResponseDto initiateUserCreation(@Valid @RequestBody UserCreationRequestDto userCreationRequest,
                                                        @RequestHeader(X_FORWARDED_PROTO) String xForwardedProto,
                                                        @RequestHeader(X_FORWARDED_HOST) String xForwardedHost,
                                                        @RequestHeader(X_FORWARDED_PORT) int xForwardedPort); @RequestMapping(value = "/creations", method = RequestMethod.GET) UserCreationResponseDto getCurrentUserCreationInfo(@RequestParam("patientId") Long patientId); @RequestMapping(value = "/activations", method = RequestMethod.POST) UserActivationResponseDto activateUser(@Valid @RequestBody UserActivationRequestDto userActivationRequest,
                                                  @RequestHeader(X_FORWARDED_PROTO) String xForwardedProto,
                                                  @RequestHeader(X_FORWARDED_HOST) String xForwardedHost,
                                                  @RequestHeader(X_FORWARDED_PORT) int xForwardedPort); @RequestMapping(value = "/verifications", method = RequestMethod.GET) VerificationResponseDto verify(@RequestParam("emailToken") String emailToken,
                                          @RequestParam("verificationCode") Optional<String> verificationCode,
                                          @RequestParam("birthDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Optional<LocalDate> birthDate); @RequestMapping(value = "/scopeAssignments", method = RequestMethod.POST) ScopeAssignmentResponseDto assignScope(@Valid @RequestBody ScopeAssignmentRequestDto scopeAssignmentRequestDto); static final String X_FORWARDED_PROTO; static final String X_FORWARDED_HOST; static final String X_FORWARDED_PORT; }
@Test public void testActivateUser_Password_Length_Upper_Limit() throws Exception { final Long patientId = 10L; final UserActivationRequestDtoForTest request = new UserActivationRequestDtoForTest(); final UserActivationResponseDto response = new UserActivationResponseDto(); final String email = "email"; final String username = "email"; final String verificationCode = "verificationCode"; final int year = 2010; final int month = 2; final int day = 3; final LocalDate birthDate = LocalDate.of(year, month, day); final String firstName = "firstName"; final String lastName = "lastName"; final String genderCode = "genderCode "; final String emailToken = "emailToken"; final String password = "Paaaaaaaaaaaasword#1"; final String confirmPassword = "Paaaaaaaaaaaasword#1"; final boolean verified = true; response.setEmail(email); response.setBirthDate(birthDate); response.setFirstName(firstName); response.setLastName(lastName); response.setId(patientId); response.setGenderCode(genderCode); response.setBirthDate(birthDate); response.setGenderCode(genderCode); response.setVerified(verified); request.setVerificationCode(verificationCode); request.setBirthDate(Arrays.asList(year, month, day)); request.setEmailToken(emailToken); request.setPassword(password); request.setConfirmPassword(confirmPassword); request.setUsername(username); when(userCreationService.activateUser(argThat(matching( req -> req.getBirthDate().equals(birthDate) && req.getVerificationCode().equals(verificationCode) && req.getEmailToken().equals(emailToken) && req.getPassword().equals(password) )), xForwardedProto, xForwardedHost, xForwardedPort)).thenReturn(response); mvc.perform(post("/activations") .contentType(MediaType.APPLICATION_JSON_UTF8) .content(objectMapper.writeValueAsBytes(request)) .header(UserCreationController.X_FORWARDED_PROTO, xForwardedProto) .header(UserCreationController.X_FORWARDED_HOST, xForwardedHost) .header(UserCreationController.X_FORWARDED_PORT, xForwardedPort)) .andExpect(status().isOk()) .andExpect(jsonPath("$.id", is(patientId.intValue()))) .andExpect(jsonPath("$.lastName", is(lastName))) .andExpect(jsonPath("$.firstName", is(firstName))) .andExpect(jsonPath("$.email", is(email))) .andExpect(jsonPath("$.birthDate.[0]", is(year))) .andExpect(jsonPath("$.birthDate.[1]", is(month))) .andExpect(jsonPath("$.birthDate.[2]", is(day))) .andExpect(jsonPath("$.genderCode", is(genderCode))) .andExpect(jsonPath("$.verified", is(Boolean.TRUE))); }
@Test public void testActivateUser_Password_Length_Lower_Limit() throws Exception { final Long patientId = 10L; final UserActivationRequestDtoForTest request = new UserActivationRequestDtoForTest(); final UserActivationResponseDto response = new UserActivationResponseDto(); final String email = "email"; final String username = "email"; final String verificationCode = "verificationCode"; final int year = 2010; final int month = 2; final int day = 3; final LocalDate birthDate = LocalDate.of(year, month, day); final String firstName = "firstName"; final String lastName = "lastName"; final String genderCode = "genderCode "; final String emailToken = "emailToken"; final String password = "Pwrd#1"; final String confirmPassword = "Pwrd#1"; final boolean verified = true; response.setEmail(email); response.setBirthDate(birthDate); response.setFirstName(firstName); response.setLastName(lastName); response.setId(patientId); response.setGenderCode(genderCode); response.setBirthDate(birthDate); response.setGenderCode(genderCode); response.setVerified(verified); request.setVerificationCode(verificationCode); request.setBirthDate(Arrays.asList(year, month, day)); request.setEmailToken(emailToken); request.setPassword(password); request.setConfirmPassword(confirmPassword); request.setUsername(username); when(userCreationService.activateUser(argThat(matching( req -> req.getBirthDate().equals(birthDate) && req.getVerificationCode().equals(verificationCode) && req.getEmailToken().equals(emailToken) && req.getPassword().equals(password) )), xForwardedProto, xForwardedHost, xForwardedPort)).thenReturn(response); mvc.perform(post("/activations") .contentType(MediaType.APPLICATION_JSON_UTF8) .content(objectMapper.writeValueAsBytes(request)) .header(UserCreationController.X_FORWARDED_PROTO, xForwardedProto) .header(UserCreationController.X_FORWARDED_HOST, xForwardedHost) .header(UserCreationController.X_FORWARDED_PORT, xForwardedPort)) .andExpect(status().isOk()) .andExpect(jsonPath("$.id", is(patientId.intValue()))) .andExpect(jsonPath("$.lastName", is(lastName))) .andExpect(jsonPath("$.firstName", is(firstName))) .andExpect(jsonPath("$.email", is(email))) .andExpect(jsonPath("$.birthDate.[0]", is(year))) .andExpect(jsonPath("$.birthDate.[1]", is(month))) .andExpect(jsonPath("$.birthDate.[2]", is(day))) .andExpect(jsonPath("$.genderCode", is(genderCode))) .andExpect(jsonPath("$.verified", is(Boolean.TRUE))); }
@Test public void testActivateUser_Throws_PasswordConfirmationFailedException() throws Exception { final Long patientId = 10L; final UserActivationRequestDtoForTest request = new UserActivationRequestDtoForTest(); final UserActivationResponseDto response = new UserActivationResponseDto(); final String email = "email"; final String username = "email"; final String verificationCode = "verificationCode"; final int year = 2010; final int month = 2; final int day = 3; final LocalDate birthDate = LocalDate.of(year, month, day); final String firstName = "firstName"; final String lastName = "lastName"; final String genderCode = "genderCode "; final String emailToken = "emailToken"; final String password = "Pwrd#1"; final String confirmPassword = "Pwrd#1Different"; final boolean verified = true; response.setEmail(email); response.setBirthDate(birthDate); response.setFirstName(firstName); response.setLastName(lastName); response.setId(patientId); response.setGenderCode(genderCode); response.setBirthDate(birthDate); response.setGenderCode(genderCode); response.setVerified(verified); request.setVerificationCode(verificationCode); request.setBirthDate(Arrays.asList(year, month, day)); request.setEmailToken(emailToken); request.setPassword(password); request.setConfirmPassword(confirmPassword); request.setUsername(username); when(userCreationService.activateUser(argThat(matching( req -> req.getBirthDate().equals(birthDate) && req.getVerificationCode().equals(verificationCode) && req.getEmailToken().equals(emailToken) && req.getPassword().equals(password) && req.getConfirmPassword().equals(confirmPassword) )), xForwardedProto, xForwardedHost, xForwardedPort)).thenThrow(PasswordConfirmationFailedException.class); mvc.perform(post("/activations") .contentType(MediaType.APPLICATION_JSON_UTF8) .content(objectMapper.writeValueAsBytes(request)) .header(UserCreationController.X_FORWARDED_PROTO, xForwardedProto) .header(UserCreationController.X_FORWARDED_HOST, xForwardedHost) .header(UserCreationController.X_FORWARDED_PORT, xForwardedPort)) .andExpect(status().isPreconditionFailed()); }
@Test public void testActivateUser_Weak_Password_No_Upper_Case() throws Exception { final Long patientId = 10L; final UserActivationRequestDtoForTest request = new UserActivationRequestDtoForTest(); final UserActivationResponseDto response = new UserActivationResponseDto(); final String email = "email"; final String verificationCode = "verificationCode"; final int year = 2010; final int month = 2; final int day = 3; final LocalDate birthDate = LocalDate.of(year, month, day); final String firstName = "firstName"; final String lastName = "lastName"; final String genderCode = "genderCode "; final String emailToken = "emailToken"; final String password = "password#1"; final boolean verified = true; response.setEmail(email); response.setBirthDate(birthDate); response.setFirstName(firstName); response.setLastName(lastName); response.setId(patientId); response.setGenderCode(genderCode); response.setBirthDate(birthDate); response.setGenderCode(genderCode); response.setVerified(verified); request.setVerificationCode(verificationCode); request.setBirthDate(Arrays.asList(year, month, day)); request.setEmailToken(emailToken); request.setPassword(password); when(userCreationService.activateUser(argThat(matching( req -> req.getBirthDate().equals(birthDate) && req.getVerificationCode().equals(verificationCode) && req.getEmailToken().equals(emailToken) && req.getPassword().equals(password) )), xForwardedProto, xForwardedHost, xForwardedPort)).thenReturn(response); mvc.perform(post("/activations") .contentType(MediaType.APPLICATION_JSON_UTF8) .content(objectMapper.writeValueAsBytes(request)) .header(UserCreationController.X_FORWARDED_PROTO, xForwardedProto) .header(UserCreationController.X_FORWARDED_HOST, xForwardedHost) .header(UserCreationController.X_FORWARDED_PORT, xForwardedPort)) .andExpect(status().isBadRequest()); }
@Test public void testActivateUser_Weak_Password_No_Special_Character() throws Exception { final Long patientId = 10L; final UserActivationRequestDtoForTest request = new UserActivationRequestDtoForTest(); final UserActivationResponseDto response = new UserActivationResponseDto(); final String email = "email"; final String verificationCode = "verificationCode"; final int year = 2010; final int month = 2; final int day = 3; final LocalDate birthDate = LocalDate.of(year, month, day); final String firstName = "firstName"; final String lastName = "lastName"; final String genderCode = "genderCode "; final String emailToken = "emailToken"; final String password = "Password1"; final boolean verified = true; response.setEmail(email); response.setBirthDate(birthDate); response.setFirstName(firstName); response.setLastName(lastName); response.setId(patientId); response.setGenderCode(genderCode); response.setBirthDate(birthDate); response.setGenderCode(genderCode); response.setVerified(verified); request.setVerificationCode(verificationCode); request.setBirthDate(Arrays.asList(year, month, day)); request.setEmailToken(emailToken); request.setPassword(password); when(userCreationService.activateUser(argThat(matching( req -> req.getBirthDate().equals(birthDate) && req.getVerificationCode().equals(verificationCode) && req.getEmailToken().equals(emailToken) && req.getPassword().equals(password) )), xForwardedProto, xForwardedHost, xForwardedPort)).thenReturn(response); mvc.perform(post("/activations") .contentType(MediaType.APPLICATION_JSON_UTF8) .content(objectMapper.writeValueAsBytes(request)) .header(UserCreationController.X_FORWARDED_PROTO, xForwardedProto) .header(UserCreationController.X_FORWARDED_HOST, xForwardedHost) .header(UserCreationController.X_FORWARDED_PORT, xForwardedPort)) .andExpect(status().isBadRequest()); }
@Test public void testActivateUser_Weak_Password_No_Number() throws Exception { final Long patientId = 10L; final UserActivationRequestDtoForTest request = new UserActivationRequestDtoForTest(); final UserActivationResponseDto response = new UserActivationResponseDto(); final String email = "email"; final String verificationCode = "verificationCode"; final int year = 2010; final int month = 2; final int day = 3; final LocalDate birthDate = LocalDate.of(year, month, day); final String firstName = "firstName"; final String lastName = "lastName"; final String genderCode = "genderCode "; final String emailToken = "emailToken"; final String password = "Password#"; final boolean verified = true; response.setEmail(email); response.setBirthDate(birthDate); response.setFirstName(firstName); response.setLastName(lastName); response.setId(patientId); response.setGenderCode(genderCode); response.setBirthDate(birthDate); response.setGenderCode(genderCode); response.setVerified(verified); request.setVerificationCode(verificationCode); request.setBirthDate(Arrays.asList(year, month, day)); request.setEmailToken(emailToken); request.setPassword(password); when(userCreationService.activateUser(argThat(matching( req -> req.getBirthDate().equals(birthDate) && req.getVerificationCode().equals(verificationCode) && req.getEmailToken().equals(emailToken) && req.getPassword().equals(password) )), xForwardedProto, xForwardedHost, xForwardedPort)).thenReturn(response); mvc.perform(post("/activations") .contentType(MediaType.APPLICATION_JSON_UTF8) .content(objectMapper.writeValueAsBytes(request)) .header(UserCreationController.X_FORWARDED_PROTO, xForwardedProto) .header(UserCreationController.X_FORWARDED_HOST, xForwardedHost) .header(UserCreationController.X_FORWARDED_PORT, xForwardedPort)) .andExpect(status().isBadRequest()); }
@Test public void testActivateUser_Weak_Password_Too_Short() throws Exception { final Long patientId = 10L; final UserActivationRequestDtoForTest request = new UserActivationRequestDtoForTest(); final UserActivationResponseDto response = new UserActivationResponseDto(); final String email = "email"; final String verificationCode = "verificationCode"; final int year = 2010; final int month = 2; final int day = 3; final LocalDate birthDate = LocalDate.of(year, month, day); final String firstName = "firstName"; final String lastName = "lastName"; final String genderCode = "genderCode "; final String emailToken = "emailToken"; final String password = "Prd#1"; final boolean verified = true; response.setEmail(email); response.setBirthDate(birthDate); response.setFirstName(firstName); response.setLastName(lastName); response.setId(patientId); response.setGenderCode(genderCode); response.setBirthDate(birthDate); response.setGenderCode(genderCode); response.setVerified(verified); request.setVerificationCode(verificationCode); request.setBirthDate(Arrays.asList(year, month, day)); request.setEmailToken(emailToken); request.setPassword(password); when(userCreationService.activateUser(argThat(matching( req -> req.getBirthDate().equals(birthDate) && req.getVerificationCode().equals(verificationCode) && req.getEmailToken().equals(emailToken) && req.getPassword().equals(password) )), xForwardedProto, xForwardedHost, xForwardedPort)).thenReturn(response); mvc.perform(post("/activations") .contentType(MediaType.APPLICATION_JSON_UTF8) .content(objectMapper.writeValueAsBytes(request)) .header(UserCreationController.X_FORWARDED_PROTO, xForwardedProto) .header(UserCreationController.X_FORWARDED_HOST, xForwardedHost) .header(UserCreationController.X_FORWARDED_PORT, xForwardedPort)) .andExpect(status().isBadRequest()); }
@Test public void testActivateUser_Weak_Password_Too_Long() throws Exception { final Long patientId = 10L; final UserActivationRequestDtoForTest request = new UserActivationRequestDtoForTest(); final UserActivationResponseDto response = new UserActivationResponseDto(); final String email = "email"; final String verificationCode = "verificationCode"; final int year = 2010; final int month = 2; final int day = 3; final LocalDate birthDate = LocalDate.of(year, month, day); final String firstName = "firstName"; final String lastName = "lastName"; final String genderCode = "genderCode "; final String emailToken = "emailToken"; final String password = "Paaaaaaaaaaaaasword#1"; final boolean verified = true; response.setEmail(email); response.setBirthDate(birthDate); response.setFirstName(firstName); response.setLastName(lastName); response.setId(patientId); response.setGenderCode(genderCode); response.setBirthDate(birthDate); response.setGenderCode(genderCode); response.setVerified(verified); request.setVerificationCode(verificationCode); request.setBirthDate(Arrays.asList(year, month, day)); request.setEmailToken(emailToken); request.setPassword(password); when(userCreationService.activateUser(argThat(matching( req -> req.getBirthDate().equals(birthDate) && req.getVerificationCode().equals(verificationCode) && req.getEmailToken().equals(emailToken) && req.getPassword().equals(password) )), xForwardedProto, xForwardedHost, xForwardedPort)).thenReturn(response); mvc.perform(post("/activations") .contentType(MediaType.APPLICATION_JSON_UTF8) .content(objectMapper.writeValueAsBytes(request)) .header(UserCreationController.X_FORWARDED_PROTO, xForwardedProto) .header(UserCreationController.X_FORWARDED_HOST, xForwardedHost) .header(UserCreationController.X_FORWARDED_PORT, xForwardedPort)) .andExpect(status().isBadRequest()); }
@Test public void testActivateUser_Throws_UserActivationCannotBeVerifiedException() throws Exception { final Long patientId = 10L; final UserActivationRequestDtoForTest request = new UserActivationRequestDtoForTest(); final UserActivationResponseDto response = new UserActivationResponseDto(); final String email = "email"; final String username = "email"; final String verificationCode = "verificationCode"; final int year = 2010; final int month = 2; final int day = 3; final LocalDate birthDate = LocalDate.of(year, month, day); final String firstName = "firstName"; final String lastName = "lastName"; final String genderCode = "genderCode "; final String emailToken = "emailToken"; final String password = "Password#1"; final String confirmPassword = "Password#1"; final boolean verified = true; response.setEmail(email); response.setBirthDate(birthDate); response.setFirstName(firstName); response.setLastName(lastName); response.setId(patientId); response.setGenderCode(genderCode); response.setBirthDate(birthDate); response.setGenderCode(genderCode); response.setVerified(verified); request.setVerificationCode(verificationCode); request.setBirthDate(Arrays.asList(year, month, day)); request.setEmailToken(emailToken); request.setPassword(password); request.setConfirmPassword(confirmPassword); request.setUsername(username); when(userCreationService.activateUser(argThat(matching( req -> req.getBirthDate().equals(birthDate) && req.getVerificationCode().equals(verificationCode) && req.getEmailToken().equals(emailToken) && req.getPassword().equals(password) )), xForwardedProto, xForwardedHost, xForwardedPort)).thenThrow(UserActivationCannotBeVerifiedException.class); mvc.perform(post("/activations") .contentType(MediaType.APPLICATION_JSON_UTF8) .content(objectMapper.writeValueAsBytes(request)) .header(UserCreationController.X_FORWARDED_PROTO, xForwardedProto) .header(UserCreationController.X_FORWARDED_HOST, xForwardedHost) .header(UserCreationController.X_FORWARDED_PORT, xForwardedPort)) .andExpect(status().isPreconditionFailed()); }
@Test public void testActivateUser_Throws_UserIsAlreadyVerifiedException() throws Exception { final Long patientId = 10L; final UserActivationRequestDtoForTest request = new UserActivationRequestDtoForTest(); final UserActivationResponseDto response = new UserActivationResponseDto(); final String email = "email"; final String username = "email"; final String verificationCode = "verificationCode"; final int year = 2010; final int month = 2; final int day = 3; final LocalDate birthDate = LocalDate.of(year, month, day); final String firstName = "firstName"; final String lastName = "lastName"; final String genderCode = "genderCode "; final String emailToken = "emailToken"; final String password = "Password#1"; final String confirmPassword = "Password#1"; final boolean verified = true; response.setEmail(email); response.setBirthDate(birthDate); response.setFirstName(firstName); response.setLastName(lastName); response.setId(patientId); response.setGenderCode(genderCode); response.setBirthDate(birthDate); response.setGenderCode(genderCode); response.setVerified(verified); request.setVerificationCode(verificationCode); request.setBirthDate(Arrays.asList(year, month, day)); request.setEmailToken(emailToken); request.setPassword(password); request.setConfirmPassword(confirmPassword); request.setUsername(username); when(userCreationService.activateUser(argThat(matching( req -> req.getBirthDate().equals(birthDate) && req.getVerificationCode().equals(verificationCode) && req.getEmailToken().equals(emailToken) && req.getPassword().equals(password) )), xForwardedProto, xForwardedHost, xForwardedPort)).thenThrow(UserIsAlreadyVerifiedException.class); mvc.perform(post("/activations") .contentType(MediaType.APPLICATION_JSON_UTF8) .content(objectMapper.writeValueAsBytes(request)) .header(UserCreationController.X_FORWARDED_PROTO, xForwardedProto) .header(UserCreationController.X_FORWARDED_HOST, xForwardedHost) .header(UserCreationController.X_FORWARDED_PORT, xForwardedPort)) .andExpect(status().isPreconditionFailed()); }
@Test public void testActivateUser_Throws_EmailTokenExpiredException() throws Exception { final Long patientId = 10L; final UserActivationRequestDtoForTest request = new UserActivationRequestDtoForTest(); final UserActivationResponseDto response = new UserActivationResponseDto(); final String email = "email"; final String username = "email"; final String verificationCode = "verificationCode"; final int year = 2010; final int month = 2; final int day = 3; final LocalDate birthDate = LocalDate.of(year, month, day); final String firstName = "firstName"; final String lastName = "lastName"; final String genderCode = "genderCode "; final String emailToken = "emailToken"; final String password = "Password#1"; final String confirmPassword = "Password#1"; final boolean verified = true; response.setEmail(email); response.setBirthDate(birthDate); response.setFirstName(firstName); response.setLastName(lastName); response.setId(patientId); response.setGenderCode(genderCode); response.setBirthDate(birthDate); response.setGenderCode(genderCode); response.setVerified(verified); request.setVerificationCode(verificationCode); request.setBirthDate(Arrays.asList(year, month, day)); request.setEmailToken(emailToken); request.setPassword(password); request.setConfirmPassword(confirmPassword); request.setUsername(username); when(userCreationService.activateUser(argThat(matching( req -> req.getBirthDate().equals(birthDate) && req.getVerificationCode().equals(verificationCode) && req.getEmailToken().equals(emailToken) && req.getPassword().equals(password) )), xForwardedProto, xForwardedHost, xForwardedPort)).thenThrow(EmailTokenExpiredException.class); mvc.perform(post("/activations") .contentType(MediaType.APPLICATION_JSON_UTF8) .content(objectMapper.writeValueAsBytes(request)) .header(UserCreationController.X_FORWARDED_PROTO, xForwardedProto) .header(UserCreationController.X_FORWARDED_HOST, xForwardedHost) .header(UserCreationController.X_FORWARDED_PORT, xForwardedPort)) .andExpect(status().isPreconditionFailed()); }
@Test public void testActivateUser_Throws_PhrPatientNotFoundException() throws Exception { final Long patientId = 10L; final UserActivationRequestDtoForTest request = new UserActivationRequestDtoForTest(); final UserActivationResponseDto response = new UserActivationResponseDto(); final String email = "email"; final String username = "email"; final String verificationCode = "verificationCode"; final int year = 2010; final int month = 2; final int day = 3; final LocalDate birthDate = LocalDate.of(year, month, day); final String firstName = "firstName"; final String lastName = "lastName"; final String genderCode = "genderCode "; final String emailToken = "emailToken"; final String password = "Password#1"; final String confirmPassword = "Password#1"; final boolean verified = true; response.setEmail(email); response.setBirthDate(birthDate); response.setFirstName(firstName); response.setLastName(lastName); response.setId(patientId); response.setGenderCode(genderCode); response.setBirthDate(birthDate); response.setGenderCode(genderCode); response.setVerified(verified); request.setVerificationCode(verificationCode); request.setBirthDate(Arrays.asList(year, month, day)); request.setEmailToken(emailToken); request.setPassword(password); request.setConfirmPassword(confirmPassword); request.setUsername(username); when(userCreationService.activateUser(argThat(matching( req -> req.getBirthDate().equals(birthDate) && req.getVerificationCode().equals(verificationCode) && req.getEmailToken().equals(emailToken) && req.getPassword().equals(password) )), xForwardedProto, xForwardedHost, xForwardedPort)).thenThrow(PhrPatientNotFoundException.class); mvc.perform(post("/activations") .contentType(MediaType.APPLICATION_JSON_UTF8) .content(objectMapper.writeValueAsBytes(request)) .header(UserCreationController.X_FORWARDED_PROTO, xForwardedProto) .header(UserCreationController.X_FORWARDED_HOST, xForwardedHost) .header(UserCreationController.X_FORWARDED_PORT, xForwardedPort)) .andExpect(status().isNotFound()); }
@Test public void testActivateUser_Throws_HttpClientErrorException() throws Exception { thrown.expect(NestedServletException.class); final Long patientId = 10L; final UserActivationRequestDtoForTest request = new UserActivationRequestDtoForTest(); final UserActivationResponseDto response = new UserActivationResponseDto(); final String email = "email"; final String username = "email"; final String verificationCode = "verificationCode"; final int year = 2010; final int month = 2; final int day = 3; final LocalDate birthDate = LocalDate.of(year, month, day); final String firstName = "firstName"; final String lastName = "lastName"; final String genderCode = "genderCode "; final String emailToken = "emailToken"; final String password = "Password#1"; final String confirmPassword = "Password#1"; final boolean verified = true; response.setEmail(email); response.setBirthDate(birthDate); response.setFirstName(firstName); response.setLastName(lastName); response.setId(patientId); response.setGenderCode(genderCode); response.setBirthDate(birthDate); response.setGenderCode(genderCode); response.setVerified(verified); request.setVerificationCode(verificationCode); request.setBirthDate(Arrays.asList(year, month, day)); request.setEmailToken(emailToken); request.setPassword(password); request.setConfirmPassword(confirmPassword); request.setUsername(username); when(userCreationService.activateUser(argThat(matching( req -> req.getBirthDate().equals(birthDate) && req.getVerificationCode().equals(verificationCode) && req.getEmailToken().equals(emailToken) && req.getPassword().equals(password) )), xForwardedProto, xForwardedHost, xForwardedPort)).thenThrow(HttpClientErrorException.class); mvc.perform(post("/activations") .contentType(MediaType.APPLICATION_JSON_UTF8) .content(objectMapper.writeValueAsBytes(request)) .header(UserCreationController.X_FORWARDED_PROTO, xForwardedProto) .header(UserCreationController.X_FORWARDED_HOST, xForwardedHost) .header(UserCreationController.X_FORWARDED_PORT, xForwardedPort)) .andExpect(status().isInternalServerError()); }
@Test public void testActivateUser_Throws_EmailSenderException() throws Exception { thrown.expect(NestedServletException.class); final Long patientId = 10L; final UserActivationRequestDtoForTest request = new UserActivationRequestDtoForTest(); final UserActivationResponseDto response = new UserActivationResponseDto(); final String email = "email"; final String username = "email"; final String verificationCode = "verificationCode"; final int year = 2010; final int month = 2; final int day = 3; final LocalDate birthDate = LocalDate.of(year, month, day); final String firstName = "firstName"; final String lastName = "lastName"; final String genderCode = "genderCode "; final String emailToken = "emailToken"; final String password = "Password#1"; final String confirmPassword = "Password#1"; final boolean verified = true; response.setEmail(email); response.setBirthDate(birthDate); response.setFirstName(firstName); response.setLastName(lastName); response.setId(patientId); response.setGenderCode(genderCode); response.setBirthDate(birthDate); response.setGenderCode(genderCode); response.setVerified(verified); request.setVerificationCode(verificationCode); request.setBirthDate(Arrays.asList(year, month, day)); request.setEmailToken(emailToken); request.setPassword(password); request.setConfirmPassword(confirmPassword); request.setUsername(username); when(userCreationService.activateUser(argThat(matching( req -> req.getBirthDate().equals(birthDate) && req.getVerificationCode().equals(verificationCode) && req.getEmailToken().equals(emailToken) && req.getPassword().equals(password) )), xForwardedProto, xForwardedHost, xForwardedPort)).thenThrow(EmailSenderException.class); mvc.perform(post("/activations") .contentType(MediaType.APPLICATION_JSON_UTF8) .content(objectMapper.writeValueAsBytes(request)) .header(UserCreationController.X_FORWARDED_PROTO, xForwardedProto) .header(UserCreationController.X_FORWARDED_HOST, xForwardedHost) .header(UserCreationController.X_FORWARDED_PORT, xForwardedPort)) .andExpect(status().isInternalServerError()); }
@Test public void testActivateUser_Throws_RuntimeException() throws Exception { thrown.expect(NestedServletException.class); final Long patientId = 10L; final UserActivationRequestDtoForTest request = new UserActivationRequestDtoForTest(); final UserActivationResponseDto response = new UserActivationResponseDto(); final String email = "email"; final String username = "email"; final String verificationCode = "verificationCode"; final int year = 2010; final int month = 2; final int day = 3; final LocalDate birthDate = LocalDate.of(year, month, day); final String firstName = "firstName"; final String lastName = "lastName"; final String genderCode = "genderCode "; final String emailToken = "emailToken"; final String password = "Password#1"; final String confirmPassword = "Password#1"; final boolean verified = true; response.setEmail(email); response.setBirthDate(birthDate); response.setFirstName(firstName); response.setLastName(lastName); response.setId(patientId); response.setGenderCode(genderCode); response.setBirthDate(birthDate); response.setGenderCode(genderCode); response.setVerified(verified); request.setVerificationCode(verificationCode); request.setBirthDate(Arrays.asList(year, month, day)); request.setEmailToken(emailToken); request.setPassword(password); request.setConfirmPassword(confirmPassword); request.setUsername(username); when(userCreationService.activateUser(argThat(matching( req -> req.getBirthDate().equals(birthDate) && req.getVerificationCode().equals(verificationCode) && req.getEmailToken().equals(emailToken) && req.getPassword().equals(password) )), xForwardedProto, xForwardedHost, xForwardedPort)).thenThrow(RuntimeException.class); mvc.perform(post("/activations") .contentType(MediaType.APPLICATION_JSON_UTF8) .content(objectMapper.writeValueAsBytes(request)) .header(UserCreationController.X_FORWARDED_PROTO, xForwardedProto) .header(UserCreationController.X_FORWARDED_HOST, xForwardedHost) .header(UserCreationController.X_FORWARDED_PORT, xForwardedPort)) .andExpect(status().isInternalServerError()); }