当前位置: 首页>>代码示例>>Java>>正文


Java ScimUser.setId方法代码示例

本文整理汇总了Java中org.cloudfoundry.identity.uaa.scim.ScimUser.setId方法的典型用法代码示例。如果您正苦于以下问题:Java ScimUser.setId方法的具体用法?Java ScimUser.setId怎么用?Java ScimUser.setId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.cloudfoundry.identity.uaa.scim.ScimUser的用法示例。


在下文中一共展示了ScimUser.setId方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test_addOrgUser_userExists

import org.cloudfoundry.identity.uaa.scim.ScimUser; //导入方法依赖的package包/类
@Test
public void test_addOrgUser_userExists() {
    List<Role> roles = Collections.singletonList(Role.MANAGERS);
    UUID orgGuid = UUID.randomUUID();
    UUID userGuid = UUID.randomUUID();
    User expectedUser = new User("testuser", userGuid, roles, orgGuid);
    String password = "testpassword";
    UserRequest cfCreateUser = new UserRequest(expectedUser.getUsername());
    cfCreateUser.setRoles(roles);

    ScimUser scimUser = ScimUserFactory.newUser(expectedUser.getUsername(), password);
    scimUser.setId(expectedUser.getGuid().toString());

    UserIdNamePair idNamePair = UserIdNamePair.of(
        expectedUser.getGuid(),
        expectedUser.getUsername());
    when(uaaOperations.findUserIdByName(expectedUser.getUsername())).thenReturn(Optional.ofNullable(idNamePair));

    when(uaaOperations.createUser(expectedUser.getUsername(), password)).thenReturn(scimUser);
    CfUsersService cfUsersService =
            new CfUsersService(ccClient, uaaOperations, invitationService, accessInvitationsService);
    Optional<User> resultUser = cfUsersService.addOrgUser(cfCreateUser, orgGuid, "admin_test");
    assertThat(resultUser.get(), equalTo(expectedUser));

    verify(ccClient).assignOrgRole(eq(userGuid), eq(orgGuid), eq(roles.get(0)));
}
 
开发者ID:trustedanalytics,项目名称:user-management,代码行数:27,代码来源:CfUsersServiceTest.java

示例2: testSave

import org.cloudfoundry.identity.uaa.scim.ScimUser; //导入方法依赖的package包/类
@Test
public void testSave() throws Exception {
    // Arrange
    final String id = "id";
    final ScimUser scimUser = new ScimUser();
    final ScimUser scimUserResponse = new ScimUser();
    scimUserResponse.setId(id);
    when(restTemplate.postForObject(usersEndpoint, scimUser, ScimUser.class)).thenReturn(scimUserResponse);

    // Act
    final ScimUser response = sut.save(scimUser);

    // Assert
    assertEquals(scimUserResponse, response);
}
 
开发者ID:bhits,项目名称:patient-user-api,代码行数:16,代码来源:ScimServiceImplTest.java

示例3: testActivateUser

