Browse Source

cherry-pick Remove equals in User to fix UT

#12487
3.1.1-release
Wenjun Ruan 2 years ago committed by zhuangchong
parent
commit
5598ab01e9
  1. 29
      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. 19
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UserMapperTest.java

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

@ -62,6 +62,7 @@ import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
@ -294,26 +295,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));
Assert.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());
result = usersService.updateUser(getLoginUser(), 1, userName, userPassword, "32222s@qq.com", 1, when(userMapper.updateById(any())).thenReturn(1);
"13457864543", "queue", 1, "Asia/Shanghai"); result = usersService.updateUser(getLoginUser(), 1, userName, userPassword, "32222s@qq.com", 1,
logger.info(result.toString()); "13457864543", "queue", 1, "Asia/Shanghai");
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
} catch (Exception e) {
logger.error("update user error", e);
Assert.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;
}
} }

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

@ -32,6 +32,7 @@ import java.util.List;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
@ -73,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");
@ -87,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;
@ -286,9 +282,9 @@ public class UserMapperTest extends BaseDaoTest {
public void testQueryTenantCodeByUserId() { public void testQueryTenantCodeByUserId() {
//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());
Assert.assertEquals(queryUser, user); Assert.assertEquals(queryUser, user);
} }
@ -304,8 +300,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());
Assert.assertEquals(userToken, user); Assertions.assertEquals(userToken.getId(), user.getId());
} }
@Test @Test

Loading…
Cancel
Save