diff --git a/src/test/java/com/dispose/test/haohan/HaoHanInterfaceTestCase.java b/src/test/java/com/dispose/test/haohan/HaoHanInterfaceTestCase.java index 6ee07f2c..e2069863 100644 --- a/src/test/java/com/dispose/test/haohan/HaoHanInterfaceTestCase.java +++ b/src/test/java/com/dispose/test/haohan/HaoHanInterfaceTestCase.java @@ -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()); + } } }