use of io.grpc.Metadata in project grpc-java by grpc.
the class Http2ClientStreamTransportStateTest method transportTrailersReceived_missingStatusUsesHttpStatus.
@Test
public void transportTrailersReceived_missingStatusUsesHttpStatus() {
BaseTransportState state = new BaseTransportState();
state.setListener(mockListener);
Metadata trailers = new Metadata();
trailers.put(Metadata.Key.of(":status", Metadata.ASCII_STRING_MARSHALLER), "401");
trailers.put(Metadata.Key.of("content-type", Metadata.ASCII_STRING_MARSHALLER), "application/grpc");
state.transportTrailersReceived(trailers);
verify(mockListener, never()).headersRead(any(Metadata.class));
verify(mockListener).closed(statusCaptor.capture(), same(trailers));
assertEquals(Code.UNAUTHENTICATED, statusCaptor.getValue().getCode());
assertTrue(statusCaptor.getValue().getDescription().contains("401"));
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class Http2ClientStreamTransportStateTest method transportHeadersReceived_doesntRequire200.
@Test
public void transportHeadersReceived_doesntRequire200() {
BaseTransportState state = new BaseTransportState();
state.setListener(mockListener);
Metadata headers = new Metadata();
headers.put(Metadata.Key.of(":status", Metadata.ASCII_STRING_MARSHALLER), "500");
headers.put(Metadata.Key.of("content-type", Metadata.ASCII_STRING_MARSHALLER), "application/grpc");
state.transportHeadersReceived(headers);
verify(mockListener, never()).closed(any(Status.class), any(Metadata.class));
verify(mockListener).headersRead(headers);
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class Http2ClientStreamTransportStateTest method transportHeadersReceived_handles_1xx.
@Test
public void transportHeadersReceived_handles_1xx() {
BaseTransportState state = new BaseTransportState();
state.setListener(mockListener);
Metadata infoHeaders = new Metadata();
infoHeaders.put(Metadata.Key.of(":status", Metadata.ASCII_STRING_MARSHALLER), "100");
state.transportHeadersReceived(infoHeaders);
Metadata infoHeaders2 = new Metadata();
infoHeaders2.put(Metadata.Key.of(":status", Metadata.ASCII_STRING_MARSHALLER), "101");
state.transportHeadersReceived(infoHeaders2);
Metadata headers = new Metadata();
headers.put(Metadata.Key.of(":status", Metadata.ASCII_STRING_MARSHALLER), "200");
headers.put(Metadata.Key.of("content-type", Metadata.ASCII_STRING_MARSHALLER), "application/grpc");
state.transportHeadersReceived(headers);
verify(mockListener, never()).closed(any(Status.class), any(Metadata.class));
verify(mockListener).headersRead(headers);
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class Http2ClientStreamTransportStateTest method transportHeadersReceived_noHttpStatus.
@Test
public void transportHeadersReceived_noHttpStatus() {
BaseTransportState state = new BaseTransportState();
state.setListener(mockListener);
Metadata headers = new Metadata();
headers.put(Metadata.Key.of("content-type", Metadata.ASCII_STRING_MARSHALLER), "application/grpc");
state.transportHeadersReceived(headers);
state.transportDataReceived(ReadableBuffers.empty(), true);
verify(mockListener, never()).headersRead(any(Metadata.class));
verify(mockListener).closed(statusCaptor.capture(), same(headers));
assertEquals(Code.INTERNAL, statusCaptor.getValue().getCode());
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class Http2ClientStreamTransportStateTest method transportDataReceived_debugData.
@Test
public void transportDataReceived_debugData() {
BaseTransportState state = new BaseTransportState();
state.setListener(mockListener);
Metadata headers = new Metadata();
headers.put(Metadata.Key.of(":status", Metadata.ASCII_STRING_MARSHALLER), "200");
headers.put(Metadata.Key.of("content-type", Metadata.ASCII_STRING_MARSHALLER), "text/html");
state.transportHeadersReceived(headers);
String testString = "This is a test";
state.transportDataReceived(ReadableBuffers.wrap(testString.getBytes(US_ASCII)), true);
verify(mockListener).closed(statusCaptor.capture(), same(headers));
assertTrue(statusCaptor.getValue().getDescription().contains(testString));
}
Aggregations