Example #1
0
  @Test
  public void saveExistingUserAndToken() {
    User existingUser = userDao.findByTopoosId("1");

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

    tokenDao.save(token);

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

    Assert.assertNotNull(updatedUser);
    Assert.assertNotNull(updatedUser.getToken());
    Assert.assertTrue(updatedUser.getToken().getAccessToken().equals("9"));
  }
Example #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"));
  }