package com.estate.expert.admin.io.processor.impl; import com.estate.expert.admin.TestCommon; import com.estate.expert.admin.io.processor.impl.business.DeviceProcessor; import com.estate.expert.admin.io.processor.impl.business.PlanProcessor; import com.estate.expert.admin.io.processor.impl.business.ProjectProcessor; import com.estate.expert.admin.io.processor.impl.record.DeviceErrorRecordProcessor; import com.estate.expert.admin.io.processor.impl.record.SystemErrorRecordProcessor; import com.estate.expert.admin.io.processor.impl.record.WarningRecordProcessor; import com.estate.expert.admin.service.*; 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.FileOutputStream; import java.io.IOException; @Slf4j @SpringBootTest @ExtendWith(SpringExtension.class) @Transactional class ExportProcessorTest { @Resource private ClientService clientService; @Resource private ErrorRecordService errorRecordService; @Resource private WarningRecordService warningRecordService; @Resource private ProjectService projectService; @Resource private DeviceService deviceService; @Resource private PlanService planService; @Resource private CheckTaskService checkTaskService; @Test void systemErrors() throws IOException { var records = errorRecordService.listSystemErrors(1); var processor = new SystemErrorRecordProcessor(); // write to file try(var fos = new FileOutputStream(TestCommon.getTmpPath("system_errors.xlsx"))) { processor.saveWorkbook(fos, records); } } @Test void deviceErrors() throws IOException { var records = errorRecordService.listDeviceErrors(1); var processor = new DeviceErrorRecordProcessor(); // write to file try(var fos = new FileOutputStream(TestCommon.getTmpPath("device_errors.xlsx"))) { processor.saveWorkbook(fos, records); } } @Test void warningRecords() throws IOException { var records = warningRecordService.findAll(); var processor = new WarningRecordProcessor(); // write to file try(var fos = new FileOutputStream(TestCommon.getTmpPath("warning_records.xlsx"))) { processor.saveWorkbook(fos, records); } } @Test void projects() throws IOException { var projects = projectService.findAll(); var processor = new ProjectProcessor(clientService, projectService); try(var fos = new FileOutputStream(TestCommon.getTmpPath("projects.xlsx"))) { processor.saveWorkbook(fos, projects); } } @Test void devices() throws IOException { var devices = deviceService.findAll(); var processor = new DeviceProcessor(); try(var fos = new FileOutputStream(TestCommon.getTmpPath("devices.xlsx"))) { processor.saveWorkbook(fos, devices); } } @Test void plans() throws IOException { var plans = planService.findAll(); var processor = new PlanProcessor(checkTaskService); try(var fos = new FileOutputStream(TestCommon.getTmpPath("plans.xlsx"))) { processor.saveWorkbook(fos, plans); } } }