import org.cloudfoundry.identity.uaa.scim.ScimUser; //导入方法依赖的package包/类
@Test
public void testActivateUser() throws Exception {
    // Arrange
    final Long patientId = 10L;
    final Boolean initialVerified = false;
    final Boolean verified = true;
    final Instant emailTokenExpiration = Instant.now().plus(Period.ofDays(7));
    final String verificationCode = "verificationCode";
    final String emailToken = "emailToken";
    final String firstName = "firstName";
    final String lastName = "lastName";
    final String email = "email";
    final String username = "email";
    final String password = "password";
    final String confirmPassword = "password";
    final String userId = "userId";
    final LocalDate birthDateInRequest = LocalDate.of(1980, 1, 1);
    final Date birthDateInPhr = Date.from(birthDateInRequest.atStartOfDay(ZoneId.systemDefault()).toInstant());
    UserActivationRequestDto userActivationRequest = mock(UserActivationRequestDto.class);
    when(userActivationRequest.getVerificationCode()).thenReturn(verificationCode);
    when(userActivationRequest.getEmailToken()).thenReturn(emailToken);
    when(userActivationRequest.getBirthDate()).thenReturn(birthDateInRequest);
    when(userActivationRequest.getPassword()).thenReturn(password);
    when(userActivationRequest.getConfirmPassword()).thenReturn(confirmPassword);
    when(userActivationRequest.getUsername()).thenReturn(username);
    final UserCreation userCreation = mock(UserCreation.class);
    when(userCreation.isVerified()).thenReturn(initialVerified).thenReturn(verified);
    when(userCreation.getEmailTokenExpirationAsInstant()).thenReturn(emailTokenExpiration);
    when(userCreation.getPatientId()).thenReturn(patientId);
    when(userCreationRepository.findOneByEmailTokenAndVerificationCode(emailToken, verificationCode)).thenReturn(Optional.of(userCreation));
    final PatientDto patientDto = mock(PatientDto.class);
    when(patientDto.getBirthDate()).thenReturn(birthDateInPhr);
    when(patientDto.getFirstName()).thenReturn(firstName);
    when(patientDto.getLastName()).thenReturn(lastName);
    when(patientDto.getEmail()).thenReturn(email);
    when(phrService.findPatientProfileById(patientId, true)).thenReturn(patientDto);
    final UserActivationResponseDto userActivationResponse = mock(UserActivationResponseDto.class);
    when(modelMapper.map(patientDto, UserActivationResponseDto.class)).thenReturn(userActivationResponse);
    final ScimUser savedScimUser = new ScimUser();
    savedScimUser.setId(userId);
    when(scimService.save(argThat(matching(
            user -> user.getEmails().get(0).getValue().equals(email) &&
                    user.getUserName().equals(email) &&
                    user.isVerified() == verified &&
                    user.getFamilyName().equals(lastName) &&
                    user.getGivenName().equals(firstName)
    )))).thenReturn(savedScimUser);

    // Act
    final UserActivationResponseDto response = sut.activateUser(userActivationRequest, xForwardedProto, xForwardedHost, xForwardedPort);

    // Assert
    assertEquals(userActivationResponse, response);
    verify(userCreation, times(1)).setVerified(verified);
    verify(userCreation, times(1)).setUserId(userId);
    verify(userActivationResponse, times(1)).setVerified(verified);
    verify(userCreationRepository, times(2)).save(userCreation);
    verify(scimService, times(1)).save(argThat(matching(
            user -> user.getEmails().get(0).getValue().equals(email) &&
                    user.getUserName().equals(email) &&
                    user.isVerified() == true &&
                    user.getFamilyName().equals(lastName) &&
                    user.getGivenName().equals(firstName)
    )));
    verify(scimService, times(1)).addUserToGroups(userCreation);
    verify(emailSender, times(1)).sendEmailToConfirmVerification(
            eq(xForwardedProto), eq(xForwardedHost), eq(xForwardedPort),
            eq(email), argThat(matching(fn -> fn.contains(firstName) && fn.contains(lastName))));
}
 
开发者ID:bhits,项目名称:patient-user-api,代码行数:70,代码来源:UserCreationServiceImplTest.java

示例4: mock

