diff --git a/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java b/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java index 717151c6..b99f71d6 100644 --- a/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java @@ -15,6 +15,11 @@ import javax.annotation.Nullable; * @author */ public class VirtualAbilityImpl implements DisposeAbility { + /** + * The Is online. + */ + private boolean isOnline = true; + /** * Init device env. * @@ -24,7 +29,11 @@ public class VirtualAbilityImpl implements DisposeAbility { */ @Override public void initDeviceEnv(String urlPath, String username, String password) { + final String offlineTarget = "0"; + if(offlineTarget.equals(username)) { + isOnline = false; + } } /** @@ -90,7 +99,7 @@ public class VirtualAbilityImpl implements DisposeAbility { */ @Override public boolean getDeviceLinkStatus() { - return true; + return isOnline; } /** diff --git a/src/test/java/com/dispose/test/common/TestHelper.java b/src/test/java/com/dispose/test/common/TestHelper.java index 02d39820..9dd56bef 100644 --- a/src/test/java/com/dispose/test/common/TestHelper.java +++ b/src/test/java/com/dispose/test/common/TestHelper.java @@ -60,12 +60,11 @@ public class TestHelper { } if (loginToken != null) { - build.contentType(MediaType.APPLICATION_JSON) - .header("Authorization", ConstValue.STRING_HTTP_AUTH_HEAD + loginToken) - .content(sendMsgContent); - } else { - build.contentType(MediaType.APPLICATION_JSON) - .content(sendMsgContent); + build.header("Authorization", ConstValue.STRING_HTTP_AUTH_HEAD + loginToken); + } + + if (reqType != RequestMethod.GET) { + build.contentType(MediaType.APPLICATION_JSON).content(sendMsgContent); } return mockMvc.perform(build) 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 052ff56f..8b2dd979 100644 --- a/src/test/java/com/dispose/test/qa/exec/TestCaseRun.java +++ b/src/test/java/com/dispose/test/qa/exec/TestCaseRun.java @@ -2,12 +2,14 @@ package com.dispose.test.qa.exec; import com.dispose.mapper.DisposeDeviceMapper; import com.dispose.mapper.DisposeTaskMapper; +import com.dispose.service.DisposeDeviceManagerService; import com.dispose.test.common.QATestItem; import com.dispose.test.qa.testcase.v20.P1All; import com.dispose.test.qa.testcase.v20.P2DeviceAdd; import com.dispose.test.qa.testcase.v20.P2DeviceDel; import com.dispose.test.qa.testcase.v20.P2DeviceQuery; 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; @@ -35,6 +37,13 @@ public interface TestCaseRun { */ DisposeTaskMapper getDisposeTaskMapper(); + /** + * Gets dispose device manager service. + * + * @return the dispose device manager service + */ + DisposeDeviceManagerService getDisposeDeviceManagerService(); + /** * Gets all test case. * @@ -52,6 +61,8 @@ public interface TestCaseRun { Collections.addAll(tolTestCase, P2DeviceUpgrade.getTestCase()); Collections.addAll(tolTestCase, P2DeviceQuery.getTestCase()); + Collections.addAll(tolTestCase, P2Info.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 816a7ccf..de4a0e08 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 @@ -4,6 +4,7 @@ import com.dispose.mapper.DisposeDeviceMapper; import com.dispose.mapper.DisposeTaskMapper; import com.dispose.pojo.dto.protocol.base.BaseRespStatus; import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO; +import com.dispose.service.DisposeDeviceManagerService; import com.dispose.test.common.CommonEnvironment; import com.dispose.test.common.CommonRestfulJson; import com.dispose.test.common.QATestItem; @@ -74,6 +75,12 @@ public class JsonTestCaseRun extends CommonRestfulJson implements TestCaseRun { @Resource private DisposeTaskMapper disposeTaskMapper; + /** + * The Dispose device manager service. + */ + @Resource + private DisposeDeviceManagerService disposeDeviceManagerService; + /** * Instantiates a new Json test case run. * @@ -100,7 +107,7 @@ 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() >= 600) + //.filter(k-> k.getId() >= 700) .collect(Collectors.toList()); } @@ -154,4 +161,14 @@ public class JsonTestCaseRun extends CommonRestfulJson implements TestCaseRun { public DisposeTaskMapper getDisposeTaskMapper() { return disposeTaskMapper; } + + /** + * Gets dispose device manager service. + * + * @return the dispose device manager service + */ + @Override + public DisposeDeviceManagerService getDisposeDeviceManagerService() { + return disposeDeviceManagerService; + } } 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 80f13229..05264ee1 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 @@ -4,6 +4,7 @@ import com.dispose.common.ProtoCryptoType; import com.dispose.mapper.DisposeDeviceMapper; import com.dispose.mapper.DisposeTaskMapper; import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO; +import com.dispose.service.DisposeDeviceManagerService; import com.dispose.test.common.CommonEnvironment; import com.dispose.test.common.CommonRestful; import com.dispose.test.common.QATestItem; @@ -50,6 +51,10 @@ public class ObjectTestCaseRun extends CommonRestful implements TestCaseRun { */ @ClassRule public static final SpringClassRule springClassRule = new SpringClassRule(); + /** + * The constant objIdFilter. + */ + private static final Integer[] objIdFilter = new Integer[]{}; /** * The Spring method rule. */ @@ -69,11 +74,11 @@ public class ObjectTestCaseRun extends CommonRestful implements TestCaseRun { */ @Resource private DisposeTaskMapper disposeTaskMapper; - /** - * The constant objIdFilter. + * The Dispose device manager service. */ - private static final Integer[] objIdFilter = new Integer[] {}; + @Resource + private DisposeDeviceManagerService disposeDeviceManagerService; /** * Instantiates a new Object test case run. @@ -152,4 +157,14 @@ public class ObjectTestCaseRun extends CommonRestful implements TestCaseRun { public DisposeTaskMapper getDisposeTaskMapper() { return disposeTaskMapper; } + + /** + * Gets dispose device manager service. + * + * @return the dispose device manager service + */ + @Override + public DisposeDeviceManagerService getDisposeDeviceManagerService() { + return disposeDeviceManagerService; + } } 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 52e189e4..146c99b5 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 @@ -319,8 +319,7 @@ public class P1All { Assert.assertEquals((long) v.getMsgContent().getStatus(), e.getCode()); 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)); + Assert.assertNotEquals(v.getMsgContent().getItems().size(), 0); }) .build(), 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 new file mode 100644 index 00000000..55031efd --- /dev/null +++ b/src/test/java/com/dispose/test/qa/testcase/v20/P2Info.java @@ -0,0 +1,423 @@ +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; +import com.dispose.common.IpAddrType; +import com.dispose.pojo.dto.protocol.base.BaseRespStatus; +import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO; +import com.dispose.pojo.dto.protocol.device.info.GetAreaInfoRsp; +import com.dispose.pojo.dto.protocol.device.info.GetDeviceInfoRsp; +import com.dispose.pojo.dto.protocol.device.info.GetPlatformVerInfoRsp; +import com.dispose.pojo.entity.DisposeCapacity; +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 com.dispose.test.qa.exec.TestCaseRun; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.springframework.web.bind.annotation.RequestMethod; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Random; + +/** + * The type P 2 info. + * + * @author + */ +@Slf4j +public class P2Info { + /** + * The constant BASE_P2_INFO_ID. + */ + public static final int BASE_P2_INFO_ID = 700; + /** + * The constant testItemArray. + */ + private static final QATestItem[] testItemArray = new QATestItem[]{ + QATestItem.builder() + .id(BASE_P2_INFO_ID) + .name("获取节点信息") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/info/areaInfo") + .method(RequestMethod.GET) + .caseJsonValue("{}") + .rspClass(GetAreaInfoRsp.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.assertEquals((long) v.getMsgContent().getStatus(), e.getCode()); + Assert.assertNotNull(v.getMsgContent().getItems()); + Assert.assertEquals(v.getMsgContent().getItems().size(), 5); + v.getMsgContent().getItems().forEach(k -> { + Assert.assertNotNull(k.getNodeId()); + Assert.assertNotNull(k.getTotalNetflow()); + Assert.assertNotNull(k.getCapacityType()); + Assert.assertNotEquals(k.getCapacityType().length, 0); + Assert.assertNotNull(k.getOnlineDevices()); + }); + }) + .prepareCallback(P2Info::prepareDisposeDevice) + .build(), + + QATestItem.builder() + .id(BASE_P2_INFO_ID + 1) + .name("获取平台版本信息") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/info/platformVersion") + .method(RequestMethod.GET) + .caseJsonValue("{}") + .rspClass(GetPlatformVerInfoRsp.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.assertEquals((long) v.getMsgContent().getStatus(), e.getCode()); + + Assert.assertNotNull(v.getMsgContent().getPlatVer()); + Assert.assertNotEquals(v.getMsgContent().getPlatVer().getBuildTime().length(), 0); + Assert.assertNotEquals(v.getMsgContent().getPlatVer().getCommitDescribe().length(), 0); + Assert.assertNotEquals(v.getMsgContent().getPlatVer().getCommitId().length(), 0); + Assert.assertNotEquals(v.getMsgContent().getPlatVer().getCommitTime().length(), 0); + Assert.assertNotEquals(v.getMsgContent().getPlatVer().getGitBranch().length(), 0); + Assert.assertNotEquals(v.getMsgContent().getPlatVer().getTagName().length(), 0); + }) + .build(), + + QATestItem.builder() + .id(BASE_P2_INFO_ID + 2) + .name("获取存在的一个设备版本信息") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/info/deviceVersion") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"id\":[\"1\"]}}") + .rspClass(GetDeviceInfoRsp.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(), 1); + + v.getMsgContent().getItems().forEach(k -> { + Assert.assertEquals(k.getId(), "1"); + Assert.assertEquals(k.getIpAddr(), "127.0.0.1"); + Assert.assertEquals(k.getIpPort(), Helper.ipPortNormalize(k.getIpPort(), HttpType.HTTP)); + Assert.assertNotEquals(k.getVersion().length(), 0); + }); + }) + .build(), + + QATestItem.builder() + .id(BASE_P2_INFO_ID + 3) + .name("获取多个设备版本信息") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/info/deviceVersion") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"id\":[\"1\"," + + "\"571\"]}}") + .rspClass(GetDeviceInfoRsp.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(), 2); + + v.getMsgContent().getItems().forEach(k -> { + if ("1".equals(k.getId())) { + Assert.assertEquals(k.getIpAddr(), "127.0.0.1"); + Assert.assertEquals(k.getIpPort(), Helper.ipPortNormalize(k.getIpPort(), HttpType.HTTP)); + Assert.assertEquals((long) k.getStatus(), ErrorCode.ERR_OK.getCode()); + } else { + Assert.assertEquals((long) k.getStatus(), ErrorCode.ERR_NOSUCHDEVICE.getCode()); + } + }); + }) + .build(), + + QATestItem.builder() + .id(BASE_P2_INFO_ID + 4) + .name("msgContent为空") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/info/deviceVersion") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":}") + .rspClass(GetDeviceInfoRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) P2Info::verifyJsonExceptionResp) + .build(), + + QATestItem.builder() + .id(BASE_P2_INFO_ID + 5) + .name("获取在线的一个设备信息") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/info/deviceLinkStatus") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"id\":[\"1\"]}}") + .rspClass(GetDeviceInfoRsp.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(), 1); + + v.getMsgContent().getItems().forEach(k -> { + Assert.assertEquals(k.getId(), "1"); + Assert.assertEquals(k.getIpAddr(), "127.0.0.1"); + Assert.assertEquals(k.getIpPort(), Helper.ipPortNormalize(k.getIpPort(), HttpType.HTTP)); + Assert.assertEquals((long) k.getStatus(), ErrorCode.ERR_OK.getCode()); + Assert.assertEquals((long) k.getOnline(), 1); + }); + }) + .build(), + + QATestItem.builder() + .id(BASE_P2_INFO_ID + 6) + .name("获取在线的多个设备信息") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/info/deviceLinkStatus") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"id\":[\"1\"," + + "\"2\"]}}") + .rspClass(GetDeviceInfoRsp.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(), 2); + + v.getMsgContent().getItems().forEach(k -> { + Assert.assertEquals(k.getIpAddr(), "127.0.0.1"); + Assert.assertEquals(k.getIpPort(), Helper.ipPortNormalize(k.getIpPort(), HttpType.HTTP)); + Assert.assertEquals((long) k.getStatus(), ErrorCode.ERR_OK.getCode()); + Assert.assertEquals((long) k.getOnline(), 1); + }); + }) + .build(), + + QATestItem.builder() + .id(BASE_P2_INFO_ID + 7) + .name("获取不在线的一个设备信息") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/info/deviceLinkStatus") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580," + + "\"msgContent\":{\"id\":[\"3\"]}}") + .rspClass(GetDeviceInfoRsp.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(), 1); + + v.getMsgContent().getItems().forEach(k -> { + Assert.assertEquals(k.getId(), "3"); + Assert.assertEquals(k.getIpAddr(), "127.0.0.1"); + Assert.assertEquals(k.getIpPort(), Helper.ipPortNormalize(k.getIpPort(), HttpType.HTTP)); + Assert.assertEquals((long) k.getStatus(), ErrorCode.ERR_OK.getCode()); + Assert.assertEquals((long) k.getOnline(), 0); + }); + }) + .build(), + + QATestItem.builder() + .id(BASE_P2_INFO_ID + 8) + .name("获取不在线的多个设备信息") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/info/deviceLinkStatus") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"id\":[\"3\"," + + "\"4\"]}}") + .rspClass(GetDeviceInfoRsp.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(), 2); + + v.getMsgContent().getItems().forEach(k -> { + Assert.assertEquals(k.getIpAddr(), "127.0.0.1"); + Assert.assertEquals((long) k.getStatus(), ErrorCode.ERR_OK.getCode()); + Assert.assertEquals((long) k.getOnline(), 0); + }); + }) + .build(), + + QATestItem.builder() + .id(BASE_P2_INFO_ID + 9) + .name("获取不存在设备的在线信息") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/info/deviceLinkStatus") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":{\"id\":[\"593\"]}}") + .rspClass(GetDeviceInfoRsp.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(), 1); + v.getMsgContent().getItems().forEach(k -> { + Assert.assertEquals(k.getId(), "593"); + Assert.assertEquals((long) k.getStatus(), ErrorCode.ERR_NOSUCHDEVICE.getCode()); + }); + }) + .build(), + + QATestItem.builder() + .id(BASE_P2_INFO_ID + 10) + .name("msgContent为空") + .priority(TestPriority.P2_PRIORITY) + .urlPath("/info/deviceLinkStatus") + .method(RequestMethod.POST) + .caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598597142580,\"msgContent\":}") + .rspClass(GetDeviceInfoRsp.class) + .rspCode(ErrorCode.ERR_PARAMEXCEPTION) + .autoLogin(true) + .verifyCallback((VerifyProtoRespCallback) P2Info::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()); + } + + /** + * Prepare dispose device. + * + * @param c the c + */ + private static void prepareDisposeDevice(TestCaseRun c) { + + List disposeDevices = new ArrayList<>(); + + List capacityList = new ArrayList<>(); + + capacityList.add( + DisposeCapacity.builder() + .capacityType(DisposeCapacityType.CLEANUP) + .objectType(DisposeObjectType.IP) + .ipType(IpAddrType.IPV4_IPV6) + .protectIp("0.0.0.0") + .reserveNetflow(30) + .build() + ); + + capacityList.add( + DisposeCapacity.builder() + .capacityType(DisposeCapacityType.BLACKHOOL) + .objectType(DisposeObjectType.IP_DOMAIN_URL) + .build() + ); + + capacityList.add( + DisposeCapacity.builder() + .capacityType(DisposeCapacityType.HIDEPEND) + .objectType(DisposeObjectType.IP) + .ipType(IpAddrType.IPV4_IPV6) + .protectIp("0.0.0.0") + .build() + ); + + capacityList.add( + DisposeCapacity.builder() + .capacityType(DisposeCapacityType.DETECTIVE) + .objectType(DisposeObjectType.IP) + .ipType(IpAddrType.IPV4_IPV6) + .protectIp("0.0.0.0") + .build() + ); + + for (int i = 0; i < 18; i++) { + + List disposeCapacities = new ArrayList<>(capacityList); + + Random rnd = new Random(System.currentTimeMillis()); + + int k = 0; + int n = rnd.nextInt(3); + + Iterator it = disposeCapacities.iterator(); + while (it.hasNext()) { + DisposeCapacity item = it.next(); + if (item.getCapacityType() != DisposeCapacityType.CLEANUP && k++ <= n) { + it.remove(); + } + } + + DisposeDevice dev = DisposeDevice.builder() + .ipAddr("127.0.0.1") + .ipPort(String.valueOf(1000 + i)) + .deviceType(DisposeDeviceType.VIRTUAL_DISPOSE) + .areaCode(i % 5) + .deviceName("实验室虚拟清洗设备") + .manufacturer("CMCC") + .model("Virtual") + .version("v0.0.1") + .userName("admin") + .password("admin") + .urlPath("") + .urlType(HttpType.HTTP) + .readme("实验室虚拟测试设备") + .devCapacity(disposeCapacities) + .build(); + + disposeDevices.add(dev); + } + + c.getDisposeDeviceManagerService().addDisposeDevice(disposeDevices); + } +} +