parent
a3b766d1c2
commit
aa4b271bd7
|
@ -17,7 +17,7 @@ import lombok.NoArgsConstructor;
|
||||||
public class StartTaskReq {
|
public class StartTaskReq {
|
||||||
private int id;
|
private int id;
|
||||||
private int type;
|
private int type;
|
||||||
private String disposeId;
|
private String disposeIp;
|
||||||
private int disposeTime;
|
private int disposeTime;
|
||||||
private Integer flowDirection;
|
private Integer flowDirection;
|
||||||
private Integer[] attackType;
|
private Integer[] attackType;
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
package com.dispose.controller;
|
||||||
|
|
||||||
|
import com.dispose.Global.InitTestEnvironment;
|
||||||
|
import com.dispose.common.ConstValue;
|
||||||
|
import com.dispose.pojo.dto.ProtocolReqDTO;
|
||||||
|
import com.dispose.pojo.vo.common.IDArrayReq;
|
||||||
|
import com.dispose.pojo.vo.task.StartTaskReq;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type Task controller test.
|
||||||
|
*/
|
||||||
|
@AutoConfigureMockMvc
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
|
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||||
|
@Slf4j
|
||||||
|
public class TaskControllerTest extends InitTestEnvironment {
|
||||||
|
@Resource
|
||||||
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* T 1 start task.
|
||||||
|
*
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void t1_startTask() throws Exception {
|
||||||
|
StartTaskReq reqData = StartTaskReq.builder()
|
||||||
|
.id(210)
|
||||||
|
.type(ConstValue.DeviceCapacity.CLEANUP.getCode())
|
||||||
|
.disposeIp("192.168.0.1")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
|
||||||
|
reqInfo.setVer(ConstValue.Protocol.VERSION);
|
||||||
|
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
|
||||||
|
reqInfo.setTimeStamp(System.currentTimeMillis());
|
||||||
|
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
|
||||||
|
|
||||||
|
log.info("Request Json:" + objectMapper.writeValueAsString(reqInfo));
|
||||||
|
|
||||||
|
mockMvc.perform(MockMvcRequestBuilders
|
||||||
|
.post("/task/start")
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.header("Authorization", "Bearer 45509b805d955cfd5ef7093e27a8bb99b3733d9a7bf90e88ba528bcbd29c6122")
|
||||||
|
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||||
|
.andDo(print()).andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.code").value(200))
|
||||||
|
.andReturn()
|
||||||
|
.getResponse()
|
||||||
|
.getContentAsString();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue