@ -19,6 +19,7 @@ package org.springframework.http.converter.protobuf;
import java.io.IOException ;
import java.io.IOException ;
import java.nio.charset.Charset ;
import java.nio.charset.Charset ;
import com.google.protobuf.ExtensionRegistry ;
import com.google.protobuf.Message ;
import com.google.protobuf.Message ;
import com.google.protobuf.util.JsonFormat ;
import com.google.protobuf.util.JsonFormat ;
import org.junit.Before ;
import org.junit.Before ;
@ -39,11 +40,15 @@ import static org.mockito.Mockito.*;
* @author Alex Antonov
* @author Alex Antonov
* @author Juergen Hoeller
* @author Juergen Hoeller
* @author Andreas Ahlenstorf
* @author Andreas Ahlenstorf
* @author Sebastien Deleuze
* /
* /
@SuppressWarnings ( "deprecation" )
public class ProtobufHttpMessageConverterTests {
public class ProtobufHttpMessageConverterTests {
private ProtobufHttpMessageConverter converter ;
private ProtobufHttpMessageConverter converter ;
private ExtensionRegistry extensionRegistry ;
private ExtensionRegistryInitializer registryInitializer ;
private ExtensionRegistryInitializer registryInitializer ;
private Msg testMsg ;
private Msg testMsg ;
@ -52,6 +57,7 @@ public class ProtobufHttpMessageConverterTests {
@Before
@Before
public void setup ( ) {
public void setup ( ) {
this . registryInitializer = mock ( ExtensionRegistryInitializer . class ) ;
this . registryInitializer = mock ( ExtensionRegistryInitializer . class ) ;
this . extensionRegistry = mock ( ExtensionRegistry . class ) ;
this . converter = new ProtobufHttpMessageConverter ( this . registryInitializer ) ;
this . converter = new ProtobufHttpMessageConverter ( this . registryInitializer ) ;
this . testMsg = Msg . newBuilder ( ) . setFoo ( "Foo" ) . setBlah ( SecondMsg . newBuilder ( ) . setBlah ( 123 ) . build ( ) ) . build ( ) ;
this . testMsg = Msg . newBuilder ( ) . setFoo ( "Foo" ) . setBlah ( SecondMsg . newBuilder ( ) . setBlah ( 123 ) . build ( ) ) . build ( ) ;
}
}
@ -62,9 +68,16 @@ public class ProtobufHttpMessageConverterTests {
verify ( this . registryInitializer , times ( 1 ) ) . initializeExtensionRegistry ( any ( ) ) ;
verify ( this . registryInitializer , times ( 1 ) ) . initializeExtensionRegistry ( any ( ) ) ;
}
}
@Test
public void extensionRegistryInitializerNull ( ) {
ProtobufHttpMessageConverter converter = new ProtobufHttpMessageConverter ( ( ExtensionRegistryInitializer ) null ) ;
assertNotNull ( converter . extensionRegistry ) ;
}
@Test
@Test
public void extensionRegistryNull ( ) {
public void extensionRegistryNull ( ) {
new ProtobufHttpMessageConverter ( null ) ;
ProtobufHttpMessageConverter converter = new ProtobufHttpMessageConverter ( ( ExtensionRegistry ) null ) ;
assertNotNull ( converter . extensionRegistry ) ;
}
}
@Test
@Test
@ -128,7 +141,7 @@ public class ProtobufHttpMessageConverterTests {
public void writeJsonWithGoogleProtobuf ( ) throws IOException {
public void writeJsonWithGoogleProtobuf ( ) throws IOException {
this . converter = new ProtobufHttpMessageConverter (
this . converter = new ProtobufHttpMessageConverter (
new ProtobufHttpMessageConverter . ProtobufJavaUtilSupport ( null , null ) ,
new ProtobufHttpMessageConverter . ProtobufJavaUtilSupport ( null , null ) ,
this . registryInitializer ) ;
this . extensionRegistry ) ;
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage ( ) ;
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage ( ) ;
MediaType contentType = MediaType . APPLICATION_JSON_UTF8 ;
MediaType contentType = MediaType . APPLICATION_JSON_UTF8 ;
this . converter . write ( this . testMsg , contentType , outputMessage ) ;
this . converter . write ( this . testMsg , contentType , outputMessage ) ;
@ -152,7 +165,7 @@ public class ProtobufHttpMessageConverterTests {
public void writeJsonWithJavaFormat ( ) throws IOException {
public void writeJsonWithJavaFormat ( ) throws IOException {
this . converter = new ProtobufHttpMessageConverter (
this . converter = new ProtobufHttpMessageConverter (
new ProtobufHttpMessageConverter . ProtobufJavaFormatSupport ( ) ,
new ProtobufHttpMessageConverter . ProtobufJavaFormatSupport ( ) ,
this . registryInitializer ) ;
this . extensionRegistry ) ;
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage ( ) ;
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage ( ) ;
MediaType contentType = MediaType . APPLICATION_JSON_UTF8 ;
MediaType contentType = MediaType . APPLICATION_JSON_UTF8 ;
this . converter . write ( this . testMsg , contentType , outputMessage ) ;
this . converter . write ( this . testMsg , contentType , outputMessage ) ;