“mitao”
2026-01-20 4e5beb844f03daec12f2b039365730b0683f8a9e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.estate.expert.admin.io;
 
import com.estate.expert.admin.domain.exam.eval.formatter.impl.DeviceFuzzySummaryResultFormatter;
import com.estate.expert.admin.domain.exam.eval.formatter.impl.DeviceScoreResultSummaryFormatter;
import com.estate.expert.admin.domain.exam.eval.formatter.impl.SysFuzzyResultFormatter;
import com.estate.expert.admin.domain.exam.eval.formatter.impl.SysScoreResultFormatter;
import com.estate.expert.admin.service.DeviceService;
import com.estate.expert.admin.service.eval.EvalFuzzyService;
import com.estate.expert.admin.service.eval.EvalScoreService;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
 
@Slf4j
@SpringBootTest
@ExtendWith(SpringExtension.class)
@Transactional
public class EvalResultFormatterTest {
 
    @Resource
    EvalFuzzyService fuzzyService;
 
    @Resource
    EvalScoreService scoreService;
 
    @Resource
    DeviceService deviceService;
    
    @Resource
    ObjectMapper objectMapper;
 
    @Test
    public void testFormatSysFuzzy() throws IOException {
        var results = fuzzyService.findAll();
        var res = results.get( results.size() - 1);
 
        var formatter = new SysFuzzyResultFormatter();
        var table = formatter.format(res);
        // write to file
        Files.write(Path.of("/Volumes/Works/tmp/sys_fuzzy_format.json"), objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(table).getBytes());
    }
 
    @Test
    public void testFormatSysScore() throws IOException {
        var results = scoreService.findAll();
        var res = results.get( results.size() - 1);
 
        var formatter = new SysScoreResultFormatter();
        var table = formatter.format(res);
        Files.write(Path.of("/Volumes/Works/tmp/sys_score_format.json"), objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(table).getBytes());
    }
 
    @Test
    public void testFormatDeviceFuzzySummary() throws IOException {
        var results = fuzzyService.findAll();
        var res = results.get( results.size() - 1);
 
        var formatter = new DeviceFuzzySummaryResultFormatter(deviceService);
        var table = formatter.format(res);
        Files.write(Path.of("/Volumes/Works/tmp/device_fuzzy_format.json"), objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(table).getBytes());
    }
 
    @Test
    public void testFormatDeviceScoreSummary() throws IOException {
        var results = scoreService.findAll();
        var res = results.get( results.size() - 1);
 
        var formatter = new DeviceScoreResultSummaryFormatter(deviceService);
        var table = formatter.format(res);
        Files.write(Path.of("/Volumes/Works/tmp/device_score_format.json"),
                 objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(table).getBytes());
    }
 
}