diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java index e9bc107d7d..fdef7e3d90 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/UsersServiceTest.java +++ b/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.Before; import org.junit.Test; +import org.junit.jupiter.api.Assertions; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; @@ -294,26 +295,20 @@ public class UsersServiceTest { } @Test - public void testUpdateUser() { + public void testUpdateUser() throws IOException { String userName = "userTest0001"; String userPassword = "userTest0001"; - try { - // user not exist - Map result = usersService.updateUser(getLoginUser(), 0, userName, userPassword, - "3443@qq.com", 1, "13457864543", "queue", 1, "Asia/Shanghai"); - Assert.assertEquals(Status.USER_NOT_EXIST, result.get(Constants.STATUS)); - logger.info(result.toString()); + // user not exist + Map 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)); - // success - when(userMapper.selectById(1)).thenReturn(getUser()); - result = usersService.updateUser(getLoginUser(), 1, userName, userPassword, "32222s@qq.com", 1, - "13457864543", "queue", 1, "Asia/Shanghai"); - logger.info(result.toString()); - Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); - } catch (Exception e) { - logger.error("update user error", e); - Assert.fail(); - } + // success + when(userMapper.selectById(1)).thenReturn(getUser()); + when(userMapper.updateById(any())).thenReturn(1); + result = usersService.updateUser(getLoginUser(), 1, userName, userPassword, "32222s@qq.com", 1, + "13457864543", "queue", 1, "Asia/Shanghai"); + Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); } @Test diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/User.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/User.java index 4517af6c84..827a2f575a 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/User.java +++ b/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; - } } diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UserMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UserMapperTest.java index 1fd07f94c4..81132edc7b 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UserMapperTest.java +++ b/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.Test; +import org.junit.jupiter.api.Assertions; import org.springframework.beans.factory.annotation.Autowired; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -73,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"); @@ -87,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; @@ -286,9 +282,9 @@ public class UserMapperTest extends BaseDaoTest { public void testQueryTenantCodeByUserId() { //insertOneTenant Tenant tenant = insertOneTenant(); - //insertOne - User user = insertOne(tenant); - //queryTenantCodeByUserId + // insertOne + User user = insertOneUser(tenant); + // queryTenantCodeByUserId User queryUser = userMapper.queryTenantCodeByUserId(user.getId()); Assert.assertEquals(queryUser, user); } @@ -304,8 +300,7 @@ public class UserMapperTest extends BaseDaoTest { AccessToken accessToken = insertOneAccessToken(user); //queryUserByToken User userToken = userMapper.queryUserByToken(accessToken.getToken(), new Date()); - Assert.assertEquals(userToken, user); - + Assertions.assertEquals(userToken.getId(), user.getId()); } @Test