@Test public void shouldSupplyHandlerForCompletionStageResponseAndHandleClientCall() throws Exception { UnaryMethodHandlerSupplier supplier = new UnaryMethodHandlerSupplier(); AnnotatedMethod method = getMethod("completionStageResponse", String.class); UnaryService service = mock(UnaryService.class); when(service.completionStageResponse(anyString())).thenReturn(CompletableFuture.completedFuture(19L)); MethodHandler<String, Long> handler = supplier.get("foo", method, () -> service); assertThat(handler, is(notNullValue())); MethodHandler.UnaryClient client = mock(MethodHandler.UnaryClient.class); when(client.unary(anyString(), any())).thenReturn(CompletableFuture.completedFuture("done!")); CompletionStage<Object> result = (CompletionStage<Object>) handler.unary(new Object[]{"bar"}, client); assertThat(result.toCompletableFuture().get(), is("done!")); verify(client).unary(eq("foo"), eq("bar")); }
@Override public <ReqT, RespT> MethodHandler<ReqT, RespT> get(String methodName, AnnotatedMethod method, Supplier<?> instance) { if (!isRequiredMethodType(method)) { throw new IllegalArgumentException("Method not annotated as a unary method: " + method); } CallType type = determineCallType(method); MethodHandler<ReqT, RespT> handler; switch (type) { case requestResponse: handler = new RequestResponse<>(methodName, method, instance); break; case responseOnly: handler = new ResponseOnly<>(methodName, method, instance); break; case requestNoResponse: handler = new RequestNoResponse<>(methodName, method, instance); break; case noRequestNoResponse: handler = new NoRequestNoResponse<>(methodName, method, instance); break; case futureResponse: handler = new FutureResponse<>(methodName, method, instance); break; case futureResponseNoRequest: handler = new FutureResponseNoRequest<>(methodName, method, instance); break; case unary: handler = new Unary<>(methodName, method, instance); break; case unaryRequest: handler = new UnaryNoRequest<>(methodName, method, instance); break; case unaryFuture: handler = new UnaryFuture<>(methodName, method, instance); break; case unaryFutureNoRequest: handler = new UnaryFutureNoRequest<>(methodName, method, instance); break; case unknown: default: throw new IllegalArgumentException("Not a supported unary method signature: " + method); } return handler; }
UnaryMethodHandlerSupplier extends AbstractMethodHandlerSupplier { @Override public <ReqT, RespT> MethodHandler<ReqT, RespT> get(String methodName, AnnotatedMethod method, Supplier<?> instance) { if (!isRequiredMethodType(method)) { throw new IllegalArgumentException("Method not annotated as a unary method: " + method); } CallType type = determineCallType(method); MethodHandler<ReqT, RespT> handler; switch (type) { case requestResponse: handler = new RequestResponse<>(methodName, method, instance); break; case responseOnly: handler = new ResponseOnly<>(methodName, method, instance); break; case requestNoResponse: handler = new RequestNoResponse<>(methodName, method, instance); break; case noRequestNoResponse: handler = new NoRequestNoResponse<>(methodName, method, instance); break; case futureResponse: handler = new FutureResponse<>(methodName, method, instance); break; case futureResponseNoRequest: handler = new FutureResponseNoRequest<>(methodName, method, instance); break; case unary: handler = new Unary<>(methodName, method, instance); break; case unaryRequest: handler = new UnaryNoRequest<>(methodName, method, instance); break; case unaryFuture: handler = new UnaryFuture<>(methodName, method, instance); break; case unaryFutureNoRequest: handler = new UnaryFutureNoRequest<>(methodName, method, instance); break; case unknown: default: throw new IllegalArgumentException("Not a supported unary method signature: " + method); } return handler; } }
UnaryMethodHandlerSupplier extends AbstractMethodHandlerSupplier { @Override public <ReqT, RespT> MethodHandler<ReqT, RespT> get(String methodName, AnnotatedMethod method, Supplier<?> instance) { if (!isRequiredMethodType(method)) { throw new IllegalArgumentException("Method not annotated as a unary method: " + method); } CallType type = determineCallType(method); MethodHandler<ReqT, RespT> handler; switch (type) { case requestResponse: handler = new RequestResponse<>(methodName, method, instance); break; case responseOnly: handler = new ResponseOnly<>(methodName, method, instance); break; case requestNoResponse: handler = new RequestNoResponse<>(methodName, method, instance); break; case noRequestNoResponse: handler = new NoRequestNoResponse<>(methodName, method, instance); break; case futureResponse: handler = new FutureResponse<>(methodName, method, instance); break; case futureResponseNoRequest: handler = new FutureResponseNoRequest<>(methodName, method, instance); break; case unary: handler = new Unary<>(methodName, method, instance); break; case unaryRequest: handler = new UnaryNoRequest<>(methodName, method, instance); break; case unaryFuture: handler = new UnaryFuture<>(methodName, method, instance); break; case unaryFutureNoRequest: handler = new UnaryFutureNoRequest<>(methodName, method, instance); break; case unknown: default: throw new IllegalArgumentException("Not a supported unary method signature: " + method); } return handler; } UnaryMethodHandlerSupplier(); }
UnaryMethodHandlerSupplier extends AbstractMethodHandlerSupplier { @Override public <ReqT, RespT> MethodHandler<ReqT, RespT> get(String methodName, AnnotatedMethod method, Supplier<?> instance) { if (!isRequiredMethodType(method)) { throw new IllegalArgumentException("Method not annotated as a unary method: " + method); } CallType type = determineCallType(method); MethodHandler<ReqT, RespT> handler; switch (type) { case requestResponse: handler = new RequestResponse<>(methodName, method, instance); break; case responseOnly: handler = new ResponseOnly<>(methodName, method, instance); break; case requestNoResponse: handler = new RequestNoResponse<>(methodName, method, instance); break; case noRequestNoResponse: handler = new NoRequestNoResponse<>(methodName, method, instance); break; case futureResponse: handler = new FutureResponse<>(methodName, method, instance); break; case futureResponseNoRequest: handler = new FutureResponseNoRequest<>(methodName, method, instance); break; case unary: handler = new Unary<>(methodName, method, instance); break; case unaryRequest: handler = new UnaryNoRequest<>(methodName, method, instance); break; case unaryFuture: handler = new UnaryFuture<>(methodName, method, instance); break; case unaryFutureNoRequest: handler = new UnaryFutureNoRequest<>(methodName, method, instance); break; case unknown: default: throw new IllegalArgumentException("Not a supported unary method signature: " + method); } return handler; } UnaryMethodHandlerSupplier(); @Override boolean supplies(AnnotatedMethod method); @Override MethodHandler<ReqT, RespT> get(String methodName, AnnotatedMethod method, Supplier<?> instance); }
UnaryMethodHandlerSupplier extends AbstractMethodHandlerSupplier { @Override public <ReqT, RespT> MethodHandler<ReqT, RespT> get(String methodName, AnnotatedMethod method, Supplier<?> instance) { if (!isRequiredMethodType(method)) { throw new IllegalArgumentException("Method not annotated as a unary method: " + method); } CallType type = determineCallType(method); MethodHandler<ReqT, RespT> handler; switch (type) { case requestResponse: handler = new RequestResponse<>(methodName, method, instance); break; case responseOnly: handler = new ResponseOnly<>(methodName, method, instance); break; case requestNoResponse: handler = new RequestNoResponse<>(methodName, method, instance); break; case noRequestNoResponse: handler = new NoRequestNoResponse<>(methodName, method, instance); break; case futureResponse: handler = new FutureResponse<>(methodName, method, instance); break; case futureResponseNoRequest: handler = new FutureResponseNoRequest<>(methodName, method, instance); break; case unary: handler = new Unary<>(methodName, method, instance); break; case unaryRequest: handler = new UnaryNoRequest<>(methodName, method, instance); break; case unaryFuture: handler = new UnaryFuture<>(methodName, method, instance); break; case unaryFutureNoRequest: handler = new UnaryFutureNoRequest<>(methodName, method, instance); break; case unknown: default: throw new IllegalArgumentException("Not a supported unary method signature: " + method); } return handler; } UnaryMethodHandlerSupplier(); @Override boolean supplies(AnnotatedMethod method); @Override MethodHandler<ReqT, RespT> get(String methodName, AnnotatedMethod method, Supplier<?> instance);  }