Commit d0d52dc1 by 钱炳权

除启动测试外全正常

parent 20f0eabc
......@@ -24,6 +24,20 @@ public class TestMissionController {
TestMissionService testMissionService;
/**
*
* @param id 测试id用来获取参数
* @param
*/
@RequestMapping(value = "/startmission", method = RequestMethod.GET)
public AjaxResult startmission(@RequestParam int id) {
try {
testMissionService.startMission(id);
} catch (Exception e) {
return AjaxResult.error("测试启动失败!");
}
return AjaxResult.success("测试启动成功!");
}
/**
* 测试信息获取
*/
@RequestMapping(value = "/getAll", method = RequestMethod.GET)
......@@ -32,7 +46,7 @@ public class TestMissionController {
try {
testAndParamsList = testMissionService.getTestAndParamsList();
} catch (Exception e) {
return AjaxResult.error();
return AjaxResult.error("测试信息获取失败!");
}
return AjaxResult.success(testAndParamsList);
}
......@@ -69,7 +83,7 @@ public class TestMissionController {
}
/**
* 给空白测试配置参数
* 给空白测试配置参数-aflnet
*/
@RequestMapping(value = "/insertWithAflnet/{id}", method = RequestMethod.POST)
public AjaxResult insertParmasInTestAflnet(@PathVariable("id")int id,@RequestBody final CmdStartParams cmdStartParams) {
......@@ -81,6 +95,9 @@ public class TestMissionController {
return AjaxResult.success("参数配置成功!");
}
/**
* 给空白测试配置参数-kitty
*/
@RequestMapping(value = "/insertWithkitty/{id}", method = RequestMethod.POST)
public AjaxResult insertParmasInTestKitty(@PathVariable("id")int id,@RequestBody TestEntity testEntity) {
try {
......@@ -90,4 +107,16 @@ public class TestMissionController {
}
return AjaxResult.success("参数配置成功!");
}
/**
* 测试名称修改
*/
@RequestMapping(value = "/editTestName", method = RequestMethod.GET)
public AjaxResult editTestName(@RequestParam String testName,@RequestParam int id) {
try {
testMissionService.editTestName(testName,id);
} catch (Exception e) {
return AjaxResult.error("修改失败!");
}
return AjaxResult.success("修改成功!");
}
}
package com.example.fuzzControll.domain.po;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
......@@ -14,7 +15,8 @@ import java.util.Date;
@AllArgsConstructor
public class TestAndParams {
private int id;
private int fuzzParamsId;
@JsonIgnore
private int fuzzParamsId;//不展示给前端
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
......
......@@ -19,4 +19,10 @@ public interface TestMapper {
Test getTestById(int id);
void edit(Test test);
List<Test> getTestList();
boolean deleteEmptyById(int id);
boolean editTestName(String testName,int id);
}
......@@ -19,4 +19,8 @@ public interface TestMissionService {
void insertParmasInTestAflnet(int id,CmdStartParams cmdStartParams);
void insertParmasInTestKitty(int id,TestEntity testEntity);
boolean editTestName(String testName,int id);
void startMission(int id) ;
}
package com.example.fuzzControll.service.impl;
import com.alibaba.fastjson.JSON;
import com.example.fuzzControll.constents.MissionStateEnum;
import com.example.fuzzControll.constents.TableClassEnum;
import com.example.fuzzControll.domain.bo.CmdStartParams;
import com.example.fuzzControll.domain.bo.FuzzParams;
import com.example.fuzzControll.domain.bo.TestEntity;
import com.example.fuzzControll.domain.po.MissionInfo;
import com.example.fuzzControll.domain.po.Test;
import com.example.fuzzControll.domain.po.TestAndParams;
import com.example.fuzzControll.exception.mysqlException.MysqlException;
import com.example.fuzzControll.mapper.FuzzParamsMapper;
import com.example.fuzzControll.mapper.MissionInfoMapper;
import com.example.fuzzControll.mapper.TestMapper;
import com.example.fuzzControll.service.TestMissionService;
import com.example.fuzzControll.tools.system.GlobalClass;
import com.example.fuzzControll.tools.system.SystemRunningParams;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -20,6 +26,8 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@Slf4j
@Service("TestMissionServiceImpl")
......@@ -28,32 +36,47 @@ public class TestMissionServiceImpl implements TestMissionService {
TestMapper testMapper;
@Autowired
FuzzParamsMapper fuzzParamsMapper;
@Autowired
MissionInfoMapper missionInfoMapper;
@Override
public List<TestAndParams> getTestAndParamsList() {
List<TestAndParams> testParamsList = new ArrayList();
List<TestAndParams> testParamsRelevantList = new ArrayList();
List<TestAndParams> testParamsListEmpty = new ArrayList();
try {
testParamsList = testMapper.getTestAndParamsList();
/*查询关联的数据*/
testParamsRelevantList = testMapper.getTestAndParamsList();
/*查询空白数据,组合起来是全数据*/
testParamsListEmpty = testMapper.getTestList().stream().map(test -> new TestAndParams(test.getId(), test.getFuzzParamsId(), test.getCreateTime()
, test.getUpdateTime(), test.getMissionIds(), test.getTestName(), "", "")).collect(Collectors.toList());
testParamsRelevantList.addAll(testParamsListEmpty);
} catch (Exception e) {
log.error("Failed to get test and params list:{}", e.getMessage());
throw new RuntimeException(e);
}
if (testParamsList == null || testParamsList.size() == 0) {
if (testParamsRelevantList == null || testParamsRelevantList.size() == 0) {
log.warn("TestAndParams is null!");
}
return testParamsList;
return testParamsRelevantList;
}
@Override
public boolean deleteById(int id) {
boolean flag = false;
try {
flag = testMapper.deleteById(id);
Test test = testMapper.getTestById(id);
/*非空白测试级联删除*/
if (!(test.getFuzzParamsId() == 0)) {
flag = testMapper.deleteById(id);
} else {
/*空白测试删除*/
flag = testMapper.deleteEmptyById(id);
}
} catch (Exception e) {
log.error("Delete error:{}", e.getMessage());
throw new RuntimeException(e);
}
return false;
return flag;
}
......@@ -76,8 +99,8 @@ public class TestMissionServiceImpl implements TestMissionService {
fuzzParamsId = fuzzParams.getId();
test.setFuzzParamsId(fuzzParamsId);
} else {//有则更新数据
FuzzParams fuzzParams = new FuzzParams(test.getFuzzParamsId(),JSON.toJSONString(cmdStartParams), cmdStartParams.getProtopcol());
if(!fuzzParamsMapper.editFuzzParams(fuzzParams.getId(),fuzzParams.getParams(),fuzzParams.getProtocol())){
FuzzParams fuzzParams = new FuzzParams(test.getFuzzParamsId(), JSON.toJSONString(cmdStartParams), cmdStartParams.getProtopcol());
if (!fuzzParamsMapper.editFuzzParams(fuzzParams.getId(), fuzzParams.getParams(), fuzzParams.getProtocol())) {
throw new RuntimeException("EditFuzzParams failed!");
}
}
......@@ -93,7 +116,54 @@ public class TestMissionServiceImpl implements TestMissionService {
@Transactional(rollbackFor = MysqlException.class)
@Override
public void insertParmasInTestKitty(int id, TestEntity testEntity) {
/*插入fuzzparams返回id*/
/*更新对应id的测试数据*/
try {
/*判断test是否存有paramsId,没数据插入有数据就改变*/
Test test = testMapper.getTestById(id);
int fuzzParamsId;
if (test.getFuzzParamsId() == 0) {//为0则插入id
FuzzParams fuzzParams = new FuzzParams(JSON.toJSONString(testEntity.getParamJson()), testEntity.getTestClassName());
fuzzParamsMapper.insertFuzzParamsReturnId(fuzzParams);
fuzzParamsId = fuzzParams.getId();
test.setFuzzParamsId(fuzzParamsId);
} else {//有则更新数据
FuzzParams fuzzParams = new FuzzParams(JSON.toJSONString(testEntity.getParamJson()), testEntity.getTestClassName());
if (!fuzzParamsMapper.editFuzzParams(fuzzParams.getId(), fuzzParams.getParams(), fuzzParams.getProtocol())) {
throw new RuntimeException("EditFuzzParams failed!");
}
}
/*更新修改时间*/
test.setUpdateTime(new Date());
testMapper.edit(test);
} catch (Exception e) {
log.error("Failed to insert:[{}]", e.getMessage());
throw new MysqlException("");
}
}
@Override
public boolean editTestName(String testName, int id) {
boolean flag = false;
try {
flag = testMapper.editTestName(testName, id);
} catch (Exception e) {
log.error("EditTestName failed!:[{}]", e.getMessage());
throw new RuntimeException(e);
}
return flag;
}
@Override
public void startMission(int id) {
Test test = testMapper.getTestById(id);
if (!(test.getFuzzParamsId() == 0)) {
log.error("This is a empty test!");
throw new RuntimeException();
}
/*生成任务*/
int missionId = GlobalClass.missionInfoMapper.selectTopMissionId() + 1;
SystemRunningParams.kittyMissionId = missionId;
MissionInfo missionInfo = new MissionInfo(missionId, TableClassEnum.KITTY_RESULT.getTableId(), new Date(), SystemRunningParams.kittyData.get("missionName"),
MissionStateEnum.RUNNING.getStateCode(), 0L);
}
}
......@@ -25,6 +25,11 @@
set fuzzParamsId = #{fuzzParamsId}, updateTime = #{updateTime}
where id = #{id}
</update>
<update id="editTestName">
update test
set testName = #{testName}
where id = #{id}
</update>
<delete id="deleteById">
DELETE
t1, t2
......@@ -32,6 +37,9 @@
INNER JOIN fuzz_params t2 ON t1.fuzzParamsId = t2.id
WHERE t1.id = #{id};
</delete>
<delete id="deleteEmptyById">
DELETE FROM test where id = #{id}
</delete>
<select id="getTestAndParamsList" resultType="com.example.fuzzControll.domain.po.TestAndParams">
select test.id, fuzzParamsId,createTime,updateTime,missionIds,testName,params,protocol from test,fuzz_params
where test.fuzzParamsId = fuzz_params.id
......@@ -40,5 +48,9 @@
<include refid="selectAll"/>
where id = #{id}
</select>
<select id="getTestList" resultType="com.example.fuzzControll.domain.po.Test">
<include refid="selectAll"/>
where fuzzParamsId = 0
</select>
</mapper>
\ No newline at end of file
......@@ -55,4 +55,11 @@ public class TestMissionController {
public AjaxResult insertParmasInTestKitty(@PathVariable("id") int id, @RequestBody TestEntity testEntity) {
return fuzzIntegrationFileApi.insertParmasInTestKitty(id, testEntity);
}
/**
* 测试名称修改
*/
@RequestMapping(value = "/editTestName", method = RequestMethod.GET)
public AjaxResult editTestName(@RequestParam String testName,@RequestParam int id) {
return fuzzIntegrationFileApi.editTestName(testName, id);
}
}
......@@ -163,7 +163,7 @@ public interface FuzzIntegrationFileApi {
* 跟据id删除测试
*/
@RequestMapping(value = "/testmission/deleteById", method = RequestMethod.GET)
AjaxResult deleteById(int id);
AjaxResult deleteById(@RequestParam int id);
/**
* 插入空白测试信息
*/
......@@ -177,4 +177,10 @@ public interface FuzzIntegrationFileApi {
AjaxResult insertParmasInTestAflnet(@PathVariable("id")int id,@RequestBody final CmdStartParams cmdStartParams);
@RequestMapping(value = "/testmission/insertWithkitty/{id}", method = RequestMethod.POST)
AjaxResult insertParmasInTestKitty(@PathVariable("id")int id,@RequestBody TestEntity testEntity);
/**
* 测试名称修改
*/
@RequestMapping(value = "/testmission/editTestName", method = RequestMethod.GET)
AjaxResult editTestName(@RequestParam String testName,@RequestParam int id);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment