Rolle im AblaufBeweist, dass alle Framework-Adapter denselben fachlichen Vertrag erfüllen.
Damit ist der zentrale Pfad abgeschlossen; der Test-/Runner-Code und die vollständige Dateiliste darunter zeigen die übrigen Varianten.
package com.example.framework.deepdive;
import com.example.framework.deepdive.adapters.*;
import com.example.framework.deepdive.application.*;
import com.example.framework.deepdive.domain.*;
import com.example.framework.deepdive.frameworks.spring.*;
import com.example.framework.deepdive.frameworks.jakarta.*;
import com.example.framework.deepdive.frameworks.quarkus.*;
import com.example.framework.deepdive.frameworks.micronaut.*;
import java.time.Clock;
import java.util.List;
public final class FrameworkDeepDiveTestRunner {
public static void main(String[] args) {
sameUseCaseContractForEveryFramework(); duplicateRequestIsConflict(); declinedPaymentIsBusinessProblem();
System.out.println("RUN24_TESTS_OK");
}
static PlaceOrderUseCase newUseCase(ApprovingPaymentAdapter payment, InMemoryOrderRepository orders, InMemoryOutbox outbox) { return new PlaceOrderUseCase(orders, payment, outbox, new SimpleTransactionTemplate(), new OrderNumberGenerator(), Clock.systemUTC()); }
static void sameUseCaseContractForEveryFramework() {
var orders = new InMemoryOrderRepository(); var outbox = new InMemoryOutbox(); var uc = newUseCase(new ApprovingPaymentAdapter(), orders, outbox);
var spring = new SpringBootOrderController(uc).place(new com.example.framework.deepdive.frameworks.spring.PlaceOrderHttpRequest("REQ-S", "C-1", List.of(new com.example.framework.deepdive.frameworks.spring.OrderLineDto("SKU", 1, "10.00"))));
var jakarta = new JakartaOrderResource(uc).place(new com.example.framework.deepdive.frameworks.jakarta.PlaceOrderHttpRequest("REQ-J", "C-1", List.of(new com.example.framework.deepdive.frameworks.jakarta.OrderLineDto("SKU", 1, "10.00"))));
var quarkus = new QuarkusOrderResource(uc).place(new com.example.framework.deepdive.frameworks.quarkus.PlaceOrderHttpRequest("REQ-Q", "C-1", List.of(new com.example.framework.deepdive.frameworks.quarkus.OrderLineDto("SKU", 1, "10.00"))));
var micronaut = new MicronautOrderController(uc).place(new com.example.framework.deepdive.frameworks.micronaut.PlaceOrderHttpRequest("REQ-M", "C-1", List.of(new com.example.framework.deepdive.frameworks.micronaut.OrderLineDto("SKU", 1, "10.00"))));
assertEquals(201, spring.status()); assertEquals(201, jakarta.status()); assertEquals(201, quarkus.status()); assertEquals(201, micronaut.status()); assertEquals(4, orders.size()); assertEquals(4, outbox.pendingCount());
}
static void duplicateRequestIsConflict() {
var orders = new InMemoryOrderRepository(); var outbox = new InMemoryOutbox(); var uc = newUseCase(new ApprovingPaymentAdapter(), orders, outbox); var c = new SpringBootOrderController(uc);
var req = new com.example.framework.deepdive.frameworks.spring.PlaceOrderHttpRequest("REQ-DUP", "C-1", List.of(new com.example.framework.deepdive.frameworks.spring.OrderLineDto("SKU", 1, "10.00")));
assertEquals(201, c.place(req).status()); assertEquals(409, c.place(req).status());
}
static void declinedPaymentIsBusinessProblem() {
var orders = new InMemoryOrderRepository(); var outbox = new InMemoryOutbox(); var uc = new PlaceOrderUseCase(orders, new DecliningPaymentAdapter(), outbox, new SimpleTransactionTemplate(), new OrderNumberGenerator(), Clock.systemUTC());
var c = new SpringBootOrderController(uc); var r = c.place(new com.example.framework.deepdive.frameworks.spring.PlaceOrderHttpRequest("REQ-DEC", "C-1", List.of(new com.example.framework.deepdive.frameworks.spring.OrderLineDto("SKU", 1, "10.00"))));
assertEquals(422, r.status()); assertEquals(1, orders.size()); assertEquals(1, outbox.pendingCount());
}
static void assertEquals(Object e, Object a) { if (!e.equals(a)) throw new AssertionError("expected " + e + " but got " + a); }
}