StructureMapperTests.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package cn.cslg.pas.mapper;
  2. import cn.cslg.pas.common.model.vo.StructureVO;
  3. import cn.cslg.pas.domain.Structure;
  4. import lombok.extern.slf4j.Slf4j;
  5. import org.junit.jupiter.api.Test;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.boot.test.context.SpringBootTest;
  8. import java.util.List;
  9. /**
  10. * 架构表的Mapper层接口测试类
  11. *
  12. * @Author chenyu
  13. * @Date 2023/3/10
  14. */
  15. @Slf4j
  16. @SpringBootTest
  17. public class StructureMapperTests {
  18. @Autowired
  19. private StructureMapper structureMapper;
  20. @Test
  21. void insert() {
  22. Structure structure = new Structure()
  23. .setParentId(1)
  24. .setPath("0,1,3")
  25. .setStructureName("手机背板")
  26. .setRemark("手机的二级架构")
  27. .setProductId(2);
  28. int rows = structureMapper.insert(structure);
  29. log.info("插入数据完成,受影响的行数为:{}", rows);
  30. }
  31. @Test
  32. void delete() {
  33. int rows = structureMapper.deleteById(0);
  34. log.info("根据id删除数据完成,受影响的行数为:{}", rows);
  35. }
  36. @Test
  37. void update() {
  38. Structure structure = new Structure()
  39. .setParentId(0)
  40. .setPath("0,1")
  41. .setStructureName("手机")
  42. .setRemark("手机的一级架构呀")
  43. .setProductId(2);
  44. int rows = structureMapper.update(structure);
  45. log.info("修改数据完成,受影响的行数为:{}", rows);
  46. }
  47. @Test
  48. void countByparentIdAndStructureName() {
  49. int count = structureMapper.countByparentIdAndStructureName(0, "手机后壳");
  50. log.info("根据名称统计数量完成,数量为:{}", count);
  51. }
  52. @Test
  53. void getStandardById() {
  54. Structure structure = structureMapper.getStandardById(3);
  55. log.info("根据id查询数据完成,数据信息为:{}", structure);
  56. }
  57. @Test
  58. void selectByParentId() {
  59. List<StructureVO> structureVOs = structureMapper.selectByParentId(3);
  60. log.info("根据父级id查询子级架构完成,数据信息为:");
  61. for (StructureVO structureVO : structureVOs) {
  62. log.info("{}", structureVO);
  63. }
  64. }
  65. @Test
  66. void selectByProductId() {
  67. List<StructureVO> structureVOs = structureMapper.selectByProductId(22);
  68. log.info("根据产品id查询数据完成,数据信息为:");
  69. for (StructureVO structureVO : structureVOs) {
  70. log.info("{}", structureVO);
  71. }
  72. }
  73. }