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
public void testUpdateUser() {
public void testUpdateUser() throws IOException {
String userName = "userTest0001";
String userPassword = "userTest0001";
try {
// user not exist
Map<String, Object> result = usersService.updateUser(getLoginUser(), 0, userName, userPassword,
"3443@qq.com", 1, "13457864543", "queue", 1, "Asia/Shanghai");
Assertions.assertEquals(Status.USER_NOT_EXIST, result.get(Constants.STATUS));
logger.info(result.toString());
// success
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,
"13457864543", "queue", 1, "Asia/Shanghai");
logger.info(result.toString());
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
} catch (Exception e) {
logger.error("update user error", e);
Assertions.fail();
}
}
@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")
public class User {
/**
* id
*/
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
/**
* user name
*/
private String userName;
/**
* user password
*/
private String userPassword;
/**
* mail
*/
private String email;
/**
* phone
*/
private String phone;
/**
* user type
*/
private UserType userType;
/**
* tenant id
*/
private int tenantId;
/**
* user state
*/
private int state;
/**
* tenant code
*/
@TableField(exist = false)
private String tenantCode;
/**
* queue name
*/
@TableField(exist = false)
private String queueName;
/**
* alert group
*/
@TableField(exist = false)
private String alertGroup;
/**
* user specified queue
*/
private String queue;
/**
* time zone
*/
private String timeZone;
/**
* create time
*/
private Date createTime;
/**
* update time
*/
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;
}
/**
* insert one user
*
* @param tenant tenant
* @return User
*/
private User insertOne(Tenant tenant) {
private User insertOneUser(Tenant tenant) {
User user = new User();
user.setUserName("user1");
user.setUserPassword("1");
@ -88,6 +82,7 @@ public class UserMapperTest extends BaseDaoTest {
user.setUserType(UserType.GENERAL_USER);
user.setCreateTime(new Date());
user.setTenantId(tenant.getId());
user.setTenantCode(tenant.getTenantCode());
user.setUpdateTime(new Date());
userMapper.insert(user);
return user;
@ -287,7 +282,7 @@ public class UserMapperTest extends BaseDaoTest {
// insertOneTenant
Tenant tenant = insertOneTenant();
// insertOne
User user = insertOne(tenant);
User user = insertOneUser(tenant);
// queryTenantCodeByUserId
User queryUser = userMapper.queryTenantCodeByUserId(user.getId());
Assertions.assertEquals(queryUser, user);
@ -304,7 +299,7 @@ public class UserMapperTest extends BaseDaoTest {
AccessToken accessToken = insertOneAccessToken(user);
// queryUserByToken
User userToken = userMapper.queryUserByToken(accessToken.getToken(), new Date());
Assertions.assertEquals(userToken, user);
Assertions.assertEquals(userToken.getId(), user.getId());
}

Loading…
Cancel
Save