1717
1818import io .grpc .ManagedChannel ;
1919import io .grpc .ManagedChannelBuilder ;
20+ import io .grpc .Status ;
21+ import io .grpc .StatusRuntimeException ;
2022import io .qameta .allure .model .Attachment ;
2123import io .qameta .allure .model .StepResult ;
2224import io .qameta .allure .test .AllureResults ;
3335import static io .qameta .allure .test .RunUtils .runWithinTestContext ;
3436import static java .util .Arrays .asList ;
3537import static org .assertj .core .api .Assertions .assertThat ;
38+ import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
3639import static org .grpcmock .GrpcMock .serverStreamingMethod ;
3740import static org .grpcmock .GrpcMock .unaryMethod ;
3841
@@ -111,6 +114,24 @@ void shouldCreateResponseAttachmentForServerStreamingResponse() {
111114 .contains ("gRPC response (collection of elements from Server stream)" );
112115 }
113116
117+ @ Test
118+ void shouldCreateResponseAttachmentOnStatusException () {
119+ final Status status = Status .NOT_FOUND ;
120+ GrpcMock .stubFor (unaryMethod (TestServiceGrpc .getCalculateMethod ())
121+ .willReturn (status ));
122+
123+ final Request request = Request .newBuilder ()
124+ .setTopic ("2" )
125+ .build ();
126+
127+ final AllureResults results = executeException (request );
128+
129+ assertThat (results .getTestResults ().get (0 ).getSteps ())
130+ .flatExtracting (StepResult ::getAttachments )
131+ .extracting (Attachment ::getName )
132+ .contains (status .getCode ().name ());
133+ }
134+
114135 protected final AllureResults execute (final Request request ) {
115136 return runWithinTestContext (() -> {
116137 try {
@@ -121,7 +142,6 @@ protected final AllureResults execute(final Request request) {
121142 }
122143 });
123144 }
124-
125145 protected final AllureResults executeStreaming (final Request request ) {
126146 return runWithinTestContext (() -> {
127147 try {
@@ -134,4 +154,10 @@ protected final AllureResults executeStreaming(final Request request) {
134154 }
135155 });
136156 }
157+
158+ protected final AllureResults executeException (final Request request ) {
159+ return runWithinTestContext (() -> {
160+ assertThatExceptionOfType (StatusRuntimeException .class ).isThrownBy (() -> blockingStub .calculate (request ));
161+ });
162+ }
137163}
0 commit comments