← 返回列表
全部 Skill›测试与安全 Testing & Security›quarkus-tdd

quarkus-tdd

作者 @affaan-m · 语言 tur
Test-driven development for Quarkus 3.x LTS using JUnit 5, Mockito, REST Assured, Camel testing, and JaCoCo. Use when adding features, fixing bugs, or refactoring event-driven services.
测试与安全 Testing & Security测试通用待翻译
存储库
最近源活动
—
检测 SKILL.md 语言
tur
星标 ★
309,846
分支 Fork
0
安装选项
提示
指令
使用 AI 助手安装
将下面的提示复制到你正在使用的 AI 助手中。
下载完整 Skill 目录(含全部配套文件)。 下载压缩包 ↓
SKILL.md 原文预览

Quarkus TDD İş Akışı

80%+ kapsam (unit + integration) ile Quarkus 3.x servisleri için TDD rehberi. Apache Camel ile event-driven mimariler için optimize edilmiştir.

When to Use

  • Yeni özellikler veya REST endpoint'leri
  • Bug düzeltmeleri veya refactoring'ler
  • Veri erişim mantığı, güvenlik kuralları veya reaktif akışlar ekleme
  • Apache Camel route'larını ve event handler'larını test etme
  • RabbitMQ ile event-driven servisleri test etme
  • Koşullu akış mantığını test etme
  • CompletableFuture async işlemlerini doğrulama
  • LogContext yayılımını test etme

How It Works

  1. Önce testleri yazın (başarısız olmalılar)
  2. Geçmek için minimal kod uygulayın
  3. Testleri yeşil tutarken refactor edin
  4. JaCoCo ile kapsamı zorlayın (%80+ hedef)

Examples

@Nested Organizasyonlu Unit Testler

Kapsamlı ve okunabilir testler için bu yapılandırılmış yaklaşımı izleyin:

@ExtendWith(MockitoExtension.class)
@DisplayName("As2ProcessingService Unit Tests")
class As2ProcessingServiceTest {

  @Mock
  private InvoiceFlowValidator invoiceFlowValidator;

  @Mock
  private EventService eventService;

  @Mock
  private DocumentJobService documentJobService;

  @Mock
  private BusinessRulesPublisher businessRulesPublisher;

  @Mock
  private FileStorageService fileStorageService;

  @InjectMocks
  private As2ProcessingService as2ProcessingService;

  private Path testFilePath;
  private LogContext testLogContext;
  private InvoiceValidationResult validationResult;
  private StoredDocumentInfo documentInfo;

  @BeforeEach
  void setUp() {
    // ARRANGE - Ortak test verisi
    testFilePath = Path.of("/tmp/test-invoice.xml");

    testLogContext = new LogContext();
    testLogContext.put(As2Constants.STRUCTURE_ID, "STRUCT-001");
    testLogContext.put(As2Constants.FILE_NAME, "invoice.xml");
    testLogContext.put(As2Constants.AS2_FROM, "PARTNER-001");

    validationResult = new InvoiceValidationResult();
    validationResult.setValid(true);
    validationResult.setSize(1024L);
    validationResult.setDocumentHash("abc123");

    documentInfo = new StoredDocumentInfo();
    documentInfo.setPath("s3://bucket/path/invoice.xml");
    documentInfo.setSize(1024L);
  }

  @Nested
  @DisplayName("processFile için testler")
  class ProcessFile {

