🐛 测试ok

This commit is contained in:
你一个人在这儿干嘛你是来拉屎的吧 2023-04-06 19:41:15 +08:00 committed by Zeeland
parent c2263de3b7
commit 83fb8d5330
6 changed files with 287 additions and 4 deletions

View File

@ -840,3 +840,9 @@ VALUES (2, 1, '100000002', 1207980.00000000, 2, '2020-11-26 21:37:18', '1');
INSERT INTO forest.forest_bank_account (id, id_bank, bank_account, account_balance, account_owner, created_time, INSERT INTO forest.forest_bank_account (id, id_bank, bank_account, account_balance, account_owner, created_time,
account_type) account_type)
VALUES (1, 1, '100000001', 997500000.00000000, 1, '2020-11-26 21:36:21', '1'); VALUES (1, 1, '100000001', 997500000.00000000, 1, '2020-11-26 21:36:21', '1');
INSERT INTO `forest`.`forest_bank_account` (`id`, `id_bank`, `bank_account`, `account_balance`, `account_owner`,
`created_time`, `account_type`)
VALUES (3, 1, '100000061', 100.00000000, 65001, '2020-11-26 21:37:18', '0');
INSERT INTO `forest`.`forest_bank_account` (`id`, `id_bank`, `bank_account`, `account_balance`, `account_owner`,
`created_time`, `account_type`)
VALUES (4, 1, '100000063', 100.00000000, 65003, '2020-11-26 21:37:18', '0');

View File

@ -1,28 +1,68 @@
package com.rymcu.forest.service; package com.rymcu.forest.service;
import com.rymcu.forest.base.BaseServiceTest; import com.rymcu.forest.base.BaseServiceTest;
import com.rymcu.forest.entity.Role;
import com.rymcu.forest.entity.User;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* 角色service测试
*/
class RoleServiceTest extends BaseServiceTest { class RoleServiceTest extends BaseServiceTest {
@Autowired
private RoleService roleService;
@BeforeEach @BeforeEach
void setUp() { void setUp() {
} }
@Test @Test
@DisplayName("查询用户角色")
void selectRoleByUser() { void selectRoleByUser() {
User user = new User();
user.setIdUser(1L);
List<Role> roles = roleService.selectRoleByUser(user);
assertFalse(roles.isEmpty());
user.setIdUser(0L);
roleService.selectRoleByUser(user);
assertFalse(roles.isEmpty());
} }
@Test @Test
@DisplayName("查询用户角色")
void findByIdUser() { void findByIdUser() {
List<Role> roles = roleService.findByIdUser(1L);
assertFalse(roles.isEmpty());
roles = roleService.findByIdUser(0L);
assertTrue(roles.isEmpty());
} }
@Test @Test
@DisplayName("更新角色状态")
void updateStatus() { void updateStatus() {
boolean b = roleService.updateStatus(1L, "1");
assertTrue(b);
} }
@Test @Test
@DisplayName("添加/更新角色")
void saveRole() { void saveRole() {
Role role = new Role();
role.setName("test_role");
role.setStatus("0");
role.setWeights(1);
boolean b = roleService.saveRole(role);
assertTrue(b);
} }
} }

View File

@ -1,16 +1,42 @@
package com.rymcu.forest.service; package com.rymcu.forest.service;
import com.rymcu.forest.base.BaseServiceTest; import com.rymcu.forest.base.BaseServiceTest;
import com.rymcu.forest.entity.Sponsor;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import java.math.BigDecimal;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* 赞赏test
*/
class SponsorServiceTest extends BaseServiceTest { class SponsorServiceTest extends BaseServiceTest {
@Autowired
private SponsorService sponsorService;
@BeforeEach @BeforeEach
void setUp() { void setUp() {
} }
@Test @Test
@DisplayName("赞赏")
void sponsorship() { void sponsorship() {
Sponsor sponsor = new Sponsor();
assertThrows(NullPointerException.class, () -> sponsorService.sponsorship(sponsor));
sponsor.setSponsor(1L);
sponsor.setSponsorshipMoney(BigDecimal.TEN);
sponsor.setDataType(200);
sponsor.setDataId(65001L);
assertThrows(DataIntegrityViolationException.class, () -> sponsorService.sponsorship(sponsor));
sponsor.setDataType(3);
sponsorService.sponsorship(sponsor);
} }
} }

View File

