feat: add integration test (#65)

* feat: add integration test

* feat: update action config

* fix: action run failed

* feat: add test report step in action
This commit is contained in:
vran
2022-03-26 19:26:50 +08:00
committed by GitHub
parent 17d0f3a024
commit 4edadae62e
41 changed files with 806 additions and 59 deletions

View File

@@ -20,6 +20,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import static com.databasir.core.infrastructure.constant.RoleConstants.GROUP_OWNER;
@Service
@RequiredArgsConstructor
public class GroupService {
@@ -39,7 +41,7 @@ public class GroupService {
private final GroupResponseConverter groupResponseConverter;
@Transactional
public void create(GroupCreateRequest request) {
public Integer create(GroupCreateRequest request) {
GroupPojo groupPojo = groupPojoConverter.of(request);
Integer groupId = groupDao.insertAndReturnId(groupPojo);
List<UserRolePojo> roles = request.getGroupOwnerUserIds()
@@ -47,25 +49,26 @@ public class GroupService {
.map(userId -> {
UserRolePojo role = new UserRolePojo();
role.setUserId(userId);
role.setRole("GROUP_OWNER");
role.setRole(GROUP_OWNER);
role.setGroupId(groupId);
return role;
})
.collect(Collectors.toList());
userRoleDao.batchInsert(roles);
return groupId;
}
@Transactional
public void update(GroupUpdateRequest request) {
GroupPojo groupPojo = groupPojoConverter.of(request);
groupDao.updateById(groupPojo);
userRoleDao.deleteByRoleAndGroupId("GROUP_OWNER", groupPojo.getId());
userRoleDao.deleteByRoleAndGroupId(GROUP_OWNER, groupPojo.getId());
List<UserRolePojo> roles = request.getGroupOwnerUserIds()
.stream()
.map(userId -> {
UserRolePojo role = new UserRolePojo();
role.setUserId(userId);
role.setRole("GROUP_OWNER");
role.setRole(GROUP_OWNER);
role.setGroupId(groupPojo.getId());
return role;
})
@@ -114,7 +117,7 @@ public class GroupService {
public GroupResponse get(Integer groupId) {
GroupPojo groupPojo = groupDao.selectById(groupId);
List<UserPojo> users = userDao.selectLimitUsersByRoleAndGroup(groupId, "GROUP_OWNER", 50);
List<UserPojo> users = userDao.selectLimitUsersByRoleAndGroup(groupId, GROUP_OWNER, 50);
return groupResponseConverter.toResponse(groupPojo, users);
}

View File

@@ -1,10 +1,14 @@
package com.databasir.core.domain.project.data;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotBlank;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class DataSourcePropertyValue {
@NotBlank

View File

@@ -59,7 +59,7 @@ public class ProjectService {
}
@Transactional
public void create(ProjectCreateRequest request) {
public Integer create(ProjectCreateRequest request) {
ProjectPojo project = projectPojoConverter.of(request);
Integer projectId = null;
try {
@@ -78,6 +78,7 @@ public class ProjectService {
ProjectSyncRulePojo syncRule = projectPojoConverter.of(request.getProjectSyncRule(), projectId);
projectSyncRuleDao.insertAndReturnId(syncRule);
return projectId;
}
@Transactional

View File

@@ -26,6 +26,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.*;
import static com.databasir.core.infrastructure.constant.RoleConstants.SYS_OWNER;
import static java.util.stream.Collectors.*;
@Service
@@ -63,7 +64,7 @@ public class UserService {
.filter(ur -> ur.getGroupId() != null)
.collect(groupingBy(UserRolePojo::getUserId, mapping(UserRolePojo::getGroupId, toList())));
Map<Integer, List<UserRolePojo>> sysOwnerGroupByUserId = userRoles.stream()
.filter(ur -> ur.getRole().equals("SYS_OWNER"))
.filter(ur -> ur.getRole().equals(SYS_OWNER))
.collect(groupingBy(UserRolePojo::getUserId));
return users.map(user ->
userResponseConverter.pageResponse(user, sysOwnerGroupByUserId.containsKey(user.getId()),
@@ -143,16 +144,16 @@ public class UserService {
}
public void removeSysOwnerFrom(Integer userId) {
if (userRoleDao.hasRole(userId, "SYS_OWNER")) {
userRoleDao.deleteRole(userId, "SYS_OWNER");
if (userRoleDao.hasRole(userId, SYS_OWNER)) {
userRoleDao.deleteRole(userId, SYS_OWNER);
}
}
public void addSysOwnerTo(Integer userId) {
if (!userRoleDao.hasRole(userId, "SYS_OWNER")) {
if (!userRoleDao.hasRole(userId, SYS_OWNER)) {
UserRolePojo role = new UserRolePojo();
role.setUserId(userId);
role.setRole("SYS_OWNER");
role.setRole(SYS_OWNER);
userRoleDao.insertAndReturnId(role);
}
}
@@ -167,6 +168,7 @@ public class UserService {
}
String newHashedPassword = bCryptPasswordEncoder.encode(request.getNewPassword());
userDao.updatePassword(userId, newHashedPassword);
loginDao.deleteByUserId(userId);
}
public void updateNickname(Integer userId, UserNicknameUpdateRequest request) {

View File

@@ -0,0 +1,10 @@
package com.databasir.core.infrastructure.constant;
public interface RoleConstants {
String SYS_OWNER = "SYS_OWNER";
String GROUP_OWNER = "GROUP_OWNER";
String GROUP_MEMBER = "GROUP_MEMBER";
}

View File

@@ -27,6 +27,8 @@ import java.util.Optional;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
import static com.databasir.core.infrastructure.constant.RoleConstants.SYS_OWNER;
@Component
@Slf4j
@RequiredArgsConstructor
@@ -129,7 +131,7 @@ public class SystemStartedEventSubscriber {
Integer userId = userDao.insertAndReturnId(admin);
UserRolePojo role = new UserRolePojo();
role.setUserId(userId);
role.setRole("SYS_OWNER");
role.setRole(SYS_OWNER);
userRoleDao.insertAndReturnId(role);
}
}