예제 #1
0
  @Test
  public void testUser() {
    User user = new User();
    user.setUserName("MyName1");
    user.setEmail("*****@*****.**");
    user.setCreatedUser(getUser("user"));
    user.setCreatedDate(new Date());
    user.setUserId("hello");
    user.setRole(Role.USER);
    user = userRepository.save(user);
    User user2 = new User();
    user2.setUserId("hello2");
    user2.setUserName("MyName2");
    user2.setEmail("*****@*****.**");
    user2.setCreatedUser(getUser("user"));
    user2.setCreatedDate(new Date());
    user2.setRole(Role.USER);
    userRepository.save(user2);

    assertThat(userRepository.count(), is(2L));

    assertThat(userRepository.findAll(UserSpecification.emailLike("gmail")).size(), is(1));

    assertThat(
        userRepository
            .findAll(
                Specifications.where(UserSpecification.emailLike("@paran"))
                    .and(UserSpecification.nameLike("MyName2")))
            .size(),
        is(1));
  }
 /**
  * Add new user into local db.
  *
  * @param securedUser user
  */
 @Transactional
 public void addNewUserIntoLocal(SecuredUser securedUser) {
   User user = securedUser.getUser();
   user.setAuthProviderClass(securedUser.getUserInfoProviderClass());
   user.setCreatedDate(new Date());
   User newUser = userService.getUserById(user.getUserId());
   if (newUser != null) {
     user = newUser.merge(user);
   }
   if (user.getRole() == null) {
     user.setRole(Role.USER);
   }
   User savedUser = userService.saveUser(user);
   securedUser.setUser(savedUser);
 }