单元测试

This commit is contained in:
star 2024-11-07 08:39:40 +08:00
parent 0a5367ccfb
commit 2974922d41
9 changed files with 358 additions and 9 deletions

View File

@ -0,0 +1,122 @@
import com.ktg.RuoYiApplication;
import com.ktg.common.core.domain.AjaxResult;
import com.ktg.mes.md.controller.BaseKnifeController;
import com.ktg.mes.md.domain.BaseKnife;
import com.ktg.mes.md.service.IBaseKnifeService;
import com.ktg.mes.wm.domain.WmsZdTask;
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.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.bind.annotation.RequestBody;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import static org.mockito.Mockito.mock;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = RuoYiApplication.class,webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class BaseKnifeTest {
@Autowired
private IBaseKnifeService iBaseKnifeService;
@Autowired
private BaseKnifeController baseKnifeController;
/**
* 台账新增
*/
@Test
public void saveBaseKnifeTest(){
BaseKnife baseKnife = new BaseKnife();
baseKnife.setKnifeCode("knifeCode");
baseKnife.setKnifeName("纸箱");
baseKnife.setKnifeType("包装类");
baseKnife.setMbbBdMrlId(86L);
baseKnife.setKnifeUnit("");
baseKnife.setSafeStock("1");
baseKnife.setStandardQuantity("1");
baseKnife.setAreaCode("A0033");
baseKnife.setKnifeLife("100");
baseKnife.setKnifeFineState(0);
iBaseKnifeService.insertBaseKnife(baseKnife);
}
/**
* 台账修改
*/
@Test
public void UpdateBaseKnifeTest(){
BaseKnife baseKnife = new BaseKnife();
baseKnife.setBaseKnifeId(76L);
baseKnife.setKnifeCode("knifeCode");
baseKnife.setKnifeName("纸箱");
baseKnife.setKnifeType("包装类");
baseKnife.setMbbBdMrlId(86L);
baseKnife.setKnifeUnit("");
baseKnife.setSafeStock("1");
baseKnife.setStandardQuantity("1");
baseKnife.setAreaCode("A0055");
baseKnife.setKnifeLife("100");
baseKnife.setKnifeFineState(0);
iBaseKnifeService.updateBaseKnife(baseKnife);
}
/**
* 台账详情查询
*/
@Test
public void getBaseKnifeTest(){
BaseKnife baseKnife = iBaseKnifeService.selectBaseKnifeByBaseKnifeId(86L);
System.out.println(baseKnife.toString());
}
/**
* 台账详情查询列表
*/
@Test
public void getBaseKnifeTests(){
List<BaseKnife> baseKnifes = iBaseKnifeService.selectBaseKnifeList(new BaseKnife());
for (BaseKnife baseKnife : baseKnifes) {
System.out.println(baseKnife.toString());
}
}
/**
* 台账删除
*/
@Test
public void delBaseKnifeTest(){
int i = iBaseKnifeService.deleteBaseKnifeByBaseKnifeId(77L);
System.out.println(i);
}
/**
* 重置台账寿命
*/
@Test
public void anewKnifeTest(){
int i = iBaseKnifeService.resetBaseKnifeByBaseKnifeId(77L);
System.out.println(i);
}
/**
* 组刀
*/
@Test
public void scrapKnifeTest(){
WmsZdTask wmsZdTask = new WmsZdTask();
wmsZdTask.setAttr1(8L);
wmsZdTask.setmProductId(99L);
AjaxResult ajaxResult = baseKnifeController.zdTask(wmsZdTask);
System.out.println(ajaxResult.toString());
}
}

View File

