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 c6a2fc47..65807fec 100644 --- a/src/test/java/com/dispose/test/qa/exec/TestCaseRun.java +++ b/src/test/java/com/dispose/test/qa/exec/TestCaseRun.java @@ -2,6 +2,12 @@ package com.dispose.test.qa.exec; import com.dispose.mapper.DisposeDeviceMapper; import com.dispose.mapper.DisposeTaskMapper; +import com.dispose.test.common.QATestItem; +import com.dispose.test.qa.testcase.v20.P1; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; /** * The interface Test case run. @@ -22,4 +28,15 @@ public interface TestCaseRun { * @return the dispose task mapper */ DisposeTaskMapper getDisposeTaskMapper(); + + /** + * Gets all test case. + * + * @return the all test case + */ + static List getAllTestCase() { + List tolTestCase = new ArrayList<>(); + Collections.addAll(tolTestCase, P1.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 7abe4c12..3bc749cb 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 @@ -8,7 +8,6 @@ import com.dispose.test.common.CommonEnvironment; import com.dispose.test.common.CommonRestfulJson; import com.dispose.test.common.QATestItem; import com.dispose.test.qa.exec.TestCaseRun; -import com.dispose.test.qa.testcase.v20.P1; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.junit.ClassRule; @@ -26,8 +25,10 @@ import org.springframework.test.context.junit4.rules.SpringMethodRule; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -49,6 +50,10 @@ public class JsonTestCaseRun extends CommonRestfulJson implements TestCaseRun { */ @ClassRule public static final SpringClassRule springClassRule = new SpringClassRule(); + /** + * The constant jsonIdFilter. + */ + private static final Integer[] jsonIdFilter = new Integer[]{}; /** * The Spring method rule. */ @@ -69,11 +74,6 @@ public class JsonTestCaseRun extends CommonRestfulJson implements TestCaseRun { @Resource private DisposeTaskMapper disposeTaskMapper; - /** - * The constant jsonIdFilter. - */ - private static final Integer[] jsonIdFilter = new Integer[] {}; - /** * Instantiates a new Json test case run. * @@ -90,10 +90,13 @@ public class JsonTestCaseRun extends CommonRestfulJson implements TestCaseRun { */ @Parameters public static Collection paramData() { - List usedId = Arrays.asList(CommonEnvironment.commonIdFilter); - usedId.addAll(Arrays.asList(jsonIdFilter)); - return Arrays.stream(P1.getTestCase()) + List usedId = new ArrayList<>(); + + Collections.addAll(usedId, jsonIdFilter); + Collections.addAll(usedId, CommonEnvironment.commonIdFilter); + + return TestCaseRun.getAllTestCase().stream() .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)) diff --git a/src/test/java/com/dispose/test/qa/exec/impl/ObjectTestCaseRun.java b/src/test/java/com/dispose/test/qa/exec/impl/ObjectTestCaseRun.java index aa50adeb..54079202 100644 --- a/src/test/java/com/dispose/test/qa/exec/impl/ObjectTestCaseRun.java +++ b/src/test/java/com/dispose/test/qa/exec/impl/ObjectTestCaseRun.java @@ -8,7 +8,6 @@ import com.dispose.test.common.CommonEnvironment; import com.dispose.test.common.CommonRestful; import com.dispose.test.common.QATestItem; import com.dispose.test.qa.exec.TestCaseRun; -import com.dispose.test.qa.testcase.v20.P1; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.junit.ClassRule; @@ -25,8 +24,10 @@ import org.springframework.test.context.junit4.rules.SpringMethodRule; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -90,10 +91,12 @@ public class ObjectTestCaseRun extends CommonRestful implements TestCaseRun { */ @Parameterized.Parameters public static Collection paramData() { - List usedId = Arrays.asList(CommonEnvironment.commonIdFilter); - usedId.addAll(Arrays.asList(objIdFilter)); + List usedId = new ArrayList<>(); - return Arrays.stream(P1.getTestCase()) + Collections.addAll(usedId, objIdFilter); + Collections.addAll(usedId, CommonEnvironment.commonIdFilter); + + return TestCaseRun.getAllTestCase().stream() .filter(k -> k.getReqObject() != null) .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)) diff --git a/src/test/java/com/dispose/test/qa/testcase/v20/P1.java b/src/test/java/com/dispose/test/qa/testcase/v20/P1.java index a56f7f1b..91d513d8 100644 --- a/src/test/java/com/dispose/test/qa/testcase/v20/P1.java +++ b/src/test/java/com/dispose/test/qa/testcase/v20/P1.java @@ -2,7 +2,6 @@ package com.dispose.test.qa.testcase.v20; import com.dispose.common.DisposeCapacityType; import com.dispose.common.DisposeDeviceType; -import com.dispose.common.DisposeObjectType; import com.dispose.common.ErrorCode; import com.dispose.common.Helper; import com.dispose.common.HttpType; @@ -14,7 +13,7 @@ import com.dispose.pojo.dto.protocol.device.manager.AddDeviceRsp; import com.dispose.pojo.dto.protocol.device.manager.CommDeviceListRsp; import com.dispose.pojo.dto.protocol.task.GetTaskRsp; import com.dispose.pojo.dto.protocol.task.TaskStartRsp; -import com.dispose.pojo.entity.DisposeCapacity; +import com.dispose.pojo.dto.protocol.task.TaskStopRsp; import com.dispose.pojo.entity.DisposeDevice; import com.dispose.test.common.QATestItem; import com.dispose.test.common.TestPriority; @@ -23,8 +22,6 @@ import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.springframework.web.bind.annotation.RequestMethod; -import java.util.ArrayList; - /** * The type P 1. * @@ -167,8 +164,8 @@ public class P1 { .urlPath("/manager/upgrade") .method(RequestMethod.POST) .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1599094454403," + - "\"msgContent\":{\"items\":[{\"ipAddr\":\"10.88.77.16\",\"ipPort\":\"\"," + - "\"deviceType\":0,\"areaCode\":0,\"deviceName\":\"中移杭研实验室迪普清洗设备\"," + + "\"msgContent\":{\"items\":[{\"ipAddr\":\"127.0.0.1\",\"ipPort\":\"\"," + + "\"deviceType\":999,\"areaCode\":0,\"deviceName\":\"中移杭研实验室迪普清洗设备\"," + "\"manufacturer\":\"DPTech\",\"model\":\"UMC\",\"version\":\"5.7.13\"," + "\"userName\":\"test\",\"password\":\"testpassword\"," + "\"urlPath\":\"UMC/service/AbnormalFlowCleaningService\",\"urlType\":0," + @@ -189,45 +186,37 @@ public class P1 { Assert.assertNotNull(k.getDevStatus()); }); - DisposeDevice dev = c.getDisposeDeviceMapper().getDeviceByAddress("10.88.77.16", ""); + DisposeDevice dev = c.getDisposeDeviceMapper().getDeviceByAddress("127.0.0.1", ""); Assert.assertNotNull(dev); Assert.assertEquals(dev.getDevCapacity().size(), 2); - dev.getDevCapacity().stream().filter(k -> k.getCapacityType() == DisposeCapacityType.BLACKHOOL).forEach(m -> { - Assert.assertEquals((long)m.getObjectType().getValue(), 4L); - Assert.assertEquals((long)m.getReserveNetflow(), 20); - }); - }) - .prepareCallback(c -> { - DisposeDevice dev = DisposeDevice.builder() - .ipAddr("10.88.77.16") - .ipPort("") - .deviceType(DisposeDeviceType.DPTECH_UMC) - .areaCode(0) - .deviceName("中移杭研实验室迪普清洗设备") - .manufacturer("DPTech") - .model("UMC") - .version("5.7.13") - .userName("test") - .password("testpassword") - .urlPath("UMC/service/AbnormalFlowCleaningService") - .urlType(HttpType.HTTP) - .readme("实验室测试设备") - .status(ObjectStatus.NORMAL) - .devCapacity(new ArrayList<>()) - .build(); + Assert.assertEquals(dev.getDeviceType(), DisposeDeviceType.VIRTUAL_DISPOSE); + Assert.assertEquals((long) dev.getAreaCode(), 0); + Assert.assertEquals(dev.getManufacturer(), "DPTech"); + Assert.assertEquals(dev.getModel(), "UMC"); + Assert.assertEquals(dev.getVersion(), "5.7.13"); + Assert.assertEquals(dev.getUserName(), "test"); + Assert.assertEquals(dev.getPassword(), "testpassword"); - dev.getDevCapacity().add(DisposeCapacity.builder() - .protectIp("192.168.20.1/24") - .capacityType(DisposeCapacityType.CLEANUP) - .objectType(DisposeObjectType.IP) - .ipType(IpAddrType.IPV4) - .reserveNetflow(10) - .build()); + dev.getDevCapacity() + .stream() + .filter(k -> k.getCapacityType() == DisposeCapacityType.BLACKHOOL) + .forEach(m -> { + Assert.assertEquals((long) m.getObjectType().getValue(), 4L); + Assert.assertEquals((long) m.getReserveNetflow(), 20); + }); - c.getDisposeDeviceMapper().addNewDisposeDevice(dev); + dev.getDevCapacity() + .stream() + .filter(k -> k.getCapacityType() == DisposeCapacityType.CLEANUP) + .forEach(m -> { + Assert.assertEquals((long) m.getObjectType().getValue(), 1L); + Assert.assertEquals((long) m.getReserveNetflow(), 10); + Assert.assertEquals(m.getProtectIp(), "192.168.20.1/24"); + Assert.assertEquals(m.getIpType(), IpAddrType.IPV4); + }); }) .build(), @@ -276,6 +265,27 @@ public class P1 { QATestItem.builder() .id(BASE_P1_ID + 8) .priority(TestPriority.P1_PRIORITY) + .urlPath("/task/stop") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580," + + "\"msgContent\":{\"taskId\":[\"1\"]}}") + .rspClass(TaskStopRsp.class) + .rspCode(ErrorCode.ERR_OK) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) (v, e, c) -> { + Assert.assertNotNull(v); + Assert.assertNotNull(v.getMsgContent()); + Assert.assertNotNull(v.getMsgContent().getItems()); + Assert.assertEquals(v.getMsgContent().getItems().size(), 1); + Assert.assertEquals((long) v.getMsgContent().getItems().get(0).getStatus(), e.getCode()); + Assert.assertEquals(v.getMsgContent().getItems().get(0).getTaskId(), "1"); + Assert.assertEquals(v.getMsgContent().getItems().get(0).getDisposeIp(), "192.168.10.1"); + }) + .build(), + + QATestItem.builder() + .id(BASE_P1_ID + 9) + .priority(TestPriority.P1_PRIORITY) .urlPath("/task/taskList") .method(RequestMethod.POST) .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234,\"msgContent\":{\"startPage\":1," + @@ -287,8 +297,8 @@ public class P1 { Assert.assertNotNull(v); Assert.assertNotNull(v.getMsgContent()); Assert.assertEquals((long) v.getMsgContent().getStatus(), e.getCode()); - Assert.assertEquals((long)v.getMsgContent().getCurPageNumber(), 1); - Assert.assertEquals((long)v.getMsgContent().getPageSize(), 10); + Assert.assertEquals((long) v.getMsgContent().getCurPageNumber(), 1); + Assert.assertEquals((long) v.getMsgContent().getPageSize(), 10); Assert.assertEquals(v.getMsgContent().getItems().size(), Math.min(v.getMsgContent().getTotalItems(), 10)); })