mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-06-13 11:41:22 +08:00
docs: drop incomplete ja-JP and zh-CN Quarkus translations
The ja-JP and zh-CN translations of the four Quarkus skills are missing content (quarkus-tdd: 8/11 sections, quarkus-verification: 10/15 sections; quarkus-security trimmed by 60-100 lines). Removing rather than shipping partial translations. Turkish translations remain — they mirror the English source. ja-JP and zh-CN to be redone in a focused follow-up.
This commit is contained in:
@@ -1,766 +0,0 @@
|
||||
---
|
||||
name: quarkus-patterns
|
||||
description: Quarkus 3.x LTSアーキテクチャパターン、Camelメッセージング、RESTful API設計、CDIサービス、Panacheデータアクセス、非同期処理。イベント駆動アーキテクチャを持つJava Quarkusバックエンド作業に使用。
|
||||
origin: ECC
|
||||
---
|
||||
|
||||
# Quarkus 開発パターン
|
||||
|
||||
Apache Camelを使用したクラウドネイティブなイベント駆動サービスのためのQuarkus 3.xアーキテクチャとAPIパターン。
|
||||
|
||||
## いつアクティブにするか
|
||||
|
||||
- JAX-RSまたはRESTEasy ReactiveでREST APIを構築する
|
||||
- リソース → サービス → リポジトリレイヤーを構造化する
|
||||
- Apache CamelとRabbitMQでイベント駆動パターンを実装する
|
||||
- Hibernate Panache、キャッシング、またはリアクティブストリームを構成する
|
||||
- バリデーション、例外マッピング、またはページネーションを追加する
|
||||
- dev/staging/production環境のプロファイルを設定する(YAML構成)
|
||||
- LogContextとLogback/Logstashエンコーダーでカスタムロギング
|
||||
- CompletableFutureで非同期操作を行う
|
||||
- 条件付きフロー処理を実装する
|
||||
- GraalVMネイティブコンパイルで作業する
|
||||
|
||||
## 複数依存関係を持つサービスレイヤー(Lombok)
|
||||
|
||||
```java
|
||||
@Slf4j
|
||||
@ApplicationScoped
|
||||
@RequiredArgsConstructor
|
||||
public class As2ProcessingService {
|
||||
|
||||
private final InvoiceFlowValidator invoiceFlowValidator;
|
||||
private final EventService eventService;
|
||||
private final DocumentJobService documentJobService;
|
||||
private final BusinessRulesPublisher businessRulesPublisher;
|
||||
private final FileStorageService fileStorageService;
|
||||
|
||||
public void processFile(Path filePath) throws Exception {
|
||||
LogContext logContext = CustomLog.getCurrentContext();
|
||||
try (SafeAutoCloseable ignored = CustomLog.startScope(logContext)) {
|
||||
|
||||
String structureIdPartner = logContext.get(As2Constants.STRUCTURE_ID);
|
||||
|
||||
// 条件付きフローロジック
|
||||
boolean isChorusFlow = Boolean.parseBoolean(logContext.get(As2Constants.CHORUS_FLOW));
|
||||
log.info("Is CHORUS_FLOW message: {}", isChorusFlow);
|
||||
|
||||
ValidationFlowConfig validationFlowConfig = isChorusFlow
|
||||
? ValidationFlowConfig.xsdOnly()
|
||||
: ValidationFlowConfig.allValidations();
|
||||
|
||||
InvoiceValidationResult invoiceValidationResult = this.invoiceFlowValidator
|
||||
.validateFlowWithConfig(filePath, validationFlowConfig,
|
||||
EInvoiceSyntaxFormat.UBL, logContext);
|
||||
|
||||
FlowProfile flowProfile = isChorusFlow ?
|
||||
FlowProfile.EXTENDED_CTC_FR :
|
||||
this.invoiceFlowValidator.computeFlowProfile(invoiceValidationResult,
|
||||
invoiceValidationResult.getInvoiceDetails().invoiceFormat().getProfile());
|
||||
|
||||
log.info("Invoice validation completed. Message is valid");
|
||||
|
||||
// CompletableFuture非同期操作
|
||||
try(InputStream inputStream = Files.newInputStream(filePath)) {
|
||||
CompletableFuture<StoredDocumentInfo> documentInfoCompletableFuture =
|
||||
fileStorageService.uploadOriginalFile(inputStream,
|
||||
invoiceValidationResult.getSize(), logContext,
|
||||
invoiceValidationResult.getInvoiceFormat());
|
||||
|
||||
StoredDocumentInfo documentInfo = documentInfoCompletableFuture.join();
|
||||
log.info("File uploaded successfully: {}", documentInfo.getPath());
|
||||
|
||||
if (StringUtils.isBlank(documentInfo.getPath())) {
|
||||
String errorMsg = "File path is empty after upload";
|
||||
log.error(errorMsg);
|
||||
this.eventService.createErrorEvent(documentInfo, "FILE_UPLOAD_FAILED", errorMsg);
|
||||
throw new As2ServerProcessingException(errorMsg);
|
||||
}
|
||||
|
||||
this.eventService.createSuccessEvent(documentInfo, "PERSISTENCE_BLOB_EVENT_TYPE");
|
||||
|
||||
BusinessRulesPayload payload = this.documentJobService.createDocumentAndJobEntities(
|
||||
documentInfo, originalFileName, structureIdPartner,
|
||||
flowProfile, invoiceValidationResult.getDocumentHash());
|
||||
|
||||
// 非同期Camelパブリッシング
|
||||
businessRulesPublisher.publishAsync(payload);
|
||||
this.eventService.createSuccessEvent(payload, "BUSINESS_RULES_MESSAGE_SENT");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**主要パターン:**
|
||||
- Lombokによるコンストラクタインジェクション用の`@RequiredArgsConstructor`
|
||||
- Logbackロギング用の`@Slf4j`
|
||||
- try-with-resourcesによるスコープ付きLogContext
|
||||
- ランタイムパラメータに基づく条件付きフローロジック
|
||||
- 非同期操作用の`.join()`付きCompletableFuture
|
||||
- 成功/エラーシナリオのイベントトラッキング
|
||||
- 非同期Camelメッセージパブリッシング
|
||||
|
||||
## カスタムロギングコンテキストパターン(Logback)
|
||||
|
||||
```java
|
||||
@ApplicationScoped
|
||||
public class ProcessingService {
|
||||
|
||||
public void processDocument(Document doc) {
|
||||
LogContext logContext = CustomLog.getCurrentContext();
|
||||
try (SafeAutoCloseable ignored = CustomLog.startScope(logContext)) {
|
||||
// すべてのログステートメントにコンテキストを追加
|
||||
logContext.put("documentId", doc.getId().toString());
|
||||
logContext.put("documentType", doc.getType());
|
||||
logContext.put("userId", SecurityContext.getUserId());
|
||||
|
||||
log.info("Starting document processing");
|
||||
|
||||
// このスコープ内のすべてのログはコンテキストを継承
|
||||
processInternal(doc);
|
||||
|
||||
log.info("Document processing completed");
|
||||
} catch (Exception e) {
|
||||
log.error("Document processing failed", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Logback構成(logback.xml):**
|
||||
|
||||
```xml
|
||||
<configuration>
|
||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
|
||||
<includeContext>true</includeContext>
|
||||
<includeMdc>true</includeMdc>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<logger name="com.example" level="INFO"/>
|
||||
<root level="WARN">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</root>
|
||||
</configuration>
|
||||
```
|
||||
|
||||
## イベントサービスパターン
|
||||
|
||||
```java
|
||||
@ApplicationScoped
|
||||
@RequiredArgsConstructor
|
||||
public class EventService {
|
||||
private final EventRepository eventRepository;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public void createSuccessEvent(Object payload, String eventType) {
|
||||
Objects.requireNonNull(payload, "Payload cannot be null");
|
||||
Event event = new Event();
|
||||
event.setType(eventType);
|
||||
event.setStatus(EventStatus.SUCCESS);
|
||||
event.setPayload(serializePayload(payload));
|
||||
event.setTimestamp(Instant.now());
|
||||
|
||||
eventRepository.persist(event);
|
||||
log.info("Success event created: {}", eventType);
|
||||
}
|
||||
|
||||
public void createErrorEvent(Object payload, String eventType, String errorMessage) {
|
||||
Objects.requireNonNull(payload, "Payload cannot be null");
|
||||
if (errorMessage == null || errorMessage.isBlank()) {
|
||||
throw new IllegalArgumentException("Error message cannot be blank");
|
||||
}
|
||||
Event event = new Event();
|
||||
event.setType(eventType);
|
||||
event.setStatus(EventStatus.ERROR);
|
||||
event.setErrorMessage(errorMessage);
|
||||
event.setPayload(serializePayload(payload));
|
||||
event.setTimestamp(Instant.now());
|
||||
|
||||
eventRepository.persist(event);
|
||||
log.error("Error event created: {} - {}", eventType, errorMessage);
|
||||
}
|
||||
|
||||
private String serializePayload(Object payload) {
|
||||
try {
|
||||
return objectMapper.writeValueAsString(payload);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new IllegalStateException("Failed to serialize event payload", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Camelメッセージパブリッシング(RabbitMQ)
|
||||
|
||||
```java
|
||||
@ApplicationScoped
|
||||
@RequiredArgsConstructor
|
||||
public class BusinessRulesPublisher {
|
||||
private final ProducerTemplate producerTemplate;
|
||||
|
||||
@ConfigProperty(name = "camel.rabbitmq.queue.business-rules")
|
||||
String businessRulesQueue;
|
||||
|
||||
public void publishAsync(BusinessRulesPayload payload) {
|
||||
producerTemplate.asyncSendBody(
|
||||
"direct:business-rules-publisher",
|
||||
payload
|
||||
);
|
||||
log.info("Message published to business rules queue: {}", payload.getDocumentId());
|
||||
}
|
||||
|
||||
public void publishSync(BusinessRulesPayload payload) {
|
||||
producerTemplate.sendBody(
|
||||
"direct:business-rules-publisher",
|
||||
payload
|
||||
);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Camelルート構成:**
|
||||
|
||||
```java
|
||||
@ApplicationScoped
|
||||
public class BusinessRulesRoute extends RouteBuilder {
|
||||
|
||||
@ConfigProperty(name = "camel.rabbitmq.queue.business-rules")
|
||||
String businessRulesQueue;
|
||||
|
||||
@ConfigProperty(name = "rabbitmq.host")
|
||||
String rabbitHost;
|
||||
|
||||
@ConfigProperty(name = "rabbitmq.port")
|
||||
Integer rabbitPort;
|
||||
|
||||
@Override
|
||||
public void configure() {
|
||||
from("direct:business-rules-publisher")
|
||||
.routeId("business-rules-publisher")
|
||||
.log("Publishing message to RabbitMQ: ${body}")
|
||||
.marshal().json(JsonLibrary.Jackson)
|
||||
.toF("spring-rabbitmq:%s?hostname=%s&portNumber=%d",
|
||||
businessRulesQueue, rabbitHost, rabbitPort);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Camel Directルート(インメモリ)
|
||||
|
||||
```java
|
||||
@ApplicationScoped
|
||||
public class DocumentProcessingRoute extends RouteBuilder {
|
||||
|
||||
@Override
|
||||
public void configure() {
|
||||
// エラーハンドリング
|
||||
onException(ValidationException.class)
|
||||
.handled(true)
|
||||
.to("direct:validation-error-handler")
|
||||
.log("Validation error: ${exception.message}");
|
||||
|
||||
// メイン処理ルート
|
||||
from("direct:process-document")
|
||||
.routeId("document-processing")
|
||||
.log("Processing document: ${header.documentId}")
|
||||
.bean(DocumentValidator.class, "validate")
|
||||
.bean(DocumentTransformer.class, "transform")
|
||||
.choice()
|
||||
.when(header("documentType").isEqualTo("INVOICE"))
|
||||
.to("direct:process-invoice")
|
||||
.when(header("documentType").isEqualTo("CREDIT_NOTE"))
|
||||
.to("direct:process-credit-note")
|
||||
.otherwise()
|
||||
.to("direct:process-generic")
|
||||
.end();
|
||||
|
||||
from("direct:validation-error-handler")
|
||||
.bean(EventService.class, "createErrorEvent")
|
||||
.log("Validation error handled");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Camelファイル処理
|
||||
|
||||
```java
|
||||
@ApplicationScoped
|
||||
public class FileMonitoringRoute extends RouteBuilder {
|
||||
|
||||
@ConfigProperty(name = "file.input.directory")
|
||||
String inputDirectory;
|
||||
|
||||
@ConfigProperty(name = "file.processed.directory")
|
||||
String processedDirectory;
|
||||
|
||||
@ConfigProperty(name = "file.error.directory")
|
||||
String errorDirectory;
|
||||
|
||||
@Override
|
||||
public void configure() {
|
||||
from("file:" + inputDirectory + "?move=" + processedDirectory +
|
||||
"&moveFailed=" + errorDirectory + "&delay=5000")
|
||||
.routeId("file-monitor")
|
||||
.log("Processing file: ${header.CamelFileName}")
|
||||
.to("direct:process-file");
|
||||
|
||||
from("direct:process-file")
|
||||
.bean(As2ProcessingService.class, "processFile")
|
||||
.log("File processing completed");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Camel Bean呼び出し
|
||||
|
||||
```java
|
||||
@ApplicationScoped
|
||||
public class InvoiceRoute extends RouteBuilder {
|
||||
|
||||
@Override
|
||||
public void configure() {
|
||||
from("direct:invoice-validation")
|
||||
.bean(InvoiceFlowValidator.class, "validateFlowWithConfig")
|
||||
.log("Validation result: ${body}");
|
||||
|
||||
from("direct:persist-and-publish")
|
||||
.bean(DocumentJobService.class, "createDocumentAndJobEntities")
|
||||
.bean(BusinessRulesPublisher.class, "publishAsync")
|
||||
.bean(EventService.class, "createSuccessEvent(${body}, 'PUBLISHED')");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## REST API構造
|
||||
|
||||
```java
|
||||
@Path("/api/documents")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@RequiredArgsConstructor
|
||||
public class DocumentResource {
|
||||
private final DocumentService documentService;
|
||||
|
||||
@GET
|
||||
public Response list(
|
||||
@QueryParam("page") @DefaultValue("0") int page,
|
||||
@QueryParam("size") @DefaultValue("20") int size) {
|
||||
List<Document> documents = documentService.list(page, size);
|
||||
return Response.ok(documents).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
public Response create(@Valid CreateDocumentRequest request, @Context UriInfo uriInfo) {
|
||||
Document document = documentService.create(request);
|
||||
URI location = uriInfo.getAbsolutePathBuilder()
|
||||
.path(String.valueOf(document.id))
|
||||
.build();
|
||||
return Response.created(location).entity(DocumentResponse.from(document)).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{id}")
|
||||
public Response getById(@PathParam("id") Long id) {
|
||||
return documentService.findById(id)
|
||||
.map(DocumentResponse::from)
|
||||
.map(Response::ok)
|
||||
.orElse(Response.status(Response.Status.NOT_FOUND))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## リポジトリパターン(Panache Repository)
|
||||
|
||||
```java
|
||||
@ApplicationScoped
|
||||
public class DocumentRepository implements PanacheRepository<Document> {
|
||||
|
||||
public List<Document> findByStatus(DocumentStatus status, int page, int size) {
|
||||
return find("status = ?1 order by createdAt desc", status)
|
||||
.page(page, size)
|
||||
.list();
|
||||
}
|
||||
|
||||
public Optional<Document> findByReferenceNumber(String referenceNumber) {
|
||||
return find("referenceNumber", referenceNumber).firstResultOptional();
|
||||
}
|
||||
|
||||
public long countByStatusAndDate(DocumentStatus status, LocalDate date) {
|
||||
return count("status = ?1 and createdAt >= ?2", status, date.atStartOfDay());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## トランザクション付きサービスレイヤー
|
||||
|
||||
```java
|
||||
@ApplicationScoped
|
||||
@RequiredArgsConstructor
|
||||
public class DocumentService {
|
||||
private final DocumentRepository repo;
|
||||
private final EventService eventService;
|
||||
|
||||
@Transactional
|
||||
public Document create(CreateDocumentRequest request) {
|
||||
Document document = new Document();
|
||||
document.setReferenceNumber(request.referenceNumber());
|
||||
document.setDescription(request.description());
|
||||
document.setStatus(DocumentStatus.PENDING);
|
||||
document.setCreatedAt(Instant.now());
|
||||
|
||||
repo.persist(document);
|
||||
|
||||
eventService.createSuccessEvent(document, "DOCUMENT_CREATED");
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
public Optional<Document> findById(Long id) {
|
||||
return repo.findByIdOptional(id);
|
||||
}
|
||||
|
||||
public List<Document> list(int page, int size) {
|
||||
return repo.findAll()
|
||||
.page(page, size)
|
||||
.list();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## DTOとバリデーション
|
||||
|
||||
```java
|
||||
public record CreateDocumentRequest(
|
||||
@NotBlank @Size(max = 200) String referenceNumber,
|
||||
@NotBlank @Size(max = 2000) String description,
|
||||
@NotNull @FutureOrPresent Instant validUntil,
|
||||
@NotEmpty List<@NotBlank String> categories) {}
|
||||
|
||||
public record DocumentResponse(Long id, String referenceNumber, DocumentStatus status) {
|
||||
public static DocumentResponse from(Document document) {
|
||||
return new DocumentResponse(document.getId(), document.getReferenceNumber(),
|
||||
document.getStatus());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 例外マッピング
|
||||
|
||||
```java
|
||||
@Provider
|
||||
public class ValidationExceptionMapper implements ExceptionMapper<ConstraintViolationException> {
|
||||
@Override
|
||||
public Response toResponse(ConstraintViolationException exception) {
|
||||
String message = exception.getConstraintViolations().stream()
|
||||
.map(cv -> cv.getPropertyPath() + ": " + cv.getMessage())
|
||||
.collect(Collectors.joining(", "));
|
||||
|
||||
return Response.status(Response.Status.BAD_REQUEST)
|
||||
.entity(Map.of("error", "validation_error", "message", message))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@Provider
|
||||
@Slf4j
|
||||
public class GenericExceptionMapper implements ExceptionMapper<Exception> {
|
||||
|
||||
@Override
|
||||
public Response toResponse(Exception exception) {
|
||||
log.error("Unhandled exception", exception);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
|
||||
.entity(Map.of("error", "internal_error", "message", "An unexpected error occurred"))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## CompletableFuture非同期操作
|
||||
|
||||
```java
|
||||
@Slf4j
|
||||
@ApplicationScoped
|
||||
@RequiredArgsConstructor
|
||||
public class FileStorageService {
|
||||
private final S3Client s3Client;
|
||||
private final ExecutorService executorService;
|
||||
|
||||
@ConfigProperty(name = "storage.bucket-name") String bucketName;
|
||||
|
||||
public CompletableFuture<StoredDocumentInfo> uploadOriginalFile(
|
||||
InputStream inputStream,
|
||||
long size,
|
||||
LogContext logContext,
|
||||
InvoiceFormat format) {
|
||||
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try (SafeAutoCloseable ignored = CustomLog.startScope(logContext)) {
|
||||
String path = generateStoragePath(format);
|
||||
|
||||
PutObjectRequest request = PutObjectRequest.builder()
|
||||
.bucket(bucketName)
|
||||
.key(path)
|
||||
.contentLength(size)
|
||||
.build();
|
||||
|
||||
s3Client.putObject(request, RequestBody.fromInputStream(inputStream, size));
|
||||
|
||||
log.info("File uploaded to S3: {}", path);
|
||||
|
||||
return new StoredDocumentInfo(path, size, Instant.now());
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to upload file to S3", e);
|
||||
throw new StorageException("Upload failed", e);
|
||||
}
|
||||
}, executorService);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## キャッシング
|
||||
|
||||
```java
|
||||
@ApplicationScoped
|
||||
@RequiredArgsConstructor
|
||||
public class DocumentCacheService {
|
||||
private final DocumentRepository repo;
|
||||
|
||||
@CacheResult(cacheName = "document-cache")
|
||||
public Optional<Document> getById(@CacheKey Long id) {
|
||||
return repo.findByIdOptional(id);
|
||||
}
|
||||
|
||||
@CacheInvalidate(cacheName = "document-cache")
|
||||
public void evict(@CacheKey Long id) {}
|
||||
|
||||
@CacheInvalidateAll(cacheName = "document-cache")
|
||||
public void evictAll() {}
|
||||
}
|
||||
```
|
||||
|
||||
## YAML構成
|
||||
|
||||
```yaml
|
||||
# application.yml
|
||||
"%dev":
|
||||
quarkus:
|
||||
datasource:
|
||||
jdbc:
|
||||
url: jdbc:postgresql://localhost:5432/dev_db
|
||||
username: dev_user
|
||||
password: dev_pass
|
||||
hibernate-orm:
|
||||
database:
|
||||
generation: drop-and-create
|
||||
|
||||
rabbitmq:
|
||||
host: localhost
|
||||
port: 5672
|
||||
username: guest
|
||||
password: guest
|
||||
|
||||
"%test":
|
||||
quarkus:
|
||||
datasource:
|
||||
jdbc:
|
||||
url: jdbc:h2:mem:test
|
||||
hibernate-orm:
|
||||
database:
|
||||
generation: drop-and-create
|
||||
|
||||
"%prod":
|
||||
quarkus:
|
||||
datasource:
|
||||
jdbc:
|
||||
url: ${DATABASE_URL}
|
||||
username: ${DB_USER}
|
||||
password: ${DB_PASSWORD}
|
||||
hibernate-orm:
|
||||
database:
|
||||
generation: validate
|
||||
|
||||
rabbitmq:
|
||||
host: ${RABBITMQ_HOST}
|
||||
port: ${RABBITMQ_PORT}
|
||||
username: ${RABBITMQ_USER}
|
||||
password: ${RABBITMQ_PASSWORD}
|
||||
|
||||
# Camel構成
|
||||
camel:
|
||||
rabbitmq:
|
||||
queue:
|
||||
business-rules: business-rules-queue
|
||||
invoice-processing: invoice-processing-queue
|
||||
```
|
||||
|
||||
## ヘルスチェック
|
||||
|
||||
```java
|
||||
@Readiness
|
||||
@ApplicationScoped
|
||||
@RequiredArgsConstructor
|
||||
public class DatabaseHealthCheck implements HealthCheck {
|
||||
private final AgroalDataSource dataSource;
|
||||
|
||||
@Override
|
||||
public HealthCheckResponse call() {
|
||||
try (Connection conn = dataSource.getConnection()) {
|
||||
boolean valid = conn.isValid(2);
|
||||
return HealthCheckResponse.named("Database connection")
|
||||
.status(valid)
|
||||
.build();
|
||||
} catch (SQLException e) {
|
||||
return HealthCheckResponse.down("Database connection");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Liveness
|
||||
@ApplicationScoped
|
||||
public class CamelHealthCheck implements HealthCheck {
|
||||
@Inject
|
||||
CamelContext camelContext;
|
||||
|
||||
@Override
|
||||
public HealthCheckResponse call() {
|
||||
boolean isStarted = camelContext.getStatus().isStarted();
|
||||
return HealthCheckResponse.named("Camel Context")
|
||||
.status(isStarted)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 依存関係(Maven)
|
||||
|
||||
```xml
|
||||
<properties>
|
||||
<quarkus.platform.version>3.27.0</quarkus.platform.version>
|
||||
<lombok.version>1.18.42</lombok.version>
|
||||
<assertj-core.version>3.24.2</assertj-core.version>
|
||||
<jacoco-maven-plugin.version>0.8.13</jacoco-maven-plugin.version>
|
||||
<maven.compiler.release>17</maven.compiler.release>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.quarkus.platform</groupId>
|
||||
<artifactId>quarkus-bom</artifactId>
|
||||
<version>${quarkus.platform.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus.platform</groupId>
|
||||
<artifactId>quarkus-camel-bom</artifactId>
|
||||
<version>${quarkus.platform.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<!-- Quarkusコア -->
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-arc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-config-yaml</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Camelエクステンション -->
|
||||
<dependency>
|
||||
<groupId>org.apache.camel.quarkus</groupId>
|
||||
<artifactId>camel-quarkus-spring-rabbitmq</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel.quarkus</groupId>
|
||||
<artifactId>camel-quarkus-direct</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel.quarkus</groupId>
|
||||
<artifactId>camel-quarkus-bean</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- ロギング -->
|
||||
<dependency>
|
||||
<groupId>io.quarkiverse.logging.logback</groupId>
|
||||
<artifactId>quarkus-logging-logback</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.logstash.logback</groupId>
|
||||
<artifactId>logstash-logback-encoder</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
```
|
||||
|
||||
## ベストプラクティス
|
||||
|
||||
### アーキテクチャ
|
||||
- コンストラクタインジェクション用にLombokの`@RequiredArgsConstructor`を使用
|
||||
- サービスレイヤーは薄く保ち、複雑なロジックは専門クラスに委譲
|
||||
- メッセージルーティングと統合パターンにCamelルートを使用
|
||||
- データアクセスにはPanache Repositoryパターンを優先
|
||||
|
||||
### イベント駆動
|
||||
- 常にEventServiceで操作をトラッキング(成功/エラーイベント)
|
||||
- インメモリルーティングにCamelの`direct:`エンドポイントを使用
|
||||
- RabbitMQ統合に`spring-rabbitmq`コンポーネントを使用
|
||||
- `ProducerTemplate.asyncSendBody()`で非同期パブリッシングを実装
|
||||
|
||||
### ロギング
|
||||
- 構造化ロギング用にLogstashエンコーダー付きLogbackを使用
|
||||
- `SafeAutoCloseable`でサービスコール間でLogContextを伝播
|
||||
- リクエストトレーシング用にLogContextにコンテキスト情報を追加
|
||||
- 手動ロガーインスタンス化の代わりに`@Slf4j`を使用
|
||||
|
||||
### 非同期操作
|
||||
- ノンブロッキングI/O操作にCompletableFutureを使用
|
||||
- 完了を待つ必要がある場合は`.join()`を呼び出す
|
||||
- CompletableFutureからの例外を適切にハンドリング
|
||||
- トレーシング用に非同期操作にLogContextを渡す
|
||||
|
||||
### 構成
|
||||
- YAML構成を使用(`quarkus-config-yaml`)
|
||||
- dev/test/prod環境のプロファイル対応構成
|
||||
- 機密構成を環境変数に外部化
|
||||
- 型安全な構成インジェクション用に`@ConfigProperty`を使用
|
||||
|
||||
### バリデーション
|
||||
- リソースレイヤーで`@Valid`によるバリデーション
|
||||
- DTOにBean Validationアノテーションを使用
|
||||
- `@Provider`で例外を適切なHTTPレスポンスにマッピング
|
||||
|
||||
### トランザクション
|
||||
- データを変更するサービスメソッドに`@Transactional`を使用
|
||||
- トランザクションは短く焦点を絞る
|
||||
- トランザクション内で非同期操作を呼び出さない
|
||||
|
||||
### テスト
|
||||
- ルートテストに`camel-quarkus-junit5`を使用
|
||||
- アサーションにAssertJを使用
|
||||
- すべての外部依存関係をモック
|
||||
- 条件付きフローロジックを徹底的にテスト
|
||||
|
||||
### Quarkus固有
|
||||
- 最新のLTSバージョン(3.x)を維持
|
||||
- ホットリロード用にQuarkus devモードを使用
|
||||
- 本番準備のためにヘルスチェックを追加
|
||||
- ネイティブコンパイル互換性を定期的にテスト
|
||||
@@ -1,404 +0,0 @@
|
||||
---
|
||||
name: quarkus-security
|
||||
description: Quarkusセキュリティのベストプラクティス:認証、認可、JWT/OIDC、RBAC、入力バリデーション、CSRF、シークレット管理、依存関係セキュリティ。
|
||||
origin: ECC
|
||||
---
|
||||
|
||||
# Quarkus セキュリティレビュー
|
||||
|
||||
認証、認可、入力バリデーションによるQuarkusアプリケーションのセキュリティベストプラクティス。
|
||||
|
||||
## いつアクティブにするか
|
||||
|
||||
- 認証の追加(JWT、OIDC、Basic Auth)
|
||||
- @RolesAllowedまたはSecurityIdentityによる認可の実装
|
||||
- ユーザー入力のバリデーション(Bean Validation、カスタムバリデータ)
|
||||
- CORSまたはセキュリティヘッダーの構成
|
||||
- シークレット管理(Vault、環境変数、構成ソース)
|
||||
- レート制限またはブルートフォース保護の追加
|
||||
- 依存関係のCVEスキャン
|
||||
- MicroProfile JWTまたはSmallRye JWTの使用
|
||||
|
||||
## 認証
|
||||
|
||||
### JWT認証
|
||||
|
||||
```java
|
||||
@Path("/api/protected")
|
||||
@Authenticated
|
||||
public class ProtectedResource {
|
||||
|
||||
@Inject
|
||||
JsonWebToken jwt;
|
||||
|
||||
@Inject
|
||||
SecurityIdentity securityIdentity;
|
||||
|
||||
@GET
|
||||
public Response getData() {
|
||||
String username = jwt.getName();
|
||||
Set<String> roles = jwt.getGroups();
|
||||
return Response.ok(Map.of(
|
||||
"username", username,
|
||||
"roles", roles,
|
||||
"principal", securityIdentity.getPrincipal().getName()
|
||||
)).build();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
構成(application.properties):
|
||||
```properties
|
||||
mp.jwt.verify.publickey.location=publicKey.pem
|
||||
mp.jwt.verify.issuer=https://auth.example.com
|
||||
|
||||
# OIDC
|
||||
quarkus.oidc.auth-server-url=https://auth.example.com/realms/myrealm
|
||||
quarkus.oidc.client-id=backend-service
|
||||
quarkus.oidc.credentials.secret=${OIDC_SECRET}
|
||||
```
|
||||
|
||||
### カスタム認証フィルター
|
||||
|
||||
```java
|
||||
@Provider
|
||||
@Priority(Priorities.AUTHENTICATION)
|
||||
public class CustomAuthFilter implements ContainerRequestFilter {
|
||||
|
||||
@Inject
|
||||
SecurityIdentity identity;
|
||||
|
||||
@Override
|
||||
public void filter(ContainerRequestContext requestContext) {
|
||||
String authHeader = requestContext.getHeaderString(HttpHeaders.AUTHORIZATION);
|
||||
|
||||
// ヘッダーが存在しないか不正な場合は即座に拒否
|
||||
if (authHeader == null || !authHeader.startsWith("Bearer ")) {
|
||||
requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED).build());
|
||||
return;
|
||||
}
|
||||
|
||||
String token = authHeader.substring(7);
|
||||
if (!validateToken(token)) {
|
||||
requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED).build());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean validateToken(String token) {
|
||||
// トークンバリデーションロジック
|
||||
return true;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 認可
|
||||
|
||||
### ロールベースアクセス制御
|
||||
|
||||
```java
|
||||
@Path("/api/admin")
|
||||
@RolesAllowed("ADMIN")
|
||||
public class AdminResource {
|
||||
|
||||
@GET
|
||||
@Path("/users")
|
||||
public List<UserDto> listUsers() {
|
||||
return userService.findAll();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/users/{id}")
|
||||
@RolesAllowed({"ADMIN", "SUPER_ADMIN"})
|
||||
public Response deleteUser(@PathParam("id") Long id) {
|
||||
userService.delete(id);
|
||||
return Response.noContent().build();
|
||||
}
|
||||
}
|
||||
|
||||
@Path("/api/users")
|
||||
public class UserResource {
|
||||
|
||||
@Inject
|
||||
SecurityIdentity securityIdentity;
|
||||
|
||||
@GET
|
||||
@Path("/{id}")
|
||||
@RolesAllowed("USER")
|
||||
public Response getUser(@PathParam("id") Long id) {
|
||||
// オーナーシップチェック
|
||||
if (!securityIdentity.hasRole("ADMIN") &&
|
||||
!isOwner(id, securityIdentity.getPrincipal().getName())) {
|
||||
return Response.status(Response.Status.FORBIDDEN).build();
|
||||
}
|
||||
return Response.ok(userService.findById(id)).build();
|
||||
}
|
||||
|
||||
private boolean isOwner(Long userId, String username) {
|
||||
return userService.isOwner(userId, username);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### プログラマティックセキュリティ
|
||||
|
||||
```java
|
||||
@ApplicationScoped
|
||||
public class SecurityService {
|
||||
|
||||
@Inject
|
||||
SecurityIdentity securityIdentity;
|
||||
|
||||
public boolean canAccessResource(Long resourceId) {
|
||||
if (securityIdentity.isAnonymous()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (securityIdentity.hasRole("ADMIN")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String userId = securityIdentity.getPrincipal().getName();
|
||||
return resourceRepository.isOwner(resourceId, userId);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 入力バリデーション
|
||||
|
||||
### Bean Validation
|
||||
|
||||
```java
|
||||
// BAD: バリデーションなし
|
||||
@POST
|
||||
public Response createUser(UserDto dto) {
|
||||
return Response.ok(userService.create(dto)).build();
|
||||
}
|
||||
|
||||
// GOOD: バリデーション付きDTO
|
||||
public record CreateUserDto(
|
||||
@NotBlank @Size(max = 100) String name,
|
||||
@NotBlank @Email String email,
|
||||
@NotNull @Min(18) @Max(150) Integer age,
|
||||
@Pattern(regexp = "^\\+?[1-9]\\d{1,14}$") String phone
|
||||
) {}
|
||||
|
||||
@POST
|
||||
@Path("/users")
|
||||
public Response createUser(@Valid CreateUserDto dto) {
|
||||
User user = userService.create(dto);
|
||||
return Response.status(Response.Status.CREATED).entity(user).build();
|
||||
}
|
||||
```
|
||||
|
||||
### カスタムバリデータ
|
||||
|
||||
```java
|
||||
@Target({ElementType.FIELD, ElementType.PARAMETER})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Constraint(validatedBy = UsernameValidator.class)
|
||||
public @interface ValidUsername {
|
||||
String message() default "Invalid username format";
|
||||
Class<?>[] groups() default {};
|
||||
Class<? extends Payload>[] payload() default {};
|
||||
}
|
||||
|
||||
public class UsernameValidator implements ConstraintValidator<ValidUsername, String> {
|
||||
@Override
|
||||
public boolean isValid(String value, ConstraintValidatorContext context) {
|
||||
if (value == null) return false;
|
||||
return value.matches("^[a-zA-Z0-9_-]{3,20}$");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## SQLインジェクション防止
|
||||
|
||||
### Panache Active Record(デフォルトで安全)
|
||||
|
||||
```java
|
||||
// GOOD: Panacheによるパラメータ化クエリ
|
||||
List<User> users = User.list("email = ?1 and active = ?2", email, true);
|
||||
|
||||
Optional<User> user = User.find("username", username).firstResultOptional();
|
||||
|
||||
// GOOD: 名前付きパラメータ
|
||||
List<User> users = User.list("email = :email and age > :minAge",
|
||||
Parameters.with("email", email).and("minAge", 18));
|
||||
```
|
||||
|
||||
### ネイティブクエリ(パラメータを使用)
|
||||
|
||||
```java
|
||||
// BAD: 文字列連結
|
||||
@Query(value = "SELECT * FROM users WHERE name = '" + name + "'", nativeQuery = true)
|
||||
|
||||
// GOOD: パラメータ化ネイティブクエリ
|
||||
@Entity
|
||||
public class User extends PanacheEntity {
|
||||
public static List<User> findByEmailNative(String email) {
|
||||
return getEntityManager()
|
||||
.createNativeQuery("SELECT * FROM users WHERE email = :email", User.class)
|
||||
.setParameter("email", email)
|
||||
.getResultList();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## パスワードハッシュ
|
||||
|
||||
```java
|
||||
@ApplicationScoped
|
||||
public class PasswordService {
|
||||
|
||||
public String hash(String plainPassword) {
|
||||
return BcryptUtil.bcryptHash(plainPassword);
|
||||
}
|
||||
|
||||
public boolean verify(String plainPassword, String hashedPassword) {
|
||||
return BcryptUtil.matches(plainPassword, hashedPassword);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## CORS構成
|
||||
|
||||
```properties
|
||||
# application.properties
|
||||
quarkus.http.cors=true
|
||||
quarkus.http.cors.origins=https://app.example.com,https://admin.example.com
|
||||
quarkus.http.cors.methods=GET,POST,PUT,DELETE
|
||||
quarkus.http.cors.headers=accept,authorization,content-type,x-requested-with
|
||||
quarkus.http.cors.exposed-headers=Content-Disposition
|
||||
quarkus.http.cors.access-control-max-age=24H
|
||||
quarkus.http.cors.access-control-allow-credentials=true
|
||||
```
|
||||
|
||||
## シークレット管理
|
||||
|
||||
```properties
|
||||
# application.properties — ここにシークレットを置かない
|
||||
|
||||
# 環境変数を使用
|
||||
quarkus.datasource.username=${DB_USER}
|
||||
quarkus.datasource.password=${DB_PASSWORD}
|
||||
quarkus.oidc.credentials.secret=${OIDC_CLIENT_SECRET}
|
||||
|
||||
# またはVaultを使用
|
||||
quarkus.vault.url=https://vault.example.com
|
||||
quarkus.vault.authentication.kubernetes.role=my-role
|
||||
```
|
||||
|
||||
## レート制限
|
||||
|
||||
**セキュリティ注意**: `X-Forwarded-For`を直接使用しないでください — クライアントが偽装できます。
|
||||
サーブレットリクエストの実際のリモートアドレス、または認証済みIDを使用してください。
|
||||
|
||||
```java
|
||||
@ApplicationScoped
|
||||
public class RateLimitFilter implements ContainerRequestFilter {
|
||||
private final Map<String, RateLimiter> limiters = new ConcurrentHashMap<>();
|
||||
|
||||
@Inject
|
||||
HttpServletRequest servletRequest;
|
||||
|
||||
@Override
|
||||
public void filter(ContainerRequestContext requestContext) {
|
||||
String clientId = getClientIdentifier();
|
||||
RateLimiter limiter = limiters.computeIfAbsent(clientId,
|
||||
k -> RateLimiter.create(100.0)); // 1秒あたり100リクエスト
|
||||
|
||||
if (!limiter.tryAcquire()) {
|
||||
requestContext.abortWith(
|
||||
Response.status(429)
|
||||
.entity(Map.of("error", "Too many requests"))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private String getClientIdentifier() {
|
||||
// コンテナ提供のリモートアドレスを使用(X-Forwarded-Forではない)。
|
||||
// 信頼できるプロキシの背後にある場合はquarkus.http.proxy.proxy-address-forwarding=trueを設定。
|
||||
return servletRequest.getRemoteAddr();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## セキュリティヘッダー
|
||||
|
||||
```java
|
||||
@Provider
|
||||
public class SecurityHeadersFilter implements ContainerResponseFilter {
|
||||
|
||||
@Override
|
||||
public void filter(ContainerRequestContext request, ContainerResponseContext response) {
|
||||
MultivaluedMap<String, Object> headers = response.getHeaders();
|
||||
|
||||
// クリックジャッキング防止
|
||||
headers.putSingle("X-Frame-Options", "DENY");
|
||||
|
||||
// XSS保護
|
||||
headers.putSingle("X-Content-Type-Options", "nosniff");
|
||||
headers.putSingle("X-XSS-Protection", "1; mode=block");
|
||||
|
||||
// HSTS
|
||||
headers.putSingle("Strict-Transport-Security", "max-age=31536000; includeSubDomains");
|
||||
|
||||
// CSP — script-srcに'unsafe-inline'を使用しないでください。XSS保護が無効になります。
|
||||
// 代わりにnonceまたはhashを使用してください。
|
||||
headers.putSingle("Content-Security-Policy",
|
||||
"default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 監査ロギング
|
||||
|
||||
```java
|
||||
@ApplicationScoped
|
||||
public class AuditService {
|
||||
private static final Logger LOG = Logger.getLogger(AuditService.class);
|
||||
|
||||
@Inject
|
||||
SecurityIdentity securityIdentity;
|
||||
|
||||
public void logAccess(String resource, String action) {
|
||||
String user = securityIdentity.isAnonymous()
|
||||
? "anonymous"
|
||||
: securityIdentity.getPrincipal().getName();
|
||||
|
||||
LOG.infof("AUDIT: user=%s action=%s resource=%s timestamp=%s",
|
||||
user, action, resource, Instant.now());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 依存関係セキュリティスキャン
|
||||
|
||||
```bash
|
||||
# Maven
|
||||
mvn org.owasp:dependency-check-maven:check
|
||||
|
||||
# Gradle
|
||||
./gradlew dependencyCheckAnalyze
|
||||
|
||||
# Quarkusエクステンション確認
|
||||
quarkus extension list --installable
|
||||
```
|
||||
|
||||
## ベストプラクティス
|
||||
|
||||
- 本番環境では常にHTTPSを使用
|
||||
- ステートレス認証にJWTまたはOIDCを有効化
|
||||
- 宣言的認可に`@RolesAllowed`を使用
|
||||
- Bean Validationですべての入力をバリデーション
|
||||
- BCryptでパスワードをハッシュ(平文禁止)
|
||||
- シークレットはVaultまたは環境変数に保存
|
||||
- SQLインジェクション防止にパラメータ化クエリを使用
|
||||
- すべてのレスポンスにセキュリティヘッダーを追加
|
||||
- パブリックエンドポイントにレート制限を実装
|
||||
- 機密操作を監査
|
||||
- 依存関係を最新に保ちCVEをスキャン
|
||||
- プログラマティックチェックにSecurityIdentityを使用
|
||||
- 適切なCORSポリシーを設定
|
||||
- 認証・認可パスをテスト
|
||||
@@ -1,390 +0,0 @@
|
||||
---
|
||||
name: quarkus-tdd
|
||||
description: Quarkus 3.x LTS向けテスト駆動開発。JUnit 5、Mockito、REST Assured、Camelテスト、JaCoCoを使用。機能追加、バグ修正、イベント駆動サービスのリファクタリングに使用。
|
||||
origin: ECC
|
||||
---
|
||||
|
||||
# Quarkus TDDワークフロー
|
||||
|
||||
80%以上のカバレッジ(ユニット+統合)を目指すQuarkus 3.xサービスのTDDガイダンス。Apache Camelによるイベント駆動アーキテクチャに最適化。
|
||||
|
||||
## いつ使用するか
|
||||
|
||||
- 新機能またはRESTエンドポイント
|
||||
- バグ修正またはリファクタリング
|
||||
- データアクセスロジック、セキュリティルール、またはリアクティブストリームの追加
|
||||
- Apache Camelルートとイベントハンドラーのテスト
|
||||
- RabbitMQによるイベント駆動サービスのテスト
|
||||
- 条件付きフローロジックのテスト
|
||||
- CompletableFuture非同期操作のバリデーション
|
||||
- LogContext伝播のテスト
|
||||
|
||||
## ワークフロー
|
||||
|
||||
1. まずテストを書く(失敗するはず)
|
||||
2. テストを通過する最小限のコードを実装
|
||||
3. テストがグリーンの状態でリファクタリング
|
||||
4. JaCoCoでカバレッジを強制(80%以上が目標)
|
||||
|
||||
## @Nestedによるユニットテスト構成
|
||||
|
||||
包括的で読みやすいテストのための構造化アプローチ:
|
||||
|
||||
```java
|
||||
@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 - 共通テストデータ
|
||||
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("Tests for processFile")
|
||||
class ProcessFile {
|
||||
|
||||
@Test
|
||||
@DisplayName("Should successfully process non-CHORUS file with all validations")
|
||||
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(businessRulesPublisher).publishAsync(any(BusinessRulesPayload.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should create error event when file upload fails")
|
||||
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(), any()))
|
||||
.thenReturn(FlowProfile.BASIC);
|
||||
|
||||
documentInfo.setPath(""); // 空パスでエラーをトリガー
|
||||
when(fileStorageService.uploadOriginalFile(any(), anyLong(), any(), any()))
|
||||
.thenReturn(CompletableFuture.completedFuture(documentInfo));
|
||||
|
||||
// ACT & ASSERT
|
||||
As2ServerProcessingException exception = assertThrows(
|
||||
As2ServerProcessingException.class,
|
||||
() -> as2ProcessingService.processFile(testFilePath)
|
||||
);
|
||||
|
||||
assertThat(exception.getMessage())
|
||||
.contains("File path is empty after upload");
|
||||
|
||||
verify(businessRulesPublisher, never()).publishAsync(any());
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 主要テストパターン
|
||||
|
||||
1. **@Nestedクラス**: テスト対象メソッドごとにテストをグループ化
|
||||
2. **@DisplayName**: テストレポート用の読みやすい説明
|
||||
3. **命名規則**: 明確さのために`givenX_whenY_thenZ`
|
||||
4. **AAAパターン**: 明示的な`// ARRANGE`、`// ACT`、`// ASSERT`コメント
|
||||
5. **@BeforeEach**: 重複削減のための共通テストデータセットアップ
|
||||
6. **assertDoesNotThrow**: 例外をキャッチせずに成功シナリオをテスト
|
||||
7. **assertThrows**: メッセージバリデーション付きの例外シナリオテスト
|
||||
8. **包括的カバレッジ**: ハッピーパス、null入力、エッジケース、例外をテスト
|
||||
9. **インタラクション検証**: Mockitoの`verify()`でメソッドが正しく呼ばれることを確認
|
||||
10. **Never検証**: エラーシナリオでメソッドが呼ばれないことを`never()`で確認
|
||||
|
||||
## Camelルートのテスト
|
||||
|
||||
```java
|
||||
@QuarkusTest
|
||||
@DisplayName("Business Rules Camel Route Tests")
|
||||
class BusinessRulesRouteTest {
|
||||
|
||||
@Inject
|
||||
CamelContext camelContext;
|
||||
|
||||
@Inject
|
||||
ProducerTemplate producerTemplate;
|
||||
|
||||
@InjectMock
|
||||
EventService eventService;
|
||||
|
||||
@InjectMock
|
||||
DocumentValidator documentValidator;
|
||||
|
||||
private BusinessRulesPayload testPayload;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
// ARRANGE - テストデータ
|
||||
testPayload = new BusinessRulesPayload();
|
||||
testPayload.setDocumentId(1L);
|
||||
testPayload.setFlowProfile(FlowProfile.BASIC);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should successfully publish message to RabbitMQ")
|
||||
void givenValidPayload_whenPublish_thenMessageSentToQueue() throws Exception {
|
||||
// ARRANGE
|
||||
MockEndpoint mockRabbitMQ = camelContext.getEndpoint("mock:rabbitmq", MockEndpoint.class);
|
||||
mockRabbitMQ.expectedMessageCount(1);
|
||||
|
||||
camelContext.getRouteController().stopRoute("business-rules-publisher");
|
||||
AdviceWith.adviceWith(camelContext, "business-rules-publisher", advice -> {
|
||||
advice.replaceFromWith("direct:business-rules-publisher");
|
||||
advice.weaveByToString(".*spring-rabbitmq.*").replace().to("mock:rabbitmq");
|
||||
});
|
||||
camelContext.getRouteController().startRoute("business-rules-publisher");
|
||||
|
||||
// ACT
|
||||
producerTemplate.sendBody("direct:business-rules-publisher", testPayload);
|
||||
|
||||
// ASSERT
|
||||
mockRabbitMQ.assertIsSatisfied(5000);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## リソースレイヤーテスト(REST Assured)
|
||||
|
||||
```java
|
||||
@QuarkusTest
|
||||
@DisplayName("DocumentResource API Tests")
|
||||
class DocumentResourceTest {
|
||||
|
||||
@InjectMock
|
||||
DocumentService documentService;
|
||||
|
||||
@Nested
|
||||
@DisplayName("Tests for POST /api/documents")
|
||||
class CreateDocument {
|
||||
|
||||
@Test
|
||||
@DisplayName("Should create document and return 201")
|
||||
void givenValidRequest_whenCreate_thenReturns201() {
|
||||
// ARRANGE
|
||||
Document document = createDocument(1L, "DOC-001");
|
||||
when(documentService.create(any())).thenReturn(document);
|
||||
|
||||
// ACT & ASSERT
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
"referenceNumber": "DOC-001",
|
||||
"description": "Test document",
|
||||
"validUntil": "2030-01-01T00:00:00Z",
|
||||
"categories": ["test"]
|
||||
}
|
||||
""")
|
||||
.when().post("/api/documents")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("referenceNumber", equalTo("DOC-001"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should return 400 for invalid input")
|
||||
void givenInvalidRequest_whenCreate_thenReturns400() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
"referenceNumber": "",
|
||||
"description": "Test"
|
||||
}
|
||||
""")
|
||||
.when().post("/api/documents")
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## JaCoCoカバレッジ
|
||||
|
||||
### Maven構成
|
||||
|
||||
```xml
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.8.13</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>prepare-agent</id>
|
||||
<goals><goal>prepare-agent</goal></goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>report</id>
|
||||
<phase>verify</phase>
|
||||
<goals><goal>report</goal></goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>check</id>
|
||||
<goals><goal>check</goal></goals>
|
||||
<configuration>
|
||||
<rules>
|
||||
<rule>
|
||||
<element>BUNDLE</element>
|
||||
<limits>
|
||||
<limit>
|
||||
<counter>LINE</counter>
|
||||
<value>COVEREDRATIO</value>
|
||||
<minimum>0.80</minimum>
|
||||
</limit>
|
||||
</limits>
|
||||
</rule>
|
||||
</rules>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
```
|
||||
|
||||
カバレッジ付きテスト実行:
|
||||
```bash
|
||||
mvn clean test
|
||||
mvn jacoco:report
|
||||
mvn jacoco:check
|
||||
|
||||
# レポート: target/site/jacoco/index.html
|
||||
```
|
||||
|
||||
## テスト依存関係
|
||||
|
||||
```xml
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-junit5</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-junit5-mockito</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>3.24.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel.quarkus</groupId>
|
||||
<artifactId>camel-quarkus-junit5</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
```
|
||||
|
||||
## ベストプラクティス
|
||||
|
||||
### テスト構成
|
||||
- テスト対象メソッドごとに`@Nested`クラスでグループ化
|
||||
- レポートに表示される読みやすい説明に`@DisplayName`を使用
|
||||
- テストメソッドに`givenX_whenY_thenZ`命名規則を使用
|
||||
|
||||
### テスト構造
|
||||
- 明示的コメント付きAAAパターン(`// ARRANGE`、`// ACT`、`// ASSERT`)
|
||||
- 成功シナリオに`assertDoesNotThrow`を使用
|
||||
- メッセージバリデーション付き例外シナリオに`assertThrows`を使用
|
||||
|
||||
### アサーション
|
||||
- 値チェックにはJUnitアサーションより**AssertJを優先**(`assertThat`)
|
||||
- 読みやすさのためにAssertJのfluent APIを使用
|
||||
- 例外: JUnitの`assertThrows`でキャプチャし、AssertJでメッセージを検証
|
||||
- 成功パス: JUnitの`assertDoesNotThrow`を使用
|
||||
|
||||
### イベント駆動テスト
|
||||
- `AdviceWith`と`MockEndpoint`でCamelルートをテスト
|
||||
- メッセージコンテンツ、ヘッダー、ルーティングロジックを検証
|
||||
- エラーハンドリングルートを個別にテスト
|
||||
- ユニットテストで外部システム(RabbitMQ、S3、データベース)をモック
|
||||
|
||||
### Quarkus固有
|
||||
- 最新のLTSバージョン(Quarkus 3.x)を維持
|
||||
- ネイティブコンパイル互換性を定期的にテスト
|
||||
- 異なるシナリオにQuarkusテストプロファイルを使用
|
||||
- `@MockBean`の代わりに`@InjectMock`を使用(Quarkus固有)
|
||||
|
||||
**覚えておいてください**: テストは高速、分離、決定的に保ちます。実装の詳細ではなく動作をテストしてください。
|
||||
@@ -1,312 +0,0 @@
|
||||
---
|
||||
name: quarkus-verification
|
||||
description: "Quarkusプロジェクトの検証ループ: ビルド、静的解析、カバレッジ付きテスト、セキュリティスキャン、ネイティブコンパイル、リリースまたはPR前のdiffレビュー。"
|
||||
origin: ECC
|
||||
---
|
||||
|
||||
# Quarkus 検証ループ
|
||||
|
||||
PR前、大きな変更後、デプロイ前に実行。
|
||||
|
||||
## いつアクティブにするか
|
||||
|
||||
- Quarkusサービスのプルリクエストを開く前
|
||||
- 大規模なリファクタリングまたは依存関係アップグレード後
|
||||
- ステージングまたは本番のデプロイ前検証
|
||||
- 完全なビルド → lint → テスト → セキュリティスキャン → ネイティブコンパイルパイプラインの実行
|
||||
- テストカバレッジが閾値を満たしていることの検証(80%以上)
|
||||
- ネイティブイメージ互換性のテスト
|
||||
|
||||
## フェーズ1: ビルド
|
||||
|
||||
```bash
|
||||
# Maven
|
||||
mvn clean verify -DskipTests
|
||||
|
||||
# Gradle
|
||||
./gradlew clean assemble -x test
|
||||
```
|
||||
|
||||
ビルドが失敗した場合、停止してコンパイルエラーを修正。
|
||||
|
||||
## フェーズ2: 静的解析
|
||||
|
||||
### Checkstyle、PMD、SpotBugs(Maven)
|
||||
|
||||
```bash
|
||||
mvn checkstyle:check pmd:check spotbugs:check
|
||||
```
|
||||
|
||||
### SonarQube(構成されている場合)
|
||||
|
||||
```bash
|
||||
mvn sonar:sonar \
|
||||
-Dsonar.projectKey=my-quarkus-project \
|
||||
-Dsonar.host.url=http://localhost:9000 \
|
||||
-Dsonar.login=${SONAR_TOKEN}
|
||||
```
|
||||
|
||||
### 対処すべき一般的な問題
|
||||
|
||||
- 未使用のimportまたは変数
|
||||
- 複雑なメソッド(高い循環的複雑度)
|
||||
- 潜在的なnullポインター参照
|
||||
- SpotBugsが検出したセキュリティ問題
|
||||
|
||||
## フェーズ3: テスト + カバレッジ
|
||||
|
||||
```bash
|
||||
# すべてのテストを実行
|
||||
mvn clean test
|
||||
|
||||
# カバレッジレポートを生成
|
||||
mvn jacoco:report
|
||||
|
||||
# カバレッジ閾値を強制(80%)
|
||||
mvn jacoco:check
|
||||
|
||||
# またはGradleで
|
||||
./gradlew test jacocoTestReport jacocoTestCoverageVerification
|
||||
```
|
||||
|
||||
### テストカテゴリ
|
||||
|
||||
#### ユニットテスト
|
||||
モック化された依存関係でサービスロジックをテスト:
|
||||
|
||||
```java
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class UserServiceTest {
|
||||
@Mock UserRepository userRepository;
|
||||
@InjectMocks UserService userService;
|
||||
|
||||
@Test
|
||||
void createUser_validInput_returnsUser() {
|
||||
var dto = new CreateUserDto("Alice", "alice@example.com");
|
||||
|
||||
// Panacheのpersist()はvoidを返す — doNothing + verifyを使用
|
||||
doNothing().when(userRepository).persist(any(User.class));
|
||||
|
||||
User result = userService.create(dto);
|
||||
|
||||
assertThat(result.name).isEqualTo("Alice");
|
||||
verify(userRepository).persist(any(User.class));
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 統合テスト
|
||||
実データベース(Testcontainers)でテスト:
|
||||
|
||||
```java
|
||||
@QuarkusTest
|
||||
@QuarkusTestResource(PostgresTestResource.class)
|
||||
class UserRepositoryIntegrationTest {
|
||||
|
||||
@Inject
|
||||
UserRepository userRepository;
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void findByEmail_existingUser_returnsUser() {
|
||||
User user = new User();
|
||||
user.name = "Alice";
|
||||
user.email = "alice@example.com";
|
||||
userRepository.persist(user);
|
||||
|
||||
Optional<User> found = userRepository.findByEmail("alice@example.com");
|
||||
|
||||
assertThat(found).isPresent();
|
||||
assertThat(found.get().name).isEqualTo("Alice");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### APIテスト
|
||||
REST AssuredでRESTエンドポイントをテスト:
|
||||
|
||||
```java
|
||||
@QuarkusTest
|
||||
class UserResourceTest {
|
||||
|
||||
@Test
|
||||
void createUser_validInput_returns201() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name": "Alice", "email": "alice@example.com"}
|
||||
""")
|
||||
.when().post("/api/users")
|
||||
.then()
|
||||
.statusCode(201)
|
||||
.body("name", equalTo("Alice"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createUser_invalidEmail_returns400() {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{"name": "Alice", "email": "invalid"}
|
||||
""")
|
||||
.when().post("/api/users")
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### カバレッジレポート
|
||||
|
||||
詳細カバレッジは`target/site/jacoco/index.html`を確認:
|
||||
- 全体行カバレッジ(目標: 80%以上)
|
||||
- ブランチカバレッジ(目標: 70%以上)
|
||||
- カバーされていない重要パスを特定
|
||||
|
||||
## フェーズ4: セキュリティスキャン
|
||||
|
||||
### 依存関係脆弱性(Maven)
|
||||
|
||||
```bash
|
||||
mvn org.owasp:dependency-check-maven:check
|
||||
```
|
||||
|
||||
CVEについて`target/dependency-check-report.html`を確認。
|
||||
|
||||
### Quarkusセキュリティ監査
|
||||
|
||||
```bash
|
||||
# 脆弱なエクステンションを確認
|
||||
mvn quarkus:audit
|
||||
|
||||
# すべてのエクステンションをリスト
|
||||
mvn quarkus:list-extensions
|
||||
```
|
||||
|
||||
### 一般的なセキュリティチェック
|
||||
|
||||
- [ ] すべてのシークレットが環境変数に(コード内ではなく)
|
||||
- [ ] すべてのエンドポイントで入力バリデーション
|
||||
- [ ] 認証/認可が構成済み
|
||||
- [ ] CORSが適切に構成済み
|
||||
- [ ] セキュリティヘッダーが設定済み
|
||||
- [ ] パスワードがBCryptでハッシュ済み
|
||||
- [ ] SQLインジェクション保護(パラメータ化クエリ)
|
||||
- [ ] パブリックエンドポイントでレート制限
|
||||
|
||||
## フェーズ5: ネイティブコンパイル
|
||||
|
||||
GraalVMネイティブイメージ互換性をテスト:
|
||||
|
||||
```bash
|
||||
# ネイティブ実行可能ファイルをビルド
|
||||
mvn package -Dnative
|
||||
|
||||
# またはコンテナで
|
||||
mvn package -Dnative -Dquarkus.native.container-build=true
|
||||
|
||||
# ネイティブ実行可能ファイルをテスト
|
||||
./target/*-runner
|
||||
|
||||
# 基本的なスモークテストを実行
|
||||
curl http://localhost:8080/q/health/live
|
||||
curl http://localhost:8080/q/health/ready
|
||||
```
|
||||
|
||||
### ネイティブイメージトラブルシューティング
|
||||
|
||||
一般的な問題:
|
||||
- **Reflection**: 動的クラス用のreflection構成を追加
|
||||
- **Resources**: `quarkus.native.resources.includes`でリソースを含める
|
||||
- **JNI**: ネイティブライブラリ使用時にJNIクラスを登録
|
||||
|
||||
例のreflection構成:
|
||||
```java
|
||||
@RegisterForReflection(targets = {MyDynamicClass.class})
|
||||
public class ReflectionConfiguration {}
|
||||
```
|
||||
|
||||
## フェーズ6: ヘルスチェック
|
||||
|
||||
```bash
|
||||
# Liveness
|
||||
curl http://localhost:8080/q/health/live
|
||||
|
||||
# Readiness
|
||||
curl http://localhost:8080/q/health/ready
|
||||
|
||||
# すべてのヘルスチェック
|
||||
curl http://localhost:8080/q/health
|
||||
|
||||
# メトリクス(有効な場合)
|
||||
curl http://localhost:8080/q/metrics
|
||||
```
|
||||
|
||||
## 検証チェックリスト
|
||||
|
||||
### コード品質
|
||||
- [ ] ビルドが警告なしで通過
|
||||
- [ ] 静的解析クリーン(高/中の問題なし)
|
||||
- [ ] コードがチーム規約に従う
|
||||
- [ ] PRにコメントアウトされたコードやTODOがない
|
||||
|
||||
### テスト
|
||||
- [ ] すべてのテストが通過
|
||||
- [ ] コードカバレッジ ≥ 80%
|
||||
- [ ] 実データベースとの統合テスト
|
||||
- [ ] セキュリティテストが通過
|
||||
- [ ] パフォーマンスが許容範囲内
|
||||
|
||||
### セキュリティ
|
||||
- [ ] 依存関係脆弱性なし
|
||||
- [ ] 認証/認可がテスト済み
|
||||
- [ ] 入力バリデーション完了
|
||||
- [ ] ソースコードにシークレットなし
|
||||
- [ ] セキュリティヘッダーが構成済み
|
||||
|
||||
### デプロイメント
|
||||
- [ ] ネイティブコンパイル成功
|
||||
- [ ] コンテナイメージがビルド可能
|
||||
- [ ] ヘルスチェックが正しく応答
|
||||
- [ ] ターゲット環境で構成が有効
|
||||
|
||||
## 自動検証スクリプト
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "=== フェーズ1: ビルド ==="
|
||||
mvn clean verify -DskipTests
|
||||
|
||||
echo "=== フェーズ2: 静的解析 ==="
|
||||
mvn checkstyle:check pmd:check spotbugs:check
|
||||
|
||||
echo "=== フェーズ3: テスト + カバレッジ ==="
|
||||
mvn test jacoco:report jacoco:check
|
||||
|
||||
echo "=== フェーズ4: セキュリティスキャン ==="
|
||||
mvn org.owasp:dependency-check-maven:check
|
||||
|
||||
echo "=== フェーズ5: ネイティブコンパイル ==="
|
||||
mvn package -Dnative -Dquarkus.native.container-build=true
|
||||
|
||||
echo "=== 全フェーズ完了 ==="
|
||||
echo "レポートを確認:"
|
||||
echo " - カバレッジ: target/site/jacoco/index.html"
|
||||
echo " - セキュリティ: target/dependency-check-report.html"
|
||||
echo " - ネイティブ: target/*-runner"
|
||||
```
|
||||
|
||||
## ベストプラクティス
|
||||
|
||||
- すべてのPR前に検証ループを実行
|
||||
- CI/CDパイプラインで自動化
|
||||
- 問題を即座に修正し、技術的負債を蓄積しない
|
||||
- カバレッジを80%以上に維持
|
||||
- 依存関係を定期的に更新
|
||||
- ネイティブコンパイルを定期的にテスト
|
||||
- パフォーマンストレンドを監視
|
||||
- 破壊的変更を文書化
|
||||
- セキュリティスキャン結果をレビュー
|
||||
- 各環境の構成を検証
|
||||
Reference in New Issue
Block a user