From 6f08f56b37f849268592074984ff948f35725ac9 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Thu, 30 Apr 2020 10:27:45 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=E5=A2=9E=E5=8A=A0=E5=8D=95?= =?UTF-8?q?=E5=85=83=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 --- .../TestSuit/AllDisposePlatformTest.java | 4 ++- .../controller/AuthControllerTest.java | 29 +++++++++++++++ .../controller/TaskControllerTest.java | 31 ++++++++++++++++ .../service/DisposeNodeManagerTest.java | 5 +++ .../com/dispose/service/TaskServiceTest.java | 35 +++++++++++++++++++ 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/dispose/service/TaskServiceTest.java diff --git a/src/test/java/com/dispose/TestSuit/AllDisposePlatformTest.java b/src/test/java/com/dispose/TestSuit/AllDisposePlatformTest.java index e12dd28e..edc24e94 100644 --- a/src/test/java/com/dispose/TestSuit/AllDisposePlatformTest.java +++ b/src/test/java/com/dispose/TestSuit/AllDisposePlatformTest.java @@ -13,6 +13,7 @@ import com.dispose.mapper.DisposeDeviceMapperTest; import com.dispose.mapper.DisposeTaskMapperTest; import com.dispose.mapper.UserAccountMapperTest; import com.dispose.service.DisposeNodeManagerTest; +import com.dispose.service.TaskServiceTest; import com.dispose.service.UserAccountServiceTest; import org.junit.runner.RunWith; import org.junit.runners.Suite; @@ -34,7 +35,8 @@ import org.junit.runners.Suite; DeviceNodeManagerControllerTest.class, DeviceNodeInfoControllerTest.class, UserAccountServiceTest.class, - TaskControllerTest.class + TaskControllerTest.class, + TaskServiceTest.class }) public class AllDisposePlatformTest { diff --git a/src/test/java/com/dispose/controller/AuthControllerTest.java b/src/test/java/com/dispose/controller/AuthControllerTest.java index 33245bab..fece7ba6 100644 --- a/src/test/java/com/dispose/controller/AuthControllerTest.java +++ b/src/test/java/com/dispose/controller/AuthControllerTest.java @@ -105,4 +105,33 @@ public class AuthControllerTest extends InitTestEnvironment { .getResponse() .getContentAsString(); } + + /** + * Logout 2. + * + * @throws Exception the exception + */ + @Test + public void logout3() throws Exception { + LoginReq logReq = LoginReq.builder() + .userName("admin2") + .build(); + + ProtocolReqDTO reqInfo = new ProtocolReqDTO(); + reqInfo.setVer(ConstValue.Protocol.VERSION); + reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); + reqInfo.setTimeStamp(System.currentTimeMillis()); + reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq)); + + mockMvc.perform(MockMvcRequestBuilders + .post("/auth/logout") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer " + getLogToken()) + .content(objectMapper.writeValueAsString(reqInfo))) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(502)) + .andReturn() + .getResponse() + .getContentAsString(); + } } diff --git a/src/test/java/com/dispose/controller/TaskControllerTest.java b/src/test/java/com/dispose/controller/TaskControllerTest.java index d0f3ffda..8189e2e8 100644 --- a/src/test/java/com/dispose/controller/TaskControllerTest.java +++ b/src/test/java/com/dispose/controller/TaskControllerTest.java @@ -190,6 +190,37 @@ public class TaskControllerTest extends InitTestEnvironment { .getContentAsString(); } + @Test + public void t3_stopAllNodeIpTask() throws Exception { + StopTaskData itemData = StopTaskData.builder() + .disposeIp("192.168.5.2") + .type(DeviceCapacity.CLEANUP.getCode()) + .id("-1") + .build(); + + StopTaskReq reqData = new StopTaskReq(); + + reqData.setItems(new ArrayList<>()); + reqData.getItems().add(itemData); + + ProtocolReqDTO reqInfo = new ProtocolReqDTO(); + reqInfo.setVer(ConstValue.Protocol.VERSION); + reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE); + reqInfo.setTimeStamp(System.currentTimeMillis()); + reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData)); + + mockMvc.perform(MockMvcRequestBuilders + .post("/task/stop_ip") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer " + getLogToken()) + .content(objectMapper.writeValueAsString(reqInfo))) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(200)) + .andReturn() + .getResponse() + .getContentAsString(); + } + /** * T 4 stop node task. * diff --git a/src/test/java/com/dispose/service/DisposeNodeManagerTest.java b/src/test/java/com/dispose/service/DisposeNodeManagerTest.java index 5889261c..91300c5a 100644 --- a/src/test/java/com/dispose/service/DisposeNodeManagerTest.java +++ b/src/test/java/com/dispose/service/DisposeNodeManagerTest.java @@ -8,6 +8,7 @@ import com.dispose.pojo.po.MReturnType; import com.fasterxml.jackson.databind.ObjectMapper; import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; +import org.junit.After; import org.junit.Assert; import org.junit.FixMethodOrder; import org.junit.Test; @@ -59,6 +60,10 @@ public class DisposeNodeManagerTest extends InitTestEnvironment { */ @Override public void userLogin() { + } + + @After + public void reloadCacheData() { disposeNodeManager.loadDisposeNodeFromDB(); } diff --git a/src/test/java/com/dispose/service/TaskServiceTest.java b/src/test/java/com/dispose/service/TaskServiceTest.java new file mode 100644 index 00000000..8bdb4819 --- /dev/null +++ b/src/test/java/com/dispose/service/TaskServiceTest.java @@ -0,0 +1,35 @@ +package com.dispose.service; + +import com.dispose.Global.InitTestEnvironment; +import com.dispose.common.ErrorCode; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +@RunWith(SpringRunner.class) +@SpringBootTest +@Slf4j +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TaskServiceTest extends InitTestEnvironment { + @Resource + private TaskService taskService; + + @Override + public void userLogin() { + + } + + @Test + public void t1_stopTaskTest() { + ErrorCode err = taskService.stopTask(-1L); + + Assert.assertEquals(err, ErrorCode.ERR_NOSUCHDEVICE); + } +}