REM:
1. 完成P1单元测试用例
This commit is contained in:
HuangXin 2020-09-11 15:40:45 +08:00
parent d2cdb75cf2
commit 90ee2946f0
4 changed files with 86 additions and 53 deletions

View File

@ -2,6 +2,12 @@ package com.dispose.test.qa.exec;
import com.dispose.mapper.DisposeDeviceMapper; import com.dispose.mapper.DisposeDeviceMapper;
import com.dispose.mapper.DisposeTaskMapper; 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. * The interface Test case run.
@ -22,4 +28,15 @@ public interface TestCaseRun {
* @return the dispose task mapper * @return the dispose task mapper
*/ */
DisposeTaskMapper getDisposeTaskMapper(); DisposeTaskMapper getDisposeTaskMapper();
/**
* Gets all test case.
*
* @return the all test case
*/
static List<QATestItem> getAllTestCase() {
List<QATestItem> tolTestCase = new ArrayList<>();
Collections.addAll(tolTestCase, P1.getTestCase());
return tolTestCase;
}
} }

View File

@ -8,7 +8,6 @@ import com.dispose.test.common.CommonEnvironment;
import com.dispose.test.common.CommonRestfulJson; import com.dispose.test.common.CommonRestfulJson;
import com.dispose.test.common.QATestItem; import com.dispose.test.common.QATestItem;
import com.dispose.test.qa.exec.TestCaseRun; import com.dispose.test.qa.exec.TestCaseRun;
import com.dispose.test.qa.testcase.v20.P1;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Assert; import org.junit.Assert;
import org.junit.ClassRule; import org.junit.ClassRule;
@ -26,8 +25,10 @@ import org.springframework.test.context.junit4.rules.SpringMethodRule;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -49,6 +50,10 @@ public class JsonTestCaseRun extends CommonRestfulJson implements TestCaseRun {
*/ */
@ClassRule @ClassRule
public static final SpringClassRule springClassRule = new SpringClassRule(); public static final SpringClassRule springClassRule = new SpringClassRule();
/**
* The constant jsonIdFilter.
*/
private static final Integer[] jsonIdFilter = new Integer[]{};
/** /**
* The Spring method rule. * The Spring method rule.
*/ */
@ -69,11 +74,6 @@ public class JsonTestCaseRun extends CommonRestfulJson implements TestCaseRun {
@Resource @Resource
private DisposeTaskMapper disposeTaskMapper; private DisposeTaskMapper disposeTaskMapper;
/**
* The constant jsonIdFilter.
*/
private static final Integer[] jsonIdFilter = new Integer[] {};
/** /**
* Instantiates a new Json test case run. * Instantiates a new Json test case run.
* *
@ -90,10 +90,13 @@ public class JsonTestCaseRun extends CommonRestfulJson implements TestCaseRun {
*/ */
@Parameters @Parameters
public static Collection<QATestItem> paramData() { public static Collection<QATestItem> paramData() {
List<Integer> usedId = Arrays.asList(CommonEnvironment.commonIdFilter);
usedId.addAll(Arrays.asList(jsonIdFilter));
return Arrays.stream(P1.getTestCase()) List<Integer> 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 -> k.getCaseJsonValue() != null && k.getCaseJsonValue().length() > 0)
.filter(k -> usedId.size() == 0 || usedId.stream().anyMatch(v -> Objects.equals(v, k.getId()))) .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 -> Arrays.stream(CommonEnvironment.commonPriorityFilter).anyMatch(v -> k.getPriority() == v))

View File

@ -8,7 +8,6 @@ import com.dispose.test.common.CommonEnvironment;
import com.dispose.test.common.CommonRestful; import com.dispose.test.common.CommonRestful;
import com.dispose.test.common.QATestItem; import com.dispose.test.common.QATestItem;
import com.dispose.test.qa.exec.TestCaseRun; import com.dispose.test.qa.exec.TestCaseRun;
import com.dispose.test.qa.testcase.v20.P1;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Assert; import org.junit.Assert;
import org.junit.ClassRule; import org.junit.ClassRule;
@ -25,8 +24,10 @@ import org.springframework.test.context.junit4.rules.SpringMethodRule;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -90,10 +91,12 @@ public class ObjectTestCaseRun extends CommonRestful implements TestCaseRun {
*/ */
@Parameterized.Parameters @Parameterized.Parameters
public static Collection<QATestItem> paramData() { public static Collection<QATestItem> paramData() {
List<Integer> usedId = Arrays.asList(CommonEnvironment.commonIdFilter); List<Integer> usedId = new ArrayList<>();
usedId.addAll(Arrays.asList(objIdFilter));
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 -> k.getReqObject() != null)
.filter(k -> usedId.size() == 0 || usedId.stream().anyMatch(v -> Objects.equals(v, k.getId()))) .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 -> Arrays.stream(CommonEnvironment.commonPriorityFilter).anyMatch(v -> k.getPriority() == v))

View File

@ -2,7 +2,6 @@ package com.dispose.test.qa.testcase.v20;
import com.dispose.common.DisposeCapacityType; import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeDeviceType; import com.dispose.common.DisposeDeviceType;
import com.dispose.common.DisposeObjectType;
import com.dispose.common.ErrorCode; import com.dispose.common.ErrorCode;
import com.dispose.common.Helper; import com.dispose.common.Helper;
import com.dispose.common.HttpType; 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.device.manager.CommDeviceListRsp;
import com.dispose.pojo.dto.protocol.task.GetTaskRsp; import com.dispose.pojo.dto.protocol.task.GetTaskRsp;
import com.dispose.pojo.dto.protocol.task.TaskStartRsp; 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.pojo.entity.DisposeDevice;
import com.dispose.test.common.QATestItem; import com.dispose.test.common.QATestItem;
import com.dispose.test.common.TestPriority; import com.dispose.test.common.TestPriority;
@ -23,8 +22,6 @@ import lombok.extern.slf4j.Slf4j;
import org.junit.Assert; import org.junit.Assert;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import java.util.ArrayList;
/** /**
* The type P 1. * The type P 1.
* *
@ -167,8 +164,8 @@ public class P1 {
.urlPath("/manager/upgrade") .urlPath("/manager/upgrade")
.method(RequestMethod.POST) .method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1599094454403," + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1599094454403," +
"\"msgContent\":{\"items\":[{\"ipAddr\":\"10.88.77.16\",\"ipPort\":\"\"," + "\"msgContent\":{\"items\":[{\"ipAddr\":\"127.0.0.1\",\"ipPort\":\"\"," +
"\"deviceType\":0,\"areaCode\":0,\"deviceName\":\"中移杭研实验室迪普清洗设备\"," + "\"deviceType\":999,\"areaCode\":0,\"deviceName\":\"中移杭研实验室迪普清洗设备\"," +
"\"manufacturer\":\"DPTech\",\"model\":\"UMC\",\"version\":\"5.7.13\"," + "\"manufacturer\":\"DPTech\",\"model\":\"UMC\",\"version\":\"5.7.13\"," +
"\"userName\":\"test\",\"password\":\"testpassword\"," + "\"userName\":\"test\",\"password\":\"testpassword\"," +
"\"urlPath\":\"UMC/service/AbnormalFlowCleaningService\",\"urlType\":0," + "\"urlPath\":\"UMC/service/AbnormalFlowCleaningService\",\"urlType\":0," +
@ -189,45 +186,37 @@ public class P1 {
Assert.assertNotNull(k.getDevStatus()); 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.assertNotNull(dev);
Assert.assertEquals(dev.getDevCapacity().size(), 2); Assert.assertEquals(dev.getDevCapacity().size(), 2);
dev.getDevCapacity().stream().filter(k -> k.getCapacityType() == DisposeCapacityType.BLACKHOOL).forEach(m -> { Assert.assertEquals(dev.getDeviceType(), DisposeDeviceType.VIRTUAL_DISPOSE);
Assert.assertEquals((long)m.getObjectType().getValue(), 4L); Assert.assertEquals((long) dev.getAreaCode(), 0);
Assert.assertEquals((long)m.getReserveNetflow(), 20); 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()
.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();
dev.getDevCapacity().add(DisposeCapacity.builder() dev.getDevCapacity()
.protectIp("192.168.20.1/24") .stream()
.capacityType(DisposeCapacityType.CLEANUP) .filter(k -> k.getCapacityType() == DisposeCapacityType.CLEANUP)
.objectType(DisposeObjectType.IP) .forEach(m -> {
.ipType(IpAddrType.IPV4) Assert.assertEquals((long) m.getObjectType().getValue(), 1L);
.reserveNetflow(10) Assert.assertEquals((long) m.getReserveNetflow(), 10);
.build()); Assert.assertEquals(m.getProtectIp(), "192.168.20.1/24");
Assert.assertEquals(m.getIpType(), IpAddrType.IPV4);
c.getDisposeDeviceMapper().addNewDisposeDevice(dev); });
}) })
.build(), .build(),
@ -276,6 +265,27 @@ public class P1 {
QATestItem.builder() QATestItem.builder()
.id(BASE_P1_ID + 8) .id(BASE_P1_ID + 8)
.priority(TestPriority.P1_PRIORITY) .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<TaskStopRsp>) (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") .urlPath("/task/taskList")
.method(RequestMethod.POST) .method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234,\"msgContent\":{\"startPage\":1," + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234,\"msgContent\":{\"startPage\":1," +
@ -287,8 +297,8 @@ public class P1 {
Assert.assertNotNull(v); Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent()); Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long) v.getMsgContent().getStatus(), e.getCode()); Assert.assertEquals((long) v.getMsgContent().getStatus(), e.getCode());
Assert.assertEquals((long)v.getMsgContent().getCurPageNumber(), 1); Assert.assertEquals((long) v.getMsgContent().getCurPageNumber(), 1);
Assert.assertEquals((long)v.getMsgContent().getPageSize(), 10); Assert.assertEquals((long) v.getMsgContent().getPageSize(), 10);
Assert.assertEquals(v.getMsgContent().getItems().size(), Assert.assertEquals(v.getMsgContent().getItems().size(),
Math.min(v.getMsgContent().getTotalItems(), 10)); Math.min(v.getMsgContent().getTotalItems(), 10));
}) })