import org.cloudfoundry.identity.uaa.scim.ScimUser; //导入方法依赖的package包/类
@Test
public void testActivateUser_Throws_UserActivationCannotBeVerifiedException_When_Username_Does_Not_Match_Email_In_PHR() throws Exception {
    // Arrange
    thrown.expect(UserActivationCannotBeVerifiedException.class);
    final Long patientId = 10L;
    final Boolean initialVerified = false;
    final Boolean verified = true;
    final Instant emailTokenExpiration = Instant.now().plus(Period.ofDays(7));
    final String verificationCode = "verificationCode";
    final String emailToken = "emailToken";
    final String firstName = "firstName";
    final String lastName = "lastName";
    final String email = "email";
    final String username = "emailDifferent";
    final String password = "password";
    final String confirmPassword = "password";
    final String userId = "userId";
    final LocalDate birthDateInRequest = LocalDate.of(1980, 1, 1);
    final Date birthDateInPhr = Date.from(birthDateInRequest.atStartOfDay(ZoneId.systemDefault()).toInstant());
    UserActivationRequestDto userActivationRequest = mock(UserActivationRequestDto.class);
    when(userActivationRequest.getVerificationCode()).thenReturn(verificationCode);
    when(userActivationRequest.getEmailToken()).thenReturn(emailToken);
    when(userActivationRequest.getBirthDate()).thenReturn(birthDateInRequest);
    when(userActivationRequest.getPassword()).thenReturn(password);
    when(userActivationRequest.getConfirmPassword()).thenReturn(confirmPassword);
    when(userActivationRequest.getUsername()).thenReturn(username);
    final UserCreation userCreation = mock(UserCreation.class);
    when(userCreation.isVerified()).thenReturn(initialVerified).thenReturn(verified);
    when(userCreation.getEmailTokenExpirationAsInstant()).thenReturn(emailTokenExpiration);
    when(userCreation.getPatientId()).thenReturn(patientId);
    when(userCreationRepository.findOneByEmailTokenAndVerificationCode(emailToken, verificationCode)).thenReturn(Optional.of(userCreation));
    final PatientDto patientDto = mock(PatientDto.class);
    when(patientDto.getBirthDate()).thenReturn(birthDateInPhr);
    when(patientDto.getFirstName()).thenReturn(firstName);
    when(patientDto.getLastName()).thenReturn(lastName);
    when(patientDto.getEmail()).thenReturn(email);
    when(phrService.findPatientProfileById(patientId, true)).thenReturn(patientDto);
    final UserActivationResponseDto userActivationResponse = mock(UserActivationResponseDto.class);
    when(modelMapper.map(patientDto, UserActivationResponseDto.class)).thenReturn(userActivationResponse);
    final ScimUser savedScimUser = new ScimUser();
    savedScimUser.setId(userId);
    when(scimService.save(argThat(matching(
            user -> user.getEmails().get(0).getValue().equals(email) &&
                    user.getUserName().equals(email) &&
                    user.isVerified() == verified &&
                    user.getFamilyName().equals(lastName) &&
                    user.getGivenName().equals(firstName)
    )))).thenReturn(savedScimUser);

    // Act
    final UserActivationResponseDto response = sut.activateUser(userActivationRequest, xForwardedProto, xForwardedHost, xForwardedPort);

    // Assert
    assertEquals(userActivationResponse, response);
    verify(userCreation, times(1)).setVerified(verified);
    verify(userCreation, times(1)).setUserId(userId);
    verify(userActivationResponse, times(1)).setVerified(verified);
    verify(userCreationRepository, times(2)).save(userCreation);
    verify(scimService, times(1)).save(argThat(matching(
            user -> user.getEmails().get(0).getValue().equals(email) &&
                    user.getUserName().equals(email) &&
                    user.isVerified() == true &&
                    user.getFamilyName().equals(lastName) &&
                    user.getGivenName().equals(firstName)
    )));
    verify(scimService, times(1)).addUserToGroups(userCreation);
    verify(emailSender, times(1)).sendEmailToConfirmVerification(
            eq(xForwardedProto), eq(xForwardedHost), eq(xForwardedPort),
            eq(email), argThat(matching(fn -> fn.contains(firstName) && fn.contains(lastName))));
}
 
开发者ID:bhits,项目名称:patient-user-api,代码行数:71,代码来源:UserCreationServiceImplTest.java

示例5: testActivateUser_Throws_PasswordConfirmationFailedException_When_Password_Confirmation_Fails

