BatteryServiceTest.java 1.78 KB
package cn.com.glsx.stdinterface.modules.service;

import cn.com.glsx.Application;
import cn.com.glsx.alarm.services.model.DevicePowerDto;
import cn.com.glsx.stdinterface.modules.entity.DevicePower;
import cn.com.glsx.stdinterface.modules.remote.RemoteFeignDevicePowerService;
import cn.com.glsx.stdinterface.modules.util.DateUtils;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.*;

/**
 * @author xiangyanlin
 * @date 2022/4/29
 */
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class BatteryServiceTest {

    @Autowired
    private RemoteFeignDevicePowerService remoteFeignDevicePowerService;

    @Autowired
    private BatteryService batteryService;


    @Test
    public void testGetDevicePowerListBySn() {
        List<DevicePowerDto> devicePowerList = remoteFeignDevicePowerService.getDevicePowerListBySn(Lists.newArrayList("1670816541"));
        devicePowerList.stream().map(DevicePowerDto::getCreatetime).map(DateUtils::formatNormal).forEach(System.err::println);
        List<DevicePower> collect = devicePowerList.stream().map(e -> batteryService.convert(e, null, null, null)).collect(Collectors.toList());
        collect.stream().map(DevicePower::getCreatedDate).map(DateUtils::formatNormal).forEach(System.err::println);
        System.out.println(JSON.toJSONString(collect));
    }

}