package com.huatek.busi.ws.mock.arrester;

import java.time.LocalDate;
import java.time.LocalDateTime;

import org.junit.Test;

import com.huatek.busi.common.CacMonitorTypeCode;
import com.huatek.busi.common.util.DateUtil;
import com.huatek.busi.ws.mock.AbstractMockTest;
import com.huatek.busi.ws.protocol.CacRequest;

public class LightningrodImMockTest extends AbstractMockTest {
    static final int times = 10;
    private String sensorCodeList[] = {"JYJC2019092016271", "JYJC2019092016272"};
    private String type = CacMonitorTypeCode.LIGHTNINGROD_IM.getCode();

    @Test
    public void uploadCACDataTest() {
        for (int i = 1; i <= 30; i++) {
            uploadCACDataTest(LocalDate.of(2019, 9, i), "A相");
        }
    }

    private void uploadCACDataTest(LocalDate date, String phase) {
        for (String sensorCode : sensorCodeList) {
            extracted(date, phase, sensorCode);
        }
    }

    private void extracted(LocalDate date, String phase, String sensorCode) {
        for (int i = 0; i < times; i++) {
            LocalDateTime LastActionTime = randomTime(date);
            CacRequest request = newRequeset(sensorCode, type, date, phase);
            String[] vals = randomVal(4);
            addAttr(request, "Phase", phase);
            addAttr(request, "SystemVoltage", vals[0]);
            addAttr(request, "TotalCurrent", vals[1]);
            addAttr(request, "ResistiveCurrent", vals[2]);
            addAttr(request, "CapacitanceCurrent", vals[3]);
            addAttr(request, "ActionCount", String.valueOf(randomInt(0, 999)));
            addAttr(request, "LastActionTime", DateUtil.format(LastActionTime));
            client.uploadCACData(XSTREAM.toXML(request));
        }
    }
}