import org.cloudfoundry.identity.uaa.scim.ScimUser; //导入方法依赖的package包/类
@Test
public void testActivateUser_Throws_PasswordConfirmationFailedException_When_Password_Confirmation_Fails() throws Exception {
    // Arrange
    thrown.expect(PasswordConfirmationFailedException.class);
    final Long patientId = 10L;
    final Boolean initialVerified = false;
    final Boolean verified = true;
    final Instant emailTokenExpiration = Instant.now().plus(Period.ofDays(7));
    final String verificationCode = "verificationCode";
    final String emailToken = "emailToken";
    final String firstName = "firstName";
    final String lastName = "lastName";
    final String email = "email";
    final String password = "password";
    final String confirmPassword = "confirmPassword";
    final String userId = "userId";
    final LocalDate birthDateInRequest = LocalDate.of(1980, 1, 1);
    final Date birthDateInPhr = Date.from(birthDateInRequest.atStartOfDay(ZoneId.systemDefault()).toInstant());
    UserActivationRequestDto userActivationRequest = mock(UserActivationRequestDto.class);
    when(userActivationRequest.getVerificationCode()).thenReturn(verificationCode);
    when(userActivationRequest.getEmailToken()).thenReturn(emailToken);
    when(userActivationRequest.getBirthDate()).thenReturn(birthDateInRequest);
    when(userActivationRequest.getPassword()).thenReturn(password);
    when(userActivationRequest.getConfirmPassword()).thenReturn(confirmPassword);
    final UserCreation userCreation = mock(UserCreation.class);
    when(userCreation.isVerified()).thenReturn(initialVerified).thenReturn(verified);
    when(userCreation.getEmailTokenExpirationAsInstant()).thenReturn(emailTokenExpiration);
    when(userCreation.getPatientId()).thenReturn(patientId);
    when(userCreationRepository.findOneByEmailTokenAndVerificationCode(emailToken, verificationCode)).thenReturn(Optional.of(userCreation));
    final PatientDto patientDto = mock(PatientDto.class);
    when(patientDto.getBirthDate()).thenReturn(birthDateInPhr);
    when(patientDto.getFirstName()).thenReturn(firstName);
    when(patientDto.getLastName()).thenReturn(lastName);
    when(patientDto.getEmail()).thenReturn(email);
    when(phrService.findPatientProfileById(patientId, true)).thenReturn(patientDto);
    final UserActivationResponseDto userActivationResponse = mock(UserActivationResponseDto.class);
    when(modelMapper.map(patientDto, UserActivationResponseDto.class)).thenReturn(userActivationResponse);
    final ScimUser savedScimUser = new ScimUser();
    savedScimUser.setId(userId);
    when(scimService.save(argThat(matching(
            user -> user.getEmails().get(0).getValue().equals(email) &&
                    user.getUserName().equals(email) &&
                    user.isVerified() == verified &&
                    user.getFamilyName().equals(lastName) &&
                    user.getGivenName().equals(firstName)
    )))).thenReturn(savedScimUser);

    // Act
    final UserActivationResponseDto response = sut.activateUser(userActivationRequest, xForwardedProto, xForwardedHost, xForwardedPort);

    // Assert
    assertEquals(userActivationResponse, response);
    verify(userCreation, times(1)).setVerified(verified);
    verify(userCreation, times(1)).setUserId(userId);
    verify(userActivationResponse, times(1)).setVerified(verified);
    verify(userCreationRepository, times(2)).save(userCreation);
    verify(scimService, times(1)).save(argThat(matching(
            user -> user.getEmails().get(0).getValue().equals(email) &&
                    user.getUserName().equals(email) &&
                    user.isVerified() == true &&
                    user.getFamilyName().equals(lastName) &&
                    user.getGivenName().equals(firstName)
    )));
    verify(scimService, times(1)).addUserToGroups(userCreation);
    verify(emailSender, times(1)).sendEmailToConfirmVerification(
            eq(xForwardedProto), eq(xForwardedHost), eq(xForwardedPort),
            eq(email), argThat(matching(fn -> fn.contains(firstName) && fn.contains(lastName))));
}
 
开发者ID:bhits,项目名称:patient-user-api,代码行数:69,代码来源:UserCreationServiceImplTest.java

示例6: testActivateUser_Throws_UserActivationCannotBeVerifiedException_When_UserCreation_Not_Found

