TestDeviceLocationUtil.java 4.02 KB
package cn.com.glsx.stdinterface.modules.util;

import cn.com.glsx.stdinterface.common.constants.Constants;
import cn.hutool.core.date.DateUtil;
import org.junit.Assert;
import org.junit.Test;

import java.util.Date;

public class TestDeviceLocationUtil {

    @Test
    public void testDeviceType01() {
        // 无效位置数据状态验证
        String gpsTime = "";
        String bsTime = "";
        Integer source = null;
        Integer deviceType = DeviceLocationUtil.resolutionGpsType(gpsTime, bsTime, source);
        Assert.assertSame(deviceType, Constants.Verification.SN_INVALID);
    }

    @Test
    public void testDeviceType02() {
        // 无效位置数据状态验证;不存在的设备类型source
        String gpsTime = "";
        String bsTime = "";
        Integer source = 2;
        Integer deviceType = DeviceLocationUtil.resolutionGpsType(gpsTime, bsTime, source);
        Assert.assertSame(deviceType, Constants.Verification.SN_INVALID);
    }

    @Test
    public void testDeviceType03() {
        // 有线设备:无效位置数据状态验证,4小时内上报的数据为有效
        Date gpsDate = DateUtil.offsetHour(new Date(), -4);
        String gpsTime = DateUtils.toString(gpsDate, DateUtils.pattern19);
        String bsTime = "";
        Integer source = Constants.DeviceSource.WIRED;
        Integer deviceType = DeviceLocationUtil.resolutionGpsType(gpsTime, bsTime, source);
        Assert.assertSame(deviceType, Constants.Verification.SN_INVALID);
    }

    @Test
    public void testDeviceType04() {
        // 有线设备:无效位置数据状态验证,4小时内上报的数据为有效
        // 有线设备只做GPS数据的验证
        Date gpsDate = DateUtil.offsetHour(new Date(), -5);
        String gpsTime = DateUtils.toString(gpsDate, DateUtils.pattern19);
        String bsTime = "2022-02-23 09:16:17";
        Integer source = Constants.DeviceSource.WIRED;
        Integer deviceType = DeviceLocationUtil.resolutionGpsType(gpsTime, bsTime, source);
        Assert.assertSame(deviceType, Constants.Verification.SN_INVALID);
    }

    @Test
    public void testDeviceType05() {
        // 有线设备:有效位置数据状态验证,4小时内上报的数据为有效
        // 有线设备只做GPS数据的验证
        Date gpsDate = DateUtil.offsetHour(new Date(), -3);
        String gpsTime = DateUtils.toString(gpsDate, DateUtils.pattern19);
        String bsTime = "2022-02-23 09:16:17";
        Integer source = Constants.DeviceSource.WIRED;
        Integer deviceType = DeviceLocationUtil.resolutionGpsType(gpsTime, bsTime, source);
        Assert.assertSame(deviceType, Constants.Verification.SN_VALID);
    }

    @Test
    public void testDeviceType06() {
        // 无线设备:无效位置数据状态验证,24小时内上报的数据为有效
        // 无线设备GPS和基站数据取最新的数据
        Date gpsDate = DateUtil.offsetHour(new Date(), -25);
        Date bsDate = DateUtil.offsetHour(new Date(), -25);
        String gpsTime = DateUtils.toString(gpsDate, DateUtils.pattern19);
        String bsTime = DateUtils.toString(bsDate, DateUtils.pattern19);
        Integer source = Constants.DeviceSource.WIRELESS;
        Integer deviceType = DeviceLocationUtil.resolutionGpsType(gpsTime, bsTime, source);
        Assert.assertSame(deviceType, Constants.Verification.SN_INVALID);
    }

    @Test
    public void testDeviceType07() {
        // 无线设备:有效位置数据状态验证,24小时内上报的数据为有效
        // 无线设备GPS和基站数据取最新的数据
        Date gpsDate = DateUtil.offsetHour(new Date(), -25);
        Date bsDate = DateUtil.offsetHour(new Date(), -5);
        String gpsTime = DateUtils.toString(gpsDate, DateUtils.pattern19);
        String bsTime = DateUtils.toString(bsDate, DateUtils.pattern19);
        Integer source = Constants.DeviceSource.WIRELESS;
        Integer deviceType = DeviceLocationUtil.resolutionGpsType(gpsTime, bsTime, source);
        Assert.assertSame(deviceType, Constants.Verification.SN_VALID);
    }

}