Exemplo n.º 1
0
  @Test
  public void testUpdateUser_OK() {

    User defaultUser = UserFactoryForTests.getDefaultTestUser();
    String salt = "salt";

    try {

      assertEquals(0, userDAO.countUsersTable(dbConnection));
      userDAO.createUser(dbConnection, defaultUser, defaultUser.getPassword(), salt);
      assertEquals(1, userDAO.countUsersTable(dbConnection));

      User updatedUser = UserFactoryForTests.getDefaultTestUser(1);
      boolean userWasUpdated =
          userDAO.updateUser(
              dbConnection,
              defaultUser.getUsername(),
              updatedUser.getName(),
              updatedUser.getPassword());

      assertEquals(true, userWasUpdated);
      assertEquals(1, userDAO.countUsersTable(dbConnection));

      User retrievedUser = userDAO.getUserByUsername(dbConnection, defaultUser.getUsername());
      assertEquals(defaultUser.getUsername(), retrievedUser.getUsername());
      assertEquals(updatedUser.getName(), retrievedUser.getName());
      assertEquals(updatedUser.getPassword(), retrievedUser.getPassword());

    } catch (SQLException e) {

      ExceptionUtilsForTests.logAndFailOnUnexpectedException(e);
    }
  }
Exemplo n.º 2
0
  @Test
  public void testGetUserByUsername_OK() {

    User user = UserFactoryForTests.getDefaultTestUser();
    String salt = "salt";

    try {

      userDAO.createUser(dbConnection, user, user.getPassword(), salt);
      User retrievedUser = userDAO.getUserByUsername(dbConnection, user.getUsername());
      assertEquals(0, user.compareTo(retrievedUser));

    } catch (SQLException e) {

      ExceptionUtilsForTests.logAndFailOnUnexpectedException(e);
    }
  }
Exemplo n.º 3
0
  @Test
  public void testDeleteUser_NOK() {

    User defaultUser = UserFactoryForTests.getDefaultTestUser();

    try {

      assertEquals(0, userDAO.countUsersTable(dbConnection));
      boolean userWasDeleted = userDAO.deleteUser(dbConnection, defaultUser.getUsername());

      assertEquals(false, userWasDeleted);
      assertEquals(0, userDAO.countUsersTable(dbConnection));

    } catch (SQLException e) {

      ExceptionUtilsForTests.logAndFailOnUnexpectedException(e);
    }
  }
Exemplo n.º 4
0
  @Test
  public void testGetPasswordByUsername_NOK() {

    User user = UserFactoryForTests.getDefaultTestUser();

    try {

      assertEquals(0, userDAO.countUsersTable(dbConnection));
      String password = userDAO.getPasswordByUsername(dbConnection, user.getUsername());

      assertNotNull(password);
      assertEquals("", password);

    } catch (SQLException e) {

      ExceptionUtilsForTests.logAndFailOnUnexpectedException(e);
    }
  }
Exemplo n.º 5
0
  @Test
  public void testGetUserByUsername_NOK() {

    User user = UserFactoryForTests.getDefaultTestUser();
    String salt = "salt";

    try {

      userDAO.createUser(dbConnection, user, user.getPassword(), salt);
      String unknownUsername = "******";

      User retrievedUser = userDAO.getUserByUsername(dbConnection, unknownUsername);
      assertNull(retrievedUser);

    } catch (SQLException e) {

      ExceptionUtilsForTests.logAndFailOnUnexpectedException(e);
    }
  }
Exemplo n.º 6
0
  @Test
  public void testGetPasswordByUsername_OK() {

    User user = UserFactoryForTests.getDefaultTestUser();
    String salt = "salt";

    try {

      assertEquals(0, userDAO.countUsersTable(dbConnection));
      userDAO.createUser(dbConnection, user, user.getPassword(), salt);
      assertEquals(1, userDAO.countUsersTable(dbConnection));

      String password = userDAO.getPasswordByUsername(dbConnection, user.getUsername());
      assertEquals(user.getPassword(), password);

    } catch (SQLException e) {

      ExceptionUtilsForTests.logAndFailOnUnexpectedException(e);
    }
  }
Exemplo n.º 7
0
  @Test
  public void testCountUsersTable_NOK() {

    User user = UserFactoryForTests.getDefaultTestUser();

    try {

      assertEquals(0, userDAO.countUsersTable(dbConnection));
      int numberOfUsersIntoDb = userDAO.getAllUsers(dbConnection).size();

      assertEquals(0, numberOfUsersIntoDb);
      assertEquals(numberOfUsersIntoDb, userDAO.countUsersTable(dbConnection));

      User retrievedUser = userDAO.getUserByUsername(dbConnection, user.getUsername());
      assertEquals(0, user.compareTo(retrievedUser));

    } catch (SQLException e) {

      ExceptionUtilsForTests.logAndFailOnUnexpectedException(e);
    }
  }
Exemplo n.º 8
0
  @Test
  public void testGetAllUsers_NOK() {

    int listSize = 0;
    List<User> userList = UserFactoryForTests.getUserList(listSize);
    String salt = "123";

    try {

      for (User user : userList) {
        userDAO.createUser(dbConnection, user, user.getPassword(), salt);
      }

      assertEquals(listSize, userDAO.countUsersTable(dbConnection));
      List<User> retrievedUsers = userDAO.getAllUsers(dbConnection);
      assertEquals(listSize, retrievedUsers.size());

    } catch (SQLException e) {

      ExceptionUtilsForTests.logAndFailOnUnexpectedException(e);
    }
  }