diff --git a/config/application-test.properties b/config/application-test.properties index b76c0c14..8985a781 100644 --- a/config/application-test.properties +++ b/config/application-test.properties @@ -4,15 +4,15 @@ server.tomcat.basedir=./basedir # 多个项目放在nginx下同个端口,通过该配置区分 server.servlet.context-path=/dispose # 配置数据源 -#spring.datasource.url=jdbc:mysql://10.88.77.65:33061/ci_dispose_v2?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior\ -# =convertToNull&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true -#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -#spring.datasource.username=root -#spring.datasource.password=h0K0_8u -spring.datasource.url=jdbc:mysql://172.28.72.118:33061/ci_dispose_v2?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull&useUnicode=true +spring.datasource.url=jdbc:mysql://10.88.77.65:33061/ci_dispose_v2?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior\ + =convertToNull&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -spring.datasource.username=phoenix -spring.datasource.password=Hy@rfph32 +spring.datasource.username=root +spring.datasource.password=h0K0_8u +#spring.datasource.url=jdbc:mysql://172.28.72.118:33061/ci_dispose_v2?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull&useUnicode=true +#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver +#spring.datasource.username=phoenix +#spring.datasource.password=Hy@rfph32 # 配置连接池 spring.datasource.schema=classpath:test_db/unit_test.sql diff --git a/src/main/resources/test_db/unit_test.sql b/src/main/resources/test_db/unit_test.sql index 53e0a78b..27a1825f 100644 --- a/src/main/resources/test_db/unit_test.sql +++ b/src/main/resources/test_db/unit_test.sql @@ -132,7 +132,8 @@ CREATE TABLE `dispose_task` ( -- ---------------------------- -- Records of dispose_task -- ---------------------------- -INSERT INTO `dispose_task` VALUES (1, -1, 1, 0, '192.168.10.1', CURRENT_TIMESTAMP, date_add(now(), interval 10 MINUTE), null, 2, 8796093022207, 1024, 0); +INSERT INTO `dispose_task` VALUES (1, -1, 1, 0, '192.168.10.1', CURRENT_TIMESTAMP, date_add(now(), interval 60 MINUTE), null, 2, 8796093022207, 1024, 0); +INSERT INTO `dispose_task` VALUES (2, -1, 1, 0, '192.168.10.2', CURRENT_TIMESTAMP, date_add(now(), interval 60 MINUTE), null, 2, 8796093022207, 1024, 0); -- ---------------------------- -- Table structure for user_account diff --git a/src/test/java/com/dispose/test/qa/exec/TestCaseRun.java b/src/test/java/com/dispose/test/qa/exec/TestCaseRun.java index 8b2dd979..681a88ee 100644 --- a/src/test/java/com/dispose/test/qa/exec/TestCaseRun.java +++ b/src/test/java/com/dispose/test/qa/exec/TestCaseRun.java @@ -12,6 +12,11 @@ import com.dispose.test.qa.testcase.v20.P2DeviceUpgrade; import com.dispose.test.qa.testcase.v20.P2Info; import com.dispose.test.qa.testcase.v20.P2Login; import com.dispose.test.qa.testcase.v20.P2Logout; +import com.dispose.test.qa.testcase.v20.P2TaskList; +import com.dispose.test.qa.testcase.v20.P2TaskStart; +import com.dispose.test.qa.testcase.v20.P2TaskStartMulIp; +import com.dispose.test.qa.testcase.v20.P2TaskStop; +import com.dispose.test.qa.testcase.v20.P3All; import java.util.ArrayList; import java.util.Collections; @@ -52,6 +57,7 @@ public interface TestCaseRun { static List getAllTestCase() { List tolTestCase = new ArrayList<>(); Collections.addAll(tolTestCase, P1All.getTestCase()); + Collections.addAll(tolTestCase, P3All.getTestCase()); Collections.addAll(tolTestCase, P2Login.getTestCase()); Collections.addAll(tolTestCase, P2Logout.getTestCase()); @@ -63,6 +69,11 @@ public interface TestCaseRun { Collections.addAll(tolTestCase, P2Info.getTestCase()); + Collections.addAll(tolTestCase, P2TaskStart.getTestCase()); + Collections.addAll(tolTestCase, P2TaskStartMulIp.getTestCase()); + Collections.addAll(tolTestCase, P2TaskStop.getTestCase()); + Collections.addAll(tolTestCase, P2TaskList.getTestCase()); + return tolTestCase; } } diff --git a/src/test/java/com/dispose/test/qa/exec/impl/JsonTestCaseRun.java b/src/test/java/com/dispose/test/qa/exec/impl/JsonTestCaseRun.java index de4a0e08..949a2ab4 100644 --- a/src/test/java/com/dispose/test/qa/exec/impl/JsonTestCaseRun.java +++ b/src/test/java/com/dispose/test/qa/exec/impl/JsonTestCaseRun.java @@ -107,7 +107,6 @@ public class JsonTestCaseRun extends CommonRestfulJson implements TestCaseRun { .filter(k -> k.getCaseJsonValue() != null && k.getCaseJsonValue().length() > 0) .filter(k -> usedId.size() == 0 || usedId.stream().anyMatch(v -> Objects.equals(v, k.getId()))) .filter(k -> Arrays.stream(CommonEnvironment.commonPriorityFilter).anyMatch(v -> k.getPriority() == v)) - //.filter(k-> k.getId() >= 700) .collect(Collectors.toList()); } diff --git a/src/test/java/com/dispose/test/qa/testcase/v20/P1All.java b/src/test/java/com/dispose/test/qa/testcase/v20/P1All.java index 146c99b5..b7dd3cb1 100644 --- a/src/test/java/com/dispose/test/qa/testcase/v20/P1All.java +++ b/src/test/java/com/dispose/test/qa/testcase/v20/P1All.java @@ -18,16 +18,14 @@ import com.dispose.pojo.entity.DisposeDevice; import com.dispose.test.common.QATestItem; import com.dispose.test.common.TestPriority; import com.dispose.test.common.VerifyProtoRespCallback; -import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.springframework.web.bind.annotation.RequestMethod; - /** * The type P 1. * * @author */ -@Slf4j + public class P1All { /** * The Base p 1 id. diff --git a/src/test/java/com/dispose/test/qa/testcase/v20/P2DeviceAdd.java b/src/test/java/com/dispose/test/qa/testcase/v20/P2DeviceAdd.java index dee15667..d160cc6c 100644 --- a/src/test/java/com/dispose/test/qa/testcase/v20/P2DeviceAdd.java +++ b/src/test/java/com/dispose/test/qa/testcase/v20/P2DeviceAdd.java @@ -11,7 +11,6 @@ import com.dispose.test.common.QATestItem; import com.dispose.test.common.TestPriority; import com.dispose.test.common.VerifyProtoRespCallback; import com.dispose.test.qa.exec.TestCaseRun; -import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.springframework.web.bind.annotation.RequestMethod; @@ -20,7 +19,6 @@ import org.springframework.web.bind.annotation.RequestMethod; * * @author */ -@Slf4j public class P2DeviceAdd { /** * The constant BASE_P2_DEVICE_ADD_ID. diff --git a/src/test/java/com/dispose/test/qa/testcase/v20/P2DeviceDel.java b/src/test/java/com/dispose/test/qa/testcase/v20/P2DeviceDel.java index 5d521224..eee58f26 100644 --- a/src/test/java/com/dispose/test/qa/testcase/v20/P2DeviceDel.java +++ b/src/test/java/com/dispose/test/qa/testcase/v20/P2DeviceDel.java @@ -7,7 +7,6 @@ import com.dispose.test.common.QATestItem; import com.dispose.test.common.TestPriority; import com.dispose.test.common.VerifyProtoRespCallback; import com.dispose.test.qa.exec.TestCaseRun; -import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.springframework.web.bind.annotation.RequestMethod; @@ -16,7 +15,6 @@ import org.springframework.web.bind.annotation.RequestMethod; * * @author */ -@Slf4j public class P2DeviceDel { /** * The constant BASE_P2_DEVICE_DEL_ID. diff --git a/src/test/java/com/dispose/test/qa/testcase/v20/P2DeviceUpgrade.java b/src/test/java/com/dispose/test/qa/testcase/v20/P2DeviceUpgrade.java index 8d9cc673..29a45b93 100644 --- a/src/test/java/com/dispose/test/qa/testcase/v20/P2DeviceUpgrade.java +++ b/src/test/java/com/dispose/test/qa/testcase/v20/P2DeviceUpgrade.java @@ -12,7 +12,6 @@ import com.dispose.test.common.QATestItem; import com.dispose.test.common.TestPriority; import com.dispose.test.common.VerifyProtoRespCallback; import com.dispose.test.qa.exec.TestCaseRun; -import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.springframework.web.bind.annotation.RequestMethod; @@ -23,7 +22,6 @@ import java.util.HashMap; * * @author */ -@Slf4j public class P2DeviceUpgrade { /** * The constant BASE_P2_DEVICE_UPGRADE_ID. diff --git a/src/test/java/com/dispose/test/qa/testcase/v20/P2Info.java b/src/test/java/com/dispose/test/qa/testcase/v20/P2Info.java index 55031efd..092b695d 100644 --- a/src/test/java/com/dispose/test/qa/testcase/v20/P2Info.java +++ b/src/test/java/com/dispose/test/qa/testcase/v20/P2Info.java @@ -18,7 +18,6 @@ import com.dispose.test.common.QATestItem; import com.dispose.test.common.TestPriority; import com.dispose.test.common.VerifyProtoRespCallback; import com.dispose.test.qa.exec.TestCaseRun; -import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.springframework.web.bind.annotation.RequestMethod; @@ -32,7 +31,6 @@ import java.util.Random; * * @author */ -@Slf4j public class P2Info { /** * The constant BASE_P2_INFO_ID. diff --git a/src/test/java/com/dispose/test/qa/testcase/v20/P2Login.java b/src/test/java/com/dispose/test/qa/testcase/v20/P2Login.java index c436d5ce..e0847a4d 100644 --- a/src/test/java/com/dispose/test/qa/testcase/v20/P2Login.java +++ b/src/test/java/com/dispose/test/qa/testcase/v20/P2Login.java @@ -7,7 +7,6 @@ import com.dispose.test.common.QATestItem; import com.dispose.test.common.TestPriority; import com.dispose.test.common.VerifyProtoRespCallback; import com.dispose.test.qa.exec.TestCaseRun; -import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.springframework.web.bind.annotation.RequestMethod; @@ -16,7 +15,6 @@ import org.springframework.web.bind.annotation.RequestMethod; * * @author */ -@Slf4j public class P2Login { /** * The constant BASE_P2_LOGIN_ID. diff --git a/src/test/java/com/dispose/test/qa/testcase/v20/P2Logout.java b/src/test/java/com/dispose/test/qa/testcase/v20/P2Logout.java index ca0f31ad..dc3fb81f 100644 --- a/src/test/java/com/dispose/test/qa/testcase/v20/P2Logout.java +++ b/src/test/java/com/dispose/test/qa/testcase/v20/P2Logout.java @@ -7,7 +7,6 @@ import com.dispose.test.common.QATestItem; import com.dispose.test.common.TestPriority; import com.dispose.test.common.VerifyProtoRespCallback; import com.dispose.test.qa.exec.TestCaseRun; -import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.springframework.web.bind.annotation.RequestMethod; @@ -16,7 +15,6 @@ import org.springframework.web.bind.annotation.RequestMethod; * * @author */ -@Slf4j public class P2Logout { /** * The constant BASE_P2_LOGOUT_ID. diff --git a/src/test/java/com/dispose/test/qa/testcase/v20/P2TaskList.java b/src/test/java/com/dispose/test/qa/testcase/v20/P2TaskList.java new file mode 100644 index 00000000..675dd7b8 --- /dev/null +++ b/src/test/java/com/dispose/test/qa/testcase/v20/P2TaskList.java @@ -0,0 +1,112 @@ +package com.dispose.test.qa.testcase.v20; + +import com.dispose.common.DDoSAttackType; +import com.dispose.common.DisposeCapacityType; +import com.dispose.common.ErrorCode; +import com.dispose.common.NetflowDirection; +import com.dispose.pojo.dto.protocol.task.GetTaskRsp; +import com.dispose.pojo.entity.DisposeTask; +import com.dispose.test.common.QATestItem; +import com.dispose.test.common.TestPriority; +import com.dispose.test.common.VerifyProtoRespCallback; +import com.dispose.test.qa.exec.TestCaseRun; +import org.junit.Assert; +import org.springframework.web.bind.annotation.RequestMethod; + +/** + * The type P 2 task list. + * + * @author + */ +public class P2TaskList { + /** + * The constant BASE_P2_TASK_LIST_ID. + */ + public static final int BASE_P2_TASK_LIST_ID = 1100; + /** + * The constant testItemArray. + */ + private static final QATestItem[] testItemArray = new QATestItem[]{ + QATestItem.builder() + .id(BASE_P2_TASK_LIST_ID) + .name("获取第二页20个设备信息") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/taskList") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234,\"msgContent\":{\"startPage\":2," + + "\"pageSize\":20}}") + .rspClass(GetTaskRsp.class) + .rspCode(ErrorCode.ERR_OK) + .autoLogin(true) + .prepareCallback(P2TaskList::prepareDisposeDevice) + .verifyCallback((VerifyProtoRespCallback) (v, e, c) -> { + Assert.assertNotNull(v); + Assert.assertNotNull(v.getMsgContent()); + Assert.assertEquals((long) v.getCode(), e.getHttpCode()); + Assert.assertEquals((long) v.getMsgContent().getStatus(), e.getCode()); + + Assert.assertEquals((long) v.getMsgContent().getCurPageNumber(), 2); + Assert.assertEquals((long)v.getMsgContent().getPageSize(), 20); + + Assert.assertNotNull(v.getMsgContent().getItems()); + Assert.assertEquals(v.getMsgContent().getItems().size(), 20); + + Assert.assertNotEquals(v.getMsgContent().getItems().size(), 0); + v.getMsgContent().getItems().forEach(k -> { + Assert.assertNotNull(k.getTaskId()); + Assert.assertNotEquals(k.getDisposeIp().length(), 0); + Assert.assertNotNull(k.getCurrentStatus()); + }); + }) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_LIST_ID) + .name("msgContent为空") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/taskList") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":}") + .rspClass(GetTaskRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) (v, e, c) -> { + Assert.assertNotNull(v); + Assert.assertNotNull(v.getMsgContent()); + Assert.assertEquals((long) v.getCode(), e.getHttpCode()); + Assert.assertEquals((long) v.getMsgContent().getStatus(), e.getCode()); + }) + .build(), + }; + + /** + * Get test case qa test item [ ]. + * + * @return the qa test item [ ] + */ + public static QATestItem[] getTestCase() { + return testItemArray; + } + + + /** + * Prepare dispose device. + * + * @param c the c + */ + private static void prepareDisposeDevice(TestCaseRun c) { + for (int i = 1; i <= 100; i++) { + DisposeTask task = DisposeTask.builder() + .deviceId(1L) + .accountId(1L) + .disposeCapacity(DisposeCapacityType.CLEANUP) + .disposeIp("192.168.0." + i) + .planEndTime("60") + .flowDirection(NetflowDirection.DIRECTION_BI) + .attackType(DDoSAttackType.getTypeMaskFromAttackType(new DDoSAttackType[]{DDoSAttackType.ALL_ATTACKS})) + .flowBandWidth(1024) + .build(); + c.getDisposeTaskMapper().addNewTask(task); + } + } +} diff --git a/src/test/java/com/dispose/test/qa/testcase/v20/P2TaskStart.java b/src/test/java/com/dispose/test/qa/testcase/v20/P2TaskStart.java new file mode 100644 index 00000000..39ba0216 --- /dev/null +++ b/src/test/java/com/dispose/test/qa/testcase/v20/P2TaskStart.java @@ -0,0 +1,279 @@ +package com.dispose.test.qa.testcase.v20; + +import com.dispose.common.ErrorCode; +import com.dispose.common.Helper; +import com.dispose.pojo.dto.protocol.base.BaseRespStatus; +import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO; +import com.dispose.pojo.dto.protocol.task.TaskStartRsp; +import com.dispose.test.common.QATestItem; +import com.dispose.test.common.TestPriority; +import com.dispose.test.common.VerifyProtoRespCallback; +import com.dispose.test.qa.exec.TestCaseRun; +import org.junit.Assert; +import org.springframework.web.bind.annotation.RequestMethod; + +/** + * The type P 2 task start. + * + * @author + */ +public class P2TaskStart { + /** + * The constant BASE_P2_TASK_START_ID. + */ + public static final int BASE_P2_TASK_START_ID = 800; + /** + * The constant testItemArray. + */ + private static final QATestItem[] testItemArray = new QATestItem[]{ + QATestItem.builder() + .id(BASE_P2_TASK_START_ID) + .name("对一个IP全部攻击类型进行清洗") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/start") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," + + "\"disposeIp\":\"192.168.51.2\",\"disposeTime\":10,\"flowDirection\":2," + + "\"attackType\":[-1]}}") + .rspClass(TaskStartRsp.class) + .rspCode(ErrorCode.ERR_OK) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) (v, e, c) -> verifySucceed(v, e, "192.168.51.2")) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_ID + 1) + .name("对IPV6全部攻击类型进行清洗") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/start") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," + + "\"disposeIp\":\"ABCD:EF01:2345:6789:ABCD:EF01:2345:6789\",\"disposeTime\":10," + + "\"flowDirection\":2,\"attackType\":[-1]}}") + .rspClass(TaskStartRsp.class) + .rspCode(ErrorCode.ERR_OK) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) (v, e, c) -> verifySucceed(v, e, "ABCD:EF01:2345" + + ":6789:ABCD:EF01:2345:6789")) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_ID + 2) + .name("对一个IP入向进行清洗") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/start") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," + + "\"disposeIp\":\"192.168.50.2\",\"disposeTime\":10,\"flowDirection\":0," + + "\"attackType\":[1,2,3,4,5]}}") + .rspClass(TaskStartRsp.class) + .rspCode(ErrorCode.ERR_OK) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) (v, e, c) -> verifySucceed(v, e, "192.168.50.2")) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_ID + 3) + .name("对一个IP出向进行清洗") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/start") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," + + "\"disposeIp\":\"192.168.50.3\",\"disposeTime\":10,\"flowDirection\":1," + + "\"attackType\":[1,2,3,4,5]}}") + .rspClass(TaskStartRsp.class) + .rspCode(ErrorCode.ERR_OK) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) (v, e, c) -> verifySucceed(v, e, "192.168.50.3")) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_ID + 4) + .name("对一个IP进行高防处置") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/start") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":1," + + "\"disposeIp\":\"192.168.50.3\",\"disposeTime\":10,\"flowDirection\":2," + + "\"attackType\":[-1]}}") + .rspClass(TaskStartRsp.class) + .rspCode(ErrorCode.ERR_OK) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) (v, e, c) -> verifySucceed(v, e, "192.168.50.3")) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_ID + 5) + .name("对一个IP进行压制处置") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/start") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":2," + + "\"disposeIp\":\"192.168.50.2\",\"disposeTime\":10,\"flowDirection\":2," + + "\"attackType\":[-1]}}") + .rspClass(TaskStartRsp.class) + .rspCode(ErrorCode.ERR_OK) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) (v, e, c) -> verifySucceed(v, e, "192.168.50.2")) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_ID + 6) + .name("对一个IP进行检测处置") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/start") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":3," + + "\"disposeIp\":\"192.168.50.2\",\"disposeTime\":10,\"flowDirection\":2," + + "\"attackType\":[-1]}}") + .rspClass(TaskStartRsp.class) + .rspCode(ErrorCode.ERR_OK) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) (v, e, c) -> verifySucceed(v, e, "192.168.50.2")) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_ID + 7) + .name("msgContent为空") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/start") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":}") + .rspClass(TaskStartRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback)P2TaskStart::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_ID + 8) + .name("type为null") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/start") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":null," + + "\"disposeIp\":\"192.168.50.2\",\"disposeTime\":10,\"flowDirection\":2," + + "\"attackType\":[1,2,3,4,5]}}") + .rspClass(TaskStartRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback)P2TaskStart::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_ID + 9) + .name("type为字符串") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/start") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":\"0\"," + + "\"disposeIp\":\"192.168.50.2\",\"disposeTime\":10,\"flowDirection\":2," + + "\"attackType\":[1,2,3,4,5]}}") + .rspClass(TaskStartRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback)P2TaskStart::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_ID + 10) + .name("disposeIp为null") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/start") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," + + "\"disposeIp\":null,\"disposeTime\":10,\"flowDirection\":2,\"attackType\":[1,2,3,4,5]}}") + .rspClass(TaskStartRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback)P2TaskStart::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_ID + 11) + .name("disposeIp为非法IP地址") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/start") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," + + "\"disposeIp\":192.168.50.2,\"disposeTime\":10,\"flowDirection\":2,\"attackType\":[1," + + "2,3,4,5]}}") + .rspClass(TaskStartRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback)P2TaskStart::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_ID + 12) + .name("disposeTime为null") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/start") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," + + "\"disposeIp\":\"192.168.50.2\",\"disposeTime\":null,\"flowDirection\":2," + + "\"attackType\":[1,2,3,4,5]}}") + .rspClass(TaskStartRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback)P2TaskStart::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_ID + 13) + .name("disposeTime为字符串") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/start") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," + + "\"disposeIp\":\"192.168.50.2\",\"disposeTime\":\"10\",\"flowDirection\":2," + + "\"attackType\":[1,2,3,4,5]}}") + .rspClass(TaskStartRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback)P2TaskStart::verifyJsonExceptionResp) + .build(), + }; + + /** + * Get test case qa test item [ ]. + * + * @return the qa test item [ ] + */ + public static QATestItem[] getTestCase() { + return testItemArray; + } + + /** + * Verify succeed. + * + * @param v the v + * @param e the e + * @param ipAddr the ip addr + */ + private static void verifySucceed(ProtocolRespDTO v, ErrorCode e, String ipAddr) { + String disposeIp = v.getMsgContent().getDisposeIp(); + Assert.assertNotNull(v); + Assert.assertNotNull(v.getMsgContent()); + Assert.assertEquals((long) v.getCode(), e.getHttpCode()); + Assert.assertEquals((long) v.getMsgContent().getStatus(), e.getCode()); + Assert.assertNotNull(disposeIp); + Assert.assertEquals(ipAddr, Helper.ipAddressNormalize(disposeIp)); + Assert.assertNotEquals(v.getMsgContent().getDisposeIp().length(), 0); + } + + /** + * Verify json exception resp. + * + * @param v the v + * @param e the e + * @param c the c + */ + private static void verifyJsonExceptionResp(ProtocolRespDTO v, ErrorCode e, + TestCaseRun c) { + Assert.assertNotNull(v); + Assert.assertNotNull(v.getMsgContent()); + Assert.assertEquals((long) v.getCode(), e.getHttpCode()); + Assert.assertEquals((long) v.getMsgContent().getStatus(), e.getCode()); + } +} diff --git a/src/test/java/com/dispose/test/qa/testcase/v20/P2TaskStartMulIp.java b/src/test/java/com/dispose/test/qa/testcase/v20/P2TaskStartMulIp.java new file mode 100644 index 00000000..203a6f10 --- /dev/null +++ b/src/test/java/com/dispose/test/qa/testcase/v20/P2TaskStartMulIp.java @@ -0,0 +1,370 @@ +package com.dispose.test.qa.testcase.v20; + +import com.dispose.common.ErrorCode; +import com.dispose.pojo.dto.protocol.base.BaseRespStatus; +import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO; +import com.dispose.pojo.dto.protocol.task.TaskStartMulRsp; +import com.dispose.test.common.QATestItem; +import com.dispose.test.common.TestPriority; +import com.dispose.test.common.VerifyProtoRespCallback; +import com.dispose.test.qa.exec.TestCaseRun; +import org.junit.Assert; +import org.springframework.web.bind.annotation.RequestMethod; + +import java.util.Arrays; + +/** + * The type P 2 task start mul ip. + * + * @author + */ +public class P2TaskStartMulIp { + + /** + * The constant BASE_P2_TASK_START_MUL_ID. + */ + public static final int BASE_P2_TASK_START_MUL_ID = 900; + /** + * The constant testItemArray. + */ + private static final QATestItem[] testItemArray = new QATestItem[]{ + QATestItem.builder() + .id(BASE_P2_TASK_START_MUL_ID) + .name("对一个IP全部攻击类型进行清洗") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/startMulIp") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," + + "\"mulDisposeIp\":[\"192.168.50.4\",\"192.168.50.3\"],\"disposeTime\":10," + + "\"flowDirection\":2,\"attackType\":[1,2,3,4,5]}}") + .rspClass(TaskStartMulRsp.class) + .rspCode(ErrorCode.ERR_OK) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) (v, e, c) -> verifySucceed(v, e, new String[]{ + "192.168.50.4", "192.168.50.3" + })) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_MUL_ID + 1) + .name("对多个IP全部攻击类型进行清洗") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/startMulIp") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," + + "\"mulDisposeIp\":[\"192.168.50.4\",\"192.168.50.3\"],\"disposeTime\":10," + + "\"flowDirection\":2,\"attackType\":[-1]}}") + .rspClass(TaskStartMulRsp.class) + .rspCode(ErrorCode.ERR_OK) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) (v, e, c) -> verifySucceed(v, e, new String[]{ + "192.168.50.4", "192.168.50.3" + })) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_MUL_ID + 2) + .name("对多个IP全部攻击类型进行清洗") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/startMulIp") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," + + "\"mulDisposeIp\":[\"192.168.50.4\",\"192.168.50.3\"],\"disposeTime\":10," + + "\"flowDirection\":2}}") + .rspClass(TaskStartMulRsp.class) + .rspCode(ErrorCode.ERR_OK) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) (v, e, c) -> verifySucceed(v, e, new String[]{ + "192.168.50.4", "192.168.50.3" + })) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_MUL_ID + 3) + .name("对多个IPV6指定攻击类型进行清洗") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/startMulIp") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," + + "\"mulDisposeIp\":[\"ABCD:EF01:2345:6789:ABCD:EF01:2345:6789\"," + + "\"ABCD:EF01:2345:6789:ABCD:EF01:2345:1234\"],\"disposeTime\":10,\"flowDirection\":2," + + "\"attackType\":[1,2,3,4,5]}}") + .rspClass(TaskStartMulRsp.class) + .rspCode(ErrorCode.ERR_OK) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) (v, e, c) -> verifySucceed(v, e, new String[]{ + "ABCD:EF01:2345:6789:ABCD:EF01:2345:6789", "ABCD:EF01:2345:6789:ABCD:EF01:2345:1234" + })) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_MUL_ID + 4) + .name("对多个IPV6全部攻击类型进行清洗") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/startMulIp") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," + + "\"mulDisposeIp\":[\"ABCD:EF01:2345:6789:ABCD:EF01:2345:6789\"," + + "\"ABCD:EF01:2345:6789:ABCD:EF01:2345:1234\"],\"disposeTime\":10,\"flowDirection\":2," + + "\"attackType\":[-1]}}") + .rspClass(TaskStartMulRsp.class) + .rspCode(ErrorCode.ERR_OK) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) (v, e, c) -> verifySucceed(v, e, new String[]{ + "ABCD:EF01:2345:6789:ABCD:EF01:2345:6789", "ABCD:EF01:2345:6789:ABCD:EF01:2345:1234" + })) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_MUL_ID + 5) + .name("对IPV4和IPV6进行清洗") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/startMulIp") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," + + "\"mulDisposeIp\":[\"192.168.50.4\",\"192.168.50.3\"," + + "\"ABCD:EF01:2345:6789:ABCD:EF01:2345:6789\"],\"disposeTime\":10,\"flowDirection\":2," + + "\"attackType\":[1,2,3,4,5]}}") + .rspClass(TaskStartMulRsp.class) + .rspCode(ErrorCode.ERR_OK) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) (v, e, c) -> verifySucceed(v, e, new String[]{ + "192.168.50.4", "192.168.50.3","ABCD:EF01:2345:6789:ABCD:EF01:2345:6789" + })) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_MUL_ID + 6) + .name("对多个IP入向进行清洗") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/startMulIp") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," + + "\"mulDisposeIp\":[\"192.168.50.4\",\"192.168.50.3\"],\"disposeTime\":10," + + "\"flowDirection\":0,\"attackType\":[1,2,3,4,5]}}") + .rspClass(TaskStartMulRsp.class) + .rspCode(ErrorCode.ERR_OK) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) (v, e, c) -> verifySucceed(v, e, new String[]{ + "192.168.50.4", "192.168.50.3" + })) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_MUL_ID + 7) + .name("对多个IP出向进行清洗") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/startMulIp") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," + + "\"mulDisposeIp\":[\"192.168.50.4\",\"192.168.50.3\"],\"disposeTime\":10," + + "\"flowDirection\":1,\"attackType\":[1,2,3,4,5]}}") + .rspClass(TaskStartMulRsp.class) + .rspCode(ErrorCode.ERR_OK) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) (v, e, c) -> verifySucceed(v, e, new String[]{ + "192.168.50.4", "192.168.50.3" + })) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_MUL_ID + 8) + .name("对多个IP进行高防处置") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/startMulIp") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":1," + + "\"mulDisposeIp\":[\"192.168.50.4\",\"192.168.50.3\"],\"disposeTime\":10," + + "\"flowDirection\":2,\"attackType\":[-1]}}") + .rspClass(TaskStartMulRsp.class) + .rspCode(ErrorCode.ERR_OK) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) (v, e, c) -> verifySucceed(v, e, new String[]{ + "192.168.50.4", "192.168.50.3" + })) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_MUL_ID + 9) + .name("对多个IP进行压制处置") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/startMulIp") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":2," + + "\"mulDisposeIp\":[\"192.168.50.4\",\"192.168.50.3\"],\"disposeTime\":10," + + "\"flowDirection\":2,\"attackType\":[-1]}}") + .rspClass(TaskStartMulRsp.class) + .rspCode(ErrorCode.ERR_OK) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) (v, e, c) -> verifySucceed(v, e, new String[]{ + "192.168.50.4", "192.168.50.3" + })) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_MUL_ID + 10) + .name("对多个IP进行检测处置") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/startMulIp") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":3," + + "\"mulDisposeIp\":[\"192.168.50.4\",\"192.168.50.3\"],\"disposeTime\":10," + + "\"flowDirection\":2,\"attackType\":[-1]}}") + .rspClass(TaskStartMulRsp.class) + .rspCode(ErrorCode.ERR_OK) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) (v, e, c) -> verifySucceed(v, e, new String[]{ + "192.168.50.4", "192.168.50.3" + })) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_MUL_ID + 11) + .name("msgContent为空") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/startMulIp") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":}") + .rspClass(TaskStartMulRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback(P2TaskStartMulIp::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_MUL_ID + 12) + .name("type为null") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/startMulIp") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":null," + + "\"mulDisposeIp\":[\"192.168.50.4\",\"192.168.50.3\"],\"disposeTime\":10," + + "\"flowDirection\":2,\"attackType\":[1,2,3,4,5]}}") + .rspClass(TaskStartMulRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback(P2TaskStartMulIp::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_MUL_ID + 13) + .name("type为字符串") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/startMulIp") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":\"0\"," + + "\"mulDisposeIp\":[\"192.168.50.4\",\"192.168.50.3\"],\"disposeTime\":10," + + "\"flowDirection\":2,\"attackType\":[1,2,3,4,5]}}") + .rspClass(TaskStartMulRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback(P2TaskStartMulIp::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_MUL_ID + 14) + .name("disposeIp为null") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/startMulIp") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," + + "\"disposeIp\":null,\"disposeTime\":10,\"flowDirection\":2,\"attackType\":[1,2,3,4,5]}}") + .rspClass(TaskStartMulRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback(P2TaskStartMulIp::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_MUL_ID + 15) + .name("disposeIp为整形") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/startMulIp") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," + + "\"disposeIp\":192.168.50.2,\"disposeTime\":10,\"flowDirection\":2,\"attackType\":[1," + + "2,3,4,5]}}") + .rspClass(TaskStartMulRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback(P2TaskStartMulIp::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_MUL_ID + 16) + .name("disposeTime为null") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/startMulIp") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," + + "\"mulDisposeIp\":[\"192.168.50.4\",\"192.168.50.3\"],\"disposeTime\":null," + + "\"flowDirection\":2,\"attackType\":[1,2,3,4,5]}}") + .rspClass(TaskStartMulRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback(P2TaskStartMulIp::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_MUL_ID + 17) + .name("disposeTime为字符串") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/startMulIp") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"type\":0," + + "\"mulDisposeIp\":[\"192.168.50.4\",\"192.168.50.3\"],\"disposeTime\":\"10\"," + + "\"flowDirection\":2,\"attackType\":[1,2,3,4,5]}}") + .rspClass(TaskStartMulRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback(P2TaskStartMulIp::verifyJsonExceptionResp) + .build(), + }; + + /** + * Get test case qa test item [ ]. + * + * @return the qa test item [ ] + */ + public static QATestItem[] getTestCase() { + return testItemArray; + } + + /** + * Verify succeed. + * + * @param v the v + * @param e the e + * @param ipList the ip list + */ + private static void verifySucceed(ProtocolRespDTO v, ErrorCode e, String[] ipList) { + Assert.assertNotNull(v); + Assert.assertNotNull(v.getMsgContent()); + Assert.assertEquals((long) v.getCode(), e.getHttpCode()); + Assert.assertNotNull(v.getMsgContent().getItems()); + Assert.assertEquals(v.getMsgContent().getItems().size(), ipList.length); + + v.getMsgContent().getItems().forEach(k -> { + Assert.assertNotNull(k.getDisposeIp()); + Assert.assertEquals((long) k.getStatus(), e.getCode()); + Assert.assertNotNull(k.getTaskId()); + Assert.assertNotNull(k.getExpireTime()); + Assert.assertTrue(Arrays.stream(ipList).anyMatch(m -> m.equals(k.getDisposeIp()))); + }); + } + + /** + * Verify json exception resp. + * + * @param v the v + * @param e the e + * @param c the c + */ + private static void verifyJsonExceptionResp(ProtocolRespDTO v, ErrorCode e, + TestCaseRun c) { + Assert.assertNotNull(v); + Assert.assertNotNull(v.getMsgContent()); + Assert.assertEquals((long) v.getCode(), e.getHttpCode()); + Assert.assertEquals((long) v.getMsgContent().getStatus(), e.getCode()); + } +} diff --git a/src/test/java/com/dispose/test/qa/testcase/v20/P2TaskStop.java b/src/test/java/com/dispose/test/qa/testcase/v20/P2TaskStop.java new file mode 100644 index 00000000..53e976b1 --- /dev/null +++ b/src/test/java/com/dispose/test/qa/testcase/v20/P2TaskStop.java @@ -0,0 +1,86 @@ +package com.dispose.test.qa.testcase.v20; + +import com.dispose.common.ErrorCode; +import com.dispose.pojo.dto.protocol.task.TaskStopRsp; +import com.dispose.test.common.QATestItem; +import com.dispose.test.common.TestPriority; +import com.dispose.test.common.VerifyProtoRespCallback; +import org.junit.Assert; +import org.springframework.web.bind.annotation.RequestMethod; + +/** + * The type P 2 task stop. + * + * @author + */ +public class P2TaskStop { + /** + * The constant BASE_P2_TASK_START_MUL_ID. + */ + public static final int BASE_P2_TASK_START_STOP_ID = 1000; + /** + * The constant testItemArray. + */ + private static final QATestItem[] testItemArray = new QATestItem[]{ + QATestItem.builder() + .id(BASE_P2_TASK_START_STOP_ID) + .name("停止多个处置任务") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/stop") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580," + + "\"msgContent\":{\"taskId\":[\"1\",\"2\",\"3\"]}}") + .rspClass(TaskStopRsp.class) + .rspCode(ErrorCode.ERR_OK) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) (v, e, c) -> { + Assert.assertNotNull(v); + Assert.assertNotNull(v.getMsgContent()); + Assert.assertEquals((long) v.getCode(), e.getHttpCode()); + Assert.assertNotNull(v.getMsgContent().getItems()); + Assert.assertEquals(v.getMsgContent().getItems().size(), 3); + + v.getMsgContent().getItems().forEach(k -> { + Assert.assertNotNull(k.getTaskId()); + if("3".equals(k.getTaskId())){ + Assert.assertEquals((long)k.getStatus(), ErrorCode.ERR_NOSUCHTASK.getCode()); + } else { + Assert.assertEquals((long)k.getStatus(), e.getCode()); + Assert.assertNotNull(k.getType()); + Assert.assertNotEquals(k.getDisposeIp().length(), 0); + Assert.assertNotNull(k.getLeftTime()); + } + + }); + + }) + .build(), + + QATestItem.builder() + .id(BASE_P2_TASK_START_STOP_ID) + .name("msgContent为空") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/task/stop") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":}") + .rspClass(TaskStopRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) (v, e, c) -> { + Assert.assertNotNull(v); + Assert.assertNotNull(v.getMsgContent()); + Assert.assertEquals((long) v.getCode(), e.getHttpCode()); + Assert.assertEquals((long) v.getMsgContent().getStatus(), e.getCode()); + }) + .build(), + }; + + /** + * Get test case qa test item [ ]. + * + * @return the qa test item [ ] + */ + public static QATestItem[] getTestCase() { + return testItemArray; + } +} diff --git a/src/test/java/com/dispose/test/qa/testcase/v20/P3All.java b/src/test/java/com/dispose/test/qa/testcase/v20/P3All.java new file mode 100644 index 00000000..77ffdecf --- /dev/null +++ b/src/test/java/com/dispose/test/qa/testcase/v20/P3All.java @@ -0,0 +1,353 @@ +package com.dispose.test.qa.testcase.v20; + +import com.dispose.common.ErrorCode; +import com.dispose.pojo.dto.protocol.auth.LoginRsp; +import com.dispose.pojo.dto.protocol.base.BaseRespStatus; +import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO; +import com.dispose.pojo.dto.protocol.device.info.GetDeviceInfoRsp; +import com.dispose.pojo.dto.protocol.device.manager.GetDeviceRsp; +import com.dispose.pojo.dto.protocol.task.GetTaskRsp; +import com.dispose.pojo.dto.protocol.task.TaskStartMulRsp; +import com.dispose.pojo.dto.protocol.task.TaskStartRsp; +import com.dispose.pojo.dto.protocol.task.TaskStopRsp; +import com.dispose.test.common.QATestItem; +import com.dispose.test.common.TestPriority; +import com.dispose.test.common.VerifyProtoRespCallback; +import com.dispose.test.qa.exec.TestCaseRun; +import org.junit.Assert; +import org.springframework.web.bind.annotation.RequestMethod; + +/** + * The type P 3 all. + * + * @author + */ +public class P3All { + + /** + * The constant BASE_P2_TASK_START_STOP_ID. + */ + public static final int BASE_P3_ALL_ID = 1200; + /** + * The constant testItemArray. + */ + private static final QATestItem[] testItemArray = new QATestItem[]{ + QATestItem.builder() + .id(BASE_P3_ALL_ID + 1) + .name("timeStamp为空") + .priority(TestPriority.P3_PRIORITY) + .urlPath("/auth/logout") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":,\"msgContent\":{\"userName\":\"admin\"}}") + .rspClass(LoginRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) P3All::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P3_ALL_ID + 2) + .name("timeStamp为null") + .priority(TestPriority.P3_PRIORITY) + .urlPath("/auth/logout") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":null,\"msgContent\":{\"userName\":\"admin\"}}") + .rspClass(LoginRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) P3All::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P3_ALL_ID + 3) + .name("userName为空") + .priority(TestPriority.P3_PRIORITY) + .urlPath("/auth/logout") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598582999559,\"msgContent\":{\"userName\":}}") + .rspClass(LoginRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) P3All::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P3_ALL_ID + 4) + .name("userName为null") + .priority(TestPriority.P3_PRIORITY) + .urlPath("/auth/logout") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598582999559,\"msgContent\":{\"userName\":null}}") + .rspClass(LoginRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) P3All::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P3_ALL_ID + 5) + .name("msgContent为null") + .priority(TestPriority.P3_PRIORITY) + .urlPath("/info/deviceVersion") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":null}") + .rspClass(GetDeviceInfoRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) P3All::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P3_ALL_ID + 6) + .name("id为null") + .priority(TestPriority.P3_PRIORITY) + .urlPath("/info/deviceVersion") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"id\":null}}") + .rspClass(GetDeviceInfoRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) P3All::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P3_ALL_ID + 7) + .name("msgContent为null") + .priority(TestPriority.P3_PRIORITY) + .urlPath("/info/deviceLinkStatus") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":null}") + .rspClass(GetDeviceInfoRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) P3All::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P3_ALL_ID + 8) + .name("id为null") + .priority(TestPriority.P3_PRIORITY) + .urlPath("/info/deviceLinkStatus") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"id\":null}}") + .rspClass(GetDeviceInfoRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) P3All::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P3_ALL_ID + 9) + .name("msgContent为null") + .priority(TestPriority.P3_PRIORITY) + .urlPath("/manager/deviceList") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234,\"msgContent\":null}") + .rspClass(GetDeviceRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) P3All::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P3_ALL_ID + 10) + .name("startPage为null") + .priority(TestPriority.P3_PRIORITY) + .urlPath("/manager/deviceList") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234," + + "\"msgContent\":{\"startPage\":null,\"pageSize\":10}}") + .rspClass(GetDeviceRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) P3All::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P3_ALL_ID + 11) + .name("startPage为字符串") + .priority(TestPriority.P3_PRIORITY) + .urlPath("/manager/deviceList") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234," + + "\"msgContent\":{\"startPage\":\"1\",\"pageSize\":10}}") + .rspClass(GetDeviceRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) P3All::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P3_ALL_ID + 12) + .name("pageSize为null") + .priority(TestPriority.P3_PRIORITY) + .urlPath("/manager/deviceList") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234,\"msgContent\":{\"startPage\":1," + + "\"pageSize\":null}}") + .rspClass(GetDeviceRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) P3All::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P3_ALL_ID + 13) + .name("pageSize为字符串") + .priority(TestPriority.P3_PRIORITY) + .urlPath("/manager/deviceList") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234,\"msgContent\":{\"startPage\":1," + + "\"pageSize\":\"10\"}}") + .rspClass(GetDeviceRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) P3All::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P3_ALL_ID + 14) + .name("msgContent为null") + .priority(TestPriority.P3_PRIORITY) + .urlPath("/task/start") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":null}") + .rspClass(TaskStartRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) P3All::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P3_ALL_ID + 15) + .name("msgContent为null") + .priority(TestPriority.P3_PRIORITY) + .urlPath("/task/startMulIp") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":null}") + .rspClass(TaskStartMulRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) P3All::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P3_ALL_ID + 16) + .name("msgContent为null") + .priority(TestPriority.P3_PRIORITY) + .urlPath("/task/stop") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":null}") + .rspClass(TaskStopRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) P3All::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P3_ALL_ID + 17) + .name("id为null") + .priority(TestPriority.P3_PRIORITY) + .urlPath("/task/stop") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"taskId\":null}}") + .rspClass(TaskStopRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) P3All::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P3_ALL_ID + 18) + .name("msgContent为null") + .priority(TestPriority.P3_PRIORITY) + .urlPath("/task/taskList") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234,\"msgContent\":null}") + .rspClass(GetTaskRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) P3All::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P3_ALL_ID + 19) + .name("startPage为null") + .priority(TestPriority.P3_PRIORITY) + .urlPath("/task/taskList") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234," + + "\"msgContent\":{\"startPage\":null,\"pageSize\":10}}") + .rspClass(GetTaskRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) P3All::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P3_ALL_ID + 20) + .name("startPage为字符串") + .priority(TestPriority.P3_PRIORITY) + .urlPath("/task/taskList") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234," + + "\"msgContent\":{\"startPage\":\"1\",\"pageSize\":10}}") + .rspClass(GetTaskRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) P3All::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P3_ALL_ID + 21) + .name("pageSize为null") + .priority(TestPriority.P3_PRIORITY) + .urlPath("/task/taskList") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234,\"msgContent\":{\"startPage\":1," + + "\"pageSize\":null}}") + .rspClass(GetTaskRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) P3All::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P3_ALL_ID + 22) + .name("pageSize为字符串") + .priority(TestPriority.P3_PRIORITY) + .urlPath("/task/taskList") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234,\"msgContent\":{\"startPage\":1," + + "\"pageSize\":\"10\"}}") + .rspClass(GetTaskRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) P3All::verifyJsonExceptionResp) + .build(), + }; + + /** + * Get test case qa test item [ ]. + * + * @return the qa test item [ ] + */ + public static QATestItem[] getTestCase() { + return testItemArray; + } + + /** + * Verify json exception resp. + * + * @param v the v + * @param e the e + * @param c the c + */ + private static void verifyJsonExceptionResp(ProtocolRespDTO v, ErrorCode e, + TestCaseRun c) { + Assert.assertNotNull(v); + Assert.assertNotNull(v.getMsgContent()); + Assert.assertEquals((long) v.getCode(), e.getHttpCode()); + Assert.assertEquals((long) v.getMsgContent().getStatus(), e.getCode()); + } +}