Browse Source

feat: add integration test (#65)

* feat: add integration test

* feat: update action config

* fix: action run failed

* feat: add test report step in action
master
vran 3 years ago
committed by GitHub
parent
commit
4edadae62e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      .github/workflows/auto-check.yml
  2. 6
      api/src/main/java/com/databasir/api/GroupController.java
  3. 10
      build.gradle
  4. 13
      core/src/main/java/com/databasir/core/domain/group/service/GroupService.java
  5. 4
      core/src/main/java/com/databasir/core/domain/project/data/DataSourcePropertyValue.java
  6. 3
      core/src/main/java/com/databasir/core/domain/project/service/ProjectService.java
  7. 12
      core/src/main/java/com/databasir/core/domain/user/service/UserService.java
  8. 10
      core/src/main/java/com/databasir/core/infrastructure/constant/RoleConstants.java
  9. 4
      core/src/main/java/com/databasir/core/infrastructure/event/subscriber/SystemStartedEventSubscriber.java
  10. 92
      core/src/test/java/com/databasir/core/domain/database/service/DatabaseTypeServiceTest.java
  11. 48
      core/src/test/java/com/databasir/core/domain/description/service/DocumentDescriptionServiceTest.java
  12. 80
      core/src/test/java/com/databasir/core/domain/discussion/service/DocumentDiscussionServiceTest.java
  13. 130
      core/src/test/java/com/databasir/core/domain/group/service/GroupServiceTest.java
  14. 125
      core/src/test/java/com/databasir/core/domain/project/service/ProjectServiceTest.java
  15. 54
      core/src/test/java/com/databasir/core/domain/user/service/UserProjectServiceTest.java
  16. 55
      core/src/test/java/com/databasir/core/domain/user/service/UserServiceTest.java
  17. 4
      core/src/test/java/com/databasir/core/infrastructure/event/subscriber/DocumentEventSubscriberTest.java
  18. 4
      core/src/test/java/com/databasir/core/infrastructure/event/subscriber/UserEventSubscriberTest.java
  19. 4
      core/src/test/resources/sql/domain/database/CreateDuplicate.sql
  20. 4
      core/src/test/resources/sql/domain/database/DeleteById.sql
  21. 4
      core/src/test/resources/sql/domain/database/Update.sql
  22. 6
      core/src/test/resources/sql/domain/discussion/Create.sql
  23. 8
      core/src/test/resources/sql/domain/discussion/DeleteById.sql
  24. 22
      core/src/test/resources/sql/domain/group/GroupDelete.sql
  25. 10
      core/src/test/resources/sql/domain/group/GroupUpdate.sql
  26. 7
      core/src/test/resources/sql/domain/group/MemberAdd.sql
  27. 9
      core/src/test/resources/sql/domain/group/MemberRemove.sql
  28. 5
      core/src/test/resources/sql/domain/group/MemberRoleChange.sql
  29. 10
      core/src/test/resources/sql/domain/project/Delete.sql
  30. 15
      core/src/test/resources/sql/domain/project/Update.sql
  31. 2
      core/src/test/resources/sql/domain/user/AddFavorites.sql
  32. 8
      core/src/test/resources/sql/domain/user/AddSysOwnerTo.sql
  33. 4
      core/src/test/resources/sql/domain/user/RemoveFavorites.sql
  34. 6
      core/src/test/resources/sql/domain/user/RemoveSysOwnerFrom.sql
  35. 4
      core/src/test/resources/sql/domain/user/RenewPassword.sql
  36. 5
      core/src/test/resources/sql/domain/user/SwitchEnableStatus.sql
  37. 7
      core/src/test/resources/sql/domain/user/UpdateNickname.sql
  38. 7
      core/src/test/resources/sql/domain/user/UpdatePassword.sql
  39. 38
      core/src/test/resources/sql/event/subscriber/DocumentEventSubscriberTest.sql
  40. 8
      core/src/test/resources/sql/event/subscriber/UserEventSubscriberTest.sql
  41. 6
      dao/src/main/java/com/databasir/dao/impl/BaseDao.java

12
.github/workflows/auto-check.yml

@ -39,14 +39,20 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '11'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
cache: 'gradle'
- name: Gradle Permission Grant
run: chmod +x ./gradlew
- name: Gradle Test
run: ./gradlew api:check core:check
- name: Publish Test Report
uses: mikepenz/action-junit-report@v3
if: always()
with:
report_paths: '**/build/test-results/test/TEST-*.xml'

6
api/src/main/java/com/databasir/api/GroupController.java

@ -17,6 +17,8 @@ import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;
import static com.databasir.core.infrastructure.constant.RoleConstants.GROUP_MEMBER;
import static com.databasir.core.infrastructure.constant.RoleConstants.GROUP_OWNER;
import static org.springframework.data.domain.Sort.Direction.DESC;
@RestController
@ -86,7 +88,7 @@ public class GroupController {
public JsonData<Void> addGroupMember(@PathVariable Integer groupId,
@RequestBody @Valid GroupMemberCreateRequest request) {
userOperationValidator.forbiddenIfUpdateSelfRole(request.getUserId());
List<String> groupRoles = Arrays.asList("GROUP_OWNER", "GROUP_MEMBER");
List<String> groupRoles = Arrays.asList(GROUP_OWNER, GROUP_MEMBER);
if (!groupRoles.contains(request.getRole())) {
throw new IllegalArgumentException("role should be GROUP_OWNER or GROUP_MEMBER");
}
@ -117,7 +119,7 @@ public class GroupController {
@PathVariable Integer userId,
@RequestBody GroupMemberRoleUpdateRequest request) {
userOperationValidator.forbiddenIfUpdateSelfRole(userId);
List<String> groupRoles = Arrays.asList("GROUP_OWNER", "GROUP_MEMBER");
List<String> groupRoles = Arrays.asList(GROUP_OWNER, GROUP_MEMBER);
if (!groupRoles.contains(request.getRole())) {
throw new IllegalArgumentException("role should be GROUP_OWNER or GROUP_MEMBER");
}

10
build.gradle

@ -20,6 +20,7 @@ subprojects {
apply plugin: 'org.springframework.boot'
apply plugin: 'nu.studer.jooq'
apply plugin: 'checkstyle'
apply plugin: 'jacoco'
group 'com.databasir'
version '1.0.0'
@ -67,6 +68,15 @@ subprojects {
ignoreFailures = false
maxWarnings = 0
}
jacocoTestReport {
dependsOn test
reports {
xml.required = false
csv.required = false
html.outputLocation = layout.buildDirectory.dir('reports/jacoco/html')
}
}
}

13
core/src/main/java/com/databasir/core/domain/group/service/GroupService.java

@ -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);
}

4
core/src/main/java/com/databasir/core/domain/project/data/DataSourcePropertyValue.java

@ -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

3
core/src/main/java/com/databasir/core/domain/project/service/ProjectService.java

@ -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

12
core/src/main/java/com/databasir/core/domain/user/service/UserService.java

@ -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) {

10
core/src/main/java/com/databasir/core/infrastructure/constant/RoleConstants.java

@ -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";
}

4
core/src/main/java/com/databasir/core/infrastructure/event/subscriber/SystemStartedEventSubscriber.java

@ -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);
}
}

