package com.huatek.busi.ws.client;

import java.time.LocalDateTime;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import com.google.common.collect.Lists;
import com.huatek.busi.ws.protocol.CacAttr;
import com.huatek.busi.ws.protocol.CacDataNode;
import com.huatek.busi.ws.protocol.CacMonitorData;
import com.huatek.busi.ws.protocol.CacRequest;
import com.thoughtworks.xstream.XStream;

public class XydlServiceTest2 {
    private XydlService service;

    @Before
    public void init() {
        this.service = new XydlServiceImplService().getXydlServiceImplPort();
    }

    @Test
    public void uploadCACDataTest() {
        service.uploadCACData(toXml());
    }

    public static String toXml() {
        XStream xstream = new XStream();
        xstream.processAnnotations(CacRequest.class);
        xstream.addImplicitCollection(CacMonitorData.class, "cacDataNode");
        // xstream.autodetectAnnotations(true);

        CacRequest request = new CacRequest();

        CacMonitorData cacMonitorData = new CacMonitorData();
        cacMonitorData.setCacid("26M00090990000987");
        cacMonitorData.setDataNodeNum(1);

        CacDataNode cacDataNode = new CacDataNode();
        cacDataNode.setSensorId("26M00090990000987");
        cacDataNode.setType("021001");
        cacDataNode.setEquipmentId("97M00090990000997");
        cacDataNode.setTimeStamp(LocalDateTime.now());

        CacDataNode cacDataNode2 = new CacDataNode();
        cacDataNode2.setSensorId("26M00090990000987");
        cacDataNode2.setType("021001");
        cacDataNode2.setEquipmentId("97M00090990000997");
        cacDataNode2.setTimeStamp(LocalDateTime.now());

        List<CacAttr> attrs = Lists.newArrayList();
        CacAttr attr1 = new CacAttr();
        CacAttr attr2 = new CacAttr();
        attr1.setName("Phase");
        attr1.setValue("A相");
        attr1.setAlarm("FALSE");
        attr2.setName("OilTemperature");
        attr2.setValue("80");
        attr2.setAlarm("TRUE");
        attrs.add(attr1);
        attrs.add(attr2);

        cacDataNode.setAttrs(attrs);
        cacMonitorData.setCacDataNode(Lists.newArrayList(cacDataNode, cacDataNode2));
        request.setCacMonitorData(cacMonitorData);
        String xml = xstream.toXML(request);
        return xml;
    }
}
