use of com.google.protobuf.Type in project grpc-java by grpc.
the class ProtoUtilsTest method testJsonRoundtrip.
@Test
public void testJsonRoundtrip() throws Exception {
Marshaller<Type> marshaller = ProtoUtils.jsonMarshaller(Type.getDefaultInstance());
InputStream is = marshaller.stream(proto);
is = new ByteArrayInputStream(ByteStreams.toByteArray(is));
assertEquals(proto, marshaller.parse(is));
}
use of com.google.protobuf.Type in project grpc-java by grpc.
the class ProtoUtilsTest method testRoundtrip.
@Test
public void testRoundtrip() throws Exception {
Marshaller<Type> marshaller = ProtoUtils.marshaller(Type.getDefaultInstance());
InputStream is = marshaller.stream(proto);
is = new ByteArrayInputStream(ByteStreams.toByteArray(is));
assertEquals(proto, marshaller.parse(is));
}
use of com.google.protobuf.Type in project grpc-java by grpc.
the class ProtoUtilsTest method testJsonIoException.
@Test
public void testJsonIoException() throws Exception {
Marshaller<Type> marshaller = ProtoUtils.jsonMarshaller(Type.getDefaultInstance());
final IOException ioe = new IOException();
try {
marshaller.parse(new ByteArrayInputStream("{}".getBytes("UTF-8")) {
@Override
public void close() throws IOException {
throw ioe;
}
});
fail("Exception expected");
} catch (StatusRuntimeException ex) {
assertEquals(Status.Code.INTERNAL, ex.getStatus().getCode());
assertEquals(ioe, ex.getCause());
}
}
use of com.google.protobuf.Type in project grpc-java by grpc.
the class ProtoUtilsTest method testJsonInvalidProto.
@Test
public void testJsonInvalidProto() throws Exception {
Marshaller<Type> marshaller = ProtoUtils.jsonMarshaller(Type.getDefaultInstance());
try {
marshaller.parse(new ByteArrayInputStream("{\"\":3}".getBytes("UTF-8")));
fail("Expected exception");
} catch (StatusRuntimeException ex) {
assertEquals(Status.Code.INTERNAL, ex.getStatus().getCode());
assertNotNull(ex.getCause());
}
}
use of com.google.protobuf.Type in project grpc-java by grpc.
the class ProtoUtilsTest method testJsonRepresentation.
@Test
public void testJsonRepresentation() throws Exception {
Marshaller<Type> marshaller = ProtoUtils.jsonMarshaller(Type.getDefaultInstance());
InputStream is = marshaller.stream(proto);
String s = new String(ByteStreams.toByteArray(is), "UTF-8");
assertEquals("{\"name\":\"value\"}", s.replaceAll("\\s", ""));
}
Aggregations