Java Code Examples for org.springframework.web.bind.support.WebBindingInitializer#initBinder()

The following examples show how to use org.springframework.web.bind.support.WebBindingInitializer#initBinder() . 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: WebFluxConfigurationSupportTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void requestMappingHandlerAdapter() throws Exception {
	ApplicationContext context = loadConfig(WebFluxConfig.class);

	String name = "requestMappingHandlerAdapter";
	RequestMappingHandlerAdapter adapter = context.getBean(name, RequestMappingHandlerAdapter.class);
	assertNotNull(adapter);

	List<HttpMessageReader<?>> readers = adapter.getMessageReaders();
	assertEquals(13, readers.size());

	ResolvableType multiValueMapType = forClassWithGenerics(MultiValueMap.class, String.class, String.class);

	assertHasMessageReader(readers, forClass(byte[].class), APPLICATION_OCTET_STREAM);
	assertHasMessageReader(readers, forClass(ByteBuffer.class), APPLICATION_OCTET_STREAM);
	assertHasMessageReader(readers, forClass(String.class), TEXT_PLAIN);
	assertHasMessageReader(readers, forClass(Resource.class), IMAGE_PNG);
	assertHasMessageReader(readers, forClass(Message.class), new MediaType("application", "x-protobuf"));
	assertHasMessageReader(readers, multiValueMapType, APPLICATION_FORM_URLENCODED);
	assertHasMessageReader(readers, forClass(TestBean.class), APPLICATION_XML);
	assertHasMessageReader(readers, forClass(TestBean.class), APPLICATION_JSON);
	assertHasMessageReader(readers, forClass(TestBean.class), new MediaType("application", "x-jackson-smile"));
	assertHasMessageReader(readers, forClass(TestBean.class), null);

	WebBindingInitializer bindingInitializer = adapter.getWebBindingInitializer();
	assertNotNull(bindingInitializer);
	WebExchangeDataBinder binder = new WebExchangeDataBinder(new Object());
	bindingInitializer.initBinder(binder);

	name = "webFluxConversionService";
	ConversionService service = context.getBean(name, ConversionService.class);
	assertSame(service, binder.getConversionService());

	name = "webFluxValidator";
	Validator validator = context.getBean(name, Validator.class);
	assertSame(validator, binder.getValidator());
}
 
Example 2
Source File: WebFluxConfigurationSupportTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void requestMappingHandlerAdapter() throws Exception {
	ApplicationContext context = loadConfig(WebFluxConfig.class);

	String name = "requestMappingHandlerAdapter";
	RequestMappingHandlerAdapter adapter = context.getBean(name, RequestMappingHandlerAdapter.class);
	assertNotNull(adapter);

	List<HttpMessageReader<?>> readers = adapter.getMessageReaders();
	assertEquals(13, readers.size());

	ResolvableType multiValueMapType = forClassWithGenerics(MultiValueMap.class, String.class, String.class);

	assertHasMessageReader(readers, forClass(byte[].class), APPLICATION_OCTET_STREAM);
	assertHasMessageReader(readers, forClass(ByteBuffer.class), APPLICATION_OCTET_STREAM);
	assertHasMessageReader(readers, forClass(String.class), TEXT_PLAIN);
	assertHasMessageReader(readers, forClass(Resource.class), IMAGE_PNG);
	assertHasMessageReader(readers, forClass(Message.class), new MediaType("application", "x-protobuf"));
	assertHasMessageReader(readers, multiValueMapType, APPLICATION_FORM_URLENCODED);
	assertHasMessageReader(readers, forClass(TestBean.class), APPLICATION_XML);
	assertHasMessageReader(readers, forClass(TestBean.class), APPLICATION_JSON);
	assertHasMessageReader(readers, forClass(TestBean.class), new MediaType("application", "x-jackson-smile"));
	assertHasMessageReader(readers, forClass(TestBean.class), null);

	WebBindingInitializer bindingInitializer = adapter.getWebBindingInitializer();
	assertNotNull(bindingInitializer);
	WebExchangeDataBinder binder = new WebExchangeDataBinder(new Object());
	bindingInitializer.initBinder(binder);

	name = "webFluxConversionService";
	ConversionService service = context.getBean(name, ConversionService.class);
	assertSame(service, binder.getConversionService());

	name = "webFluxValidator";
	Validator validator = context.getBean(name, Validator.class);
	assertSame(validator, binder.getValidator());
}