Browse Source

Remove equals in User to fix UT (#12487)

3.2.0-release
Wenjun Ruan 2 years ago committed by GitHub
parent
commit
b5193ee4e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java
  2. 69
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/User.java
  3. 13
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UserMapperTest.java

11
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java

@ -297,27 +297,20 @@ public class UsersServiceTest {
} }
@Test @Test
public void testUpdateUser() { public void testUpdateUser() throws IOException {
String userName = "userTest0001"; String userName = "userTest0001";
String userPassword = "userTest0001"; String userPassword = "userTest0001";
try {
// user not exist // user not exist
Map<String, Object> result = usersService.updateUser(getLoginUser(), 0, userName, userPassword, Map<String, Object> result = usersService.updateUser(getLoginUser(), 0, userName, userPassword,
"3443@qq.com", 1, "13457864543", "queue", 1, "Asia/Shanghai"); "3443@qq.com", 1, "13457864543", "queue", 1, "Asia/Shanghai");
Assertions.assertEquals(Status.USER_NOT_EXIST, result.get(Constants.STATUS)); Assertions.assertEquals(Status.USER_NOT_EXIST, result.get(Constants.STATUS));
logger.info(result.toString());
// success // success
when(userMapper.selectById(1)).thenReturn(getUser()); when(userMapper.selectById(1)).thenReturn(getUser());
when(userMapper.updateById(getUser())).thenReturn(1); when(userMapper.updateById(any())).thenReturn(1);
result = usersService.updateUser(getLoginUser(), 1, userName, userPassword, "32222s@qq.com", 1, result = usersService.updateUser(getLoginUser(), 1, userName, userPassword, "32222s@qq.com", 1,
"13457864543", "queue", 1, "Asia/Shanghai"); "13457864543", "queue", 1, "Asia/Shanghai");
logger.info(result.toString());
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
} catch (Exception e) {
logger.error("update user error", e);
Assertions.fail();
}
} }
@Test @Test

69
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/User.java

@ -32,107 +32,38 @@ import com.baomidou.mybatisplus.annotation.TableName;
@TableName("t_ds_user") @TableName("t_ds_user")
public class User { public class User {
/**
* id
*/
@TableId(value = "id", type = IdType.AUTO) @TableId(value = "id", type = IdType.AUTO)
private Integer id; private Integer id;
/**
* user name
*/
private String userName; private String userName;
/**
* user password
*/
private String userPassword; private String userPassword;
/**
* mail
*/
private String email; private String email;
/**
* phone
*/
private String phone; private String phone;
/**
* user type
*/
private UserType userType; private UserType userType;
/**
* tenant id
*/
private int tenantId; private int tenantId;
/**
* user state
*/
private int state; private int state;
/**
* tenant code
*/
@TableField(exist = false) @TableField(exist = false)
private String tenantCode; private String tenantCode;
/**
* queue name
*/
@TableField(exist = false) @TableField(exist = false)
private String queueName; private String queueName;
/**
* alert group
*/
@TableField(exist = false) @TableField(exist = false)
private String alertGroup; private String alertGroup;
/**
* user specified queue
*/
private String queue; private String queue;
/**
* time zone
*/
private String timeZone; private String timeZone;
/**
* create time
*/
private Date createTime; private Date createTime;
/**
* update time
*/
private Date updateTime; private Date updateTime;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
User user = (User) o;
if (id != user.id) {
return false;
}
return userName.equals(user.userName);
}
@Override
public int hashCode() {
int result = id == null ? 0 : id;
result = 31 * result + userName.hashCode();
return result;
}
} }

13
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UserMapperTest.java

@ -74,13 +74,7 @@ public class UserMapperTest extends BaseDaoTest {
return user; return user;
} }
/** private User insertOneUser(Tenant tenant) {
* insert one user
*
* @param tenant tenant
* @return User
*/
private User insertOne(Tenant tenant) {
User user = new User(); User user = new User();
user.setUserName("user1"); user.setUserName("user1");
user.setUserPassword("1"); user.setUserPassword("1");
@ -88,6 +82,7 @@ public class UserMapperTest extends BaseDaoTest {
user.setUserType(UserType.GENERAL_USER); user.setUserType(UserType.GENERAL_USER);
user.setCreateTime(new Date()); user.setCreateTime(new Date());
user.setTenantId(tenant.getId()); user.setTenantId(tenant.getId());
user.setTenantCode(tenant.getTenantCode());
user.setUpdateTime(new Date()); user.setUpdateTime(new Date());
userMapper.insert(user); userMapper.insert(user);
return user; return user;
@ -287,7 +282,7 @@ public class UserMapperTest extends BaseDaoTest {
// insertOneTenant // insertOneTenant
Tenant tenant = insertOneTenant(); Tenant tenant = insertOneTenant();
// insertOne // insertOne
User user = insertOne(tenant); User user = insertOneUser(tenant);
// queryTenantCodeByUserId // queryTenantCodeByUserId
User queryUser = userMapper.queryTenantCodeByUserId(user.getId()); User queryUser = userMapper.queryTenantCodeByUserId(user.getId());
Assertions.assertEquals(queryUser, user); Assertions.assertEquals(queryUser, user);
@ -304,7 +299,7 @@ public class UserMapperTest extends BaseDaoTest {
AccessToken accessToken = insertOneAccessToken(user); AccessToken accessToken = insertOneAccessToken(user);
// queryUserByToken // queryUserByToken
User userToken = userMapper.queryUserByToken(accessToken.getToken(), new Date()); User userToken = userMapper.queryUserByToken(accessToken.getToken(), new Date());
Assertions.assertEquals(userToken, user); Assertions.assertEquals(userToken.getId(), user.getId());
} }

Loading…
Cancel
Save