@Test
  @Transactional
  public void testDelete() throws Exception {
    User user = this.insertUser("makersoft-vertical", "makersoft-vertical", 18, User.SEX_MALE);
    assertNotNull("Insert User does not success!", user);

    int rows = userMapper.deleteById(user.getId());
    assertTrue("Delete User does not success!", rows == 1);

    user = userMapper.getById(user.getId());

    assertNull(user);
  }
  @Test
  @Transactional
  public void testUpdate() throws Exception {
    User user = this.insertUser("makersoft-vertical", "makersoft-vertical", 18, User.SEX_MALE);

    assertNotNull("Insert User does not success!", user);

    user.setUsername("fengkuok");
    user.setPassword("password");
    int rows = userMapper.updateById(user);

    assertTrue("Update User does not success!", rows == 1);

    User fengkuok = userMapper.getById(user.getId());

    assertTrue("Update User does not success!", user.equals(fengkuok));
  }
  /** for insert new user */
  private User insertUser(String username, String password, int age, int gender) {
    User user = new User(username, password, gender);
    user.setAge(age);
    int rows = userMapper.insertUser(user);

    assertTrue("Insert User does not success!", rows == 1);

    assertNotNull(user.getId());

    return user;
  }
  @Test
  @Transactional
  public void testSelect() throws Exception {
    List<User> maleUsers = Lists.newArrayList();

    for (int i = 0; i < 10; i++) {
      String name = "makersoft-vertical_" + i;
      String password = "******" + i;
      int age = i;
      int gender = (i % 2) == 0 ? User.SEX_MALE : User.SEX_FEMALE;

      User user = this.insertUser(name, password, age, gender);

      if (gender == User.SEX_MALE) {
        maleUsers.add(user);
      }
    }

    List<User> users = userMapper.findByGender(User.SEX_MALE);
    assertTrue("find by gender total size error " + users.size(), users.size() == 5);

    assertTrue(maleUsers.containsAll(users));

    List<Role> allRoles = Lists.newArrayList();
    for (int i = 0; i < 10; i++) {
      String name = "ROLE_" + i;
      String code = "CODE_" + i;

      Role role = this.insertRole(name, code);
      allRoles.add(role);
    }

    List<Role> roles = roleMapper.findAll();

    assertTrue(allRoles.containsAll(roles));
  }