From 90e0bee703a65f3e5d8b26a369a8ecaf36ef31cb Mon Sep 17 00:00:00 2001 From: HuangXin Date: Sat, 9 May 2020 18:09:06 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=E6=9B=B4=E6=96=B0local?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=202.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=A4=84=E7=BD=AE=E4=B8=AD=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=86=92=E7=83=9F=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/application-local.properties | 13 +-- .../DeviceNodeInfoControllerSmokeTest.java | 102 +++++++++++++++++- 2 files changed, 103 insertions(+), 12 deletions(-) diff --git a/config/application-local.properties b/config/application-local.properties index 1f407c80..27611156 100644 --- a/config/application-local.properties +++ b/config/application-local.properties @@ -4,7 +4,8 @@ server.tomcat.basedir=./basedir # 多个项目放在nginx下同个端口,通过该配置区分 server.servlet.context-path=/dispose # 配置数据源 -spring.datasource.url=jdbc:mysql://172.28.72.118:33061/dispose?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true +spring.datasource.url=jdbc:mysql://172.28.72.118:33061/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 @@ -22,7 +23,7 @@ spring.datasource.dbcp2.connection-properties=characterEncoding=utf8 # 下划线转驼峰 将带有下划线的表字段映射为驼峰格式的实体类属性 #mybatis.configuration.map-underscore-to-camel-case: true mybatis.mapper-locations=classpath*:mappers/*.xml -mybatis.type-aliases-package=com.cmcc.hy.phoenix.entity +mybatis.type-aliases-package=com.dispose.pojo.entity #config log logging.config=file:config/logback.xml #config tomcat @@ -50,12 +51,8 @@ phoenix.request-dec-switch=false phoenix.response-enc-switch=false #config aes 128 key,用于上述body的加解密 phoenix.aes-key=Wt4EJu6Rrq5udd/42bNpCQ== -#威胁情报文件自动下载更新 -phoenix.threat-info-key=7d79e180a6a20d4c0b5c81d146c5b85d1715d353b50ec094f966ec525fdd9897 -phoenix.threat-info-version-url=https://tip.komect.com:9099/api/v1/search/cases/reputation -phoenix.threat-info-download=https://tip.komect.com:9099/api/v1/resource/data/download #====custom config,begin with phoenix==== #调试配置 dispose.check-protocol-timeout=false -dispose.check-request-token=false -dispose.check-admin-permission=false +dispose.check-request-token=true +dispose.check-admin-permission=true diff --git a/src/test/java/com/dispose/controller/DeviceNodeInfoControllerSmokeTest.java b/src/test/java/com/dispose/controller/DeviceNodeInfoControllerSmokeTest.java index e56f790b..9b511f55 100644 --- a/src/test/java/com/dispose/controller/DeviceNodeInfoControllerSmokeTest.java +++ b/src/test/java/com/dispose/controller/DeviceNodeInfoControllerSmokeTest.java @@ -1,6 +1,7 @@ package com.dispose.controller; import com.dispose.Global.InitTestEnvironment; +import com.dispose.common.DisposeTaskStatus; import com.dispose.common.ErrorCode; import com.dispose.mapper.DisposeTaskMapper; import com.dispose.pojo.entity.DisposeDevice; @@ -32,11 +33,16 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +/** + * The type Device node info controller smoke test. + */ @AutoConfigureMockMvc @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -57,11 +63,14 @@ public class DeviceNodeInfoControllerSmokeTest extends InitTestEnvironment { @Resource private ObjectMapper objectMapper; + /** + * The Dispose task mapper. + */ @Resource private DisposeTaskMapper disposeTaskMapper; /** - * A 1 get all task Normal Test. + * A 1 get all task normal test. * * @throws Exception the exception */ @@ -97,6 +106,10 @@ public class DeviceNodeInfoControllerSmokeTest extends InitTestEnvironment { Assert.assertNotNull(taskData.getStatus()); Assert.assertNotNull(taskData.getMessage()); + Assert.assertNotNull(taskData.getStatus()); + Assert.assertNotNull(taskData.getMessage()); + Assert.assertEquals(Long.valueOf(taskData.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); + TaskInfoData taskInfoData = taskData.getTaskArray().get(0); Assert.assertNotNull(taskInfoData); Assert.assertNotNull(taskInfoData.getTaskId()); @@ -109,13 +122,94 @@ public class DeviceNodeInfoControllerSmokeTest extends InitTestEnvironment { } /** - * C 1 get Node Details Normal Test. + * A 2 get all task id null test. + * + * @throws Exception the exception + */ + @Test + public void a2_getAllTaskIdNullTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"{\\\"id\\\":null}\"}"; + + String ret = mockMvc.perform(MockMvcRequestBuilders + .post("/information/all_task") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer " + getLogToken()) + .content(reqData)) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) + .andReturn() + .getResponse() + .getContentAsString(); + + ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class); + + Assert.assertNotNull(rspInfo.getStatus()); + Assert.assertNotNull(rspInfo.getMessage()); + Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); + Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); + } + + /** + * A 3 get run task normal test. + * + * @throws Exception the exception + */ + @Test + public void a3_getRunTaskNormalTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," + + "\"msgContent\":\"{\\\"id\\\":[\\\"1\\\"]}\"}"; + + String ret = mockMvc.perform(MockMvcRequestBuilders + .post("/information/run_task") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer " + getLogToken()) + .content(reqData)) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) + .andReturn() + .getResponse() + .getContentAsString(); + + NodeTaskRsp rspInfo = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class) ; + + Assert.assertNotNull(rspInfo); + Assert.assertNotEquals(rspInfo.getItems().size(), 0); + + List taskList = disposeTaskMapper.getAllTaskByNodeDevId(1L).stream() + .filter(v -> Objects.equals(v.getCurrentStatus(), DisposeTaskStatus.TASK_RUNNING.getCode())) + .collect(Collectors.toList()); + + Assert.assertEquals(Long.valueOf(rspInfo.getItems().get(0).getTaskArray().size()), Long.valueOf(taskList.size())); + + if(taskList.size() > 0) { + NodeTaskData taskData = rspInfo.getItems().get(0); + + Assert.assertNotNull(taskData); + Assert.assertNotNull(taskData.getId()); + Assert.assertNotNull(taskData.getStatus()); + Assert.assertNotNull(taskData.getMessage()); + Assert.assertNotNull(taskData.getStatus()); + Assert.assertNotNull(taskData.getMessage()); + Assert.assertEquals(Long.valueOf(taskData.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); + + TaskInfoData taskInfoData = taskData.getTaskArray().get(0); + Assert.assertNotNull(taskInfoData); + Assert.assertNotNull(taskInfoData.getTaskId()); + Assert.assertNotNull(taskInfoData.getType()); + Assert.assertNotNull(taskInfoData.getStartTime()); + Assert.assertNotNull(taskInfoData.getDisposeTime()); + Assert.assertNotNull(taskInfoData.getDisposeIp()); + } + } + + /** + * C 1 get node details normal test. * * @throws Exception the exception */ @Test public void c1_getNodeDetailsNormalTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504,\"msgContent\":\"{\\\"id\\\":[\\\"476\\\"]}\"}"; + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504,\"msgContent\":\"{\\\"id\\\":[\\\"1\\\"]}\"}"; String ret = mockMvc.perform(MockMvcRequestBuilders .post("/information/node_details") @@ -135,7 +229,7 @@ public class DeviceNodeInfoControllerSmokeTest extends InitTestEnvironment { } /** - * C 2 get Node Details MsgContentEmpty Test. + * C 2 get node details msg content empty test. * * @throws Exception the exception */