Merge branch 'master' into 'v1.0.1_dev'

Master to dev branch

See merge request DDOSAQ/phoenix_ddos_handle!4
This commit is contained in:
黄昕 2020-07-08 14:52:31 +08:00
commit e80cfada82
16 changed files with 475 additions and 319 deletions

View File

@ -112,7 +112,7 @@ public enum IPAddrType {
return ipv4.matches(ipv4Regex);
default:
// Ip v6 + port
if (ipAddr.contains("[")) {
if (ipAddr.contains(ipv6PortChar)) {
String ipv6 = ipAddr.substring(1, ipAddr.lastIndexOf(ipv6PortChar));
return ipv6.matches(ipv6Regex);
} else {

View File

@ -117,7 +117,7 @@ public class DisposeTaskController {
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
}
if (reqInfo.getDisposeTime() == null) {
if (reqInfo.getDisposeTime() == null || reqInfo.getDisposeTime() < 0) {
log.error("Request dispose time params error, error:{} --> {}", mr.getMsgContent(), reqInfo.getDisposeTime());
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
}

View File

@ -22,6 +22,12 @@ public class DeviceRouter {
return devType + "_" + ipAddr;
}
/**
* Device router factory dispose entry manager.
*
* @param device the device
* @return the dispose entry manager
*/
public static DisposeEntryManager deviceRouterFactory(DisposeDevice device) {
String mapKey = getMapKey(device.getType(), device.getIpAddr());
@ -56,11 +62,11 @@ public class DeviceRouter {
}
/**
* Device router factory dispose entry manager.
* Gets device router factory.
*
* @param devType the dev type
* @param ipAddr the ip addr
* @return the dispose entry manager
* @return the device router factory
*/
public static DisposeEntryManager getDeviceRouterFactory(int devType, String ipAddr) {

View File

@ -1,6 +1,10 @@
package com.dispose.dispose.impl;
import com.dispose.common.*;
import com.dispose.common.CleanTaskStatus;
import com.dispose.common.DeviceCapacity;
import com.dispose.common.DpTechAttackType;
import com.dispose.common.ErrorCode;
import com.dispose.common.GlobalVar;
import com.dispose.config.DisposeConfigure;
import com.dispose.dispose.DisposeEntryManager;
import com.dispose.dispose.po.DeviceInfo;
@ -9,7 +13,6 @@ import com.dispose.pojo.po.DisposeDeviceCapacity;
import com.dispose.pojo.po.MulReturnType;
import com.dptech.dispose.AbnormalFlowCleaningServicePortType;
import com.dptech.dispose.ArrayOfProtectionObjectDataForService;
import com.dptech.dispose.NtcRequestResultInfo;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.cxf.endpoint.Client;

View File

@ -82,6 +82,16 @@ public class ProtocolRespDTO extends BaseProtocolDTO {
return result(err, getObjectJson(obj), ConstValue.Protocol.CRYPTO_NONE);
}
/**
* Result protocol resp dto.
*
* @param <T> the type parameter
* @param err the err
* @param obj the obj
* @param objType the obj type
* @return the protocol resp dto
* @throws JsonProcessingException the json processing exception
*/
public static <T> ProtocolRespDTO result(ErrorCode err, Object obj, Class<T> objType) throws JsonProcessingException {
return result(err, getObjectJson(obj, objType), ConstValue.Protocol.CRYPTO_NONE);
}

View File

@ -1,7 +1,11 @@
package com.dispose.pojo.vo.haohan;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
/**
* The type Clean rsp.

View File

@ -23,20 +23,20 @@ import org.junit.runners.Suite;
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
MyConfigTest.class,
TaskServiceTest.class,
DisposeConfigureTest.class,
DisposeTaskMapperTest.class,
DisposeNodeManagerTest.class,
DPTechInterfaceTestCase.class,
UserAccountMapperTest.class,
UserAccountManagerTest.class,
DisposeDeviceMapperTest.class,
AuthControllerTest.class,
DeviceNodeManagerControllerTest.class,
DeviceNodeInfoControllerTest.class,
UserAccountServiceTest.class,
TaskControllerTest.class
// MyConfigTest.class,
// TaskServiceTest.class,
// DisposeConfigureTest.class,
// DisposeTaskMapperTest.class,
// DisposeNodeManagerTest.class,
// DPTechInterfaceTestCase.class,
// UserAccountMapperTest.class,
// UserAccountManagerTest.class,
// DisposeDeviceMapperTest.class,
// AuthControllerTest.class,
// DeviceNodeManagerControllerTest.class,
// DeviceNodeInfoControllerTest.class,
// UserAccountServiceTest.class,
// TaskControllerTest.class
})
public class AllDisposePlatformTest {

View File

@ -13,14 +13,14 @@ import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
AuthControllerQATest.class,
AuthControllerSmokeTest.class,
DeviceNodeManagerControllerQATest.class,
DeviceNodeManagerControllerSmokeTest.class,
DeviceNodeInfoControllerQATest.class,
DeviceNodeInfoControllerSmokeTest.class,
TaskControllerQATest.class,
TaskControllerSmokeTest.class
// AuthControllerQATest.class,
// AuthControllerSmokeTest.class,
// DeviceNodeManagerControllerQATest.class,
// DeviceNodeManagerControllerSmokeTest.class,
// DeviceNodeInfoControllerQATest.class,
// DeviceNodeInfoControllerSmokeTest.class,
// TaskControllerQATest.class,
// TaskControllerSmokeTest.class
})
public class QATest {
}

View File

@ -12,10 +12,10 @@ import org.junit.runners.Suite;
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
AuthControllerSmokeTest.class,
DeviceNodeManagerControllerSmokeTest.class,
DeviceNodeInfoControllerSmokeTest.class,
TaskControllerSmokeTest.class
// AuthControllerSmokeTest.class,
// DeviceNodeManagerControllerSmokeTest.class,
// DeviceNodeInfoControllerSmokeTest.class,
// TaskControllerSmokeTest.class
})
public class SmokeTest {

View File

@ -2623,8 +2623,16 @@ public class DeviceNodeInfoControllerQATest extends InitTestEnvironment {
rspInfo.getItems().forEach(v -> {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getId());
Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHTASK.getCode()));
Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHTASK.getMsg());
Assert.assertNotNull(v.getStatus());
Assert.assertNotNull(v.getMessage());
if(v.getStatus() == 19){
Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode()));
Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg());
}else if(v.getStatus() == 30){
Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHTASK.getCode()));
Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHTASK.getMsg());
}
});
}

View File

@ -5,7 +5,6 @@ import com.dispose.common.ErrorCode;
import com.dispose.common.GlobalVar;
import com.dispose.mapper.DisposeTaskMapper;
import com.dispose.pojo.po.ReturnStatus;
import com.dispose.pojo.vo.common.DisposeCapacity;
import com.dispose.pojo.vo.common.TaskInfoData;
import com.dispose.pojo.vo.common.TaskInfoDetail;
import com.dispose.pojo.vo.information.DisposeNodeData;

View File

@ -92,17 +92,20 @@ public class DeviceNodeManagerControllerSmokeTest extends InitTestEnvironment {
}
/**
* A 1 add Normal DeviceNodeManager test.
* A 1 add Normal DPTech DeviceNodeManager test.
*
* @throws Exception the exception
*/
@Test
public void a1_addNormalDeviceNodeManager() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587628826908," +
public void a1_addNormalDPTechDeviceNodeManager() throws Exception {
String reqData = "{\"ver\": 2,\"cryptoType\": 0,\"timeStamp\": 1589437275258," +
"\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"10.88.77.15\\\"," +
"\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\"," +
"\\\"name\\\":\\\"中移杭研实验室清洗设备\\\",\\\"readme\\\":\\\"实验室测试设备\\\"," +
"\\\"type\\\":0,\\\"version\\\":\\\"5.7.13\\\"}]}\"}";
"\\\"type\\\":0,\\\"version\\\":\\\"5.7.13\\\",\\\"userName\\\":\\\"admin\\\"," +
"\\\"password\\\":\\\"UMCAdministrator\\\"," +
"\\\"url\\\":\\\"http://%s/UMC/service/AbnormalFlowCleaningService\\\" }]}\"\n" +
"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.put("/manager/device")
@ -133,6 +136,51 @@ public class DeviceNodeManagerControllerSmokeTest extends InitTestEnvironment {
}
}
/**
* A 2 add Normal HaoHan DeviceNodeManager test.
*
* @throws Exception the exception
*/
@Test
public void a2_addNormalHaoHanDeviceNodeManager() throws Exception {
String reqData = "{\n" +
"\"ver\": 2,\n" +
"\"cryptoType\": 0,\n" +
"\"timeStamp\": 1589437275258,\n" +
"\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"10.88.77.88:18080\\\"," +
"\\\"manufacturer\\\":\\\"HaoHan\\\",\\\"model\\\":\\\"Unknown\\\"," +
"\\\"name\\\":\\\"中移杭研实验室浩瀚清洗设备\\\",\\\"readme\\\":\\\"实验室测试设备\\\",\\\"type\\\":1," +
"\\\"version\\\":\\\"Unknown\\\",\\\"url\\\":\\\"http://%s/DDoSClean/clean\\\" }]}\"\n" +
"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.put("/manager/device")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
AddNodeRsp retStatus = objectMapper.readValue(verifyResp(ret), AddNodeRsp.class);
List<AddNodeRetData> r = retStatus.getItems();
for (AddNodeRetData v : r
) {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getIpAddr());
Assert.assertNotNull(v.getDevId());
Assert.assertNotNull(v.getMessage());
Assert.assertNotNull(v.getStatus());
if (v.getStatus() == 0) {
Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
} else if (v.getStatus() == 20) {
Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_DEVICEEXISTS.getCode()));
}
}
}
/**
* B 1 delete Normal DeviceNodeManager test.

View File

@ -313,8 +313,6 @@ public class DeviceNodeManagerControllerTest extends InitTestEnvironment {
reqInfo.setTimeStamp(reqTimeStamp);
reqInfo.setMsgContent(objectMapper.writeValueAsString(addReq));
List<DisposeDevice> decsBef = disposeNodeManager.getAllDisposeDevice();
mockMvc.perform(MockMvcRequestBuilders
.put("/manager/device")
.contentType(MediaType.APPLICATION_JSON)
@ -351,8 +349,6 @@ public class DeviceNodeManagerControllerTest extends InitTestEnvironment {
reqInfo.setTimeStamp(reqTimeStamp);
reqInfo.setMsgContent(objectMapper.writeValueAsString(addReq));
List<DisposeDevice> decsBef = disposeNodeManager.getAllDisposeDevice();
mockMvc.perform(MockMvcRequestBuilders
.put("/manager/device")
.contentType(MediaType.APPLICATION_JSON)

View File

@ -54,7 +54,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
@Test
public void a1_NormalContainsNonEmptyTaskTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," +
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," +
"\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.5.4\\\", " +
"\\\"disposeTime\\\":120, \\\"flowDirection\\\":2, \\\"attackType\\\":[0], " +
"\\\"flowBandwidth\\\":1024}\"}";
@ -85,6 +85,9 @@ public class TaskControllerQATest extends InitTestEnvironment {
} else if (startTaskRsp.getStatus() == 26) {
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_TASKRUNNING.getCode()));
Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_TASKRUNNING.getMsg());
} else if (startTaskRsp.getStatus() == 19) {
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode()));
Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg());
}
}
@ -95,7 +98,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
*/
@Test
public void a2_startTaskDisPoseIpEmptyExceptionTest() throws Exception {
String reqDataNoIp = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," +
String reqDataNoIp = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," +
"\\\"type\\\":0, \\\"disposeIp\\\":\\\"\\\", \\\"disposeTime\\\":120}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
@ -125,7 +128,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
@Test
public void a3_startTaskDisposeIpNullExceptionTest() throws Exception {
//disposeIp null
String reqDataNullIp = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," +
String reqDataNullIp = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," +
"\\\"type\\\":0, \\\"disposeIp\\\":null, \\\"disposeTime\\\":120}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
@ -154,7 +157,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
*/
@Test
public void a4_startTaskDisposeIpIntegerExceptionTest() throws Exception {
String reqDataIntegerIp = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," +
String reqDataIntegerIp = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," +
"\\\"type\\\":0, \\\"disposeIp\\\":192345, \\\"disposeTime\\\":120}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
@ -212,7 +215,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
*/
@Test
public void a6_startTaskTypeEmptyExceptionTest() throws Exception {
String reqDataNoType = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," +
String reqDataNoType = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," +
"\\\"type\\\":, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
@ -241,7 +244,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
*/
@Test
public void a7_startTaskTypeNullExceptionTest() throws Exception { //null type
String reqDataNullType = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," +
String reqDataNullType = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," +
"\\\"type\\\":null, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
@ -271,7 +274,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
@Test
public void a8_startTaskDisposeTimeEmptyExceptionTest() throws Exception {
//no disposeTime
String reqDataNoDisposeTime = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," +
String reqDataNoDisposeTime = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," +
"\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
@ -301,7 +304,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
@Test
public void a9_startTaskDisposeTimeNullExceptionTest() throws Exception {
//null disposeTime
String reqDataNullDisposeTime = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," +
String reqDataNullDisposeTime = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," +
"\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":null}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
@ -331,7 +334,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
@Test
public void a10_startTaskDisposeTimeStringExceptionTest() throws Exception {
//string disposeTime
String reqDataStringDisposeTime = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," +
String reqDataStringDisposeTime = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," +
"\\\"type\\\":null, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":\\\"120\\\"}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
@ -354,40 +357,12 @@ public class TaskControllerQATest extends InitTestEnvironment {
}
/**
* a11 id empty exception test.
* a11 id zero test.
*
* @throws Exception the exception
*/
@Test
public void a11_startTaskIdEmptyExceptionTest() throws Exception {
String reqDataIdEmpty = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":\\\"\\\"," +
"\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/task/start")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
.content(reqDataIdEmpty))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class);
Assert.assertNotNull(returnStatus.getStatus());
Assert.assertNotNull(returnStatus.getMessage());
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode()));
Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg());
}
/**
* a12 id zero test.
*
* @throws Exception the exception
*/
@Test
public void a12_startTaskIdZeroTest() throws Exception {
public void a11_startTaskIdZeroTest() throws Exception {
String reqDataIdZero = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":\\\"0\\\"," +
"\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}";
@ -407,67 +382,17 @@ public class TaskControllerQATest extends InitTestEnvironment {
Assert.assertNotNull(startTaskRsp);
Assert.assertNotNull(startTaskRsp.getStatus());
Assert.assertNotNull(startTaskRsp.getMessage());
if (startTaskRsp.getStatus() == 0) {
Assert.assertNotNull(String.valueOf(startTaskRsp.getExpireTime()));
Assert.assertNotNull(startTaskRsp.getId());
Assert.assertNotNull(startTaskRsp.getTaskId());
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_OK.getMsg());
} else if (startTaskRsp.getStatus() == 26) {
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_TASKRUNNING.getCode()));
Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_TASKRUNNING.getMsg());
} else if (startTaskRsp.getStatus() == 19) {
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode()));
Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg());
}
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode()));
Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg());
}
/**
* a13 id normal exception test.
* a12 type error exception test.
*
* @throws Exception the exception
*/
@Test
public void a13_startTaskIdNormalTest() throws Exception {
String reqDataIdNormal = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":\\\"1\\\"," +
"\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/task/start")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
.content(reqDataIdNormal))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
StartTaskRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), StartTaskRsp.class);
Assert.assertNotNull(startTaskRsp);
Assert.assertNotNull(startTaskRsp.getStatus());
Assert.assertNotNull(startTaskRsp.getMessage());
if (startTaskRsp.getStatus() == 0) {
Assert.assertNotNull(String.valueOf(startTaskRsp.getExpireTime()));
Assert.assertNotNull(startTaskRsp.getId());
Assert.assertNotNull(startTaskRsp.getTaskId());
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_OK.getMsg());
} else if (startTaskRsp.getStatus() == 26) {
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_TASKRUNNING.getCode()));
Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_TASKRUNNING.getMsg());
}
}
/**
* a14 type error exception test.
*
* @throws Exception the exception
*/
@Test
public void a14_startTaskTypeErrorExceptionTest() throws Exception {
public void a12_startTaskTypeErrorExceptionTest() throws Exception {
String reqDataTypeError = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," +
"\\\"type\\\":5, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}";
@ -489,16 +414,17 @@ public class TaskControllerQATest extends InitTestEnvironment {
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode()));
Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg());
}
/**
* a15 disposeTime negative exception test.
* a13 disposeTime negative exception test.
*
* @throws Exception the exception
*/
@Test
public void a15_startTaskDisposeTimeNegativeExceptionTest() throws Exception {
public void a13_startTaskDisposeTimeNegativeExceptionTest() throws Exception {
//string disposeTime
String reqDataDisposeTimeNegative = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," +
"\\\"type\\\":null, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":-10}\"}";
"\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":-10}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/task/start")
@ -518,22 +444,106 @@ public class TaskControllerQATest extends InitTestEnvironment {
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode()));
Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg());
}
/**
* a16 disposeTime zero exception test.
* a14 start dispose task Broadcast
*
* @throws Exception the exception
*/
@Test
public void a16_startTaskDisposeTimeZeroExceptionTest() throws Exception {
//string disposeTime
String reqDataDisposeTimeZero = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," +
"\\\"type\\\":null, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":0}\"}";
public void a14_BroadcastNormalContainsNonEmptyTaskTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," +
"\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.5.2\\\", " +
"\\\"disposeTime\\\":120, \\\"flowDirection\\\":2, \\\"attackType\\\":[0], " +
"\\\"flowBandwidth\\\":1024}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/task/start")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
.content(reqDataDisposeTimeZero))
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
StartTaskRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), StartTaskRsp.class);
Assert.assertNotNull(startTaskRsp);
Assert.assertNotNull(startTaskRsp.getStatus());
Assert.assertNotNull(startTaskRsp.getMessage());
if (startTaskRsp.getStatus() == 0) {
Assert.assertNotNull(String.valueOf(startTaskRsp.getExpireTime()));
Assert.assertNotNull(startTaskRsp.getId());
Assert.assertNotNull(startTaskRsp.getTaskId());
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_OK.getMsg());
} else if (startTaskRsp.getStatus() == 26) {
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_TASKRUNNING.getCode()));
Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_TASKRUNNING.getMsg());
}
}
/**
* a15 start dispose task Broadcast type negative. -1代表所有任务类型 清洗高防黑洞检测
*
* @throws Exception the exception
*/
@Test
public void a15_broadCastStartTaskTypeNegativeExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," +
"\\\"type\\\":-1, \\\"disposeIp\\\":\\\"192.168.5.2\\\", " +
"\\\"disposeTime\\\":120, \\\"flowDirection\\\":2, \\\"attackType\\\":[0], " +
"\\\"flowBandwidth\\\":1024}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/task/start")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
StartTaskRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), StartTaskRsp.class);
Assert.assertNotNull(startTaskRsp);
Assert.assertNotNull(startTaskRsp.getStatus());
Assert.assertNotNull(startTaskRsp.getMessage());
if (startTaskRsp.getStatus() == 0) {
Assert.assertNotNull(String.valueOf(startTaskRsp.getExpireTime()));
Assert.assertNotNull(startTaskRsp.getId());
Assert.assertNotNull(startTaskRsp.getTaskId());
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_OK.getMsg());
} else if (startTaskRsp.getStatus() == 26) {
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_TASKRUNNING.getCode()));
Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_TASKRUNNING.getMsg());
}
}
/**
* a16 start dispose task Broadcast type negative. < -1
*
* @throws Exception the exception
*/
@Test
public void a16_broadCastStartTaskTypeNegativeExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," +
"\\\"type\\\":-2, \\\"disposeIp\\\":\\\"192.168.5.2\\\", " +
"\\\"disposeTime\\\":120, \\\"flowDirection\\\":2, \\\"attackType\\\":[0], " +
"\\\"flowBandwidth\\\":1024}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/task/start")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode()))
.andReturn()
@ -547,6 +557,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode()));
Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg());
}
/**
* b1 taskId empty exception test. 停止指定任务的时候必须指定id id不能为空字符串
*
@ -741,6 +752,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
}
}
}
/**
* b7 taskId int exception test.
*
@ -769,6 +781,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg());
}
/**
* c1 id null exception test.
*
@ -1000,6 +1013,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode()));
Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg());
}
/**
* c9 type negative exception test.
*/
@ -1024,6 +1038,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode()));
Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg());
}
/**
* c10 normal stop tasks by dispose ip test.
*/
@ -1061,6 +1076,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
}
}
}
/**
* d1 stop task by single node test.
*/
@ -1254,6 +1270,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode()));
Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg());
}
/**
* d7 type string exception test.
*
@ -1492,6 +1509,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
}
}
}
/**
* e7 type error exception test.
*
@ -1518,6 +1536,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode()));
Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg());
}
/**
* f1 get node task of node test.
*/
@ -1540,7 +1559,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
NodeTaskRsp nodeTaskRsp = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class);
Assert.assertNotNull(nodeTaskRsp);
nodeTaskRsp.getItems().forEach(v->{
nodeTaskRsp.getItems().forEach(v -> {
Assert.assertNotNull(v.getStatus());
Assert.assertNotNull(v.getMessage());
@ -1570,7 +1589,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
}
/**
*f2 get node task id empty exception test.空表示所有能力节点
* f2 get node task id empty exception test.空表示所有能力节点
*/
@Test
public void f2_NormalGetNodeTaskInfoIdTest() throws Exception {
@ -1591,7 +1610,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
NodeTaskRsp nodeTaskRsp = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class);
Assert.assertNotNull(nodeTaskRsp);
nodeTaskRsp.getItems().forEach(v->{
nodeTaskRsp.getItems().forEach(v -> {
Assert.assertNotNull(v.getStatus());
Assert.assertNotNull(v.getMessage());
@ -1799,6 +1818,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
}
});
}
/**
* f8 get node task Array contains character test .
*/
@ -1851,7 +1871,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
TaskInfoRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), TaskInfoRsp.class);
Assert.assertNotNull(startTaskRsp);
startTaskRsp.getItems().forEach(v->{
startTaskRsp.getItems().forEach(v -> {
Assert.assertNotNull(v.getId());
Assert.assertNotNull(v.getTaskId());
Assert.assertNotNull(v.getStartTime());
@ -1939,7 +1959,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
TaskInfoRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), TaskInfoRsp.class);
Assert.assertNotNull(startTaskRsp);
startTaskRsp.getItems().forEach(v->{
startTaskRsp.getItems().forEach(v -> {
Assert.assertNotNull(v.getId());
Assert.assertNotNull(v.getTaskId());
Assert.assertNotNull(v.getStartTime());
@ -1973,24 +1993,25 @@ public class TaskControllerQATest extends InitTestEnvironment {
TaskInfoRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), TaskInfoRsp.class);
Assert.assertNotNull(startTaskRsp);
startTaskRsp.getItems().forEach(v->{
startTaskRsp.getItems().forEach(v -> {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getTaskId());
Assert.assertNotNull(v.getStatus());
Assert.assertNotNull(v.getMessage());
if(v.getStatus() == 0){
if (v.getStatus() == 0) {
Assert.assertNotNull(v.getId());
Assert.assertNotNull(v.getStartTime());
Assert.assertNotNull(v.getDisposeTime());
Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg());
}else if(v.getStatus() == 30){
} else if (v.getStatus() == 30) {
Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHTASK.getCode()));
Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHTASK.getMsg());
}
});
}
/**
* g6 get node detailed taskId int exception test .
*/

View File

@ -1,6 +1,8 @@
package com.dispose.test.haohan;
import com.dispose.common.GlobalVar;
import com.dispose.common.Http;
import com.dispose.test.Global.InitTestEnvironment;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
@ -18,273 +20,309 @@ import javax.annotation.Resource;
@Slf4j
@SpringBootTest
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class HaoHanInterfaceTestCase {
public class HaoHanInterfaceTestCase extends InitTestEnvironment {
@Resource
private ObjectMapper objectMapper;
@Override
public void userLogin(){
}
@Test
public void a1_sendTowWhitelistTest() throws JsonProcessingException {
String jsonRequest = "{\"ip\":\"192.168.1.1\",\"orderFrom\":\"hangyan\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/sendTow",
null,
jsonRequest);
if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) {
String jsonRequest = "{\"ip\":\"192.168.1.1\",\"orderFrom\":\"hangyan\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/sendTow",
null,
jsonRequest);
log.info("Server Return: [{}]", svrReturn);
sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class);
log.info("Server Return: [{}]", svrReturn);
sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class);
Assert.assertNotNull(result);
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_WHITELIST.getMsg());
Assert.assertEquals(result.getState(), Integer.valueOf(1));
Assert.assertNotNull(result);
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_WHITELIST.getMsg());
Assert.assertEquals(result.getState(), Integer.valueOf(1));
}
}
@Test
public void a2_sendTowWhitelistContainsDurationTest() throws JsonProcessingException {
String jsonRequest = "{\"ip\":\"192.168.1.1\",\"duration\":20, \"orderFrom\":\"hangyan\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/sendTow",
null,
jsonRequest);
if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) {
String jsonRequest = "{\"ip\":\"192.168.1.1\",\"duration\":20, \"orderFrom\":\"hangyan\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/sendTow",
null,
jsonRequest);
log.info("Server Return: [{}]", svrReturn);
sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class);
log.info("Server Return: [{}]", svrReturn);
sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class);
Assert.assertNotNull(result);
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_WHITELIST.getMsg());
Assert.assertEquals(result.getState(), Integer.valueOf(1));
Assert.assertNotNull(result);
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_WHITELIST.getMsg());
Assert.assertEquals(result.getState(), Integer.valueOf(1));
}
}
@Test
public void a3_normalSendTowTest() throws JsonProcessingException {
String jsonRequest = "{\"ip\":\"192.168.1.2\",\"orderFrom\":\"hangyan\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/sendTow",
null,
jsonRequest);
if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) {
String jsonRequest = "{\"ip\":\"192.168.1.2\",\"orderFrom\":\"hangyan\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/sendTow",
null,
jsonRequest);
log.info("Server Return: [{}]", svrReturn);
sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class);
log.info("Server Return: [{}]", svrReturn);
sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class);
Assert.assertNotNull(result);
if (result.getState() == 0) {
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg());
Assert.assertNotNull(result.getCleanTaskId());
} else {
Assert.assertNotEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg());
Assert.assertNotNull(result);
if (result.getState() == 0) {
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg());
Assert.assertNotNull(result.getCleanTaskId());
} else {
Assert.assertNotEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg());
}
}
}
@Test
public void a4_normalSendTowContainsDurationTest() throws JsonProcessingException {
String jsonRequest = "{\"ip\":\"192.168.1.20\",\"duration\":20,\"orderFrom\":\"hangyan\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/sendTow",
null,
jsonRequest);
if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) {
String jsonRequest = "{\"ip\":\"192.168.1.20\",\"duration\":20,\"orderFrom\":\"hangyan\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/sendTow",
null,
jsonRequest);
log.info("Server Return: [{}]", svrReturn);
sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class);
log.info("Server Return: [{}]", svrReturn);
sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class);
Assert.assertNotNull(result);
if (result.getState() == 0) {
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg());
Assert.assertNotNull(result.getCleanTaskId());
} else {
Assert.assertNotEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg());
Assert.assertNotNull(result);
if (result.getState() == 0) {
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg());
Assert.assertNotNull(result.getCleanTaskId());
} else {
Assert.assertNotEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg());
}
}
}
@Test
public void a5_sendTowIpErrorTest() throws JsonProcessingException {
String jsonRequest = "{\"ip\":\"192.168.120\",\"duration\":20,\"orderFrom\":\"hangyan\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/sendTow",
null,
jsonRequest);
if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) {
String jsonRequest = "{\"ip\":\"192.168.120\",\"duration\":20,\"orderFrom\":\"hangyan\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/sendTow",
null,
jsonRequest);
log.info("Server Return: [{}]", svrReturn);
sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class);
log.info("Server Return: [{}]", svrReturn);
sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class);
Assert.assertNotNull(result);
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_DISPOSEIPFORMAT.getMsg());
Assert.assertEquals(result.getState(), Integer.valueOf(1));
Assert.assertNotNull(result);
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_DISPOSEIPFORMAT.getMsg());
Assert.assertEquals(result.getState(), Integer.valueOf(1));
}
}
@Test
public void a6_sendTowDurationErrorTest() throws JsonProcessingException {
String jsonRequest = "{\"ip\":\"192.168.1.20\",\"duration\":\"20\",\"orderFrom\":\"hangyan\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/sendTow",
null,
jsonRequest);
if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) {
String jsonRequest = "{\"ip\":\"192.168.1.20\",\"duration\":\"20\",\"orderFrom\":\"hangyan\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/sendTow",
null,
jsonRequest);
log.info("Server Return: [{}]", svrReturn);
sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class);
log.info("Server Return: [{}]", svrReturn);
sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class);
Assert.assertNotNull(result);
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_DURATIONFORMAT.getMsg());
Assert.assertEquals(result.getState(), Integer.valueOf(1));
Assert.assertNotNull(result);
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_DURATIONFORMAT.getMsg());
Assert.assertEquals(result.getState(), Integer.valueOf(1));
}
}
@Test
public void a7_sendTowOrderFromErrorTest() throws JsonProcessingException {
String jsonRequest = "{\"ip\":\"192.168.1.20\",\"duration\":20,\"orderFrom\":123}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/sendTow",
null,
jsonRequest);
if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) {
String jsonRequest = "{\"ip\":\"192.168.1.20\",\"duration\":20,\"orderFrom\":123}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/sendTow",
null,
jsonRequest);
log.info("Server Return: [{}]", svrReturn);
sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class);
log.info("Server Return: [{}]", svrReturn);
sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class);
Assert.assertNotNull(result);
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_ORDERFROMFORMA.getMsg());
Assert.assertEquals(result.getState(), Integer.valueOf(1));
Assert.assertNotNull(result);
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_ORDERFROMFORMA.getMsg());
Assert.assertEquals(result.getState(), Integer.valueOf(1));
}
}
@Test
public void b1_delTowTest() throws JsonProcessingException {
String jsonRequest = "{\"cleanTaskId\":105,\"orderFrom\":\"hangyan\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/delTow",
null,
jsonRequest);
if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) {
String jsonRequest = "{\"cleanTaskId\":105,\"orderFrom\":\"hangyan\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/delTow",
null,
jsonRequest);
log.info("Server Return: [{}]", svrReturn);
sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class);
log.info("Server Return: [{}]", svrReturn);
sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class);
Assert.assertNotNull(result);
if (result.getState() == 0) {
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg());
} else {
Assert.assertNotEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg());
Assert.assertNotNull(result);
if (result.getState() == 0) {
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg());
} else {
Assert.assertNotEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg());
}
}
}
@Test
public void b2_delTowCleanTaskIdErrorTest() throws JsonProcessingException {
String jsonRequest = "{\"cleanTaskId\":\"105\",\"orderFrom\":\"hangyan\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/delTow",
null,
jsonRequest);
if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) {
String jsonRequest = "{\"cleanTaskId\":\"105\",\"orderFrom\":\"hangyan\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/delTow",
null,
jsonRequest);
log.info("Server Return: [{}]", svrReturn);
sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class);
log.info("Server Return: [{}]", svrReturn);
sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class);
Assert.assertNotNull(result);
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_CLEANTASKIDFORMA.getMsg());
Assert.assertEquals(result.getState(), Integer.valueOf(1));
Assert.assertNotNull(result);
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_CLEANTASKIDFORMA.getMsg());
Assert.assertEquals(result.getState(), Integer.valueOf(1));
}
}
@Test
public void b3_delTowOrderFromErrorTest() throws JsonProcessingException {
String jsonRequest = "{\"cleanTaskId\":105,\"orderFrom\":123}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/delTow",
null,
jsonRequest);
if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) {
String jsonRequest = "{\"cleanTaskId\":105,\"orderFrom\":123}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/delTow",
null,
jsonRequest);
log.info("Server Return: [{}]", svrReturn);
sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class);
log.info("Server Return: [{}]", svrReturn);
sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class);
Assert.assertNotNull(result);
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_ORDERFROMFORMA.getMsg());
Assert.assertEquals(result.getState(), Integer.valueOf(1));
Assert.assertNotNull(result);
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_ORDERFROMFORMA.getMsg());
Assert.assertEquals(result.getState(), Integer.valueOf(1));
}
}
@Test
public void c1_allIpFlowTest() throws JsonProcessingException {
String jsonRequest = "{\"orderFrom\":\"hangyan\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/allIpFlow",
null,
jsonRequest);
if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) {
String jsonRequest = "{\"orderFrom\":\"hangyan\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/allIpFlow",
null,
jsonRequest);
log.info("Server Return: [{}]", svrReturn);
allIpFlowResult result = objectMapper.readValue(svrReturn, allIpFlowResult.class);
log.info("Server Return: [{}]", svrReturn);
allIpFlowResult result = objectMapper.readValue(svrReturn, allIpFlowResult.class);
Assert.assertNotNull(result);
if (result.getState() == 0) {
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg());
for (allIpFlowData data : result.getData()
) {
Assert.assertNotNull(data.getIp());
Assert.assertNotNull(result);
if (result.getState() == 0) {
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg());
for (allIpFlowData data : result.getData()
) {
Assert.assertNotNull(data.getIp());
}
} else {
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_NORUNNINGTASK.getMsg());
}
} else {
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_NORUNNINGTASK.getMsg());
}
}
@Test
public void c2_allIpFlowTest() throws JsonProcessingException {
String jsonRequest = "{\"orderFrom\":123}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/allIpFlow",
null,
jsonRequest);
if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) {
String jsonRequest = "{\"orderFrom\":123}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/allIpFlow",
null,
jsonRequest);
log.info("Server Return: [{}]", svrReturn);
allIpFlowResult result = objectMapper.readValue(svrReturn, allIpFlowResult.class);
log.info("Server Return: [{}]", svrReturn);
allIpFlowResult result = objectMapper.readValue(svrReturn, allIpFlowResult.class);
Assert.assertNotNull(result);
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_ORDERFROMFORMA.getMsg());
Assert.assertEquals(result.getState(), Integer.valueOf(1));
Assert.assertNotNull(result);
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_ORDERFROMFORMA.getMsg());
Assert.assertEquals(result.getState(), Integer.valueOf(1));
}
}
@Test
public void d1_cleanTaskFlowTest() throws JsonProcessingException {
String jsonRequest = "{\"cleanTaskId\":119}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/cleanTaskFlow",
null,
jsonRequest);
if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) {
String jsonRequest = "{\"cleanTaskId\":119}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/cleanTaskFlow",
null,
jsonRequest);
log.info("Server Return: [{}]", svrReturn);
allIpFlowResult result = objectMapper.readValue(svrReturn, allIpFlowResult.class);
log.info("Server Return: [{}]", svrReturn);
allIpFlowResult result = objectMapper.readValue(svrReturn, allIpFlowResult.class);
Assert.assertNotNull(result);
if (result.getState() == 0) {
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg());
for (allIpFlowData data : result.getData()
) {
Assert.assertNotNull(data.getIp());
Assert.assertNotNull(result);
if (result.getState() == 0) {
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg());
for (allIpFlowData data : result.getData()
) {
Assert.assertNotNull(data.getIp());
}
} else {
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_TASKNOEND.getMsg());
}
} else {
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_TASKNOEND.getMsg());
}
}
@Test
public void d2_cleanTaskFlowTest() throws JsonProcessingException {
String jsonRequest = "{\"cleanTaskId\":\"abc\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/cleanTaskFlow",
null,
jsonRequest);
if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) {
String jsonRequest = "{\"cleanTaskId\":\"abc\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/cleanTaskFlow",
null,
jsonRequest);
log.info("Server Return: [{}]", svrReturn);
allIpFlowResult result = objectMapper.readValue(svrReturn, allIpFlowResult.class);
Assert.assertNotNull(result);
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_CLEANTASKIDFORMA.getMsg());
log.info("Server Return: [{}]", svrReturn);
allIpFlowResult result = objectMapper.readValue(svrReturn, allIpFlowResult.class);
Assert.assertNotNull(result);
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_CLEANTASKIDFORMA.getMsg());
}
}
@Test
public void e1_getCleanTaskStateTest() throws JsonProcessingException {
String jsonRequest = "{\"cleanTaskId\":119}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/getCleanTaskState",
null,
jsonRequest);
if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) {
String jsonRequest = "{\"cleanTaskId\":119}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/getCleanTaskState",
null,
jsonRequest);
log.info("Server Return: [{}]", svrReturn);
sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class);
log.info("Server Return: [{}]", svrReturn);
sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class);
Assert.assertNotNull(result);
if (result.getState() == 0) {
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg());
} else {
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_NOTASK.getMsg());
Assert.assertNotNull(result);
if (result.getState() == 0) {
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_OK.getMsg());
} else {
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_NOTASK.getMsg());
}
}
}
@Test
public void e2_getCleanTaskStateTest() throws JsonProcessingException {
String jsonRequest = "{\"cleanTaskId\":\"adb\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/getCleanTaskState",
null,
jsonRequest);
if (!GlobalVar.USED_VIRTUAL_DISPOSE_MODE) {
String jsonRequest = "{\"cleanTaskId\":\"adb\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/getCleanTaskState",
null,
jsonRequest);
log.info("Server Return: [{}]", svrReturn);
sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class);
Assert.assertNotNull(result);
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_CLEANTASKIDFORMA.getMsg());
log.info("Server Return: [{}]", svrReturn);
sendTowResult result = objectMapper.readValue(svrReturn, sendTowResult.class);
Assert.assertNotNull(result);
Assert.assertEquals(result.getMsg(), HaoHanErrorCode.ERR_CLEANTASKIDFORMA.getMsg());
}
}
}