@ -0,0 +1,114 @@
import com.ktg.RuoYiApplication;
import com.ktg.mes.qc.domain.InventoryRequest;
import com.ktg.mes.qc.domain.InventoryTask;
import com.ktg.mes.qc.service.InventoryRequestService;
import com.ktg.mes.qc.service.InventoryTaskService;
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.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
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 InventoryTaskResultTest {
@Autowired
private InventoryRequestService inventoryRequestService;
/**
* 新增方法单元测试
*/
@Test
public void saveTest(){
//新建任务对象
InventoryRequest inventoryRequest = new InventoryRequest();
Timestamp frockDate = Timestamp.valueOf("2022-01-01 00:00:00");
inventoryRequest.setFrockDate(frockDate);
inventoryRequest.setFrockId(25L);
inventoryRequest.setRequestCode("TEST001");
inventoryRequest.setFrockName("测试计划");
inventoryRequest.setResultName("测试计划结果");
inventoryRequest.setMrlWlGid("75");
inventoryRequest.setFrockResult("0");
inventoryRequest.setFrockUser("张三");
//新增
int i = inventoryRequestService.createInventoryRequest(inventoryRequest);
}
/**
* 修改方法单元测试
*/
@Test
public void UpdateTest(){
InventoryRequest inventoryRequest = new InventoryRequest();
Timestamp frockDate = Timestamp.valueOf("2022-01-01 00:00:00");
inventoryRequest.setFrockDate(frockDate);
inventoryRequest.setRequestId(16L);
inventoryRequest.setFrockId(25L);
inventoryRequest.setRequestCode("TEST001");
inventoryRequest.setFrockName("测试计划");
inventoryRequest.setResultName("测试计划结果");
inventoryRequest.setMrlWlGid("75");
inventoryRequest.setFrockResult("0");
inventoryRequest.setFrockUser("李四");
//新增
int i = inventoryRequestService.updateInventoryRequest(inventoryRequest);
}
/**
* 获取工装定检结果详情
*/
@Test
public void getInfoTest(){
InventoryRequest inventoryRequest = inventoryRequestService.queryInventoryRequest(16L);
System.out.println(inventoryRequest.toString());
}
/**
* 删除工装定检
*/
@Test
public void delTest(){
int i = inventoryRequestService.deleteInventoryRequest(16L);
System.out.println(i);
}
/**
* 批量删除工装定检
*/
@Test
public void delIdsTest(){
Long[] ids = {13L,16L};
int i = inventoryRequestService.deleteInventoryRequestByIds(ids);
System.out.println(i);
}
/**
* 查询结果集合
*/
@Test
public void getListTest(){
InventoryRequest inventoryRequest = new InventoryRequest();
Map<String, Object> stringIntegerMap = new HashMap<>();
stringIntegerMap.put("pageNum",1);
stringIntegerMap.put("pageSize",1);
inventoryRequest.setParams(stringIntegerMap);
List<InventoryRequest> inventoryRequests = inventoryRequestService.queryInventoryRequestList(inventoryRequest);
System.out.println(inventoryRequests.size());
for (InventoryRequest request : inventoryRequests) {
System.out.println(request.toString());
}
}
}

View File

@ -1,4 +1,5 @@
import com.ktg.RuoYiApplication;
import com.ktg.mes.qc.domain.InventoryRequest;
import com.ktg.mes.qc.domain.InventoryTask;
import com.ktg.mes.qc.service.InventoryTaskService;
import org.junit.Test;
@ -7,26 +8,114 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
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 InventoryTaskTest {
@Autowired
private InventoryTaskService inventoryTaskService;
/**
* 新增方法单元测试
*/
@Test
public void saveTest(){
//新建任务对象
InventoryTask inventoryTaskTest = new InventoryTask();
inventoryTaskTest.setWmsInventoryCode("TEST001");
inventoryTaskTest.setUomId("TEST001");
inventoryTaskTest.setUomId("200");
inventoryTaskTest.setName("测试计划");
inventoryTaskTest.setPlanPeriod("");
inventoryTaskTest.setStartTime("2022-01-01");
inventoryTaskTest.setFinishTime("2022-12-31");
inventoryTaskTest.setSuperiorTime("2022-01-01");
inventoryTaskTest.setBelowTime("2022-12-31");
inventoryTaskTest.setProductId("TEST001");
inventoryTaskTest.setProductId("75");
inventoryTaskTest.setMrlModel("19");
inventoryTaskTest.setMrlPeriod("");
//新增
int i = inventoryTaskService.insertInventoryTask(inventoryTaskTest);
}
/**
* 修改方法单元测试
*/
@Test
public void UpdateTest(){
//新建任务对象
InventoryTask inventoryTaskTest = new InventoryTask();
inventoryTaskTest.setWmsInventoryID(25L);
inventoryTaskTest.setWmsInventoryCode("TEST001");
inventoryTaskTest.setUomId("200");
inventoryTaskTest.setName("测试计划");
inventoryTaskTest.setPlanPeriod("");
inventoryTaskTest.setStartTime("2022-01-01");
inventoryTaskTest.setFinishTime("2022-12-31");
inventoryTaskTest.setSuperiorTime("2022-01-01");
inventoryTaskTest.setBelowTime("2022-12-31");
inventoryTaskTest.setProductId("75");
inventoryTaskTest.setMrlModel("19");
inventoryTaskTest.setMrlPeriod("");
//新增
int i = inventoryTaskService.updateInventoryTask(inventoryTaskTest);
}
/**
* 获取工装定检详情
*/
@Test
public void getInfoTest(){
InventoryTask inventoryTask = inventoryTaskService.selectInventoryTaskById(25L);
System.out.println(inventoryTask.toString());
}
/**
* 删除工装定检
*/
@Test
public void delTest(){
int i = inventoryTaskService.delById(25L);
System.out.println(i);
}
/**
* 批量删除工装定检
*/
@Test
public void delIdsTest(){
Long[] ids = {25L,26L};
int i = inventoryTaskService.delByIds(ids);
System.out.println(i);
}
/**
* 重新定检
*/
@Test
public void anewTest(){
int i = inventoryTaskService.recheck(25L);
System.out.println(i);
}
/**
* 查询结果集合
*/
@Test
public void getListTest(){
InventoryTask inventoryTask = new InventoryTask();
Map<String, Object> stringIntegerMap = new HashMap<>();
stringIntegerMap.put("pageNum",1);
stringIntegerMap.put("pageSize",1);
inventoryTask.setParams(stringIntegerMap);
List<InventoryTask> inventoryRequests = inventoryTaskService.getList(inventoryTask);
System.out.println(inventoryRequests.size());
for (InventoryTask request : inventoryRequests) {
System.out.println(request.toString());
}
}
}