import org.cloudfoundry.identity.uaa.scim.ScimUser; //导入方法依赖的package包/类
@Test
public void testActivateUser_Throws_UserActivationCannotBeVerifiedException_When_UserCreation_Not_Found() throws Exception {
    // Arrange
    thrown.expect(UserActivationCannotBeVerifiedException.class);
    final Long patientId = 10L;
    final Boolean initialVerified = false;
    final Boolean verified = true;
    final Instant emailTokenExpiration = Instant.now().plus(Period.ofDays(7));
    final String verificationCode = "verificationCode";
    final String emailToken = "emailToken";
    final String firstName = "firstName";
    final String lastName = "lastName";
    final String email = "email";
    final String password = "password";
    final String confirmPassword = "password";
    final String userId = "userId";
    final LocalDate birthDateInRequest = LocalDate.of(1980, 1, 1);
    final Date birthDateInPhr = Date.from(birthDateInRequest.atStartOfDay(ZoneId.systemDefault()).toInstant());
    UserActivationRequestDto userActivationRequest = mock(UserActivationRequestDto.class);
    when(userActivationRequest.getVerificationCode()).thenReturn(verificationCode);
    when(userActivationRequest.getEmailToken()).thenReturn(emailToken);
    when(userActivationRequest.getBirthDate()).thenReturn(birthDateInRequest);
    when(userActivationRequest.getPassword()).thenReturn(password);
    when(userActivationRequest.getConfirmPassword()).thenReturn(confirmPassword);
    final UserCreation userCreation = mock(UserCreation.class);
    when(userCreation.isVerified()).thenReturn(initialVerified).thenReturn(verified);
    when(userCreation.getEmailTokenExpirationAsInstant()).thenReturn(emailTokenExpiration);
    when(userCreation.getPatientId()).thenReturn(patientId);
    when(userCreationRepository.findOneByEmailTokenAndVerificationCode(emailToken, verificationCode)).thenReturn(Optional.empty());
    final PatientDto patientDto = mock(PatientDto.class);
    when(patientDto.getBirthDate()).thenReturn(birthDateInPhr);
    when(patientDto.getFirstName()).thenReturn(firstName);
    when(patientDto.getLastName()).thenReturn(lastName);
    when(patientDto.getEmail()).thenReturn(email);
    when(phrService.findPatientProfileById(patientId, true)).thenReturn(patientDto);
    final UserActivationResponseDto userActivationResponse = mock(UserActivationResponseDto.class);
    when(modelMapper.map(patientDto, UserActivationResponseDto.class)).thenReturn(userActivationResponse);
    final ScimUser savedScimUser = new ScimUser();
    savedScimUser.setId(userId);
    when(scimService.save(argThat(matching(
            user -> user.getEmails().get(0).getValue().equals(email) &&
                    user.getUserName().equals(email) &&
                    user.isVerified() == verified &&
                    user.getFamilyName().equals(lastName) &&
                    user.getGivenName().equals(firstName)
    )))).thenReturn(savedScimUser);

    // Act
    final UserActivationResponseDto response = sut.activateUser(userActivationRequest, xForwardedProto, xForwardedHost, xForwardedPort);

    // Assert
    assertEquals(userActivationResponse, response);
    verify(userCreation, times(1)).setVerified(verified);
    verify(userCreation, times(1)).setUserId(userId);
    verify(userActivationResponse, times(1)).setVerified(verified);
    verify(userCreationRepository, times(2)).save(userCreation);
    verify(scimService, times(1)).save(argThat(matching(
            user -> user.getEmails().get(0).getValue().equals(email) &&
                    user.getUserName().equals(email) &&
                    user.isVerified() == true &&
                    user.getFamilyName().equals(lastName) &&
                    user.getGivenName().equals(firstName)
    )));
    verify(scimService, times(1)).addUserToGroups(userCreation);
    verify(emailSender, times(1)).sendEmailToConfirmVerification(
            eq(xForwardedProto), eq(xForwardedHost), eq(xForwardedPort),
            eq(email), argThat(matching(fn -> fn.contains(firstName) && fn.contains(lastName))));
}
 
开发者ID:bhits,项目名称:patient-user-api,代码行数:69,代码来源:UserCreationServiceImplTest.java

示例7: testActivateUser_Throws_UserIsAlreadyVerifiedException_When_User_Is_Already_Verified

