package cn.iocoder.yudao.module.product.service.deviceoperatelog;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;

import javax.annotation.Resource;

import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;

import cn.iocoder.yudao.module.product.controller.admin.deviceoperatelog.vo.*;
import cn.iocoder.yudao.module.product.dal.dataobject.deviceoperatelog.DeviceOperateLogDO;
import cn.iocoder.yudao.module.product.dal.mysql.deviceoperatelog.DeviceOperateLogMapper;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import javax.annotation.Resource;
import org.springframework.context.annotation.Import;
import java.util.*;
import java.time.LocalDateTime;

import static cn.hutool.core.util.RandomUtil.*;
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

/**
* {@link DeviceOperateLogServiceImpl} 的单元测试类
*
* @author 芋道源码
*/
@Import(DeviceOperateLogServiceImpl.class)
public class DeviceOperateLogServiceImplTest extends BaseDbUnitTest {

    @Resource
    private DeviceOperateLogServiceImpl deviceOperateLogService;

    @Resource
    private DeviceOperateLogMapper deviceOperateLogMapper;

    @Test
    public void testCreateDeviceOperateLog_success() {
        // 准备参数
        DeviceOperateLogCreateReqVO reqVO = randomPojo(DeviceOperateLogCreateReqVO.class);

        // 调用
        Long deviceOperateLogId = deviceOperateLogService.createDeviceOperateLog(reqVO);
        // 断言
        assertNotNull(deviceOperateLogId);
        // 校验记录的属性是否正确
        DeviceOperateLogDO deviceOperateLog = deviceOperateLogMapper.selectById(deviceOperateLogId);
        assertPojoEquals(reqVO, deviceOperateLog);
    }

    @Test
    public void testDeleteDeviceOperateLog_success() {
        // mock 数据
        DeviceOperateLogDO dbDeviceOperateLog = randomPojo(DeviceOperateLogDO.class);
        deviceOperateLogMapper.insert(dbDeviceOperateLog);// @Sql: 先插入出一条存在的数据
        // 准备参数
        Long id = dbDeviceOperateLog.getId();

        // 调用
        deviceOperateLogService.deleteDeviceOperateLog(id);
       // 校验数据不存在了
       assertNull(deviceOperateLogMapper.selectById(id));
    }

    @Test
    public void testDeleteDeviceOperateLog_notExists() {
        // 准备参数
        Long id = randomLongId();

        // 调用, 并断言异常
        assertServiceException(() -> deviceOperateLogService.deleteDeviceOperateLog(id), DEVICE_OPERATE_LOG_NOT_EXISTS);
    }

}
