|
20 | 20 | import static org.junit.jupiter.api.Assertions.assertThrows; |
21 | 21 |
|
22 | 22 | import com.google.api.gax.grpc.GrpcStatusCode; |
| 23 | +import com.google.api.gax.rpc.ApiException; |
23 | 24 | import com.google.api.gax.rpc.CancelledException; |
24 | 25 | import com.google.api.gax.rpc.StatusCode; |
25 | 26 | import com.google.rpc.Status; |
26 | 27 | import com.google.showcase.v1beta1.EchoClient; |
27 | 28 | import com.google.showcase.v1beta1.EchoRequest; |
28 | 29 | import com.google.showcase.v1beta1.EchoResponse; |
| 30 | +import com.google.showcase.v1beta1.FailEchoWithDetailsRequest; |
| 31 | +import com.google.showcase.v1beta1.PoetryError; |
29 | 32 | import com.google.showcase.v1beta1.it.util.TestClientInitializer; |
30 | 33 | import java.util.concurrent.TimeUnit; |
31 | 34 | import org.junit.jupiter.api.AfterAll; |
@@ -72,6 +75,31 @@ void testGrpc_serverResponseError_throwsException() { |
72 | 75 | assertThat(exception.getStatusCode().getCode()).isEqualTo(GrpcStatusCode.Code.CANCELLED); |
73 | 76 | } |
74 | 77 |
|
| 78 | + @Test |
| 79 | + void grpc_failEchoWithDetails() { |
| 80 | + FailEchoWithDetailsRequest request = |
| 81 | + FailEchoWithDetailsRequest.newBuilder().build(); |
| 82 | + try { |
| 83 | + grpcClient.failEchoWithDetails(request); |
| 84 | + } catch (ApiException e) { |
| 85 | + System.out.println(e.getErrorDetails().getMessage(PoetryError.class)); |
| 86 | + System.out.println(e.getErrorDetails().getLocalizedMessage()); |
| 87 | + System.out.println(e.getErrorDetails().getHelp()); |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + @Test |
| 92 | + void http_failEchoWithDetails() { |
| 93 | + FailEchoWithDetailsRequest request = |
| 94 | + FailEchoWithDetailsRequest.newBuilder().build(); |
| 95 | + try { |
| 96 | + httpjsonClient.failEchoWithDetails(request); |
| 97 | + } catch (ApiException e) { |
| 98 | + e.printStackTrace(); |
| 99 | + System.out.println(e.getErrorDetails()); |
| 100 | + } |
| 101 | + } |
| 102 | + |
75 | 103 | @Test |
76 | 104 | void testHttpJson_receiveContent() { |
77 | 105 | assertThat(echoHttpJson("http-echo?")).isEqualTo("http-echo?"); |
|
0 commit comments