import org.cloudfoundry.identity.uaa.scim.ScimUser; //导入方法依赖的package包/类
@Test
public void testActivateUser_Throws_UserIsAlreadyVerifiedException_When_User_Is_Already_Verified() throws Exception {
    // Arrange
    thrown.expect(UserIsAlreadyVerifiedException.class);
    final Long patientId = 10L;
    final Boolean initialVerified = true;
    final Boolean verified = true;
    final Instant emailTokenExpiration = Instant.now().plus(Period.ofDays(7));
    final String verificationCode = "verificationCode";
    final String emailToken = "emailToken";
    final String firstName = "firstName";
    final String lastName = "lastName";
    final String email = "email";
    final String password = "password";
    final String confirmPassword = "password";
    final String userId = "userId";
    final LocalDate birthDateInRequest = LocalDate.of(1980, 1, 1);
    final Date birthDateInPhr = Date.from(birthDateInRequest.atStartOfDay(ZoneId.systemDefault()).toInstant());
    UserActivationRequestDto userActivationRequest = mock(UserActivationRequestDto.class);
    when(userActivationRequest.getVerificationCode()).thenReturn(verificationCode);
    when(userActivationRequest.getEmailToken()).thenReturn(emailToken);
    when(userActivationRequest.getBirthDate()).thenReturn(birthDateInRequest);
    when(userActivationRequest.getPassword()).thenReturn(password);
    when(userActivationRequest.getConfirmPassword()).thenReturn(confirmPassword);
    final UserCreation userCreation = mock(UserCreation.class);
    when(userCreation.isVerified()).thenReturn(initialVerified).thenReturn(verified);
    when(userCreation.getEmailTokenExpirationAsInstant()).thenReturn(emailTokenExpiration);
    when(userCreation.getPatientId()).thenReturn(patientId);
    when(userCreationRepository.findOneByEmailTokenAndVerificationCode(emailToken, verificationCode)).thenReturn(Optional.of(userCreation));
    final PatientDto patientDto = mock(PatientDto.class);
    when(patientDto.getBirthDate()).thenReturn(birthDateInPhr);
    when(patientDto.getFirstName()).thenReturn(firstName);
    when(patientDto.getLastName()).thenReturn(lastName);
    when(patientDto.getEmail()).thenReturn(email);
    when(phrService.findPatientProfileById(patientId, true)).thenReturn(patientDto);
    final UserActivationResponseDto userActivationResponse = mock(UserActivationResponseDto.class);
    when(modelMapper.map(patientDto, UserActivationResponseDto.class)).thenReturn(userActivationResponse);
    final ScimUser savedScimUser = new ScimUser();
    savedScimUser.setId(userId);
    when(scimService.save(argThat(matching(
            user -> user.getEmails().get(0).getValue().equals(email) &&
                    user.getUserName().equals(email) &&
                    user.isVerified() == verified &&
                    user.getFamilyName().equals(lastName) &&
                    user.getGivenName().equals(firstName)
    )))).thenReturn(savedScimUser);

    // Act
    final UserActivationResponseDto response = sut.activateUser(userActivationRequest, xForwardedProto, xForwardedHost, xForwardedPort);

    // Assert
    assertEquals(userActivationResponse, response);
    verify(userCreation, times(1)).setVerified(verified);
    verify(userCreation, times(1)).setUserId(userId);
    verify(userActivationResponse, times(1)).setVerified(verified);
    verify(userCreationRepository, times(2)).save(userCreation);
    verify(scimService, times(1)).save(argThat(matching(
            user -> user.getEmails().get(0).getValue().equals(email) &&
                    user.getUserName().equals(email) &&
                    user.isVerified() == true &&
                    user.getFamilyName().equals(lastName) &&
                    user.getGivenName().equals(firstName)
    )));
    verify(scimService, times(1)).addUserToGroups(userCreation);
    verify(emailSender, times(1)).sendEmailToConfirmVerification(
            eq(xForwardedProto), eq(xForwardedHost), eq(xForwardedPort),
            eq(email), argThat(matching(fn -> fn.contains(firstName) && fn.contains(lastName))));
}
 
开发者ID:bhits,项目名称:patient-user-api,代码行数:69,代码来源:UserCreationServiceImplTest.java

示例8: testActivateUser_Throws_EmailTokenExpiredException_When_Email_Token_Already_Expired