@ -1,28 +1,145 @@
package com.rymcu.forest.service; package com.rymcu.forest.service;
import com.rymcu.forest.base.BaseServiceTest; import com.rymcu.forest.base.BaseServiceTest;
import com.rymcu.forest.core.exception.BusinessException;
import com.rymcu.forest.dto.ArticleDTO;
import com.rymcu.forest.dto.ArticleTagDTO;
import com.rymcu.forest.dto.Author;
import com.rymcu.forest.dto.LabelModel;
import com.rymcu.forest.entity.Article;
import com.rymcu.forest.entity.Tag;
import com.rymcu.forest.entity.User;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
/**
* 标签test
*/
class TagServiceTest extends BaseServiceTest { class TagServiceTest extends BaseServiceTest {
/**
* 测试用的Article数据用于该单元测试的一系列操作
*/
private final ArticleDTO testArticle;
/**
* 与Article相关联的测试User数据(建表时提前放入)
*/
private final User testUser = new User();
@Autowired
private TagService tagService;
@Autowired
private ArticleService articleService;
{
// 构建数据之间的关联结构
Author testAuthor = Author.builder()
.idUser(2L)
.userArticleCount("0")
.userAccount("testUser")
.userNickname("testUser")
.userAvatarURL(null)
.build();
BeanUtils.copyProperties(testAuthor, testUser);
ArticleTagDTO tagDTO = ArticleTagDTO.builder()
.tagTitle("Test")
.tagDescription("Test")
.idTag(111)
.tagAuthorId(testUser.getIdUser())
.build();
List<ArticleTagDTO> tags = new ArrayList<>();
tags.add(tagDTO);
testArticle = ArticleDTO.builder()
.articleAuthor(testAuthor)
.articleAuthorId(testAuthor.getIdUser())
.articleContent("Test")
.articleLink("Test")
.articlePerfect("0")
.articlePermalink("Test")
.articleAuthorName(testAuthor.getUserNickname())
.articleCommentCount(0)
.articleStatus("0")
.articleTags("Test")
.articleContentHtml("<h1>Test</h1>")
.articleTitle("Test")
.articleType("0")
.articlePreviewContent("Test")
.articleSponsorCount(12)
.articlePermalink("Test")
.articleViewCount(0)
.tags(tags)
.build();
}
@BeforeEach @BeforeEach
void setUp() { void setUp() throws UnsupportedEncodingException {
Long articleId = articleService.postArticle(testArticle, testUser);
assertNotNull(articleId);
testArticle.setIdArticle(articleId);
} }
@Test @Test
void saveTagArticle() { @DisplayName("保存文章标签")
void saveTagArticle() throws UnsupportedEncodingException {
Article article = new Article();
BeanUtils.copyProperties(testArticle, article);
Integer integer = tagService.saveTagArticle(article, "article", testUser.getIdUser());
assertEquals(1, integer);
} }
@Test @Test
void cleanUnusedTag() { @DisplayName("清除未使用标签")
void cleanUnusedTag() throws Exception {
boolean b = tagService.cleanUnusedTag();
assertFalse(b);
Tag tag = new Tag();
tag.setTagDescription("test");
tag.setTagTitle("test");
Tag tag1 = tagService.saveTag(tag);
assertNotNull(tag1.getIdTag());
b = tagService.cleanUnusedTag();
assertTrue(b);
} }
@Test @Test
void saveTag() { @DisplayName("添加/更新标签")
void saveTag() throws Exception {
List<LabelModel> tagLabels = tagService.findTagLabels();
assertTrue(tagLabels.isEmpty());
Tag tag = new Tag();
tag.setTagDescription("test");
assertThrows(IllegalArgumentException.class, () -> tagService.saveTag(tag));
tag.setTagTitle("test");
Tag tag1 = tagService.saveTag(tag);
assertNotNull(tag1.getIdTag());
tagLabels = tagService.findTagLabels();
assertTrue(tagLabels.isEmpty());
tag.setIdTag(null);
assertThrows(BusinessException.class, () -> tagService.saveTag(tag));
} }
@Test @Test
@DisplayName("获取标签列表")
void findTagLabels() { void findTagLabels() {
List<LabelModel> tagLabels = tagService.findTagLabels();
assertTrue(tagLabels.isEmpty());
} }
} }

View File