View File

@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.List;
import static com.ktg.common.utils.PageUtils.startPage;
import static com.ktg.common.utils.SecurityUtils.getUsername;
/**
* 常见缺陷Controller
@ -47,6 +48,7 @@ public class InventoryTaskController extends BaseController {
@PutMapping
public AjaxResult edit(@RequestBody InventoryTask inventoryTask)
{
inventoryTask.setUpdateBy(getUsername());
return toAjax(inventoryTaskService.updateInventoryTask(inventoryTask));
}
@ -58,6 +60,7 @@ public class InventoryTaskController extends BaseController {
@PostMapping("/save")
public AjaxResult add(@RequestBody InventoryTask inventoryTask)
{
inventoryTask.setCreateBy(getUsername());
return toAjax(inventoryTaskService.insertInventoryTask(inventoryTask));
}
@ -68,6 +71,7 @@ public class InventoryTaskController extends BaseController {
@GetMapping(value = "/{wmsInventoryID}")
public AjaxResult getInfo(@PathVariable("wmsInventoryID") Long wmsInventoryID)
{
return AjaxResult.success(inventoryTaskService.selectInventoryTaskById(wmsInventoryID));
}

View File

@ -15,6 +15,8 @@ import org.springframework.web.bind.annotation.*;
import java.util.List;
import static com.ktg.common.utils.SecurityUtils.getUsername;
@RestController
@RequestMapping("inventoryRequestController")
public class inventoryRequestController extends BaseController {
@ -40,6 +42,7 @@ public class inventoryRequestController extends BaseController {
@PutMapping
public AjaxResult edit(@RequestBody InventoryRequest InventoryRequest)
{
InventoryRequest.setUpdateBy(getUsername());
return toAjax(inventoryRequestService.updateInventoryRequest(InventoryRequest));
}
@ -51,6 +54,7 @@ public class inventoryRequestController extends BaseController {
@PostMapping("/save")
public AjaxResult add(@RequestBody InventoryRequest inventoryRequest)
{
inventoryRequest.setCreateBy(getUsername());
return toAjax(inventoryRequestService.createInventoryRequest(inventoryRequest));
}

View File

@ -164,6 +164,23 @@ public class InventoryRequest extends BaseEntity {
this.mrlWlName = mrlWlName;
}
@Override
public String toString() {
return "InventoryRequest{" +
"requestId=" + requestId +
", requestCode='" + requestCode + '\'' +
", frockUser='" + frockUser + '\'' +
", frockId=" + frockId +
", frockName='" + frockName + '\'' +
", mrlWlGid='" + mrlWlGid + '\'' +
", mrlWlName='" + mrlWlName + '\'' +
", resultName='" + resultName + '\'' +
", frockResult='" + frockResult + '\'' +
", frockError='" + frockError + '\'' +
", frockDate=" + frockDate +
", remark='" + remark + '\'' +
", isDelete=" + isDelete +
", isActive=" + isActive +
'}';
}
}

View File

@ -33,7 +33,6 @@ public class InventoryRequestServiceImpl implements InventoryRequestService {
@Override
public int createInventoryRequest(InventoryRequest inventoryRequest) {
inventoryRequest.setCreateBy(getUsername());
String s = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
@ -49,7 +48,7 @@ public class InventoryRequestServiceImpl implements InventoryRequestService {
@Override
public int updateInventoryRequest(InventoryRequest inventoryRequest) {
inventoryRequest.setUpdateBy(getUsername());
String s = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {

View File

@ -79,7 +79,7 @@ public class InventoryTaskServiceImpl implements InventoryTaskService {
@Override
public int insertInventoryTask(InventoryTask inventoryTask) {
String s = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
inventoryTask.setCreateBy(getUsername());
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
Date parsedDate = format.parse(s);
@ -93,7 +93,7 @@ public class InventoryTaskServiceImpl implements InventoryTaskService {
@Override
public int updateInventoryTask(InventoryTask inventoryTask) {
String s = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
inventoryTask.setUpdateBy(getUsername());
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
Date parsedDate = format.parse(s);

View File

@ -482,7 +482,7 @@
where BASE_KNIFE_ID = #{baseKnifeId}
</update>
<delete id="deleteBaseKnifeByBaseKnifeId" parameterType="String">
<delete id="deleteBaseKnifeByBaseKnifeId" parameterType="Long">
delete
from BASE_KNIFE
where BASE_KNIFE_ID = #{baseKnifeId}