Java Code Examples for org.springframework.protobuf.Msg#newBuilder()

The following examples show how to use org.springframework.protobuf.Msg#newBuilder() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProtobufHttpMessageConverterTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void writeJsonWithGoogleProtobuf() throws IOException {
	this.converter = new ProtobufHttpMessageConverter(
			new ProtobufHttpMessageConverter.ProtobufJavaUtilSupport(null, null),
			this.extensionRegistry);
	MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
	MediaType contentType = MediaType.APPLICATION_JSON;
	this.converter.write(this.testMsg, contentType, outputMessage);

	assertEquals(contentType, outputMessage.getHeaders().getContentType());

	final String body = outputMessage.getBodyAsString(Charset.forName("UTF-8"));
	assertFalse("body is empty", body.isEmpty());

	Msg.Builder builder = Msg.newBuilder();
	JsonFormat.parser().merge(body, builder);
	assertEquals(this.testMsg, builder.build());

	assertNull(outputMessage.getHeaders().getFirst(
			ProtobufHttpMessageConverter.X_PROTOBUF_MESSAGE_HEADER));
	assertNull(outputMessage.getHeaders().getFirst(
			ProtobufHttpMessageConverter.X_PROTOBUF_SCHEMA_HEADER));
}
 
Example 2
Source File: ProtobufHttpMessageConverterTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void writeJsonWithJavaFormat() throws IOException {
	this.converter = new ProtobufHttpMessageConverter(
			new ProtobufHttpMessageConverter.ProtobufJavaFormatSupport(),
			this.extensionRegistry);
	MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
	MediaType contentType = MediaType.APPLICATION_JSON_UTF8;
	this.converter.write(this.testMsg, contentType, outputMessage);

	assertEquals(contentType, outputMessage.getHeaders().getContentType());

	final String body = outputMessage.getBodyAsString(Charset.forName("UTF-8"));
	assertFalse("body is empty", body.isEmpty());

	Msg.Builder builder = Msg.newBuilder();
	JsonFormat.parser().merge(body, builder);
	assertEquals(this.testMsg, builder.build());

	assertNull(outputMessage.getHeaders().getFirst(
			ProtobufHttpMessageConverter.X_PROTOBUF_MESSAGE_HEADER));
	assertNull(outputMessage.getHeaders().getFirst(
			ProtobufHttpMessageConverter.X_PROTOBUF_SCHEMA_HEADER));
}
 
Example 3
Source File: ProtobufHttpMessageConverterTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void writeJsonWithGoogleProtobuf() throws IOException {
	this.converter = new ProtobufHttpMessageConverter(
			new ProtobufHttpMessageConverter.ProtobufJavaUtilSupport(null, null),
			this.extensionRegistry);
	MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
	MediaType contentType = MediaType.APPLICATION_JSON_UTF8;
	this.converter.write(this.testMsg, contentType, outputMessage);

	assertEquals(contentType, outputMessage.getHeaders().getContentType());

	final String body = outputMessage.getBodyAsString(Charset.forName("UTF-8"));
	assertFalse("body is empty", body.isEmpty());

	Msg.Builder builder = Msg.newBuilder();
	JsonFormat.parser().merge(body, builder);
	assertEquals(this.testMsg, builder.build());

	assertNull(outputMessage.getHeaders().getFirst(
			ProtobufHttpMessageConverter.X_PROTOBUF_MESSAGE_HEADER));
	assertNull(outputMessage.getHeaders().getFirst(
			ProtobufHttpMessageConverter.X_PROTOBUF_SCHEMA_HEADER));
}
 
Example 4
Source File: ProtobufHttpMessageConverterTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void writeJsonWithJavaFormat() throws IOException {
	this.converter = new ProtobufHttpMessageConverter(
			new ProtobufHttpMessageConverter.ProtobufJavaFormatSupport(),
			this.extensionRegistry);
	MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
	MediaType contentType = MediaType.APPLICATION_JSON_UTF8;
	this.converter.write(this.testMsg, contentType, outputMessage);

	assertEquals(contentType, outputMessage.getHeaders().getContentType());

	final String body = outputMessage.getBodyAsString(Charset.forName("UTF-8"));
	assertFalse("body is empty", body.isEmpty());

	Msg.Builder builder = Msg.newBuilder();
	JsonFormat.parser().merge(body, builder);
	assertEquals(this.testMsg, builder.build());

	assertNull(outputMessage.getHeaders().getFirst(
			ProtobufHttpMessageConverter.X_PROTOBUF_MESSAGE_HEADER));
	assertNull(outputMessage.getHeaders().getFirst(
			ProtobufHttpMessageConverter.X_PROTOBUF_SCHEMA_HEADER));
}