|
| 1 | +package io.quarkus.grpc.client.interceptors; |
| 2 | + |
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 5 | + |
| 6 | +import java.util.List; |
| 7 | + |
| 8 | +import org.jboss.shrinkwrap.api.ShrinkWrap; |
| 9 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; |
| 10 | +import org.junit.jupiter.api.Test; |
| 11 | +import org.junit.jupiter.api.extension.RegisterExtension; |
| 12 | +import org.slf4j.Logger; |
| 13 | +import org.slf4j.LoggerFactory; |
| 14 | + |
| 15 | +import io.grpc.examples.helloworld.Greeter; |
| 16 | +import io.grpc.examples.helloworld.GreeterBean; |
| 17 | +import io.grpc.examples.helloworld.GreeterGrpc; |
| 18 | +import io.grpc.examples.helloworld.HelloReply; |
| 19 | +import io.grpc.examples.helloworld.HelloReplyOrBuilder; |
| 20 | +import io.grpc.examples.helloworld.HelloRequest; |
| 21 | +import io.grpc.examples.helloworld.HelloRequestOrBuilder; |
| 22 | +import io.grpc.examples.helloworld.MutinyGreeterGrpc; |
| 23 | +import io.quarkus.grpc.GrpcClient; |
| 24 | +import io.quarkus.grpc.RegisterClientInterceptor; |
| 25 | +import io.quarkus.grpc.server.services.MutinyHelloService; |
| 26 | +import io.quarkus.test.QuarkusUnitTest; |
| 27 | + |
| 28 | +public class ClientInterceptorConstructorRegistrationTest { |
| 29 | + |
| 30 | + @RegisterExtension |
| 31 | + static final QuarkusUnitTest config = new QuarkusUnitTest().setArchiveProducer( |
| 32 | + () -> ShrinkWrap.create(JavaArchive.class) |
| 33 | + .addClasses(MutinyHelloService.class, MyThirdClientInterceptor.class, MyLastClientInterceptor.class, |
| 34 | + Calls.class, |
| 35 | + GreeterGrpc.class, Greeter.class, GreeterBean.class, HelloRequest.class, HelloReply.class, |
| 36 | + MutinyGreeterGrpc.class, |
| 37 | + HelloRequestOrBuilder.class, HelloReplyOrBuilder.class)) |
| 38 | + .withConfigurationResource("hello-config.properties"); |
| 39 | + private static final Logger log = LoggerFactory.getLogger(ClientInterceptorConstructorRegistrationTest.class); |
| 40 | + |
| 41 | + private GreeterGrpc.GreeterBlockingStub client; |
| 42 | + |
| 43 | + public ClientInterceptorConstructorRegistrationTest( |
| 44 | + @RegisterClientInterceptor(MyLastClientInterceptor.class) @RegisterClientInterceptor(MyThirdClientInterceptor.class) @GrpcClient("hello-service") GreeterGrpc.GreeterBlockingStub client) { |
| 45 | + this.client = client; |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + public void testInterceptorRegistration() { |
| 50 | + Calls.LIST.clear(); |
| 51 | + |
| 52 | + HelloReply reply = client |
| 53 | + .sayHello(HelloRequest.newBuilder().setName("neo").build()); |
| 54 | + assertThat(reply.getMessage()).isEqualTo("Hello neo"); |
| 55 | + |
| 56 | + List<String> calls = Calls.LIST; |
| 57 | + assertEquals(2, calls.size()); |
| 58 | + assertEquals(MyThirdClientInterceptor.class.getName(), calls.get(0)); |
| 59 | + assertEquals(MyLastClientInterceptor.class.getName(), calls.get(1)); |
| 60 | + } |
| 61 | +} |
0 commit comments