package com.njcn.gather.tool.adddata.component;

import com.njcn.gather.tool.adddata.config.AddDataInfluxDbProperties;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.time.LocalDateTime;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * add-data InfluxDB line protocol 契约测试。
 */
class AddDataInfluxWriterTest {

    @Test
    void shouldBuildEscapedLineProtocolWithTimestamp() {
        AddDataInfluxWriter writer = new AddDataInfluxWriter(new AddDataInfluxDbProperties(), new AddDataInfluxFieldMapper());
        Map<String, String> tags = new LinkedHashMap<String, String>();
        tags.put("line_id", "line 001");
        tags.put("phasic_type", "A");
        tags.put("quality_flag", "0");
        tags.put("value_type", "AVG");
        Map<String, Object> fields = new LinkedHashMap<String, Object>();
        fields.put("rms", 220.1D);

        String line = writer.buildLineProtocol("data v", tags, fields, LocalDateTime.of(2026, 5, 18, 10, 0, 0));

        Assertions.assertEquals("data\\ v,line_id=line\\ 001,phasic_type=A,quality_flag=0,value_type=AVG rms=220.1 1779098400000000000", line);
    }
}