92
core/src/test/java/com/databasir/core/domain/database/service/DatabaseTypeServiceTest.java

@ -0,0 +1,92 @@
package com.databasir.core.domain.database.service;
import com.databasir.common.DatabasirException;
import com.databasir.core.BaseTest;
import com.databasir.core.domain.DomainErrors;
import com.databasir.core.domain.database.data.DatabaseTypeCreateRequest;
import com.databasir.core.domain.database.data.DatabaseTypeUpdateRequest;
import com.databasir.dao.impl.DatabaseTypeDao;
import com.databasir.dao.tables.pojos.DatabaseTypePojo;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.transaction.annotation.Transactional;
@Transactional
class DatabaseTypeServiceTest extends BaseTest {
@Autowired
private DatabaseTypeService databaseTypeService;
@Autowired
private DatabaseTypeDao databaseTypeDao;
@Test
void create() {
DatabaseTypeCreateRequest request = new DatabaseTypeCreateRequest();
request.setDatabaseType("ut-mysql");
request.setIcon("");
request.setDescription("integration test");
request.setJdbcDriverFileUrl("some url");
request.setJdbcDriverClassName("com.mysql.jdbc.Driver");
request.setJdbcProtocol("jdbc:mysql");
request.setUrlPattern("{{jdbc.protocol}}//{{db.url}}/{{db.schema}}");
Integer id = databaseTypeService.create(request);
Assertions.assertNotNull(id);
}
@Test
@Sql("classpath:sql/domain/database/CreateDuplicate.sql")
void createWhenDatabaseTypeDuplicate() {
DatabaseTypeCreateRequest request = new DatabaseTypeCreateRequest();
request.setDatabaseType("ut-mysql");
request.setIcon("");
request.setDescription("integration test");
request.setJdbcDriverFileUrl("some url");
request.setJdbcDriverClassName("com.mysql.jdbc.Driver");
request.setJdbcProtocol("jdbc:mysql");
request.setUrlPattern("{{jdbc.protocol}}//{{db.url}}/{{db.schema}}");
DatabasirException err = Assertions.assertThrows(DatabasirException.class,
() -> databaseTypeService.create(request));
Assertions.assertEquals(DomainErrors.DATABASE_TYPE_NAME_DUPLICATE.getErrCode(), err.getErrCode());
}
@Test
@Sql("classpath:sql/domain/database/Update.sql")
void update() {
DatabaseTypeUpdateRequest request = new DatabaseTypeUpdateRequest();
request.setId(-1000);
request.setIcon("");
request.setDatabaseType("new-type");
request.setDescription("integration test");
request.setJdbcDriverFileUrl("some url");
request.setJdbcDriverClassName("com.mysql.jdbc.Driver");
request.setJdbcProtocol("jdbc:postgresql");
request.setUrlPattern("{{jdbc.protocol}}//{{db.url}}/{{db.schema}}");
databaseTypeService.update(request);
DatabaseTypePojo pojo = databaseTypeDao.selectByDatabaseType("new-type");
Assertions.assertNotNull(pojo);
Assertions.assertEquals("integration test", pojo.getDescription());
Assertions.assertEquals("jdbc:postgresql", pojo.getJdbcProtocol());
Assertions.assertEquals("{{jdbc.protocol}}//{{db.url}}/{{db.schema}}", pojo.getUrlPattern());
}
@Test
@Sql("classpath:sql/domain/database/DeleteById.sql")
void deleteById() {
int id = -1000;
databaseTypeService.deleteById(id);
Assertions.assertFalse(databaseTypeDao.existsById(id));
}
@Test
void deleteByIdWhenNotExists() {
int id = -1000;
databaseTypeService.deleteById(id);
Assertions.assertFalse(databaseTypeDao.existsById(id));
}
}

48
core/src/test/java/com/databasir/core/domain/description/service/DocumentDescriptionServiceTest.java

@ -0,0 +1,48 @@
package com.databasir.core.domain.description.service;
import com.databasir.core.BaseTest;
import com.databasir.core.domain.description.data.DocumentDescriptionSaveRequest;
import com.databasir.dao.impl.DocumentDescriptionDao;
import com.databasir.dao.tables.pojos.DocumentDescriptionPojo;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Transactional
class DocumentDescriptionServiceTest extends BaseTest {
@Autowired
private DocumentDescriptionService documentDescriptionService;
@Autowired
private DocumentDescriptionDao documentDescriptionDao;
@Test
void save() {
DocumentDescriptionSaveRequest saveRequest = new DocumentDescriptionSaveRequest();
saveRequest.setTableName("ut");
saveRequest.setColumnName("ut");
saveRequest.setContent("hello world");
int groupId = -1;
int projectId = -1;
int userId = -1;
documentDescriptionService.save(groupId, projectId, userId, saveRequest);
boolean isExists = documentDescriptionDao.exists(projectId,
saveRequest.getTableName(), saveRequest.getColumnName());
Assertions.assertTrue(isExists);
DocumentDescriptionSaveRequest updateRequest = new DocumentDescriptionSaveRequest();
updateRequest.setTableName("ut");
updateRequest.setColumnName("ut");
updateRequest.setContent("update content");
documentDescriptionService.save(groupId, projectId, userId, updateRequest);
var tableData = documentDescriptionDao.selectTableDescriptionByProjectId(projectId);
Assertions.assertEquals(0, tableData.size());
List<DocumentDescriptionPojo> descriptionData = documentDescriptionDao.selectByProjectId(projectId);
Assertions.assertEquals(1, descriptionData.size());
}
}

80
core/src/test/java/com/databasir/core/domain/discussion/service/DocumentDiscussionServiceTest.java