@ -1,40 +1,96 @@
package com.rymcu.forest.service; package com.rymcu.forest.service;
import com.rymcu.forest.base.BaseServiceTest; import com.rymcu.forest.base.BaseServiceTest;
import com.rymcu.forest.core.exception.BusinessException;
import com.rymcu.forest.core.exception.ServiceException;
import com.rymcu.forest.dto.admin.TagDTO;
import com.rymcu.forest.dto.admin.TopicTagDTO;
import com.rymcu.forest.entity.Tag;
import com.rymcu.forest.entity.Topic;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
/**
* 主题test
*/
class TopicServiceTest extends BaseServiceTest { class TopicServiceTest extends BaseServiceTest {
@Autowired
private TopicService topicService;
@BeforeEach @BeforeEach
void setUp() { void setUp() {
} }
@Test @Test
@DisplayName("获取导航主题数据")
void findTopicNav() { void findTopicNav() {
List<Topic> topicNav = topicService.findTopicNav();
assertTrue(topicNav.isEmpty());
} }
@Test @Test
@DisplayName("根据 topicUri 获取主题信息及旗下标签数据")
void findTopicByTopicUri() { void findTopicByTopicUri() {
Topic topicNav = topicService.findTopicByTopicUri("rymcu.com/topic/123792");
assertNull(topicNav);
} }
@Test @Test
@DisplayName("新增/更新主题信息")
void saveTopic() { void saveTopic() {
Topic topic = new Topic();
assertThrows(IllegalArgumentException.class, () -> topicService.saveTopic(topic));
topic.setTopicTitle("test");
topicService.saveTopic(topic);
assertNotNull(topic.getIdTopic());
topic.setIdTopic(null);
assertThrows(BusinessException.class, () -> topicService.saveTopic(topic));
} }
@Test @Test
@DisplayName("查询未绑定标签")
void findUnbindTagsById() { void findUnbindTagsById() {
List<Tag> tags = topicService.findUnbindTagsById(1L, "test");
assertTrue(tags.isEmpty());
} }
@Test @Test
@DisplayName("绑定标签")
void bindTopicTag() { void bindTopicTag() {
TopicTagDTO topicTagDTO = new TopicTagDTO();
topicTagDTO.setIdTag(1L);
topicTagDTO.setIdTopic(1L);
topicService.bindTopicTag(topicTagDTO);
assertNotNull(topicTagDTO.getIdTag());
} }
@Test @Test
@DisplayName("取消绑定标签")
void unbindTopicTag() { void unbindTopicTag() {
TopicTagDTO topicTagDTO = new TopicTagDTO();
topicTagDTO.setIdTag(1L);
topicTagDTO.setIdTopic(1L);
assertThrows(ServiceException.class, () -> topicService.unbindTopicTag(topicTagDTO));
topicService.bindTopicTag(topicTagDTO);
assertDoesNotThrow(() -> topicService.unbindTopicTag(topicTagDTO));
} }
@Test @Test
@DisplayName("获取主题下标签列表")
void findTagsByTopicUri() { void findTagsByTopicUri() {
List<TagDTO> tags = topicService.findTagsByTopicUri("test.com/topic/123792");
assertNull(tags);
} }
} }

View File

@ -1,32 +1,70 @@
package com.rymcu.forest.service; package com.rymcu.forest.service;
import com.rymcu.forest.base.BaseServiceTest; import com.rymcu.forest.base.BaseServiceTest;
import com.rymcu.forest.dto.TransactionRecordDTO;
import com.rymcu.forest.entity.TransactionRecord;
import com.rymcu.forest.enumerate.TransactionEnum;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.math.BigDecimal;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
class TransactionRecordServiceTest extends BaseServiceTest { class TransactionRecordServiceTest extends BaseServiceTest {
@Autowired
private TransactionRecordService transactionRecordService;
@BeforeEach @BeforeEach
void setUp() { void setUp() {
} }
@Test @Test
void transfer() { void transfer() {
TransactionRecord transactionRecord = new TransactionRecord();
transactionRecord.setToBankAccount("100000061");
transactionRecord.setFormBankAccount("100000063");
transactionRecord.setMoney(BigDecimal.TEN);
transactionRecordService.transfer(transactionRecord);
assertNotNull(transactionRecord.getIdTransactionRecord());
} }
@Test @Test
@DisplayName("查询指定账户的交易记录")
void findTransactionRecords() { void findTransactionRecords() {
List<TransactionRecordDTO> transactionRecords = transactionRecordService.findTransactionRecords("100000001", "2020-05-05", "2025-05-05");
assertTrue(transactionRecords.isEmpty());
} }
@Test @Test
@DisplayName("根据用户主键进行交易")
void userTransfer() { void userTransfer() {
TransactionRecord transactionRecord = transactionRecordService.userTransfer(65001L, 65003L, TransactionEnum.ArticleSponsor);
assertNotNull(transactionRecord);
assertNotNull(transactionRecord.getIdTransactionRecord());
} }
@Test @Test
@DisplayName("社区银行转账/奖励发放")
void bankTransfer() { void bankTransfer() {
TransactionRecord transactionRecord = transactionRecordService.bankTransfer(65001L, TransactionEnum.Answer);
assertNotNull(transactionRecord);
assertNotNull(transactionRecord.getIdTransactionRecord());
} }
@Test @Test
@DisplayName("发放新手奖励")
void newbieRewards() { void newbieRewards() {
TransactionRecord transactionRecord = new TransactionRecord();
transactionRecord.setToBankAccount("100000061");
transactionRecord = transactionRecordService.newbieRewards(transactionRecord);
assertNotNull(transactionRecord.getIdTransactionRecord());
} }
} }