|
@@ -1,398 +1,399 @@
|
|
|
-package com.hfln.portal.application.controller.wap;
|
|
|
-
|
|
|
-import cn.hfln.framework.dto.ApiResult;
|
|
|
-import com.hfln.portal.common.dto.data.device.DeviceDTO;
|
|
|
-import com.hfln.portal.common.request.device.DeviceListParams;
|
|
|
-import com.hfln.portal.common.request.device.DeviceBandingParams;
|
|
|
-import com.hfln.portal.common.request.device.DeviceLocationParams;
|
|
|
-import com.hfln.portal.common.response.device.WcTimesQueryRes;
|
|
|
-import com.hfln.portal.domain.gateway.DeviceGateway;
|
|
|
-import org.junit.jupiter.api.Test;
|
|
|
-import org.junit.jupiter.api.extension.ExtendWith;
|
|
|
-import org.mockito.InjectMocks;
|
|
|
-import org.mockito.Mock;
|
|
|
-import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
-import org.springframework.test.util.ReflectionTestUtils;
|
|
|
-
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
-import static org.mockito.Mockito.*;
|
|
|
-
|
|
|
-@ExtendWith(MockitoExtension.class)
|
|
|
-class DeviceControllerTest {
|
|
|
-
|
|
|
- // 常量定义
|
|
|
- private static final String SUCCESS_CODE = "200";
|
|
|
- private static final String TEST_OPEN_ID = "test_open_id";
|
|
|
- private static final String TEST_CLIENT_ID = "test_client_id";
|
|
|
- private static final String TEST_DEVICE_ID = "123456";
|
|
|
- private static final Long TEST_USER_ID = 1L;
|
|
|
- private static final Long TEST_DEV_ID = 2L;
|
|
|
-
|
|
|
- @Mock
|
|
|
- private DeviceGateway deviceGateway;
|
|
|
-
|
|
|
- @InjectMocks
|
|
|
- private DeviceController deviceController;
|
|
|
-
|
|
|
- @Test
|
|
|
- void deviceList_Success() {
|
|
|
- // 准备测试数据
|
|
|
- DeviceListParams request = new DeviceListParams();
|
|
|
- request.setUserId(TEST_USER_ID);
|
|
|
- request.setKeyWord("test");
|
|
|
- request.setStatus(1);
|
|
|
-
|
|
|
- List<DeviceDTO> expectedDevices = new ArrayList<>();
|
|
|
- DeviceDTO device = new DeviceDTO();
|
|
|
- device.setDevId(TEST_DEV_ID);
|
|
|
- device.setUserId(TEST_USER_ID);
|
|
|
- expectedDevices.add(device);
|
|
|
-
|
|
|
- // 模拟Gateway行为
|
|
|
- when(deviceGateway.queryDeviceList(request)).thenReturn(expectedDevices);
|
|
|
-
|
|
|
- // 执行测试
|
|
|
- ApiResult<List<DeviceDTO>> result = deviceController.deviceList(request);
|
|
|
-
|
|
|
- // 验证交互
|
|
|
- verify(deviceGateway, times(1)).queryDeviceList(request);
|
|
|
-
|
|
|
- // 验证结果
|
|
|
- assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
- assertEquals(expectedDevices, ReflectionTestUtils.getField(result, "data"));
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void deviceList_EmptyResult() {
|
|
|
- // 准备测试数据
|
|
|
- DeviceListParams request = new DeviceListParams();
|
|
|
- request.setUserId(TEST_USER_ID);
|
|
|
-
|
|
|
- List<DeviceDTO> expectedDevices = new ArrayList<>();
|
|
|
-
|
|
|
- // 模拟Gateway行为
|
|
|
- when(deviceGateway.queryDeviceList(request)).thenReturn(expectedDevices);
|
|
|
-
|
|
|
- // 执行测试
|
|
|
- ApiResult<List<DeviceDTO>> result = deviceController.deviceList(request);
|
|
|
-
|
|
|
- // 验证交互
|
|
|
- verify(deviceGateway, times(1)).queryDeviceList(request);
|
|
|
-
|
|
|
- // 验证结果
|
|
|
- assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
- assertEquals(expectedDevices, ReflectionTestUtils.getField(result, "data"));
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void deviceUnBind_Success() {
|
|
|
- // 准备测试数据
|
|
|
- Long userId = TEST_USER_ID;
|
|
|
- String clientId = TEST_CLIENT_ID;
|
|
|
-
|
|
|
- // 模拟Gateway行为
|
|
|
- when(deviceGateway.deviceUnBind(userId, clientId)).thenReturn(true);
|
|
|
-
|
|
|
- // 执行测试
|
|
|
- ApiResult<Boolean> result = deviceController.deviceUnBind(userId, clientId);
|
|
|
-
|
|
|
- // 验证交互
|
|
|
- verify(deviceGateway, times(1)).deviceUnBind(userId, clientId);
|
|
|
-
|
|
|
- // 验证结果
|
|
|
- assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
- assertEquals(true, ReflectionTestUtils.getField(result, "data"));
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void deviceUnBind_Failed() {
|
|
|
- // 准备测试数据
|
|
|
- Long userId = TEST_USER_ID;
|
|
|
- String clientId = TEST_CLIENT_ID;
|
|
|
-
|
|
|
- // 模拟Gateway行为
|
|
|
- when(deviceGateway.deviceUnBind(userId, clientId)).thenReturn(false);
|
|
|
-
|
|
|
- // 执行测试
|
|
|
- ApiResult<Boolean> result = deviceController.deviceUnBind(userId, clientId);
|
|
|
-
|
|
|
- // 验证交互
|
|
|
- verify(deviceGateway, times(1)).deviceUnBind(userId, clientId);
|
|
|
-
|
|
|
- // 验证结果
|
|
|
- assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
- assertEquals(false, ReflectionTestUtils.getField(result, "data"));
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void deviceBinding_Success() {
|
|
|
- // 准备测试数据
|
|
|
- DeviceBandingParams request = new DeviceBandingParams();
|
|
|
- request.setUserId(TEST_USER_ID);
|
|
|
- request.setClientId(TEST_CLIENT_ID);
|
|
|
- request.setDevName("测试设备");
|
|
|
-
|
|
|
- // 模拟Gateway行为
|
|
|
- when(deviceGateway.deviceBind(request)).thenReturn(true);
|
|
|
-
|
|
|
- // 执行测试
|
|
|
- ApiResult<Boolean> result = deviceController.deviceBinding(request);
|
|
|
-
|
|
|
- // 验证交互
|
|
|
- verify(deviceGateway, times(1)).deviceBind(request);
|
|
|
-
|
|
|
- // 验证结果
|
|
|
- assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
- assertEquals(true, ReflectionTestUtils.getField(result, "data"));
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void deviceBinding_Failed() {
|
|
|
- // 准备测试数据
|
|
|
- DeviceBandingParams request = new DeviceBandingParams();
|
|
|
- request.setUserId(TEST_USER_ID);
|
|
|
- request.setClientId(TEST_CLIENT_ID);
|
|
|
- request.setDevName("测试设备");
|
|
|
-
|
|
|
- // 模拟Gateway行为
|
|
|
- when(deviceGateway.deviceBind(request)).thenReturn(false);
|
|
|
-
|
|
|
- // 执行测试
|
|
|
- ApiResult<Boolean> result = deviceController.deviceBinding(request);
|
|
|
-
|
|
|
- // 验证交互
|
|
|
- verify(deviceGateway, times(1)).deviceBind(request);
|
|
|
-
|
|
|
- // 验证结果
|
|
|
- assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
- assertEquals(false, ReflectionTestUtils.getField(result, "data"));
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void queryDeviceInfoById_Success() {
|
|
|
- // 准备测试数据
|
|
|
- String deviceId = TEST_DEVICE_ID;
|
|
|
- DeviceDTO expectedDevice = new DeviceDTO();
|
|
|
- expectedDevice.setDevId(TEST_DEV_ID);
|
|
|
- expectedDevice.setDevName("测试设备");
|
|
|
- expectedDevice.setUserId(TEST_USER_ID);
|
|
|
-
|
|
|
- // 模拟Gateway行为
|
|
|
- when(deviceGateway.queryDeviceById(deviceId)).thenReturn(expectedDevice);
|
|
|
-
|
|
|
- // 执行测试
|
|
|
- ApiResult<DeviceDTO> result = deviceController.queryDeviceInfoById(deviceId);
|
|
|
-
|
|
|
- // 验证交互
|
|
|
- verify(deviceGateway, times(1)).queryDeviceById(deviceId);
|
|
|
-
|
|
|
- // 验证结果
|
|
|
- assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
- assertEquals(expectedDevice, ReflectionTestUtils.getField(result, "data"));
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void queryDeviceInfoById_NotFound() {
|
|
|
- // 准备测试数据
|
|
|
- String deviceId = TEST_DEVICE_ID;
|
|
|
-
|
|
|
- // 模拟Gateway行为
|
|
|
- when(deviceGateway.queryDeviceById(deviceId)).thenReturn(null);
|
|
|
-
|
|
|
- // 执行测试
|
|
|
- ApiResult<DeviceDTO> result = deviceController.queryDeviceInfoById(deviceId);
|
|
|
-
|
|
|
- // 验证交互
|
|
|
- verify(deviceGateway, times(1)).queryDeviceById(deviceId);
|
|
|
-
|
|
|
- // 验证结果
|
|
|
- assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
- assertEquals(null, ReflectionTestUtils.getField(result, "data"));
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void deviceRelations_Success() {
|
|
|
- // 执行测试
|
|
|
- ApiResult<DeviceDTO> result = deviceController.deviceRelations();
|
|
|
-
|
|
|
- // 验证结果
|
|
|
- assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
- assertEquals(null, ReflectionTestUtils.getField(result, "data"));
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void updateDevice_Success() {
|
|
|
- // 准备测试数据
|
|
|
- DeviceBandingParams request = new DeviceBandingParams();
|
|
|
- request.setUserId(TEST_USER_ID);
|
|
|
- request.setClientId(TEST_CLIENT_ID);
|
|
|
- request.setDevName("更新后的设备名称");
|
|
|
-
|
|
|
- // 模拟Gateway行为
|
|
|
- when(deviceGateway.updateDevice(request)).thenReturn(true);
|
|
|
-
|
|
|
- // 执行测试
|
|
|
- ApiResult<Boolean> result = deviceController.updateDevice(request);
|
|
|
-
|
|
|
- // 验证交互
|
|
|
- verify(deviceGateway, times(1)).updateDevice(request);
|
|
|
-
|
|
|
- // 验证结果
|
|
|
- assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
- assertEquals(true, ReflectionTestUtils.getField(result, "data"));
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void updateDevice_Failed() {
|
|
|
- // 准备测试数据
|
|
|
- DeviceBandingParams request = new DeviceBandingParams();
|
|
|
- request.setUserId(TEST_USER_ID);
|
|
|
- request.setClientId(TEST_CLIENT_ID);
|
|
|
- request.setDevName("更新后的设备名称");
|
|
|
-
|
|
|
- // 模拟Gateway行为
|
|
|
- when(deviceGateway.updateDevice(request)).thenReturn(false);
|
|
|
-
|
|
|
- // 执行测试
|
|
|
- ApiResult<Boolean> result = deviceController.updateDevice(request);
|
|
|
-
|
|
|
- // 验证交互
|
|
|
- verify(deviceGateway, times(1)).updateDevice(request);
|
|
|
-
|
|
|
- // 验证结果
|
|
|
- assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
- assertEquals(false, ReflectionTestUtils.getField(result, "data"));
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void updateDeviceLocation_Success() {
|
|
|
- // 准备测试数据
|
|
|
- DeviceLocationParams params = new DeviceLocationParams();
|
|
|
- params.setDevId(TEST_DEV_ID);
|
|
|
- params.setXxValue(new BigDecimal("100.5"));
|
|
|
- params.setYyValue(new BigDecimal("109.5"));
|
|
|
-
|
|
|
- // 模拟Gateway行为
|
|
|
- when(deviceGateway.updateDeviceLocation(params)).thenReturn(true);
|
|
|
-
|
|
|
- // 执行测试
|
|
|
- ApiResult<Boolean> result = deviceController.updateDeviceLocation(params);
|
|
|
-
|
|
|
- // 验证交互
|
|
|
- verify(deviceGateway, times(1)).updateDeviceLocation(params);
|
|
|
-
|
|
|
- // 验证结果
|
|
|
- assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
- assertEquals(true, ReflectionTestUtils.getField(result, "data"));
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void updateDeviceLocation_Failed() {
|
|
|
- // 准备测试数据
|
|
|
- DeviceLocationParams params = new DeviceLocationParams();
|
|
|
- params.setDevId(TEST_DEV_ID);
|
|
|
- params.setXxValue(new BigDecimal("100.5"));
|
|
|
- params.setYyValue(new BigDecimal("109.5"));
|
|
|
-
|
|
|
- // 模拟Gateway行为
|
|
|
- when(deviceGateway.updateDeviceLocation(params)).thenReturn(false);
|
|
|
-
|
|
|
- // 执行测试
|
|
|
- ApiResult<Boolean> result = deviceController.updateDeviceLocation(params);
|
|
|
-
|
|
|
- // 验证交互
|
|
|
- verify(deviceGateway, times(1)).updateDeviceLocation(params);
|
|
|
-
|
|
|
- // 验证结果
|
|
|
- assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
- assertEquals(false, ReflectionTestUtils.getField(result, "data"));
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void checkDevByUserId_Success() {
|
|
|
- // 准备测试数据
|
|
|
- Long userId = TEST_USER_ID;
|
|
|
- Long devId = 1L;
|
|
|
-
|
|
|
- // 模拟Gateway行为
|
|
|
- when(deviceGateway.checkDevByUserId(userId, devId)).thenReturn(true);
|
|
|
-
|
|
|
- // 执行测试
|
|
|
- ApiResult<Boolean> result = deviceController.checkDevByUserId(userId, devId);
|
|
|
-
|
|
|
- // 验证交互
|
|
|
- verify(deviceGateway, times(1)).checkDevByUserId(userId, devId);
|
|
|
-
|
|
|
- // 验证结果
|
|
|
- assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
- assertEquals(true, ReflectionTestUtils.getField(result, "data"));
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void checkDevByUserId_NotFound() {
|
|
|
- // 准备测试数据
|
|
|
- Long userId = TEST_USER_ID;
|
|
|
- Long devId = 1L;
|
|
|
-
|
|
|
- // 模拟Gateway行为
|
|
|
- when(deviceGateway.checkDevByUserId(userId, devId)).thenReturn(false);
|
|
|
-
|
|
|
- // 执行测试
|
|
|
- ApiResult<Boolean> result = deviceController.checkDevByUserId(userId, devId);
|
|
|
-
|
|
|
- // 验证交互
|
|
|
- verify(deviceGateway, times(1)).checkDevByUserId(userId, devId);
|
|
|
-
|
|
|
- // 验证结果
|
|
|
- assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
- assertEquals(false, ReflectionTestUtils.getField(result, "data"));
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void getWcTimes_Success() {
|
|
|
- // 准备测试数据
|
|
|
- Long devId = 1L;
|
|
|
- String time = "2024-03-20";
|
|
|
- WcTimesQueryRes expectedResult = new WcTimesQueryRes();
|
|
|
- expectedResult.setCount(5);
|
|
|
-
|
|
|
- // 模拟Gateway行为
|
|
|
- when(deviceGateway.getWcTimes(devId, time)).thenReturn(expectedResult);
|
|
|
-
|
|
|
- // 执行测试
|
|
|
- ApiResult<WcTimesQueryRes> result = deviceController.getWcTimes(devId, time);
|
|
|
-
|
|
|
- // 验证交互
|
|
|
- verify(deviceGateway, times(1)).getWcTimes(devId, time);
|
|
|
-
|
|
|
- // 验证结果
|
|
|
- assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
- assertEquals(expectedResult, ReflectionTestUtils.getField(result, "data"));
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- void getWcTimes_NoData() {
|
|
|
- // 准备测试数据
|
|
|
- Long devId = 1L;
|
|
|
- String time = "2024-03-20";
|
|
|
-
|
|
|
- // 模拟Gateway行为
|
|
|
- when(deviceGateway.getWcTimes(devId, time)).thenReturn(null);
|
|
|
-
|
|
|
- // 执行测试
|
|
|
- ApiResult<WcTimesQueryRes> result = deviceController.getWcTimes(devId, time);
|
|
|
-
|
|
|
- // 验证交互
|
|
|
- verify(deviceGateway, times(1)).getWcTimes(devId, time);
|
|
|
-
|
|
|
- // 验证结果
|
|
|
- assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
- assertEquals(null, ReflectionTestUtils.getField(result, "data"));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
+//package com.hfln.portal.application.controller.wap;
|
|
|
+//
|
|
|
+//import cn.hfln.framework.dto.ApiResult;
|
|
|
+//import com.hfln.portal.common.dto.data.device.DeviceDTO;
|
|
|
+//import com.hfln.portal.common.request.device.DeviceListParams;
|
|
|
+//import com.hfln.portal.common.request.device.DeviceBandingParams;
|
|
|
+//import com.hfln.portal.common.request.device.DeviceLocationParams;
|
|
|
+//import com.hfln.portal.common.request.device.UpdateDeviceParams;
|
|
|
+//import com.hfln.portal.common.response.device.WcTimesQueryRes;
|
|
|
+//import com.hfln.portal.domain.gateway.DeviceGateway;
|
|
|
+//import org.junit.jupiter.api.Test;
|
|
|
+//import org.junit.jupiter.api.extension.ExtendWith;
|
|
|
+//import org.mockito.InjectMocks;
|
|
|
+//import org.mockito.Mock;
|
|
|
+//import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
+//import org.springframework.test.util.ReflectionTestUtils;
|
|
|
+//
|
|
|
+//import java.math.BigDecimal;
|
|
|
+//import java.util.ArrayList;
|
|
|
+//import java.util.List;
|
|
|
+//
|
|
|
+//import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
+//import static org.mockito.Mockito.*;
|
|
|
+//
|
|
|
+//@ExtendWith(MockitoExtension.class)
|
|
|
+//class DeviceControllerTest {
|
|
|
+//
|
|
|
+// // 常量定义
|
|
|
+// private static final String SUCCESS_CODE = "200";
|
|
|
+// private static final String TEST_OPEN_ID = "test_open_id";
|
|
|
+// private static final String TEST_CLIENT_ID = "test_client_id";
|
|
|
+// private static final String TEST_DEVICE_ID = "123456";
|
|
|
+// private static final Long TEST_USER_ID = 1L;
|
|
|
+// private static final Long TEST_DEV_ID = 2L;
|
|
|
+//
|
|
|
+// @Mock
|
|
|
+// private DeviceGateway deviceGateway;
|
|
|
+//
|
|
|
+// @InjectMocks
|
|
|
+// private DeviceController deviceController;
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// void deviceList_Success() {
|
|
|
+// // 准备测试数据
|
|
|
+// DeviceListParams request = new DeviceListParams();
|
|
|
+// request.setUserId(TEST_USER_ID);
|
|
|
+// request.setKeyWord("test");
|
|
|
+// request.setStatus(1);
|
|
|
+//
|
|
|
+// List<DeviceDTO> expectedDevices = new ArrayList<>();
|
|
|
+// DeviceDTO device = new DeviceDTO();
|
|
|
+// device.setDevId(TEST_DEV_ID);
|
|
|
+// device.setUserId(TEST_USER_ID);
|
|
|
+// expectedDevices.add(device);
|
|
|
+//
|
|
|
+// // 模拟Gateway行为
|
|
|
+// when(deviceGateway.queryDeviceList(request)).thenReturn(expectedDevices);
|
|
|
+//
|
|
|
+// // 执行测试
|
|
|
+// ApiResult<List<DeviceDTO>> result = deviceController.deviceList(request);
|
|
|
+//
|
|
|
+// // 验证交互
|
|
|
+// verify(deviceGateway, times(1)).queryDeviceList(request);
|
|
|
+//
|
|
|
+// // 验证结果
|
|
|
+// assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
+// assertEquals(expectedDevices, ReflectionTestUtils.getField(result, "data"));
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// void deviceList_EmptyResult() {
|
|
|
+// // 准备测试数据
|
|
|
+// DeviceListParams request = new DeviceListParams();
|
|
|
+// request.setUserId(TEST_USER_ID);
|
|
|
+//
|
|
|
+// List<DeviceDTO> expectedDevices = new ArrayList<>();
|
|
|
+//
|
|
|
+// // 模拟Gateway行为
|
|
|
+// when(deviceGateway.queryDeviceList(request)).thenReturn(expectedDevices);
|
|
|
+//
|
|
|
+// // 执行测试
|
|
|
+// ApiResult<List<DeviceDTO>> result = deviceController.deviceList(request);
|
|
|
+//
|
|
|
+// // 验证交互
|
|
|
+// verify(deviceGateway, times(1)).queryDeviceList(request);
|
|
|
+//
|
|
|
+// // 验证结果
|
|
|
+// assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
+// assertEquals(expectedDevices, ReflectionTestUtils.getField(result, "data"));
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// void deviceUnBind_Success() {
|
|
|
+// // 准备测试数据
|
|
|
+// Long userId = TEST_USER_ID;
|
|
|
+// String clientId = TEST_CLIENT_ID;
|
|
|
+//
|
|
|
+// // 模拟Gateway行为
|
|
|
+// when(deviceGateway.deviceUnBind(userId, clientId)).thenReturn(true);
|
|
|
+//
|
|
|
+// // 执行测试
|
|
|
+// ApiResult<Boolean> result = deviceController.deviceUnBind(userId, clientId);
|
|
|
+//
|
|
|
+// // 验证交互
|
|
|
+// verify(deviceGateway, times(1)).deviceUnBind(userId, clientId);
|
|
|
+//
|
|
|
+// // 验证结果
|
|
|
+// assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
+// assertEquals(true, ReflectionTestUtils.getField(result, "data"));
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// void deviceUnBind_Failed() {
|
|
|
+// // 准备测试数据
|
|
|
+// Long userId = TEST_USER_ID;
|
|
|
+// String clientId = TEST_CLIENT_ID;
|
|
|
+//
|
|
|
+// // 模拟Gateway行为
|
|
|
+// when(deviceGateway.deviceUnBind(userId, clientId)).thenReturn(false);
|
|
|
+//
|
|
|
+// // 执行测试
|
|
|
+// ApiResult<Boolean> result = deviceController.deviceUnBind(userId, clientId);
|
|
|
+//
|
|
|
+// // 验证交互
|
|
|
+// verify(deviceGateway, times(1)).deviceUnBind(userId, clientId);
|
|
|
+//
|
|
|
+// // 验证结果
|
|
|
+// assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
+// assertEquals(false, ReflectionTestUtils.getField(result, "data"));
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// void deviceBinding_Success() {
|
|
|
+// // 准备测试数据
|
|
|
+// DeviceBandingParams request = new DeviceBandingParams();
|
|
|
+// request.setUserId(TEST_USER_ID);
|
|
|
+// request.setClientId(TEST_CLIENT_ID);
|
|
|
+// request.setDevName("测试设备");
|
|
|
+//
|
|
|
+// // 模拟Gateway行为
|
|
|
+// when(deviceGateway.deviceBind(request)).thenReturn(true);
|
|
|
+//
|
|
|
+// // 执行测试
|
|
|
+// ApiResult<Boolean> result = deviceController.deviceBinding(request);
|
|
|
+//
|
|
|
+// // 验证交互
|
|
|
+// verify(deviceGateway, times(1)).deviceBind(request);
|
|
|
+//
|
|
|
+// // 验证结果
|
|
|
+// assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
+// assertEquals(true, ReflectionTestUtils.getField(result, "data"));
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// void deviceBinding_Failed() {
|
|
|
+// // 准备测试数据
|
|
|
+// DeviceBandingParams request = new DeviceBandingParams();
|
|
|
+// request.setUserId(TEST_USER_ID);
|
|
|
+// request.setClientId(TEST_CLIENT_ID);
|
|
|
+// request.setDevName("测试设备");
|
|
|
+//
|
|
|
+// // 模拟Gateway行为
|
|
|
+// when(deviceGateway.deviceBind(request)).thenReturn(false);
|
|
|
+//
|
|
|
+// // 执行测试
|
|
|
+// ApiResult<Boolean> result = deviceController.deviceBinding(request);
|
|
|
+//
|
|
|
+// // 验证交互
|
|
|
+// verify(deviceGateway, times(1)).deviceBind(request);
|
|
|
+//
|
|
|
+// // 验证结果
|
|
|
+// assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
+// assertEquals(false, ReflectionTestUtils.getField(result, "data"));
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// void queryDeviceInfoById_Success() {
|
|
|
+// // 准备测试数据
|
|
|
+// String deviceId = TEST_DEVICE_ID;
|
|
|
+// DeviceDTO expectedDevice = new DeviceDTO();
|
|
|
+// expectedDevice.setDevId(TEST_DEV_ID);
|
|
|
+// expectedDevice.setDevName("测试设备");
|
|
|
+// expectedDevice.setUserId(TEST_USER_ID);
|
|
|
+//
|
|
|
+// // 模拟Gateway行为
|
|
|
+// when(deviceGateway.queryDeviceById(deviceId)).thenReturn(expectedDevice);
|
|
|
+//
|
|
|
+// // 执行测试
|
|
|
+// ApiResult<DeviceDTO> result = deviceController.queryDeviceInfoById(deviceId);
|
|
|
+//
|
|
|
+// // 验证交互
|
|
|
+// verify(deviceGateway, times(1)).queryDeviceById(deviceId);
|
|
|
+//
|
|
|
+// // 验证结果
|
|
|
+// assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
+// assertEquals(expectedDevice, ReflectionTestUtils.getField(result, "data"));
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// void queryDeviceInfoById_NotFound() {
|
|
|
+// // 准备测试数据
|
|
|
+// String deviceId = TEST_DEVICE_ID;
|
|
|
+//
|
|
|
+// // 模拟Gateway行为
|
|
|
+// when(deviceGateway.queryDeviceById(deviceId)).thenReturn(null);
|
|
|
+//
|
|
|
+// // 执行测试
|
|
|
+// ApiResult<DeviceDTO> result = deviceController.queryDeviceInfoById(deviceId);
|
|
|
+//
|
|
|
+// // 验证交互
|
|
|
+// verify(deviceGateway, times(1)).queryDeviceById(deviceId);
|
|
|
+//
|
|
|
+// // 验证结果
|
|
|
+// assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
+// assertEquals(null, ReflectionTestUtils.getField(result, "data"));
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// void deviceRelations_Success() {
|
|
|
+// // 执行测试
|
|
|
+// ApiResult<DeviceDTO> result = deviceController.deviceRelations();
|
|
|
+//
|
|
|
+// // 验证结果
|
|
|
+// assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
+// assertEquals(null, ReflectionTestUtils.getField(result, "data"));
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// void updateDevice_Success() {
|
|
|
+// // 准备测试数据
|
|
|
+// DeviceBandingParams params = new UpdateDeviceParams();
|
|
|
+// params.setUserId(TEST_USER_ID);
|
|
|
+// params.setClientId(TEST_CLIENT_ID);
|
|
|
+// params.setDevName("更新后的设备名称");
|
|
|
+//
|
|
|
+// // 模拟Gateway行为
|
|
|
+// when(deviceGateway.updateDevice(params)).thenReturn(true);
|
|
|
+//
|
|
|
+// // 执行测试
|
|
|
+// ApiResult<Boolean> result = deviceController.updateDevice(params);
|
|
|
+//
|
|
|
+// // 验证交互
|
|
|
+// verify(deviceGateway, times(1)).updateDevice(params);
|
|
|
+//
|
|
|
+// // 验证结果
|
|
|
+// assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
+// assertEquals(true, ReflectionTestUtils.getField(result, "data"));
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// void updateDevice_Failed() {
|
|
|
+// // 准备测试数据
|
|
|
+// DeviceBandingParams params = new UpdateDeviceParams();
|
|
|
+// params.setUserId(TEST_USER_ID);
|
|
|
+// params.setClientId(TEST_CLIENT_ID);
|
|
|
+// params.setDevName("更新后的设备名称");
|
|
|
+//
|
|
|
+// // 模拟Gateway行为
|
|
|
+// when(deviceGateway.updateDevice(params)).thenReturn(false);
|
|
|
+//
|
|
|
+// // 执行测试
|
|
|
+// ApiResult<Boolean> result = deviceController.updateDevice(params);
|
|
|
+//
|
|
|
+// // 验证交互
|
|
|
+// verify(deviceGateway, times(1)).updateDevice(params);
|
|
|
+//
|
|
|
+// // 验证结果
|
|
|
+// assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
+// assertEquals(false, ReflectionTestUtils.getField(result, "data"));
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// void updateDeviceLocation_Success() {
|
|
|
+// // 准备测试数据
|
|
|
+// DeviceLocationParams params = new DeviceLocationParams();
|
|
|
+// params.setDevId(TEST_DEV_ID);
|
|
|
+// params.setXxValue(new BigDecimal("100.5"));
|
|
|
+// params.setYyValue(new BigDecimal("109.5"));
|
|
|
+//
|
|
|
+// // 模拟Gateway行为
|
|
|
+// when(deviceGateway.updateDeviceLocation(params)).thenReturn(true);
|
|
|
+//
|
|
|
+// // 执行测试
|
|
|
+// ApiResult<Boolean> result = deviceController.updateDeviceLocation(params);
|
|
|
+//
|
|
|
+// // 验证交互
|
|
|
+// verify(deviceGateway, times(1)).updateDeviceLocation(params);
|
|
|
+//
|
|
|
+// // 验证结果
|
|
|
+// assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
+// assertEquals(true, ReflectionTestUtils.getField(result, "data"));
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// void updateDeviceLocation_Failed() {
|
|
|
+// // 准备测试数据
|
|
|
+// DeviceLocationParams params = new DeviceLocationParams();
|
|
|
+// params.setDevId(TEST_DEV_ID);
|
|
|
+// params.setXxValue(new BigDecimal("100.5"));
|
|
|
+// params.setYyValue(new BigDecimal("109.5"));
|
|
|
+//
|
|
|
+// // 模拟Gateway行为
|
|
|
+// when(deviceGateway.updateDeviceLocation(params)).thenReturn(false);
|
|
|
+//
|
|
|
+// // 执行测试
|
|
|
+// ApiResult<Boolean> result = deviceController.updateDeviceLocation(params);
|
|
|
+//
|
|
|
+// // 验证交互
|
|
|
+// verify(deviceGateway, times(1)).updateDeviceLocation(params);
|
|
|
+//
|
|
|
+// // 验证结果
|
|
|
+// assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
+// assertEquals(false, ReflectionTestUtils.getField(result, "data"));
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// void checkDevByUserId_Success() {
|
|
|
+// // 准备测试数据
|
|
|
+// Long userId = TEST_USER_ID;
|
|
|
+// Long devId = 1L;
|
|
|
+//
|
|
|
+// // 模拟Gateway行为
|
|
|
+// when(deviceGateway.checkDevByUserId(userId, devId)).thenReturn(true);
|
|
|
+//
|
|
|
+// // 执行测试
|
|
|
+// ApiResult<Boolean> result = deviceController.checkDevByUserId(userId, devId);
|
|
|
+//
|
|
|
+// // 验证交互
|
|
|
+// verify(deviceGateway, times(1)).checkDevByUserId(userId, devId);
|
|
|
+//
|
|
|
+// // 验证结果
|
|
|
+// assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
+// assertEquals(true, ReflectionTestUtils.getField(result, "data"));
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// void checkDevByUserId_NotFound() {
|
|
|
+// // 准备测试数据
|
|
|
+// Long userId = TEST_USER_ID;
|
|
|
+// Long devId = 1L;
|
|
|
+//
|
|
|
+// // 模拟Gateway行为
|
|
|
+// when(deviceGateway.checkDevByUserId(userId, devId)).thenReturn(false);
|
|
|
+//
|
|
|
+// // 执行测试
|
|
|
+// ApiResult<Boolean> result = deviceController.checkDevByUserId(userId, devId);
|
|
|
+//
|
|
|
+// // 验证交互
|
|
|
+// verify(deviceGateway, times(1)).checkDevByUserId(userId, devId);
|
|
|
+//
|
|
|
+// // 验证结果
|
|
|
+// assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
+// assertEquals(false, ReflectionTestUtils.getField(result, "data"));
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// void getWcTimes_Success() {
|
|
|
+// // 准备测试数据
|
|
|
+// Long devId = 1L;
|
|
|
+// String time = "2024-03-20";
|
|
|
+// WcTimesQueryRes expectedResult = new WcTimesQueryRes();
|
|
|
+// expectedResult.setCount(5);
|
|
|
+//
|
|
|
+// // 模拟Gateway行为
|
|
|
+// when(deviceGateway.getWcTimes(devId, time)).thenReturn(expectedResult);
|
|
|
+//
|
|
|
+// // 执行测试
|
|
|
+// ApiResult<WcTimesQueryRes> result = deviceController.getWcTimes(devId, time);
|
|
|
+//
|
|
|
+// // 验证交互
|
|
|
+// verify(deviceGateway, times(1)).getWcTimes(devId, time);
|
|
|
+//
|
|
|
+// // 验证结果
|
|
|
+// assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
+// assertEquals(expectedResult, ReflectionTestUtils.getField(result, "data"));
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// void getWcTimes_NoData() {
|
|
|
+// // 准备测试数据
|
|
|
+// Long devId = 1L;
|
|
|
+// String time = "2024-03-20";
|
|
|
+//
|
|
|
+// // 模拟Gateway行为
|
|
|
+// when(deviceGateway.getWcTimes(devId, time)).thenReturn(null);
|
|
|
+//
|
|
|
+// // 执行测试
|
|
|
+// ApiResult<WcTimesQueryRes> result = deviceController.getWcTimes(devId, time);
|
|
|
+//
|
|
|
+// // 验证交互
|
|
|
+// verify(deviceGateway, times(1)).getWcTimes(devId, time);
|
|
|
+//
|
|
|
+// // 验证结果
|
|
|
+// assertEquals(SUCCESS_CODE, ReflectionTestUtils.getField(result, "code"));
|
|
|
+// assertEquals(null, ReflectionTestUtils.getField(result, "data"));
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+//}
|