DomaTransactionMiddleware implements Middleware<REQ, RES, REQ, RES> { @Override public RES handle(REQ req, MiddlewareChain<REQ, RES, ?, ?> chain) { if (req instanceof Routable) { Routable routable = (Routable) req; Method m = routable.getControllerMethod(); Transactional.TxType type= getTransactionType(m); if (type != null) { switch(type) { case REQUIRED: return tm.required(() -> chain.next(req)); case REQUIRES_NEW: return tm.requiresNew(() -> chain.next(req)); default: throw new MisconfigurationException("doma2.UNSUPPORTED_TX_TYPE", type); } } } return chain.next(req); }  @Override RES handle(REQ req, MiddlewareChain<REQ, RES, ?, ?> chain);  }
@Test public void configuration() { DomaTransactionMiddleware<HttpRequest, HttpResponse> middleware = new DomaTransactionMiddleware<>(); HttpRequest request = MixinUtils.mixin(new DefaultHttpRequest(), Routable.class); MiddlewareChain<HttpRequest, HttpResponse, ?, ?> chain = new DefaultMiddlewareChain<>(new AnyPredicate<>(), null, (Endpoint<HttpRequest, HttpResponse>) req -> builder(HttpResponse.of("hello")) .set(HttpResponse::setHeaders, Headers.of("Content-Type", "text/html")) .build()); assertThatThrownBy(() -> tryReflection(() -> { Method controllerMethod = TestController.class.getMethod("index"); Routable.class.cast(request).setControllerMethod(controllerMethod); return middleware.handle(request, chain); })).isExactlyInstanceOf(MisconfigurationException.class); }