Pārlūkot izejas kodu

fix(临考突击报告): 修复展望报告渲染器装配

金逸霄 6 dienas atpakaļ
vecāks
revīzija
1c6e7fdfee

+ 2 - 0
abilities/exam-sprint/infrastructure/src/main/java/cn/yunzhixue/ability/center/examsprint/infrastructure/report/rendering/outlook/ClasspathOutlookExamSprintReportRenderer.java

@@ -8,6 +8,7 @@ import cn.yunzhixue.ability.center.examsprint.domain.report.UnmodeledReportConte
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.stereotype.Component;
 
@@ -36,6 +37,7 @@ public class ClasspathOutlookExamSprintReportRenderer implements ExamSprintRepor
     private final ObjectMapper objectMapper;
     private final String template;
 
+    @Autowired
     public ClasspathOutlookExamSprintReportRenderer(ObjectMapper objectMapper) {
         this(objectMapper, loadTemplateFromClasspath(TEMPLATE_RESOURCE));
     }

+ 22 - 0
ability-center-runtime/src/test/java/cn/yunzhixue/ability/center/examsprint/configuration/ExamSprintReportRuntimeConfigurationTest.java

@@ -9,11 +9,13 @@ import cn.yunzhixue.ability.center.examsprint.domain.report.ReportType;
 import cn.yunzhixue.ability.center.examsprint.infrastructure.report.pdf.PlaywrightPdfWorker;
 import cn.yunzhixue.ability.center.examsprint.infrastructure.report.pdf.PlaywrightPdfWorkerFactory;
 import cn.yunzhixue.ability.center.examsprint.infrastructure.report.pdf.PooledPlaywrightExamSprintReportPdfGenerator;
+import cn.yunzhixue.ability.center.examsprint.infrastructure.report.rendering.outlook.ClasspathOutlookExamSprintReportRenderer;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.junit.jupiter.api.Test;
 import org.springframework.boot.test.context.runner.ApplicationContextRunner;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
 
 import java.time.Duration;
 import java.time.Instant;
@@ -85,6 +87,16 @@ class ExamSprintReportRuntimeConfigurationTest {
                 });
     }
 
+    @Test
+    void classpathOutlookExamSprintReportRendererIsAutowiredBySpringContext() {
+        new ApplicationContextRunner()
+                .withUserConfiguration(OutlookRendererConfiguration.class)
+                .run(context -> assertThat(context)
+                        .hasBean("classpathOutlookExamSprintReportRenderer")
+                        .hasSingleBean(ClasspathOutlookExamSprintReportRenderer.class)
+                        .hasSingleBean(ExamSprintReportRenderer.class));
+    }
+
     private static PlaywrightPdfWorkerFactory fakePlaywrightPdfWorkerFactory() {
         return () -> new PlaywrightPdfWorker() {
             @Override
@@ -121,4 +133,14 @@ class ExamSprintReportRuntimeConfigurationTest {
             };
         }
     }
+
+    @Configuration
+    @Import(ClasspathOutlookExamSprintReportRenderer.class)
+    static class OutlookRendererConfiguration {
+
+        @Bean
+        ObjectMapper objectMapper() {
+            return new ObjectMapper();
+        }
+    }
 }