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


Java ScimUser类代码示例

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


ScimUser类属于org.cloudfoundry.identity.uaa.scim包,在下文中一共展示了ScimUser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: createAndRetrieveUser

import org.cloudfoundry.identity.uaa.scim.ScimUser; //导入依赖的package包/类
private Optional<UUID> createAndRetrieveUser(String username, String password) {
    return accessInvitationsService.getAccessInvitations(username)
            .map(invitations -> {
                final ScimUser user = uaaPrivilegedClient.createUser(username, password);
                final UUID userGuid = UUID.fromString(user.getId());
                ccPrivilegedClient.createUser(userGuid);
                retrieveAndAssignAccessInvitations(userGuid, invitations);
                return userGuid;
            });
}
 
开发者ID:trustedanalytics,项目名称:user-management,代码行数:11,代码来源:EmailInvitationsService.java

示例4: newUser

import org.cloudfoundry.identity.uaa.scim.ScimUser; //导入依赖的package包/类
public static ScimUser newUser(String username, String password) {
    ScimUser scimUser = new ScimUser();
    scimUser.setUserName(username);
    ScimUser.Email email = new ScimUser.Email();
    email.setPrimary(true);
    email.setValue(username);
    scimUser.setEmails(Arrays.asList(email));
    scimUser.setOrigin(Origin.UAA);
    scimUser.setPassword(password);
    scimUser.setVerified(true);

    return scimUser;
}
 
开发者ID:trustedanalytics,项目名称:cf-client,代码行数:14,代码来源:ScimUserFactory.java

示例5: getUsers

import org.cloudfoundry.identity.uaa.scim.ScimUser; //导入依赖的package包/类
@Override
public SearchResults<ScimUser> getUsers() {
    ResponseEntity<SearchResults<ScimUser>> result = uaaRestTemplate.exchange(
        uaaBaseUrl + "/Users",
        HttpMethod.GET,
        null,
        new ParameterizedTypeReference<SearchResults<ScimUser>>() {
        });

    return result.getBody();
}
 
开发者ID:trustedanalytics,项目名称:cf-client,代码行数:12,代码来源:UaaClient.java

示例6: save

import org.cloudfoundry.identity.uaa.scim.ScimUser; //导入依赖的package包/类
@Override
public ScimUser save(ScimUser scimUser) {
    final ScimUser scimUserResp = restTemplate.postForObject(usersEndpoint, scimUser, ScimUser.class);
    return scimUserResp;
}
 
开发者ID:bhits,项目名称:patient-user-api,代码行数:6,代码来源:ScimServiceImpl.java

示例7: activateUser

import org.cloudfoundry.identity.uaa.scim.ScimUser; //导入依赖的package包/类
@Override
public UserActivationResponseDto activateUser(UserActivationRequestDto userActivationRequest, String xForwardedProto, String xForwardedHost, int xForwardedPort) {
    // Verify password
    assertPasswordAndConfirmPassword(userActivationRequest);
    // Find user creation process with emailToken and verificationCode
    final UserCreation userCreation = userCreationRepository.findOneByEmailTokenAndVerificationCode(
            userActivationRequest.getEmailToken(),
            userActivationRequest.getVerificationCode())
            .orElseThrow(UserActivationCannotBeVerifiedException::new);

    // Assert user creation process preconditions
    assertNotAlreadyVerified(userCreation);
    assertEmailTokenNotExpired(userCreation);
    // Find patient profile on PHR
    final PatientDto patientProfile = phrService.findPatientProfileById(userCreation.getPatientId(), true);
    // Assert username and patient email match
    assertUsernameAndPatientEmailMatch(userActivationRequest, patientProfile);
    // Assert birth date verification
    assertBirthDateVerification(userActivationRequest, patientProfile);
    userCreation.setVerified(true);
    userCreationRepository.save(userCreation);
    // Prepare response
    final UserActivationResponseDto response = modelMapper.map(patientProfile, UserActivationResponseDto.class);
    response.setBirthDate(patientProfile.getBirthDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
    response.setVerified(userCreation.isVerified());
    // Create user using SCIM
    ScimUser scimUser = new ScimUser(null, patientProfile.getEmail(), patientProfile.getFirstName(), patientProfile.getLastName());
    scimUser.setPassword(userActivationRequest.getPassword());
    ScimUser.Email email = new ScimUser.Email();
    email.setValue(patientProfile.getEmail());
    scimUser.setEmails(Collections.singletonList(email));
    scimUser.setVerified(true);
    // Save SCIM user
    final ScimUser savedScimUser = scimService.save(scimUser);
    final String userId = savedScimUser.getId();
    Assert.hasText(userId, "SCIM userId must have text");
    // Save userId in userCreation
    userCreation.setUserId(userId);
    userCreationRepository.save(userCreation);
    // Add user to groups
    scimService.addUserToGroups(userCreation);
    emailSender.sendEmailToConfirmVerification(
            xForwardedProto, xForwardedHost, xForwardedPort,
            patientProfile.getEmail(),
            getRecipientFullName(patientProfile));
    return response;
}
 
开发者ID:bhits,项目名称:patient-user-api,代码行数:48,代码来源:UserCreationServiceImpl.java

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: newRegistration_validData_statusOkAndUserCreated

import org.cloudfoundry.identity.uaa.scim.ScimUser; //导入依赖的package包/类
@Test
public void newRegistration_validData_statusOkAndUserCreated() {
    final String username = "[email protected]";
    final String password = "asdasd";
    final String organization = "testorg";
    final String defaultSpaceName = "default";
    final UUID orgGuid = UUID.randomUUID();
    final UUID userGuid = UUID.randomUUID();
    final UUID spaceGuid = UUID.randomUUID();
    final String userGuidString = userGuid.toString();
    final String code = codeService.generateCode(username).getCode();

    when(uaaClient.createUser(anyString(), anyString()))
        .thenReturn(new ScimUser(userGuidString, username, null, null));

    when(ccClient.getOrgs()).thenReturn(Observable.<CcOrg>empty());

    setUpNotExistingUserRequest(username);

    when(ccClient.createOrganization(organization)).thenReturn(orgGuid);
    when(ccClient.createSpace(orgGuid, defaultSpaceName)).thenReturn(spaceGuid);


    when(accessInvitations.isEligibleToCreateOrg()).thenReturn(true);
    when(accessInvitationsService.getAccessInvitations(anyString())).thenReturn(Optional.of(accessInvitations));
    when(accessInvitationsService.getOrgCreationEligibility(anyString())).thenReturn(true);

    ResponseEntity<String> response =
        restTemplate.getForEntity(baseUrl + "rest/registrations/{code}", String.class, code);
    assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
    assertThat(response.getBody(), containsString(username));

    RegistrationModel user = new RegistrationModel();
    user.setOrg(organization);
    user.setPassword(password);

    response = restTemplate
        .postForEntity(baseUrl + "rest/registrations?code={code}", user, String.class, code);

    assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));

    verify(uaaClient).createUser(username, password);
    verify(ccClient).createUser(userGuid);
    verify(ccClient).createOrganization(organization);
    verify(ccClient).assignUserToOrganization(userGuid, orgGuid);
    verify(ccClient).assignUserToSpace(userGuid, spaceGuid);
}
 
开发者ID:trustedanalytics,项目名称:user-management,代码行数:48,代码来源:InvitationsIT.java


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