import org.cloudfoundry.identity.uaa.scim.ScimUser; //导入方法依赖的package包/类
@Test
public void testActivateUser_Throws_EmailTokenExpiredException_When_Email_Token_Already_Expired() throws Exception {
    // Arrange
    thrown.expect(EmailTokenExpiredException.class);
    final Long patientId = 10L;
    final Boolean initialVerified = false;
    final Boolean verified = true;
    final Instant emailTokenExpiration = Instant.now().minus(Period.ofDays(7));
    final String verificationCode = "verificationCode";
    final String emailToken = "emailToken";
    final String firstName = "firstName";
    final String lastName = "lastName";
    final String email = "email";
    final String password = "password";
    final String confirmPassword = "password";
    final String userId = "userId";
    final LocalDate birthDateInRequest = LocalDate.of(1980, 1, 1);
    final Date birthDateInPhr = Date.from(birthDateInRequest.atStartOfDay(ZoneId.systemDefault()).toInstant());
    UserActivationRequestDto userActivationRequest = mock(UserActivationRequestDto.class);
    when(userActivationRequest.getVerificationCode()).thenReturn(verificationCode);
    when(userActivationRequest.getEmailToken()).thenReturn(emailToken);
    when(userActivationRequest.getBirthDate()).thenReturn(birthDateInRequest);
    when(userActivationRequest.getPassword()).thenReturn(password);
    when(userActivationRequest.getConfirmPassword()).thenReturn(confirmPassword);
    final UserCreation userCreation = mock(UserCreation.class);
    when(userCreation.isVerified()).thenReturn(initialVerified).thenReturn(verified);
    when(userCreation.getEmailTokenExpirationAsInstant()).thenReturn(emailTokenExpiration);
    when(userCreation.getPatientId()).thenReturn(patientId);
    when(userCreationRepository.findOneByEmailTokenAndVerificationCode(emailToken, verificationCode)).thenReturn(Optional.of(userCreation));
    final PatientDto patientDto = mock(PatientDto.class);
    when(patientDto.getBirthDate()).thenReturn(birthDateInPhr);
    when(patientDto.getFirstName()).thenReturn(firstName);
    when(patientDto.getLastName()).thenReturn(lastName);
    when(patientDto.getEmail()).thenReturn(email);
    when(phrService.findPatientProfileById(patientId, true)).thenReturn(patientDto);
    final UserActivationResponseDto userActivationResponse = mock(UserActivationResponseDto.class);
    when(modelMapper.map(patientDto, UserActivationResponseDto.class)).thenReturn(userActivationResponse);
    final ScimUser savedScimUser = new ScimUser();
    savedScimUser.setId(userId);
    when(scimService.save(argThat(matching(
            user -> user.getEmails().get(0).getValue().equals(email) &&
                    user.getUserName().equals(email) &&
                    user.isVerified() == verified &&
                    user.getFamilyName().equals(lastName) &&
                    user.getGivenName().equals(firstName)
    )))).thenReturn(savedScimUser);

    // Act
    final UserActivationResponseDto response = sut.activateUser(userActivationRequest, xForwardedProto, xForwardedHost, xForwardedPort);

    // Assert
    assertEquals(userActivationResponse, response);
    verify(userCreation, times(1)).setVerified(verified);
    verify(userCreation, times(1)).setUserId(userId);
    verify(userActivationResponse, times(1)).setVerified(verified);
    verify(userCreationRepository, times(2)).save(userCreation);
    verify(scimService, times(1)).save(argThat(matching(
            user -> user.getEmails().get(0).getValue().equals(email) &&
                    user.getUserName().equals(email) &&
                    user.isVerified() == true &&
                    user.getFamilyName().equals(lastName) &&
                    user.getGivenName().equals(firstName)
    )));
    verify(scimService, times(1)).addUserToGroups(userCreation);
    verify(emailSender, times(1)).sendEmailToConfirmVerification(
            eq(xForwardedProto), eq(xForwardedHost), eq(xForwardedPort),
            eq(email), argThat(matching(fn -> fn.contains(firstName) && fn.contains(lastName))));
}
 
开发者ID:bhits,项目名称:patient-user-api,代码行数:69,代码来源:UserCreationServiceImplTest.java

示例9: testActivateUser_Throws_UserActivationCannotBeVerifiedException_When_Birth_Date_Verification_Failed