@ -0,0 +1,80 @@
package com.databasir.core.domain.discussion.service;
import com.databasir.common.exception.Forbidden;
import com.databasir.core.BaseTest;
import com.databasir.core.domain.discussion.data.DiscussionCreateRequest;
import com.databasir.core.infrastructure.event.subscriber.DiscussionEventSubscriber;
import com.databasir.dao.Tables;
import com.databasir.dao.impl.DocumentDiscussionDao;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.transaction.annotation.Transactional;
import static org.mockito.Mockito.*;
@Transactional
class DocumentDiscussionServiceTest extends BaseTest {
@Autowired
private DocumentDiscussionService documentDiscussionService;
@Autowired
private DocumentDiscussionDao documentDiscussionDao;
@MockBean
private DiscussionEventSubscriber discussionEventSubscriber;
@Test
@Sql("classpath:sql/domain/discussion/DeleteById.sql")
void deleteById() {
int groupId = -999;
int projectId = -999;
int discussionId = -999;
documentDiscussionService.deleteById(groupId, projectId, discussionId);
Assertions.assertFalse(documentDiscussionDao.existsById(discussionId));
}
@Test
void deleteByIdWhenProjectNotExists() {
int groupId = -1;
int projectId = -2;
Assertions.assertThrows(Forbidden.class,
() -> documentDiscussionService.deleteById(groupId, projectId, -1));
}
@Test
@Sql("classpath:sql/domain/discussion/Create.sql")
void create() {
doNothing().when(discussionEventSubscriber).onDiscussionCreated(any());
DiscussionCreateRequest request = new DiscussionCreateRequest();
request.setContent("test");
request.setColumnName("test");
request.setTableName("test");
int groupId = -999;
int projectId = -999;
int userId = -999;
documentDiscussionService.create(groupId, projectId, userId, request);
var data = documentDiscussionDao.selectList(Tables.DOCUMENT_DISCUSSION.PROJECT_ID.eq(projectId));
Assertions.assertEquals(1, data.size());
verify(discussionEventSubscriber, times(1)).onDiscussionCreated(any());
}
@Test
void createWhenProjectNotExists() {
DiscussionCreateRequest request = new DiscussionCreateRequest();
request.setContent("test");
request.setColumnName("test");
request.setTableName("test");
int groupId = -1;
int projectId = -1;
int userId = -1;
Assertions.assertThrows(Forbidden.class,
() -> documentDiscussionService.create(groupId, projectId, userId, request));
}
}

130
core/src/test/java/com/databasir/core/domain/group/service/GroupServiceTest.java

