Пример #1
0
  @Test
  public void saveUser() {
    User user = new User();
    user.setUsername("demo9");
    user.setEmail("*****@*****.**");
    user.setTopoosId("9");

    User savedUser = userDao.save(user);

    User demo9 = userDao.findOne(savedUser.getId());

    Assert.assertNotNull(demo9);
  }
Пример #2
0
  @Test
  public void saveNewUserAndToken() {
    User newUser = new User();
    newUser.setUsername("demo9");
    newUser.setEmail("*****@*****.**");
    newUser.setTopoosId("9");

    User existingUser = userDao.findByTopoosId(newUser.getTopoosId());

    if (existingUser == null) {
      existingUser = userDao.save(newUser);
    }

    if (existingUser.getToken() == null) {
      OauthToken token = new OauthToken();
      token.setAccessToken("9");
      token.setRefreshToken("9");
      token.setTokenType("bearer");
      token.setExpiresIn(99999999L);

      token.setUser(existingUser);
      token.setUserId(existingUser.getId());

      existingUser.setToken(token);

      existingUser = userDao.save(existingUser);

      Assert.assertNotNull(existingUser.getToken());
    }

    User createdUser = userDao.findOne(existingUser.getId());

    Assert.assertNotNull(createdUser);
    Assert.assertNotNull(createdUser.getToken());
    Assert.assertTrue(createdUser.getToken().getAccessToken().equals("9"));
  }