编写角色管理单元测试
This commit is contained in:
parent
2de329dd62
commit
2883858168
149
ktg-admin/src/test/MdItemUnitTest.java
Normal file
149
ktg-admin/src/test/MdItemUnitTest.java
Normal file
@ -0,0 +1,149 @@
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.ktg.RuoYiApplication;
|
||||
import com.ktg.common.core.domain.entity.ItemType;
|
||||
import com.ktg.common.utils.StringUtils;
|
||||
import com.ktg.mes.md.domain.MdItem;
|
||||
import com.ktg.mes.md.domain.MdUnitMeasure;
|
||||
import com.ktg.mes.md.mapper.ItemTypeMapper;
|
||||
import com.ktg.mes.md.service.IMdItemService;
|
||||
import com.ktg.mes.md.service.IMdUnitMeasureService;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 角色管理单元测试
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = RuoYiApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class MdItemUnitTest {
|
||||
@Autowired
|
||||
private IMdItemService mdItemService;
|
||||
|
||||
@Autowired
|
||||
private ItemTypeMapper itemTypeMapper;
|
||||
|
||||
@Autowired
|
||||
private IMdUnitMeasureService mdUnitMeasureService;
|
||||
|
||||
@Test
|
||||
public void add() {
|
||||
MdItem mdItem = new MdItem();
|
||||
mdItem.setItemTypeId(288L);
|
||||
mdItem.setItemCode("IF20241107002");
|
||||
mdItem.setItemName("单元测试物料002");
|
||||
mdItem.setStandardNumber(10);
|
||||
mdItem.setEnableFlag("Y");
|
||||
mdItem.setSafeStockFlag("N");
|
||||
mdItem.setMinStock((double) 0);
|
||||
mdItem.setMaxStock((double) 0);
|
||||
mdItem.setAttr1(5);
|
||||
mdItem.setUnitOfMeasure("PCS");
|
||||
ItemType type = itemTypeMapper.selectItemTypeById(mdItem.getItemTypeId());
|
||||
if (StringUtils.isNotNull(type)) {
|
||||
mdItem.setItemTypeCode(type.getItemTypeCode());
|
||||
mdItem.setItemTypeName(type.getItemTypeName());
|
||||
mdItem.setItemOrProduct(type.getItemOrProduct());
|
||||
}
|
||||
MdUnitMeasure measure = mdUnitMeasureService.selectMdUnitByCode(mdItem.getUnitOfMeasure());
|
||||
if (StringUtils.isNotNull(measure)) {
|
||||
mdItem.setUnitName(measure.getMeasureName());
|
||||
}
|
||||
mdItemService.insertMdItem(mdItem);
|
||||
System.out.println("add:" + mdItem.getItemId()); // 102
|
||||
}
|
||||
|
||||
@Test
|
||||
public void list() {
|
||||
List<MdItem> list = mdItemService.selectMdItemList(new MdItem());
|
||||
System.out.println("list:" + JSON.toJSONString(list));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getInfo() {
|
||||
System.out.println("getInfo:" + JSON.toJSONString(mdItemService.selectMdItemById(102L)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void edit() {
|
||||
MdItem mdItem = new MdItem();
|
||||
mdItem.setItemId(102L);
|
||||
mdItem.setItemTypeId(288L);
|
||||
mdItem.setItemName("单元测试物料001");
|
||||
mdItem.setStandardNumber(10);
|
||||
mdItem.setEnableFlag("Y");
|
||||
mdItem.setSafeStockFlag("N");
|
||||
mdItem.setMinStock((double) 0);
|
||||
mdItem.setMaxStock((double) 0);
|
||||
mdItem.setAttr1(5);
|
||||
mdItem.setUnitOfMeasure("PCS");
|
||||
ItemType type = itemTypeMapper.selectItemTypeById(mdItem.getItemTypeId());
|
||||
if (StringUtils.isNotNull(type)) {
|
||||
mdItem.setItemTypeCode(type.getItemTypeCode());
|
||||
mdItem.setItemTypeName(type.getItemTypeName());
|
||||
mdItem.setItemOrProduct(type.getItemOrProduct());
|
||||
}
|
||||
if (StringUtils.isNotNull(mdItem.getSafeStockFlag()) && "N".equals(mdItem.getSafeStockFlag())) {
|
||||
mdItem.setMinStock(0D);
|
||||
mdItem.setMaxStock(0D);
|
||||
}
|
||||
MdUnitMeasure measure = mdUnitMeasureService.selectMdUnitByCode(mdItem.getUnitOfMeasure());
|
||||
if (StringUtils.isNotNull(measure)) {
|
||||
mdItem.setUnitName(measure.getMeasureName());
|
||||
}
|
||||
int count = mdItemService.updateMdItem(mdItem);
|
||||
System.out.println("edit:" + count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void remove() {
|
||||
Long[] ids = {102L};
|
||||
int count = mdItemService.deleteByItemIds(ids);
|
||||
System.out.println("remove:" + count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selectItem() {
|
||||
MdItem mdItem = new MdItem();
|
||||
mdItem.setItemOrProduct("ITEM");
|
||||
List<MdItem> list = mdItemService.selectMdItemList(mdItem);
|
||||
List<Map<String, String>> result = new ArrayList<>();
|
||||
list.forEach(item -> {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("gid", item.getItemId().toString());
|
||||
map.put("code", item.getItemCode());
|
||||
map.put("safeInventory", item.getMinStock().toString().split("\\.")[0]);
|
||||
map.put("pmbbMeasure", item.getItemTypeName());
|
||||
map.put("name", item.getItemName());
|
||||
map.put("count", mdItemService.getMdItemCount(item.getItemId()).toString());
|
||||
result.add(map);
|
||||
});
|
||||
System.out.println("selectItem:" + JSON.toJSONString(list));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selectProduct() {
|
||||
MdItem mdItem = new MdItem();
|
||||
mdItem.setItemOrProduct("PRODUCT");
|
||||
List<MdItem> list = mdItemService.selectMdItemList(mdItem);
|
||||
List<Map<String, String>> result = new ArrayList<>();
|
||||
list.forEach(item -> {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("gid", item.getItemId().toString());
|
||||
map.put("code", item.getItemCode());
|
||||
map.put("safeInventory", item.getMinStock().toString().split("\\.")[0]);
|
||||
map.put("pmbbMeasure", item.getItemTypeName());
|
||||
map.put("name", item.getItemName());
|
||||
map.put("count", mdItemService.getMdItemCount(item.getItemId()).toString());
|
||||
result.add(map);
|
||||
});
|
||||
System.out.println("selectProduct:" + JSON.toJSONString(list));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user