REM:
1. 增加浩瀚设备错误码
2. 增加下发清洗返回类
3. 增加浩瀚设备下发清洗接口测试用例
This commit is contained in:
chenlinghy 2020-06-22 17:48:31 +08:00
parent 345c4abbdb
commit 92db13a726
3 changed files with 201 additions and 9 deletions

View File

@ -0,0 +1,44 @@
package com.dispose.test.haohan;
/**
* The enum Error code.
*
* @author <chenlinghy@cmhi.chinamoblie.com>
*/
public enum HaoHanErrorCode {
/**
* Err ok error code.
*/
ERR_OK("成功"),
/**
* Err whitelist error code.
*/
ERR_WHITELIST("ip已存在清洗ip白名单中不允许添加"),
/**
* Err ip format error code.
*/
ERR_DISPOSEIPFORMAT("IP地址格式有误"),
/**
* Err ip format error code.
*/
ERR_DURATIONFORMAT("清洗时长参数格式不正确,请检查!"),
/**
* Err orderFrom format error code.
*/
ERR_ORDERFROMFORMA("厂家信息参数格式不正确,请检查!"),
;
private final String errMsg;
HaoHanErrorCode(String msg) {
this.errMsg = msg;
}
/**
* Gets msg.
*
* @return the msg
*/
public String getMsg() {
return errMsg;
}
}

View File

@ -1,6 +1,8 @@
package com.dispose.test.haohan;
import com.dispose.common.Http;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.FixMethodOrder;
@ -10,37 +12,171 @@ import org.junit.runners.MethodSorters;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
@RunWith(SpringRunner.class)
@Slf4j
@SpringBootTest
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class HaoHanInterfaceTestCase {
@Resource
private ObjectMapper objectMapper;
@Test
public void a1_sendTowTest() {
String jsonRequest = "{\"ip\":\"192.168.1.1\",\"orderFrom\":\"haohandata\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/sendFlow",
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);
log.info("++++++++++++Server Return: [{}]", svrReturn);
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));
}
@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);
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));
}
@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);
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());
}
}
@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);
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());
}
}
@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);
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));
}
@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);
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));
}
@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);
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));
}
@Test
public void b1_delTowTest() {
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);
log.info("ServerReturn length: [{}]", svrReturn.length());
Assert.assertNotNull(svrReturn);
Assert.assertNotEquals(svrReturn.length(), 0);
}
@Test
public void a2_delTowTest() {
String jsonRequest = "{\"cleanTaskId\":12345,\"orderFrom\":\"haohandata\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/delFlow",
public void b2_delTowCleanTaskIdErrorTest() {
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);
log.info("Server Return: [{}]", svrReturn);
log.info("ServerReturn length: [{}]", svrReturn.length());
Assert.assertNotNull(svrReturn);
Assert.assertNotEquals(svrReturn.length(), 0);
}
@Test
public void a3_delTowTest() {
public void b3_delTowOrderFromErrorTest() {
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);
log.info("ServerReturn length: [{}]", svrReturn.length());
Assert.assertNotNull(svrReturn);
Assert.assertNotEquals(svrReturn.length(), 0);
}
@Test
public void b2_delTowTest() {
String jsonRequest = "{\"orderFrom\":\"haohandata\"}";
String svrReturn = Http.postJson("http://10.88.77.88:18080/DDoSClean/clean/allIpFlow",
null,

View File

@ -0,0 +1,12 @@
package com.dispose.test.haohan;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class sendTowResult {
private Integer state;
private String msg;
private Integer cleanTaskId;
}