import org.cloudfoundry.identity.uaa.scim.ScimUser; //导入方法依赖的package包/类
@Test
public void testActivateUser_Throws_UserActivationCannotBeVerifiedException_When_Birth_Date_Verification_Failed() throws Exception {
    // Arrange
    thrown.expect(UserActivationCannotBeVerifiedException.class);
    final Long patientId = 10L;
    final Boolean initialVerified = false;
    final Boolean verified = true;
    final Instant emailTokenExpiration = Instant.now().plus(Period.ofDays(7));
    final String verificationCode = "verificationCode";
    final String emailToken = "emailToken";
    final String firstName = "firstName";
    final String lastName = "lastName";
    final String email = "email";
    final String password = "password";
    final String confirmPassword = "password";
    final String userId = "userId";
    final LocalDate birthDateInRequest = LocalDate.of(1980, 1, 1);
    final Date birthDateInPhr = Date.from(birthDateInRequest.minus(Period.ofDays(1)).atStartOfDay(ZoneId.systemDefault()).toInstant());
    UserActivationRequestDto userActivationRequest = mock(UserActivationRequestDto.class);
    when(userActivationRequest.getVerificationCode()).thenReturn(verificationCode);
    when(userActivationRequest.getEmailToken()).thenReturn(emailToken);
    when(userActivationRequest.getBirthDate()).thenReturn(birthDateInRequest);
    when(userActivationRequest.getPassword()).thenReturn(password);
    when(userActivationRequest.getConfirmPassword()).thenReturn(confirmPassword);
    final UserCreation userCreation = mock(UserCreation.class);
    when(userCreation.isVerified()).thenReturn(initialVerified).thenReturn(verified);
    when(userCreation.getEmailTokenExpirationAsInstant()).thenReturn(emailTokenExpiration);
    when(userCreation.getPatientId()).thenReturn(patientId);
    when(userCreationRepository.findOneByEmailTokenAndVerificationCode(emailToken, verificationCode)).thenReturn(Optional.of(userCreation));
    final PatientDto patientDto = mock(PatientDto.class);
    when(patientDto.getBirthDate()).thenReturn(birthDateInPhr);
    when(patientDto.getFirstName()).thenReturn(firstName);
    when(patientDto.getLastName()).thenReturn(lastName);
    when(patientDto.getEmail()).thenReturn(email);
    when(phrService.findPatientProfileById(patientId, true)).thenReturn(patientDto);
    final UserActivationResponseDto userActivationResponse = mock(UserActivationResponseDto.class);
    when(modelMapper.map(patientDto, UserActivationResponseDto.class)).thenReturn(userActivationResponse);
    final ScimUser savedScimUser = new ScimUser();
    savedScimUser.setId(userId);
    when(scimService.save(argThat(matching(
            user -> user.getEmails().get(0).getValue().equals(email) &&
                    user.getUserName().equals(email) &&
                    user.isVerified() == verified &&
                    user.getFamilyName().equals(lastName) &&
                    user.getGivenName().equals(firstName)
    )))).thenReturn(savedScimUser);

    // Act
    final UserActivationResponseDto response = sut.activateUser(userActivationRequest, xForwardedProto, xForwardedHost, xForwardedPort);

    // Assert
    assertEquals(userActivationResponse, response);
    verify(userCreation, times(1)).setVerified(verified);
    verify(userCreation, times(1)).setUserId(userId);
    verify(userActivationResponse, times(1)).setVerified(verified);
    verify(userCreationRepository, times(2)).save(userCreation);
    verify(scimService, times(1)).save(argThat(matching(
            user -> user.getEmails().get(0).getValue().equals(email) &&
                    user.getUserName().equals(email) &&
                    user.isVerified() == true &&
                    user.getFamilyName().equals(lastName) &&
                    user.getGivenName().equals(firstName)
    )));
    verify(scimService, times(1)).addUserToGroups(userCreation);
    verify(emailSender, times(1)).sendEmailToConfirmVerification(
            eq(xForwardedProto), eq(xForwardedHost), eq(xForwardedPort),
            eq(email), argThat(matching(fn -> fn.contains(firstName) && fn.contains(lastName))));
}
 
开发者ID:bhits,项目名称:patient-user-api,代码行数:69,代码来源:UserCreationServiceImplTest.java


注:本文中的org.cloudfoundry.identity.uaa.scim.ScimUser.setId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。