    @Test
    @DisplayName("CHORUS olmayan dosyayı tüm validasyonlarla başarıyla işlemeli")
    void givenNonChorusFile_whenProcessFile_thenAllValidationsApplied() throws Exception {
      // ARRANGE
      testLogContext.put(As2Constants.CHORUS_FLOW, "false");
      CustomLog.setCurrentContext(testLogContext);

      when(invoiceFlowValidator.validateFlowWithConfig(
          eq(testFilePath),
          eq(ValidationFlowConfig.allValidations()),
          eq(EInvoiceSyntaxFormat.UBL),
          any(LogContext.class)))
          .thenReturn(validationResult);

      when(invoiceFlowValidator.computeFlowProfile(any(), any()))
          .thenReturn(FlowProfile.BASIC);

      when(fileStorageService.uploadOriginalFile(any(), anyLong(), any(), any()))
          .thenReturn(CompletableFuture.completedFuture(documentInfo));

      when(documentJobService.createDocumentAndJobEntities(any(), any(), any(), any(), any()))
          .thenReturn(new BusinessRulesPayload());

      // ACT
      assertDoesNotThrow(() -> as2ProcessingService.processFile(testFilePath));

      // ASSERT
      verify(invoiceFlowValidator).validateFlowWithConfig(
          eq(testFilePath),
          eq(ValidationFlowConfig.allValidations()),
          eq(EInvoiceSyntaxFormat.UBL),
          any(LogContext.class));

      verify(eventService).createSuccessEvent(any(StoredDocumentInfo.class),
          eq("PERSISTENCE_BLOB_EVENT_TYPE"));
      verify(eventService).createSuccessEvent(any(BusinessRulesPayload.class),
          eq("BUSINESS_RULES_MESSAGE_SENT"));
      verify(businessRulesPublisher).publishAsync(any(BusinessRulesPayload.class));
    }

    @Test
    @DisplayName("CHORUS_FLOW için schematron validasyonu atlanmalı")
    void givenChorusFlow_whenProcessFile_thenSchematronBypassed() throws Exception {
      // ARRANGE
      testLogContext.put(As2Constants.CHORUS_FLOW, "true");
      CustomLog.setCurrentContext(testLogContext);

      when(invoiceFlowValidator.validateFlowWithConfig(
          eq(testFilePath),
          eq(ValidationFlowConfig.xsdOnly()),
          eq(EInvoiceSyntaxFormat.UBL),
          any(LogContext.class)))
          .thenReturn(validationResult);

      when(fileStorageService.uploadOriginalFile(any(), anyLong(), any(), any()))
          .thenReturn(CompletableFuture.completedFuture(documentInfo));

      when(documentJobService.createDocumentAndJobEntities(any(), any(), any(),
          eq(FlowProfile.EXTENDED_CTC_FR), any()))
          .thenReturn(new BusinessRulesPayload());

      // ACT
      assertDoesNotThrow(() -> as2ProcessingService.processFile(testFilePath));

      // ASSERT
      verify(invoiceFlowValidator).validateFlowWithConfig(
          eq(testFilePath),
          eq(ValidationFlowConfig.xsdOnly()),
          eq(EInvoiceSyntaxFormat.UBL),
          any(LogContext.class));

      verify(documentJobService).createDocumentAndJobEntities(
          any(), any(), any(),
          eq(FlowProfile.EXTENDED_CTC_FR),
          any());
    }

    @Test
    @DisplayName("Dosya yükleme başarısız olduğunda hata eventi oluşturulmalı")
    void givenUploadFailure_whenProcessFile_thenErrorEventCreated() throws Exception {
      // ARRANGE
      testLogContext.put(As2Constants.CHORUS_FLOW, "false");
      CustomLog.setCurrentContext(testLogContext);

      when(invoiceFlowValidator.validateFlowWithConfig(any(), any(), any(), any()))
          .thenReturn(validationResult);

      when(invoiceFlowValidator.computeFlowProfile(any(), a
评论
Aaffaan-m
affaan-m
affaan-m/ECC
查看 GitHub 仓库 查看作者的其他 Skill
来源信息
作者@affaan-m
所属大类测试与安全 Testing & Security / 测试
国内可用性通用
最近源活动—
风险提示无
提示:风险标签为程序静态扫描结果,仅作提示,不代表安全认证。安装前请阅读 SKILL.md 及其引用的脚本、权限,自行判断是否可信。