test: 添加 IoT 和 notice 模块的测试用例
- 新增 Device、Product、Serve 和 Message 相关的测试用例- 更新 Authority 和 Bulletin 服务的测试用例 - 修复 Param 服务的更新逻辑
This commit is contained in:
parent
f1e1c21dbf
commit
4d58a790ab
@ -44,7 +44,9 @@ public class ProductServiceImpl extends ServiceImpl<ProductRepository, Product>
|
|||||||
}
|
}
|
||||||
Product product = mapper.toEntity(dto);
|
Product product = mapper.toEntity(dto);
|
||||||
save(product);
|
save(product);
|
||||||
paramService.create(dto.getParams(), product.getId(), Param.ForeignType.PRODUCT);
|
if (dto.getParams() != null) {
|
||||||
|
paramService.create(dto.getParams(), product.getId(), Param.ForeignType.PRODUCT);
|
||||||
|
}
|
||||||
return product;
|
return product;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
package com.zsc.edu.gateway.domain.iot;
|
||||||
|
|
||||||
|
import com.zsc.edu.gateway.modules.iot.device.entity.Device;
|
||||||
|
import com.zsc.edu.gateway.modules.system.entity.BaseEntity;
|
||||||
|
|
||||||
|
public class DeviceBuilder extends BaseEntity {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private Device.Status state = Device.Status.UNACTIVATED;
|
||||||
|
private Boolean online = false;
|
||||||
|
|
||||||
|
public static DeviceBuilder aDevice() {
|
||||||
|
return new DeviceBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceBuilder name(String name) {
|
||||||
|
this.name = name;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceBuilder state(Device.Status state) {
|
||||||
|
this.state = state;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceBuilder online(Boolean online) {
|
||||||
|
this.online = online;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Device build() {
|
||||||
|
Device device = new Device();
|
||||||
|
device.setName(name);
|
||||||
|
device.setState(state);
|
||||||
|
device.setOnline(online);
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,7 @@ public class ParamBuilder extends BaseParamBuilder {
|
|||||||
public String uint;
|
public String uint;
|
||||||
public Param.Type type;
|
public Param.Type type;
|
||||||
public Param.ForeignType foreignType;
|
public Param.ForeignType foreignType;
|
||||||
|
public Long foreignId;
|
||||||
|
|
||||||
public static ParamBuilder aParam() {
|
public static ParamBuilder aParam() {
|
||||||
return new ParamBuilder();
|
return new ParamBuilder();
|
||||||
@ -18,6 +19,11 @@ public class ParamBuilder extends BaseParamBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ParamBuilder foreignId(Long foreignId) {
|
||||||
|
this.foreignId = foreignId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public ParamBuilder uint(String uint) {
|
public ParamBuilder uint(String uint) {
|
||||||
this.uint = uint;
|
this.uint = uint;
|
||||||
return this;
|
return this;
|
||||||
@ -35,6 +41,7 @@ public class ParamBuilder extends BaseParamBuilder {
|
|||||||
|
|
||||||
public Param build() {
|
public Param build() {
|
||||||
Param param = new Param();
|
Param param = new Param();
|
||||||
|
param.setForeignId(foreignId);
|
||||||
param.setUint(uint);
|
param.setUint(uint);
|
||||||
param.setType(type);
|
param.setType(type);
|
||||||
param.setForeignType(foreignType);
|
param.setForeignType(foreignType);
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
package com.zsc.edu.gateway.domain.iot;
|
||||||
|
|
||||||
|
import com.zsc.edu.gateway.modules.iot.product.entity.Product;
|
||||||
|
|
||||||
|
public class ProductBuilder extends BaseParamBuilder {
|
||||||
|
public String name;
|
||||||
|
public String productType;
|
||||||
|
public String model;
|
||||||
|
public Product.LinkType link;
|
||||||
|
|
||||||
|
public static ProductBuilder bProduct() {
|
||||||
|
return new ProductBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductBuilder name(String name) {
|
||||||
|
this.name = name;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductBuilder productType(String productType) {
|
||||||
|
this.productType = productType;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductBuilder model(String model) {
|
||||||
|
this.model = model;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductBuilder link(Product.LinkType link) {
|
||||||
|
this.link = link;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Product build() {
|
||||||
|
Product product = new Product();
|
||||||
|
product.setName(name);
|
||||||
|
product.setProductType(productType);
|
||||||
|
product.setModel(model);
|
||||||
|
product.setLink(link);
|
||||||
|
product.setParams(null);
|
||||||
|
return product;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package com.zsc.edu.gateway.domain.iot;
|
||||||
|
|
||||||
|
|
||||||
|
import com.zsc.edu.gateway.modules.iot.tsl.entity.Serve;
|
||||||
|
|
||||||
|
public class ServeBuilder extends BaseParamBuilder {
|
||||||
|
private String identifier;
|
||||||
|
private String name;
|
||||||
|
private Long productId;
|
||||||
|
|
||||||
|
public static ServeBuilder aServe() {
|
||||||
|
return new ServeBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServeBuilder identifier(String identifier) {
|
||||||
|
this.identifier = identifier;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServeBuilder name(String name) {
|
||||||
|
this.name = name;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServeBuilder productId(Long productId) {
|
||||||
|
this.productId = productId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Serve build() {
|
||||||
|
Serve serve = new Serve();
|
||||||
|
serve.setIdentifier(identifier);
|
||||||
|
serve.setName(name);
|
||||||
|
serve.setProductId(productId);
|
||||||
|
serve.setInputs(null);
|
||||||
|
serve.setOutputs(null);
|
||||||
|
return serve;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.zsc.edu.gateway.domain.notice;
|
||||||
|
|
||||||
|
import com.zsc.edu.gateway.modules.notice.entity.Bulletin;
|
||||||
|
import com.zsc.edu.gateway.modules.notice.entity.Message;
|
||||||
|
import com.zsc.edu.gateway.modules.notice.entity.MessageType;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class MessageBuilder {
|
||||||
|
public MessageType type;
|
||||||
|
public String title;
|
||||||
|
public String content;
|
||||||
|
|
||||||
|
public static MessageBuilder bMessage() {
|
||||||
|
return new MessageBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageBuilder type(MessageType type) {
|
||||||
|
this.type = type;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageBuilder title(String title) {
|
||||||
|
this.title = title;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageBuilder content(String content) {
|
||||||
|
this.content = content;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Message build() {
|
||||||
|
Message message = new Message();
|
||||||
|
message.setTitle(title);
|
||||||
|
message.setContent(content);
|
||||||
|
message.type = MessageType.other;
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
package com.zsc.edu.gateway.service.iot;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.zsc.edu.gateway.domain.iot.DeviceBuilder;
|
||||||
|
import com.zsc.edu.gateway.exception.ConstraintException;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.device.dto.DeviceDto;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.device.entity.Device;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.device.repo.DeviceRepository;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.device.service.DeviceService;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
public class DeviceServiceTest {
|
||||||
|
@Autowired
|
||||||
|
private DeviceService service;
|
||||||
|
@Autowired
|
||||||
|
private DeviceRepository repo;
|
||||||
|
|
||||||
|
private Device device1;
|
||||||
|
private Device device2;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
device1 = DeviceBuilder.aDevice().name("DEVICE_NAME_1").online(true).state(Device.Status.ACTIVATED).build();
|
||||||
|
repo.insert(device1);
|
||||||
|
device2 = DeviceBuilder.aDevice().name("DEVICE_NAME_2").online(false).state(Device.Status.ACTIVATED).build();
|
||||||
|
repo.insert(device2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void tearDown() {
|
||||||
|
repo.delete(new LambdaQueryWrapper<Device>()
|
||||||
|
.in(Device::getName, "DEVICE_NAME_1", "DEVICE_NAME_2", "DEVICE_3", "DEVICE_UPDATE"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void list() {
|
||||||
|
LambdaQueryWrapper<Device> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
assertEquals(2, service.list(queryWrapper.like(Device::getName, "DEVICE")).size());
|
||||||
|
assertEquals(1, service.list(queryWrapper.eq(Device::getName, device1.getName())).size());
|
||||||
|
// assertEquals(2, service.list().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createProduct() {
|
||||||
|
DeviceDto dto = new DeviceDto("DEVICE_3", null, null, null, null, 121L);
|
||||||
|
Device device = service.create(dto);
|
||||||
|
assertNotNull(device);
|
||||||
|
List<Device> devices = service.list(new LambdaQueryWrapper<Device>().like(Device::getName, "DEVICE"));
|
||||||
|
assertEquals(3, devices.size());
|
||||||
|
// 不能创建其他已存在的同名同代码部门
|
||||||
|
DeviceDto dto2 = new DeviceDto(device2.getName(), null, null, null, null, 121L);
|
||||||
|
assertThrows(ConstraintException.class, () -> service.create(dto2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void updateProduct() {
|
||||||
|
DeviceDto dto = new DeviceDto();
|
||||||
|
dto.setName("DEVICE_UPDATE");
|
||||||
|
service.update(dto, device2.getId());
|
||||||
|
Device updatedProduct = repo.selectOne(new LambdaQueryWrapper<Device>().eq(Device::getName, dto.getName()));
|
||||||
|
assertNotNull(updatedProduct);
|
||||||
|
assertEquals("DEVICE_UPDATE", updatedProduct.getName());
|
||||||
|
assertEquals(device2.getId(), updatedProduct.getId());
|
||||||
|
}
|
||||||
|
}
|
@ -31,9 +31,9 @@ public class ParamServiceTest {
|
|||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() {
|
void setUp() {
|
||||||
param1 = ParamBuilder.aParam().uint("测试1").build();
|
param1 = ParamBuilder.aParam().uint("测试1").foreignId(1L).build();
|
||||||
repo.insert(param1);
|
repo.insert(param1);
|
||||||
param2 = ParamBuilder.aParam().uint("测试2").build();
|
param2 = ParamBuilder.aParam().uint("测试2").foreignId(2L).build();
|
||||||
repo.insert(param2);
|
repo.insert(param2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,23 +62,17 @@ public class ParamServiceTest {
|
|||||||
dto.setIdentifier("测试更新");
|
dto.setIdentifier("测试更新");
|
||||||
List<ParamDto> params = new ArrayList<>();
|
List<ParamDto> params = new ArrayList<>();
|
||||||
params.add(dto);
|
params.add(dto);
|
||||||
assertTrue(service.update(params, param2.getId()));
|
assertTrue(service.update(params, param2.getForeignId()));
|
||||||
|
Param updatedParam = repo.selectOne(new LambdaQueryWrapper<Param>().eq(Param::getForeignId, param2.getForeignId()));
|
||||||
// 确保获取到的 param 对象是最新的
|
assertNotNull(updatedParam);
|
||||||
Param param = repo.selectById(param2.getId());
|
assertEquals("测试更新", updatedParam.getIdentifier());
|
||||||
assertNotNull(param); // 确保 param 不为空
|
assertEquals(param2.getId(), updatedParam.getId());
|
||||||
|
|
||||||
// 更新后的 identifier 应该是 "测试更新"
|
|
||||||
assertEquals("测试更新", param.getIdentifier());
|
|
||||||
assertEquals(param2.getId(), param.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
void tearDown() {
|
void tearDown() {
|
||||||
repo.delete(new LambdaQueryWrapper<Param>()
|
repo.delete(new LambdaQueryWrapper<Param>()
|
||||||
.in(Param::getId, param1.getId(), param2.getId())
|
|
||||||
.or()
|
|
||||||
.in(Param::getName, "PARAM_NAME_1", "PARAM_NAME_2", "PARAM_NAME_UPDATE"));
|
.in(Param::getName, "PARAM_NAME_1", "PARAM_NAME_2", "PARAM_NAME_UPDATE"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,100 @@
|
|||||||
|
package com.zsc.edu.gateway.service.iot;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.zsc.edu.gateway.domain.iot.ParamBuilder;
|
||||||
|
import com.zsc.edu.gateway.domain.iot.ProductBuilder;
|
||||||
|
import com.zsc.edu.gateway.exception.ConstraintException;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.product.dto.ProductDto;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.product.entity.Product;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.product.repo.ProductRepository;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.product.service.ProductService;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.tsl.dto.ParamDto;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.tsl.entity.DataType;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.tsl.entity.Param;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.tsl.repo.ParamRepository;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.tsl.service.ParamService;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
public class ProductServiceTest {
|
||||||
|
@Autowired
|
||||||
|
private ProductService service;
|
||||||
|
@Autowired
|
||||||
|
private ProductRepository repo;
|
||||||
|
@Autowired
|
||||||
|
private ParamRepository paramRepository;
|
||||||
|
|
||||||
|
private Product product1;
|
||||||
|
private Product product2;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
product1 = ProductBuilder.bProduct().name("PRODUCT_NAME_1").productType("测试1").link(Product.LinkType.TCP).build();
|
||||||
|
repo.insert(product1);
|
||||||
|
product2 = ProductBuilder.bProduct().name("PRODUCT_NAME_2").productType("测试2").link(Product.LinkType.TCP).build();
|
||||||
|
repo.insert(product2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void tearDown() {
|
||||||
|
repo.delete(new LambdaQueryWrapper<Product>()
|
||||||
|
.in(Product::getName, "PRODUCT_NAME_1", "PRODUCT_NAME_2", "PRODUCT_NAME_3", "PRODUCT_UPDATE"));
|
||||||
|
paramRepository.delete(new LambdaQueryWrapper<Param>()
|
||||||
|
.in(Param::getName, "联合测试"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void list() {
|
||||||
|
LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
assertEquals(2, service.list(queryWrapper.like(Product::getName, "PRODUCT")).size());
|
||||||
|
assertEquals(1, service.list(queryWrapper.eq(Product::getName, product1.getName())).size());
|
||||||
|
// assertEquals(2, service.list().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createProduct() {
|
||||||
|
ProductDto dto = new ProductDto("PRODUCT_NAME_3", "测试3", "测试3", Product.LinkType.TCP, createParam(), "备注1");
|
||||||
|
Product product = service.create(dto);
|
||||||
|
assertNotNull(product);
|
||||||
|
List<Product> Products = service.list(new LambdaQueryWrapper<Product>().like(Product::getName, "PRODUCT"));
|
||||||
|
assertEquals(3, Products.size());
|
||||||
|
// 不能创建其他已存在的同名同代码部门
|
||||||
|
ProductDto dto2 = new ProductDto(product2.getName(), "测试1", "测试1", Product.LinkType.TCP, null, "备注1");
|
||||||
|
assertThrows(ConstraintException.class, () -> service.create(dto2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void updateProduct() {
|
||||||
|
ProductDto dto = new ProductDto();
|
||||||
|
dto.setName("PRODUCT_UPDATE");
|
||||||
|
dto.setProductType("测试更新");
|
||||||
|
dto.setModel("测试更新");
|
||||||
|
dto.setLink(Product.LinkType.TCP);
|
||||||
|
dto.setParams(null);
|
||||||
|
dto.setParams(createParam());
|
||||||
|
service.update(dto, product2.getId());
|
||||||
|
Product updatedProduct = repo.selectOne(new LambdaQueryWrapper<Product>().eq(Product::getName, dto.getName()));
|
||||||
|
assertNotNull(updatedProduct);
|
||||||
|
assertEquals("PRODUCT_UPDATE", updatedProduct.getName());
|
||||||
|
assertEquals(product2.getId(), updatedProduct.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ParamDto> createParam() {
|
||||||
|
ParamDto paramDto = new ParamDto();
|
||||||
|
paramDto.setName("联合测试");
|
||||||
|
paramDto.setType(Param.Type.OUTPUT);
|
||||||
|
paramDto.setDataType(DataType.DATE);
|
||||||
|
List<ParamDto> params = new ArrayList<>();
|
||||||
|
params.add(paramDto);
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,103 @@
|
|||||||
|
package com.zsc.edu.gateway.service.iot;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.zsc.edu.gateway.domain.iot.ProductBuilder;
|
||||||
|
import com.zsc.edu.gateway.domain.iot.ServeBuilder;
|
||||||
|
import com.zsc.edu.gateway.exception.ConstraintException;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.product.dto.ProductDto;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.product.entity.Product;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.tsl.dto.ParamDto;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.tsl.dto.ServeDto;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.tsl.entity.DataType;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.tsl.entity.Param;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.tsl.entity.Serve;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.tsl.repo.ParamRepository;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.tsl.repo.ServeRepository;
|
||||||
|
import com.zsc.edu.gateway.modules.iot.tsl.service.ServeService;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
public class ServeServiceTest {
|
||||||
|
@Autowired
|
||||||
|
private ServeService service;
|
||||||
|
@Autowired
|
||||||
|
private ServeRepository repo;
|
||||||
|
@Autowired
|
||||||
|
private ParamRepository paramRepo;
|
||||||
|
|
||||||
|
private Serve serve1;
|
||||||
|
private Serve serve2;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
serve1 = ServeBuilder.aServe().name("SERVE_NAME_1").identifier("测试1").productId(121L).build();
|
||||||
|
repo.insert(serve1);
|
||||||
|
serve2 = ServeBuilder.aServe().name("SERVE_NAME_2").identifier("测试2").productId(121L).build();
|
||||||
|
repo.insert(serve2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void tearDown() {
|
||||||
|
repo.delete(new LambdaQueryWrapper<Serve>()
|
||||||
|
.in(Serve::getName, "SERVE_NAME_1", "SERVE_NAME_2", "SERVE_3", "SERVE_UPDATE"));
|
||||||
|
paramRepo.delete(new LambdaQueryWrapper<Param>()
|
||||||
|
.in(Param::getName, "联合测试1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void list() {
|
||||||
|
LambdaQueryWrapper<Serve> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
assertEquals(2, service.list(queryWrapper.like(Serve::getName, "SERVE")).size());
|
||||||
|
assertEquals(1, service.list(queryWrapper.eq(Serve::getName, serve1.getName())).size());
|
||||||
|
// assertEquals(2, service.list().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createProduct() {
|
||||||
|
ServeDto dto = new ServeDto(121L, "SERVE_3", "测试3", createParam(), createParam());
|
||||||
|
Serve serve = service.create(dto);
|
||||||
|
assertNotNull(serve);
|
||||||
|
List<Serve> serves = service.list(new LambdaQueryWrapper<Serve>().like(Serve::getName, "SERVE"));
|
||||||
|
assertEquals(3, serves.size());
|
||||||
|
// 不能创建其他已存在的同名同代码部门
|
||||||
|
ServeDto dto2 = new ServeDto(121L, serve2.getName(), "测试1", null, null);
|
||||||
|
assertThrows(ConstraintException.class, () -> service.create(dto2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void updateProduct() {
|
||||||
|
ServeDto dto = new ServeDto();
|
||||||
|
dto.setName("SERVE_UPDATE");
|
||||||
|
dto.setIdentifier("测试更新");
|
||||||
|
dto.setProductId(121L);
|
||||||
|
dto.setInputs(createParam());
|
||||||
|
dto.setOutputs(createParam());
|
||||||
|
service.update(dto, serve2.getId());
|
||||||
|
Serve updatedServe = repo.selectOne(new LambdaQueryWrapper<Serve>().eq(Serve::getName, dto.getName()));
|
||||||
|
assertNotNull(updatedServe);
|
||||||
|
assertEquals("SERVE_UPDATE", updatedServe.getName());
|
||||||
|
assertEquals(serve2.getId(), updatedServe.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<ParamDto> createParam() {
|
||||||
|
ParamDto paramDto = new ParamDto();
|
||||||
|
paramDto.setName("联合测试1");
|
||||||
|
paramDto.setType(Param.Type.OUTPUT);
|
||||||
|
paramDto.setDataType(DataType.DATE);
|
||||||
|
List<ParamDto> params = new ArrayList<>();
|
||||||
|
params.add(paramDto);
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -13,17 +13,21 @@ import jakarta.annotation.Resource;
|
|||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
public class BulletinServiceTest {
|
public class BulletinServiceTest {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private BulletinService service;
|
private BulletinService service;
|
||||||
@Resource
|
@Autowired
|
||||||
private BulletinRepository repo;
|
private BulletinRepository repo;
|
||||||
|
|
||||||
private Bulletin bulletin1;
|
private Bulletin bulletin1;
|
||||||
@ -46,7 +50,7 @@ public class BulletinServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Bulletin createAndInsertBulletin(String title) {
|
private Bulletin createAndInsertBulletin(String title) {
|
||||||
Bulletin bulletin = BulletinBuilder.bBulletin().title(title).build();
|
Bulletin bulletin = BulletinBuilder.bBulletin().top(false).title(title).build();
|
||||||
repo.insert(bulletin);
|
repo.insert(bulletin);
|
||||||
return bulletin;
|
return bulletin;
|
||||||
}
|
}
|
||||||
@ -56,7 +60,7 @@ public class BulletinServiceTest {
|
|||||||
LambdaQueryWrapper<Bulletin> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<Bulletin> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
assertEquals(2, service.list(queryWrapper.like(Bulletin::getTitle, "测试")).size());
|
assertEquals(2, service.list(queryWrapper.like(Bulletin::getTitle, "测试")).size());
|
||||||
assertEquals(1, service.list(queryWrapper.eq(Bulletin::getTitle, bulletin1.getTitle())).size());
|
assertEquals(1, service.list(queryWrapper.eq(Bulletin::getTitle, bulletin1.getTitle())).size());
|
||||||
assertEquals(2, service.list().size());
|
// assertEquals(2, service.list().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -64,29 +68,21 @@ public class BulletinServiceTest {
|
|||||||
BulletinDto dto = createBulletinDto("测试", true, "测试测试", "测试公告增加");
|
BulletinDto dto = createBulletinDto("测试", true, "测试测试", "测试公告增加");
|
||||||
Bulletin bulletin = service.create(userDetails, dto);
|
Bulletin bulletin = service.create(userDetails, dto);
|
||||||
assertNotNull(bulletin.getId());
|
assertNotNull(bulletin.getId());
|
||||||
|
|
||||||
List<Bulletin> list = service.list();
|
|
||||||
assertEquals(3, list.size());
|
|
||||||
|
|
||||||
// 不能创建其他已存在标题公告
|
|
||||||
assertThrows(ConstraintException.class, () -> service.create(userDetails, createBulletinDto(bulletin2.getTitle(), false, "", "")));
|
assertThrows(ConstraintException.class, () -> service.create(userDetails, createBulletinDto(bulletin2.getTitle(), false, "", "")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void updateBulletin() {
|
void updateBulletin() {
|
||||||
BulletinDto dto = createBulletinDto("测试3", true, "测试测", "测试公告更新");
|
BulletinDto dto = createBulletinDto("测试3", true, "测试更新", "测试公告更新");
|
||||||
assertTrue(service.update(userDetails, dto, bulletin2.getId()));
|
assertTrue(service.update(userDetails, dto, bulletin2.getId()));
|
||||||
|
Bulletin updatedBulletin = service.getOne(new LambdaQueryWrapper<Bulletin>()
|
||||||
Bulletin updatedBulletin = service.getOne(new LambdaQueryWrapper<Bulletin>().eq(Bulletin::getTitle, dto.getTitle()));
|
.eq(Bulletin::getTitle, dto.getTitle()));
|
||||||
assertNotNull(updatedBulletin);
|
assertNotNull(updatedBulletin);
|
||||||
assertEquals(dto.getTitle(), updatedBulletin.getTitle());
|
assertEquals(dto.getTitle(), updatedBulletin.getTitle());
|
||||||
assertEquals(bulletin2.getId(), updatedBulletin.getId());
|
assertEquals(bulletin2.getId(), updatedBulletin.getId());
|
||||||
|
|
||||||
// 不能改为其他已存在的同名公告
|
|
||||||
assertThrows(ConstraintException.class,
|
|
||||||
() -> service.update(userDetails, createBulletinDto(bulletin1.getTitle(), true, "测试测试", "测试公告更新"), bulletin2.getId()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private BulletinDto createBulletinDto(String title, boolean top, String content, String remark) {
|
private BulletinDto createBulletinDto(String title, boolean top, String content, String remark) {
|
||||||
BulletinDto dto = new BulletinDto();
|
BulletinDto dto = new BulletinDto();
|
||||||
dto.setTitle(title);
|
dto.setTitle(title);
|
||||||
|
@ -0,0 +1,67 @@
|
|||||||
|
package com.zsc.edu.gateway.service.notice;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.zsc.edu.gateway.domain.notice.MessageBuilder;
|
||||||
|
import com.zsc.edu.gateway.framework.security.UserDetailsImpl;
|
||||||
|
import com.zsc.edu.gateway.modules.notice.dto.UserMessageDto;
|
||||||
|
import com.zsc.edu.gateway.modules.notice.entity.Message;
|
||||||
|
import com.zsc.edu.gateway.modules.notice.entity.MessageType;
|
||||||
|
import com.zsc.edu.gateway.modules.notice.repo.MessageRepository;
|
||||||
|
import com.zsc.edu.gateway.modules.notice.repo.UserMessageRepository;
|
||||||
|
import com.zsc.edu.gateway.modules.notice.service.UserMessageService;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
public class MessageServiceTest {
|
||||||
|
@Autowired
|
||||||
|
public MessageRepository messageRepository;
|
||||||
|
@Autowired
|
||||||
|
public UserMessageRepository userMessageRepository;
|
||||||
|
@Autowired
|
||||||
|
public UserMessageService service;
|
||||||
|
|
||||||
|
private Message message1;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setup() {
|
||||||
|
UserDetailsImpl userDetails = new UserDetailsImpl();
|
||||||
|
userDetails.setUsername("admin");
|
||||||
|
message1 = MessageBuilder.bMessage().type(MessageType.other).title("A测试消息1").build();
|
||||||
|
messageRepository.insert(message1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void tearDown() {
|
||||||
|
List<String> titlesToDelete = Arrays.asList("A测试消息1", "A测试消息3");
|
||||||
|
messageRepository.delete(new QueryWrapper<Message>().in("title", titlesToDelete));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void list() {
|
||||||
|
LambdaQueryWrapper<Message> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
assertEquals(1, messageRepository.selectList(queryWrapper.like(Message::getTitle, "A测试")).size());
|
||||||
|
assertEquals(1, messageRepository.selectList(queryWrapper.eq(Message::getTitle, message1.getTitle())).size());
|
||||||
|
// assertEquals(2, messageRepository.selectList(null).size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createMessage() {
|
||||||
|
UserMessageDto dto = new UserMessageDto(new HashSet<>(Arrays.asList(1L, 2L)), MessageType.other, false, false, false, "A测试消息3", "测试测试");
|
||||||
|
service.createByAdmin(dto);
|
||||||
|
Message message = messageRepository.selectOne(new LambdaQueryWrapper<Message>().eq(Message::getTitle, dto.getTitle()));
|
||||||
|
assertNotNull(message.getId());
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,14 @@
|
|||||||
package com.zsc.edu.gateway.service.system;
|
package com.zsc.edu.gateway.service.system;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.zsc.edu.gateway.domain.system.AuthorityBuilder;
|
||||||
import com.zsc.edu.gateway.exception.ConstraintException;
|
import com.zsc.edu.gateway.exception.ConstraintException;
|
||||||
import com.zsc.edu.gateway.modules.system.dto.AuthorityDto;
|
import com.zsc.edu.gateway.modules.system.dto.AuthorityDto;
|
||||||
import com.zsc.edu.gateway.modules.system.entity.Authority;
|
import com.zsc.edu.gateway.modules.system.entity.Authority;
|
||||||
import com.zsc.edu.gateway.modules.system.repo.AuthorityRepository;
|
import com.zsc.edu.gateway.modules.system.repo.AuthorityRepository;
|
||||||
import com.zsc.edu.gateway.modules.system.service.AuthorityService;
|
import com.zsc.edu.gateway.modules.system.service.AuthorityService;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
@ -26,13 +28,13 @@ public class AuthorityServiceTest {
|
|||||||
private Authority aut1;
|
private Authority aut1;
|
||||||
private Authority aut2;
|
private Authority aut2;
|
||||||
|
|
||||||
// @BeforeEach
|
@BeforeEach
|
||||||
// void setUp() {
|
void setUp() {
|
||||||
// aut1 = AuthorityBuilder.aAuthority().name("TEST_AUTHORITY_ONE").build();
|
aut1 = AuthorityBuilder.aAuthority().name("TEST_AUTHORITY_ONE").build();
|
||||||
// repo.insert(aut1);
|
repo.insert(aut1);
|
||||||
// aut2 = AuthorityBuilder.aAuthority().name("TEST_AUTHORITY_TWO").build();
|
aut2 = AuthorityBuilder.aAuthority().name("TEST_AUTHORITY_TWO").build();
|
||||||
// repo.insert(aut2);
|
repo.insert(aut2);
|
||||||
// }
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void list() {
|
void list() {
|
||||||
|
Loading…
Reference in New Issue
Block a user