View File

@ -171,12 +171,35 @@ public class TaskInfoMapperTest extends InitTestEnvironment {
taskInfo.getId(), taskInfo.getStatus(), changeStatus);
taskInfoMapper.changeTaskInfoStatus(taskInfo.getId(), changeStatus);
Assert.assertNotEquals(beforeStatus, new Long((long) taskInfoMapper.getTaskInfoCurrentStatus(taskInfo.getId())));
Assert.assertNotEquals(beforeStatus, new Long(taskInfoMapper.getTaskInfoCurrentStatus(taskInfo.getId())));
}
}
}
}
}
/**
* T 5 del task information by deviceId.
*/
@Test
public void t5_removeTaskInfoById() {
List<TaskInfoDetail> taskInfoDetailList = disposeTaskMapper.getAllTaskByType(DeviceCapacity.CLEANUP.getCode());
if (taskInfoDetailList.size() > 0) {
for (TaskInfoDetail task : taskInfoDetailList
) {
log.info("taskId:{}", task.getId());
TaskInfo taskInfo = taskInfoMapper.getTaskInfo(task.getId(), task.getDeviceId());
if (taskInfo != null) {
Assert.assertNotNull(taskInfo);
taskInfoMapper.removeTaskInfoById(task.getDeviceId());
taskInfo = taskInfoMapper.getTaskInfo(task.getId(), task.getDeviceId());
Assert.assertNull(taskInfo);
}
}
}
}
}