@ -1,32 +1,160 @@
package com.databasir.core.domain.group.service;
import com.databasir.common.DatabasirException;
import com.databasir.core.BaseTest;
import com.databasir.core.domain.DomainErrors;
import com.databasir.core.domain.group.data.GroupCreateRequest;
import com.databasir.core.domain.group.data.GroupMemberCreateRequest;
import com.databasir.core.domain.group.data.GroupUpdateRequest;
import com.databasir.core.infrastructure.constant.RoleConstants;
import com.databasir.dao.Tables;
import com.databasir.dao.impl.GroupDao;
import com.databasir.dao.impl.ProjectDao;
import com.databasir.dao.impl.ProjectSyncRuleDao;
import com.databasir.dao.impl.UserRoleDao;
import com.databasir.dao.tables.pojos.ProjectSyncRulePojo;
import com.databasir.dao.tables.pojos.UserRolePojo;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.*;
class GroupServiceTest {
@Transactional
class GroupServiceTest extends BaseTest {
@Autowired
private GroupService groupService;
@Autowired
private UserRoleDao userRoleDao;
@Autowired
private GroupDao groupDao;
@Autowired
private ProjectDao projectDao;
@Autowired
private ProjectSyncRuleDao projectSyncRuleDao;
@Test
void create() {
GroupCreateRequest request = new GroupCreateRequest();
request.setName(UUID.randomUUID().toString());
request.setDescription("group service test");
request.setGroupOwnerUserIds(List.of(1, 2, 3));
Integer groupId = groupService.create(request);
assertNotNull(groupId);
List<UserRolePojo> roles = userRoleDao.selectByUserIds(List.of(1, 2, 3))
.stream()
.filter(r -> Objects.equals(r.getGroupId(), groupId) && r.getRole().equals("GROUP_OWNER"))
.collect(Collectors.toList());
assertEquals(3, roles.size());
}
@Test
@Sql("classpath:sql/domain/group/GroupUpdate.sql")
void update() {
int groupId = -999;
GroupUpdateRequest request = new GroupUpdateRequest();
request.setId(groupId);
request.setName(UUID.randomUUID().toString());
request.setDescription(UUID.randomUUID().toString());
request.setGroupOwnerUserIds(List.of(1000, 1001));
groupService.update(request);
List<UserRolePojo> members = userRoleDao.selectList(Tables.USER_ROLE.GROUP_ID.eq(groupId));
assertEquals(3, members.size());
List<Integer> ownerUserIds = members.stream()
.filter(r -> r.getRole().equals("GROUP_OWNER"))
.map(UserRolePojo::getUserId)
.collect(Collectors.toList());
assertEquals(2, ownerUserIds.size());
assertTrue(ownerUserIds.contains(1000));
assertTrue(ownerUserIds.contains(1001));
}
@Test
@Sql("classpath:sql/domain/group/GroupDelete.sql")
@SuppressWarnings("checkstyle:VariableDeclarationUsageDistance")
void delete() {
int groupId = -999;
List<Integer> undeleteProjectIds = projectDao.selectProjectIdsByGroupId(groupId);
groupService.delete(groupId);
// should clear all projects
List<Integer> projectIds = projectDao.selectProjectIdsByGroupId(groupId);
assertEquals(0, projectIds.size());
// should clear group members
List<UserRolePojo> members = userRoleDao.selectList(Tables.USER_ROLE.GROUP_ID.eq(groupId));
assertEquals(0, members.size());
// should clear project sync schedule
List<ProjectSyncRulePojo> syncRule = projectSyncRuleDao.selectInProjectIds(undeleteProjectIds);
assertTrue(syncRule.stream().allMatch(r -> !r.getIsAutoSync()));
}
@Test
@Sql("classpath:sql/domain/group/MemberRemove.sql")
void removeMember() {
int groupId = -999;
// remove group member
assertTrue(userRoleDao.hasRole(-1, groupId));
groupService.removeMember(groupId, -1);
assertFalse(userRoleDao.hasRole(-1, groupId));
// remove group owner
assertTrue(userRoleDao.hasRole(-2, groupId));
groupService.removeMember(groupId, -2);
assertFalse(userRoleDao.hasRole(-2, groupId));
assertTrue(userRoleDao.hasRole(-2, -1000));
}
@Test
@Sql("classpath:sql/domain/group/MemberAdd.sql")
void addMember() {
int groupId = -999;
assertFalse(userRoleDao.hasRole(-1, groupId, RoleConstants.GROUP_MEMBER));
GroupMemberCreateRequest request = new GroupMemberCreateRequest();
request.setRole(RoleConstants.GROUP_MEMBER);
request.setUserId(-1);
groupService.addMember(groupId, request);
assertTrue(userRoleDao.hasRole(-1, groupId, RoleConstants.GROUP_MEMBER));
}
@Test
@Sql("classpath:sql/domain/group/MemberAdd.sql")
void addMemberWhenWasGroupMember() {
int groupId = -1000;
GroupMemberCreateRequest request = new GroupMemberCreateRequest();
request.setRole(RoleConstants.GROUP_MEMBER);
request.setUserId(-2);
var err = assertThrows(DatabasirException.class, () -> groupService.addMember(groupId, request));
assertEquals(DomainErrors.USER_ROLE_DUPLICATE.getErrCode(), err.getErrCode());
}
@Test
@Sql("classpath:sql/domain/group/MemberRoleChange.sql")
void changeMemberRole() {
int groupId = -999;
int userId = -1;
groupService.changeMemberRole(groupId, userId, RoleConstants.GROUP_MEMBER);
assertTrue(userRoleDao.hasRole(userId, groupId, RoleConstants.GROUP_MEMBER));
groupService.changeMemberRole(groupId, userId, RoleConstants.GROUP_OWNER);
assertTrue(userRoleDao.hasRole(userId, groupId, RoleConstants.GROUP_OWNER));
List<UserRolePojo> roles = userRoleDao.selectByUserIds(List.of(userId));
assertEquals(1, roles.size());
}
}

125
core/src/test/java/com/databasir/core/domain/project/service/ProjectServiceTest.java

@ -0,0 +1,125 @@
package com.databasir.core.domain.project.service;
import com.databasir.core.BaseTest;
import com.databasir.core.domain.project.data.DataSourcePropertyValue;
import com.databasir.core.domain.project.data.ProjectCreateRequest;
import com.databasir.core.domain.project.data.ProjectCreateRequest.DataSourceCreateRequest;
import com.databasir.core.domain.project.data.ProjectCreateRequest.ProjectSyncRuleCreateRequest;
import com.databasir.core.domain.project.data.ProjectTestConnectionRequest;
import com.databasir.core.domain.project.data.ProjectUpdateRequest;
import com.databasir.core.domain.project.data.ProjectUpdateRequest.ProjectSyncRuleUpdateRequest;
import com.databasir.core.infrastructure.connection.DatabaseTypes;
import com.databasir.dao.impl.ProjectDao;
import com.databasir.dao.impl.ProjectSyncRuleDao;
import com.databasir.dao.tables.pojos.ProjectSyncRulePojo;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Transactional
class ProjectServiceTest extends BaseTest {
@Autowired
private ProjectService projectService;
@Autowired
private ProjectDao projectDao;
@Autowired
private ProjectSyncRuleDao projectSyncRuleDao;
@Value("${databasir.db.username}")
private String dbUsername;
@Value("${databasir.db.password}")
private String dbPassword;
@Value("${databasir.db.url}")
private String dbUrl;
@Test
void create() {
ProjectCreateRequest request = new ProjectCreateRequest();
request.setName("ut");
request.setDescription("integration test");
request.setGroupId(-1000);
DataSourceCreateRequest dataSource = new DataSourceCreateRequest();
dataSource.setUsername("root");
dataSource.setPassword("123456");
dataSource.setUrl("localhost:3306");
dataSource.setDatabaseName("databasir");
dataSource.setSchemaName("databasir");
dataSource.setDatabaseType(DatabaseTypes.MYSQL);
dataSource.setProperties(List.of(new DataSourcePropertyValue("useSSL", "false")));
request.setDataSource(dataSource);
ProjectSyncRuleCreateRequest syncRule = new ProjectSyncRuleCreateRequest();
syncRule.setIgnoreTableNameRegexes(List.of("flywway.*", "demo.*"));
syncRule.setIgnoreColumnNameRegexes(List.of("id.*", "demo.*"));
syncRule.setIsAutoSync(true);
syncRule.setAutoSyncCron("0 0 0-23 0 0 ? *");
request.setProjectSyncRule(syncRule);
Integer id = projectService.create(request);
Assertions.assertNotNull(id);
}
@Test
@Sql("classpath:sql/domain/project/Update.sql")
void update() {
ProjectUpdateRequest request = new ProjectUpdateRequest();
request.setId(-1000);
request.setName("ut");
request.setDescription("integration test");
var dataSource = new ProjectUpdateRequest.DataSourceUpdateRequest();
dataSource.setUsername("root");
dataSource.setPassword("123456");
dataSource.setUrl("localhost:3306");
dataSource.setDatabaseName("databasir");
dataSource.setSchemaName("databasir");
dataSource.setDatabaseType(DatabaseTypes.MYSQL);
dataSource.setProperties(List.of(new DataSourcePropertyValue("useSSL", "false")));
request.setDataSource(dataSource);
var syncRule = new ProjectSyncRuleUpdateRequest();
syncRule.setIgnoreTableNameRegexes(List.of("flywway.*", "demo.*"));
syncRule.setIgnoreColumnNameRegexes(List.of("id.*", "demo.*"));
syncRule.setIsAutoSync(true);
syncRule.setAutoSyncCron("0 0 0-23 0 0 ? *");
request.setProjectSyncRule(syncRule);
projectService.update(-999, request);
}
@Test
@Sql("classpath:sql/domain/project/Delete.sql")
void delete() {
int projectId = -1000;
projectService.delete(projectId);
Assertions.assertFalse(projectDao.existsById(projectId));
ProjectSyncRulePojo syncRule = projectSyncRuleDao.selectByProjectId(projectId);
Assertions.assertNotNull(syncRule);
Assertions.assertNotNull(syncRule.getAutoSyncCron());
Assertions.assertFalse(syncRule.getIsAutoSync());
}
@Test
void testConnection() {
ProjectTestConnectionRequest request = new ProjectTestConnectionRequest();
request.setUsername(dbUsername);
request.setPassword(dbPassword);
request.setUrl(dbUrl);
request.setDatabaseName("databasir");
request.setSchemaName("databasir");
request.setDatabaseType(DatabaseTypes.MYSQL);
request.setProperties(List.of(new DataSourcePropertyValue("useSSL", "false")));
projectService.testConnection(request);
}
}

54
core/src/test/java/com/databasir/core/domain/user/service/UserProjectServiceTest.java

@ -0,0 +1,54 @@
package com.databasir.core.domain.user.service;
import com.databasir.common.DatabasirException;
import com.databasir.core.BaseTest;
import com.databasir.core.domain.DomainErrors;
import com.databasir.dao.impl.UserFavoriteProjectDao;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Transactional
class UserProjectServiceTest extends BaseTest {
@Autowired
private UserProjectService userProjectService;
@Autowired
private UserFavoriteProjectDao userFavoriteProjectDao;
@Test
@Sql("classpath:sql/domain/user/AddFavorites.sql")
void addFavorites() {
int userId = 1;
int projectId = 999;
userProjectService.addFavorites(projectId, userId);
var data = userFavoriteProjectDao.selectByUserIdAndProjectIds(userId, List.of(projectId));
Assertions.assertEquals(1, data.size());
}
@Test
void addFavoritesWhenProjectNotExists() {
DatabasirException ex = Assertions.assertThrows(DatabasirException.class,
() -> userProjectService.addFavorites(-999, 1));
Assertions.assertEquals(DomainErrors.PROJECT_NOT_FOUND.getErrCode(), ex.getErrCode());
}
@Test
@Sql("classpath:sql/domain/user/RemoveFavorites.sql")
void removeFavorites() {
int projectId = 999;
int userId = 999;
// remove exists data
userProjectService.removeFavorites(projectId, userId);
var data = userFavoriteProjectDao.selectByUserIdAndProjectIds(userId, List.of(projectId));
Assertions.assertEquals(0, data.size());
// remove unknown data
userProjectService.removeFavorites(-999, -999);
}
}

55
core/src/test/java/com/databasir/core/domain/user/service/UserServiceTest.java

@ -2,21 +2,29 @@ package com.databasir.core.domain.user.service;
import com.databasir.core.BaseTest;
import com.databasir.core.domain.user.data.UserCreateRequest;
import com.databasir.core.domain.user.data.UserNicknameUpdateRequest;
import com.databasir.core.domain.user.data.UserPasswordUpdateRequest;
import com.databasir.core.domain.user.data.UserSource;
import com.databasir.core.infrastructure.event.subscriber.UserEventSubscriber;
import com.databasir.dao.impl.LoginDao;
import com.databasir.dao.impl.UserDao;
import com.databasir.dao.impl.UserRoleDao;
import com.databasir.dao.tables.pojos.LoginPojo;
import com.databasir.dao.tables.pojos.UserPojo;
import com.databasir.dao.tables.pojos.UserRolePojo;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
import static com.databasir.core.infrastructure.constant.RoleConstants.SYS_OWNER;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
@ -35,6 +43,9 @@ class UserServiceTest extends BaseTest {
@Autowired
private LoginDao loginDao;
@Autowired
private UserRoleDao userRoleDao;
@Test
void create() {
doNothing().when(userEventSubscriber).onUserCreated(any());
@ -56,7 +67,7 @@ class UserServiceTest extends BaseTest {
@Sql("classpath:sql/domain/user/RenewPassword.sql")
void renewPassword() {
doNothing().when(userEventSubscriber).onPasswordRenewed(any());
String newPassword = userService.renewPassword(1, 2);
String newPassword = userService.renewPassword(-1, -2);
assertNotNull(newPassword);
assertEquals(8, newPassword.length());
verify(userEventSubscriber, times(1)).onPasswordRenewed(any());
@ -65,7 +76,7 @@ class UserServiceTest extends BaseTest {
@Test
@Sql("classpath:sql/domain/user/SwitchEnableStatus.sql")
void switchEnableStatusToFalse() {
Integer userId = 1;
Integer userId = -999;
userService.switchEnableStatus(userId, false);
UserPojo user = userDao.selectById(userId);
assertNotNull(user);
@ -76,22 +87,54 @@ class UserServiceTest extends BaseTest {
}
@Test
@Sql("classpath:sql/domain/user/RemoveSysOwnerFrom.sql")
void removeSysOwnerFrom() {
// TODO
Integer userId = -998;
userService.removeSysOwnerFrom(userId);
List<UserRolePojo> roles = userRoleDao.selectByUserIds(Collections.singletonList(userId))
.stream().filter(role -> role.getRole().equals(SYS_OWNER))
.collect(Collectors.toList());
assertEquals(0, roles.size());
}
@Test
@Sql("classpath:sql/domain/user/AddSysOwnerTo.sql")
void addSysOwnerTo() {
// TODO
Integer userId = -999;
userService.addSysOwnerTo(userId);
List<UserRolePojo> roles = userRoleDao.selectByUserIds(Collections.singletonList(userId))
.stream().filter(role -> role.getRole().equals(SYS_OWNER))
.collect(Collectors.toList());
assertEquals(1, roles.size());
assertEquals(SYS_OWNER, roles.iterator().next().getRole());
}
@Test
@Sql("classpath:sql/domain/user/UpdatePassword.sql")
void updatePassword() {
// TODO
UserPasswordUpdateRequest request = new UserPasswordUpdateRequest();
request.setNewPassword("123456");
request.setConfirmNewPassword("123456");
request.setOriginPassword("123123");
Integer userId = -999;
userService.updatePassword(userId, request);
// should delete login info
Optional<LoginPojo> loginPojoOpt = loginDao.selectByUserId(userId);
assertTrue(loginPojoOpt.isEmpty());
}
@Test
@Sql("classpath:sql/domain/user/UpdateNickname.sql")
void updateNickname() {
// TODO
Integer userId = -999;
UserNicknameUpdateRequest request = new UserNicknameUpdateRequest();
String nickname = UUID.randomUUID().toString();
request.setNickname(nickname);
userService.updateNickname(userId, request);
UserPojo user = userDao.selectById(userId);
assertNotNull(user);
assertEquals(nickname, user.getNickname());
}
}

4
core/src/test/java/com/databasir/core/infrastructure/event/subscriber/DocumentEventSubscriberTest.java

@ -11,12 +11,14 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
@Transactional
class DocumentEventSubscriberTest extends BaseTest {
@Autowired
@ -52,7 +54,7 @@ class DocumentEventSubscriberTest extends BaseTest {
event.setDiff(diff);
event.setNewVersion(2L);
event.setOldVersion(1L);
event.setProjectId(1);
event.setProjectId(-1);
documentEventSubscriber.onDocumentUpdated(event);
verify(mailSender, times(1)).batchSendHtml(any(), any(), any(), any());
}

4
core/src/test/java/com/databasir/core/infrastructure/event/subscriber/UserEventSubscriberTest.java

@ -10,11 +10,13 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import static org.mockito.Mockito.*;
@Transactional
class UserEventSubscriberTest extends BaseTest {
@Autowired
@ -39,7 +41,7 @@ class UserEventSubscriberTest extends BaseTest {
.newPassword("123456")
.nickname("demo")
.renewTime(LocalDateTime.now())
.renewByUserId(1)
.renewByUserId(-999)
.build();
userEventSubscriber.onPasswordRenewed(event);
verify(mailSender, times(1)).sendHtml(any(), any(), any(), any());

4
core/src/test/resources/sql/domain/database/CreateDuplicate.sql

@ -0,0 +1,4 @@
INSERT INTO databasir.database_type (id, database_type, icon, description, jdbc_driver_file_url, jdbc_driver_class_name,
jdbc_protocol, url_pattern)
VALUES (-1000, 'ut-mysql', '', 'system default mysql', 'N/A', 'com.mysql.cj.jdbc.Driver', 'jdbc:mysql',
'{{jdbc.protocol}}://{{db.url}}/{{db.name}}');

4
core/src/test/resources/sql/domain/database/DeleteById.sql

@ -0,0 +1,4 @@
INSERT INTO databasir.database_type (id, database_type, icon, description, jdbc_driver_file_url, jdbc_driver_class_name,
jdbc_protocol, url_pattern)
VALUES (-1000, 'ut-mysql', '', 'system default mysql', 'N/A', 'com.mysql.cj.jdbc.Driver', 'jdbc:mysql',
'{{jdbc.protocol}}://{{db.url}}/{{db.name}}');

4
core/src/test/resources/sql/domain/database/Update.sql

@ -0,0 +1,4 @@
INSERT INTO databasir.database_type (id, database_type, icon, description, jdbc_driver_file_url, jdbc_driver_class_name,
jdbc_protocol, url_pattern)
VALUES (-1000, 'ut-mysql', '', 'system default mysql', 'N/A', 'com.mysql.cj.jdbc.Driver', 'jdbc:mysql',
'{{jdbc.protocol}}://{{db.url}}/{{db.name}}');

6
core/src/test/resources/sql/domain/discussion/Create.sql

@ -0,0 +1,6 @@
INSERT INTO databasir.`group` (id, name, description, deleted, update_at, create_at)
VALUES (-999, '会员平台 ut', '会员平台', 0, '2022-03-06 02:10:40', '2022-03-06 02:10:40');
INSERT INTO databasir.project (id, name, description, group_id, deleted, deleted_token, create_at)
VALUES (-999, 'demo test', 'demo', -999, 0, 1, '2022-03-06 02:11:02');

8
core/src/test/resources/sql/domain/discussion/DeleteById.sql

@ -0,0 +1,8 @@
INSERT INTO databasir.`group` (id, name, description, deleted, update_at, create_at)
VALUES (-999, '会员平台 ut', '会员平台', 0, '2022-03-06 02:10:40', '2022-03-06 02:10:40');
INSERT INTO databasir.project (id, name, description, group_id, deleted, deleted_token, create_at)
VALUES (-999, 'demo test', 'demo', -999, 0, 1, '2022-03-06 02:11:02');
INSERT INTO databasir.document_discussion(id, content, user_id, project_id, table_name, column_name)
VALUES (-999, 'demo test', -1, -999, 'ut', 'ut');

22
core/src/test/resources/sql/domain/group/GroupDelete.sql

@ -0,0 +1,22 @@
INSERT INTO databasir.`group` (id, name, description, deleted, update_at, create_at)
VALUES (-999, '会员平台 ut', '会员平台', 0, '2022-03-06 02:10:40', '2022-03-06 02:10:40');
INSERT INTO databasir.user_role (user_id, role, group_id)
VALUES (1000, 'GROUP_OWNER', -999),
(1001, 'GROUP_OWNER', -999),
(1002, 'GROUP_OWNER', -999),
(1003, 'GROUP_OWNER', -999),
(1004, 'GROUP_MEMBER', -999);
INSERT INTO databasir.project (id, name, description, group_id, deleted, deleted_token, create_at)
VALUES (-999, 'demo test', 'demo', -999, 0, 1, '2022-03-06 02:11:02'),
(-1000, 'demo test3', 'no member', -999, 0, 1, '2022-03-25 09:00:16'),
(-1001, 'demo test2', 'demo', -999, 0, 0, '2022-03-06 02:11:35');
INSERT INTO databasir.project_sync_rule (project_id, ignore_table_name_regex_array, ignore_column_name_regex_array,
is_auto_sync, auto_sync_cron)
VALUES (-999, '[]', '[]', 1, '0 0/20 * * * ? '),
(-1000, '[]', '[]', 1, '0 0/20 * * * ? '),
(-1001, '[]', '[]', 1, '0 0/20 * * * ? ');

10
core/src/test/resources/sql/domain/group/GroupUpdate.sql

@ -0,0 +1,10 @@
INSERT INTO databasir.`group` (id, name, description, deleted, update_at, create_at)
VALUES (-999, '会员平台 ut', '会员平台', 0, '2022-03-06 02:10:40', '2022-03-06 02:10:40'),
(-1000, '商品中心 ut', '商品中心', 0, '2022-03-06 02:11:53', '2022-03-06 02:11:53');
INSERT INTO databasir.user_role (user_id, role, group_id)
VALUES (1000, 'GROUP_OWNER', -999),
(1001, 'GROUP_OWNER', -999),
(1002, 'GROUP_OWNER', -999),
(1003, 'GROUP_OWNER', -999),
(1004, 'GROUP_MEMBER', -999);

7
core/src/test/resources/sql/domain/group/MemberAdd.sql

@ -0,0 +1,7 @@
INSERT INTO databasir.`group` (id, name, description, deleted, update_at, create_at)
VALUES (-999, '会员平台 ut', '会员平台', 0, '2022-03-06 02:10:40', '2022-03-06 02:10:40'),
(-1000, '会员平台 ut2', '会员平台', 0, '2022-03-06 02:10:40', '2022-03-06 02:10:40');
INSERT INTO databasir.user_role (user_id, role, group_id)
VALUES (-2, 'GROUP_MEMBER', -999),
(-2, 'GROUP_OWNER', -1000);

9
core/src/test/resources/sql/domain/group/MemberRemove.sql

@ -0,0 +1,9 @@
INSERT INTO databasir.`group` (id, name, description, deleted, update_at, create_at)
VALUES (-999, '会员平台 ut', '会员平台', 0, '2022-03-06 02:10:40', '2022-03-06 02:10:40'),
(-1000, '会员平台 ut2', '会员平台', 0, '2022-03-06 02:10:40', '2022-03-06 02:10:40');
INSERT INTO databasir.user_role (user_id, role, group_id)
VALUES (-1, 'SYS_OWNER', NULL),
(-1, 'GROUP_OWNER', -999),
(-2, 'GROUP_MEMBER', -999),
(-2, 'GROUP_OWNER', -1000);

5
core/src/test/resources/sql/domain/group/MemberRoleChange.sql

@ -0,0 +1,5 @@
INSERT INTO databasir.`group` (id, name, description, deleted, update_at, create_at)
VALUES (-999, '会员平台 ut', '会员平台', 0, '2022-03-06 02:10:40', '2022-03-06 02:10:40');
INSERT INTO databasir.user_role (user_id, role, group_id)
VALUES (-1, 'GROUP_OWNER', -999);

10
core/src/test/resources/sql/domain/project/Delete.sql

@ -0,0 +1,10 @@
INSERT INTO databasir.`group` (id, name, description, deleted, update_at, create_at)
VALUES (-999, '会员平台 ut', '会员平台', 0, '2022-03-06 02:10:40', '2022-03-06 02:10:40');
INSERT INTO databasir.project (id, name, description, group_id, deleted, deleted_token, create_at)
VALUES (-1000, 'demo test2', 'demo', -999, 0, 0, '2022-03-06 02:11:35');
INSERT INTO databasir.project_sync_rule (project_id, ignore_table_name_regex_array, ignore_column_name_regex_array,
is_auto_sync, auto_sync_cron)
VALUES (-1000, '[]', '[]', 1, '0 0/20 * * * ? ');

15
core/src/test/resources/sql/domain/project/Update.sql

@ -0,0 +1,15 @@
INSERT INTO databasir.`group` (id, name, description, deleted, update_at, create_at)
VALUES (-999, '会员平台 ut', '会员平台', 0, '2022-03-06 02:10:40', '2022-03-06 02:10:40');
INSERT INTO databasir.project (id, name, description, group_id, deleted, deleted_token, create_at)
VALUES (-1000, 'demo test2', 'demo', -999, 0, 0, '2022-03-06 02:11:35');
INSERT INTO databasir.project_sync_rule (project_id, ignore_table_name_regex_array, ignore_column_name_regex_array,
is_auto_sync, auto_sync_cron)
VALUES (-1000, '[]', '[]', 0, '0 0/20 * * * ? ');
INSERT INTO databasir.data_source(id, project_id, database_name, schema_name, database_type, url, username, password)
VALUES (-1000, -1000, 'databasir', 'databasir', 'mysql', 'localhost:3306', 'root', '123456');
INSERT INTO databasir.data_source_property(data_source_id, `key`, value)
VALUES (-1000, 'useSSL', 'true')

2
core/src/test/resources/sql/domain/user/AddFavorites.sql

@ -0,0 +1,2 @@
INSERT IGNORE INTO databasir.project (id, NAME, DESCRIPTION, group_id, deleted, deleted_token, create_at)
VALUES (999, 'addFavoritesTest', 'demo', 1, 0, 1, '2022-03-06 02:11:02');

8
core/src/test/resources/sql/domain/user/AddSysOwnerTo.sql

@ -1,4 +1,6 @@
INSERT IGNORE INTO databasir.user (id, email, username, password, nickname, avatar, enabled)
VALUES (1, 'N/A', 'databasir', '$2a$10$8Wjfdbbk76jDNbQ0zKq', 'Databasir Admin', NULL, 1),
(2, 'sysOwner@databasir.com', 'sysOwner', '$2a$10$wXPDzPceCXeU1PLXGKRAEW', 'a', NULL, 1),
(3, 'notSysOwner@databasir.com', 'notSysOwner', '$2a$10$wXPDzPceU1PLXGKRAEW', 'b', NULL, 1);
VALUES (-998, 'sysOwner@databasir.com', 'sysOwner', '$2a$10$wXPDzPceCXeU1PLXGKRAEW', 'a', NULL, 1),
(-999, 'notSysOwner@databasir.com', 'notSysOwner', '$2a$10$wXPDzPceU1PLXGKRAEW', 'b', NULL, 1);
INSERT IGNORE INTO databasir.user_role (user_id, role, group_id, create_at)
VALUES (-998, 'SYS_OWNER', NULL, '2022-03-06 02:05:30');

4
core/src/test/resources/sql/domain/user/RemoveFavorites.sql

@ -0,0 +1,4 @@
INSERT IGNORE INTO databasir.user_favorite_project (user_id, project_id, create_at)
VALUES (999, 999, '2022-03-06 10:25:47'),
(999, 1000, '2022-03-10 09:13:30');

6
core/src/test/resources/sql/domain/user/RemoveSysOwnerFrom.sql

@ -0,0 +1,6 @@
INSERT IGNORE INTO databasir.user (id, email, username, password, nickname, avatar, enabled)
VALUES (-998, 'sysOwner@databasir.com', 'sysOwner', '$2a$10$wXPDzPceCXeU1PLXGKRAEW', 'a', NULL, 1),
(-999, 'notSysOwner@databasir.com', 'notSysOwner', '$2a$10$wXPDzPceU1PLXGKRAEW', 'b', NULL, 1);
INSERT IGNORE INTO databasir.user_role (user_id, role, group_id, create_at)
VALUES (-998, 'SYS_OWNER', NULL, '2022-03-06 02:05:30');

4
core/src/test/resources/sql/domain/user/RenewPassword.sql

@ -1,3 +1,3 @@
INSERT IGNORE INTO databasir.user (id, email, username, password, nickname, avatar, enabled)
VALUES (1, 'N/A', 'databasir', '$2a$10$8WjfdbbDpzvkz5Rc.8TBk76jDNbQ0zKq', 'Databasir Admin', NULL, 1),
(2, 'vran@databasir.com', 'vran', '$2a$10$wXPDzPceCpqYErlZ3DRh.gOpgXXeU1PLXGKRAEW', 'vranssss', NULL, 1);
VALUES (-1, 'N/A', 'databasir', '$2a$10$8WjfdbbDpzvkz5Rc.8TBk76jDNbQ0zKq', 'Databasir Admin', NULL, 1),
(-2, 'vran@databasir.com', 'vran', '$2a$10$wXPDzPceCpqYErlZ3DRh.gOpgXXeU1PLXGKRAEW', 'vranssss', NULL, 1);

5
core/src/test/resources/sql/domain/user/SwitchEnableStatus.sql

@ -1,7 +1,6 @@
INSERT IGNORE INTO databasir.user (id, email, username, password, nickname, avatar, enabled)
VALUES (1, 'N/A', 'databasir', '$2a$10$8WjfdbbDpzvkz5Rc.8TBk76jDNbQ0zKq', 'Databasir Admin', NULL, 1),
(2, 'vran@databasir.com', 'vran', '$2a$10$wXPDzPceCpqYErlZ3DRh.gOpgXXeU1PLXGKRAEW', 'vranssss', NULL, 1);
VALUES (-999, 'vran@databasir.com', 'vran', '$2a$10$wXPDzPceCpqYErlZ3DRh.gOpgXXeU1PLXGKRAEW', 'vranssss', NULL, 1);
INSERT IGNORE INTO databasir.login (user_id, access_token, refresh_token, access_token_expire_at,
refresh_token_expire_at)
VALUES (2, 'eyJ0eXAiOiJKV1QM', '1a884c14ef6542ce0261', '2022-03-12 20:24:28', '2022-03-27 20:09:29');
VALUES (-999, 'eyJ0eXAiOiJKV1QM', '1a884c14ef6542ce0261', '2022-03-12 20:24:28', '2022-03-27 20:09:29');

7
core/src/test/resources/sql/domain/user/UpdateNickname.sql

@ -0,0 +1,7 @@
INSERT IGNORE INTO databasir.login (user_id, access_token, refresh_token, access_token_expire_at,
refresh_token_expire_at)
VALUES (-999, 'eyJ0eXAiOiJKV1QM', '1a884c14ef6542ce0261', '2022-03-12 20:24:28', '2022-03-27 20:09:29');
INSERT IGNORE INTO databasir.user (id, email, username, password, nickname, avatar, enabled)
VALUES (-999, 'demo2@databasir.com', 'demo2', '$2a$10$KTi5HBIBURn/5h9d7sp2DeIxK4T03vlh34dSwyJphjeNBRGWTzEDK', 'demo2',
NULL, 1);

7
core/src/test/resources/sql/domain/user/UpdatePassword.sql

@ -0,0 +1,7 @@
INSERT INTO databasir.login (user_id, access_token, refresh_token, access_token_expire_at,
refresh_token_expire_at)
VALUES (-999, 'eyJ0eXAiOiJKV1QM', '1a884c14ef6542ce0261', '2022-03-12 20:24:28', '2022-03-27 20:09:29');
INSERT INTO databasir.user (id, email, username, password, nickname, avatar, enabled, update_at, create_at)
VALUES (-999, 'demo2@databasir.com', 'demo2', '$2a$10$KTi5HBIBURn/5h9d7sp2DeIxK4T03vlh34dSwyJphjeNBRGWTzEDK', 'demo2',
NULL, 1, '2022-03-25 15:02:49', '2022-03-25 15:02:49');

38
core/src/test/resources/sql/event/subscriber/DocumentEventSubscriberTest.sql

@ -1,22 +1,22 @@
INSERT IGNORE INTO databasir.user (id, email, username, password, nickname, avatar, enabled)
VALUES (1, 'N/A', 'databasir', '$2a$10$8WjfdbbDpzvkz5Rc.8TBk76jDNbQ0zKq', 'Databasir Admin', NULL, 1),
(2, 'vran@databasir.com', 'vran', '$2a$10$wXPDzPceCpqYErlZ3DRh.gOpgXXeU1PLXGKRAEW', 'vranssss', NULL, 1),
(3, 'test@databasir.com', 'test', '$2a$10$XbnZlQB26cKKGB4WLlgZxxwbUr9tD1Amn/3Tf5H0i', 'test', NULL, 1),
(4, 'sample@databasir.com', 'sample', '$2a$10$Ua0zrJ7.HDb6ZIRNWb7fCJiG2OZRTN1.', 'sample', NULL, 1),
(5, 'demo@databasir.com', 'demo', '$2a$10$J4JT19JBO3LpWAvRARDxieFtm/pFQtna.dDq', 'demo', NULL, 0);
INSERT INTO databasir.user (id, email, username, password, nickname, avatar, enabled)
VALUES (-1, 'jack@databasir.com', 'jack', '$2a$10$8WjfdbbDpzvkz5Rc.8TBk76jDNbQ0zKq', 'Databasir Admin', NULL, 1),
(-2, 'vran@databasir.com', 'vran', '$2a$10$wXPDzPceCpqYErlZ3DRh.gOpgXXeU1PLXGKRAEW', 'vranssss', NULL, 1),
(-3, 'test@databasir.com', 'test', '$2a$10$XbnZlQB26cKKGB4WLlgZxxwbUr9tD1Amn/3Tf5H0i', 'test', NULL, 1),
(-4, 'sample@databasir.com', 'sample', '$2a$10$Ua0zrJ7.HDb6ZIRNWb7fCJiG2OZRTN1.', 'sample', NULL, 1),
(-5, 'demo@databasir.com', 'demo', '$2a$10$J4JT19JBO3LpWAvRARDxieFtm/pFQtna.dDq', 'demo', NULL, 0);
INSERT IGNORE INTO databasir.project (id, name, description, group_id, deleted, deleted_token)
VALUES (1, 'demo', 'demo', 1, 0, 1),
(2, 'no member', 'no member', 1, 0, 1);
INSERT INTO databasir.project (id, name, description, group_id, deleted, deleted_token)
VALUES (-1, 'demo', 'demo', 1, 0, 1),
(-2, 'no member', 'no member', 1, 0, 1);
INSERT IGNORE INTO databasir.`group` (id, name, description, deleted)
VALUES (1, '会员平台', '会员平台', 0),
(2, '成员为空', '会员平台', 0);
INSERT INTO databasir.`group` (id, name, description, deleted)
VALUES (-1, '会员平台', '会员平台', 0),
(-2, '成员为空', '会员平台', 0);
INSERT IGNORE INTO databasir.user_role (user_id, role, group_id)
VALUES (1, 'SYS_OWNER', NULL),
(1, 'GROUP_OWNER', 1),
(2, 'GROUP_OWNER', 1),
(3, 'GROUP_MEMBER', 1),
(4, 'GROUP_OWNER', 1),
(5, 'GROUP_OWNER', 1);
INSERT INTO databasir.user_role (user_id, role, group_id)
VALUES (-1, 'SYS_OWNER', NULL),
(-1, 'GROUP_OWNER', 1),
(-2, 'GROUP_OWNER', 1),
(-3, 'GROUP_MEMBER', 1),
(-4, 'GROUP_OWNER', 1),
(-5, 'GROUP_OWNER', 1);

8
core/src/test/resources/sql/event/subscriber/UserEventSubscriberTest.sql

@ -1,7 +1,3 @@
INSERT IGNORE INTO databasir.user (id, email, username, password, nickname, avatar, enabled)
VALUES (1, 'N/A', 'databasir', '$2a$10$8WjfdbbDpzvkz5Rc.8TBk76jDNbQ0zKq', 'Databasir Admin', NULL, 1),
(2, 'vran@databasir.com', 'vran', '$2a$10$wXPDzPceCpqYErlZ3DRh.gOpgXXeU1PLXGKRAEW', 'vranssss', NULL, 1),
(3, 'test@databasir.com', 'test', '$2a$10$XbnZlQB26cKKGB4WLlgZxxwbUr9tD1Amn/3Tf5H0i', 'test', NULL, 1),
(4, 'sample@databasir.com', 'sample', '$2a$10$Ua0zrJ7.HDb6ZIRNWb7fCJiG2OZRTN1.', 'sample', NULL, 1),
(5, 'demo@databasir.com', 'demo', '$2a$10$J4JT19JBO3LpWAvRARDxieFtm/pFQtna.dDq', 'demo', NULL, 0);
INSERT INTO databasir.user (id, email, username, password, nickname, avatar, enabled)
VALUES (-999, 'vran@databasir.com', 'vran', '$2a$10$wXPDzPceCpqYErlZ3DRh.gOpgXXeU1PLXGKRAEW', 'vranssss', NULL, 1);

6
dao/src/main/java/com/databasir/dao/impl/BaseDao.java

@ -86,6 +86,12 @@ public abstract class BaseDao<R> {
.fetchOptionalInto(pojoType);
}
public List<R> selectList(Condition condition) {
return getDslContext()
.select(table.fields()).from(table).where(condition)
.fetchInto(pojoType);
}
public R selectOne(Condition condition) {
return selectOptionalOne(condition)
.orElseThrow(() -> new DataNotExistsException("data not exists in "

Loading…
Cancel
Save