Exemple #1
0
  @Test
  public void getUserAndToken() {
    User demo1 = userDao.findOne(1L);

    Assert.assertNotNull(demo1);
    Assert.assertNotNull(demo1.getToken());
  }
Exemple #2
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);
  }
Exemple #3
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"));
  }
Exemple #4
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"));
  }