use of org.springframework.core.convert.support.DefaultConversionService in project spring-framework by spring-projects.
the class PathVariableMethodArgumentResolverTests method resolveArgumentWrappedAsOptional.
@Test
public void resolveArgumentWrappedAsOptional() throws Exception {
Map<String, String> uriTemplateVars = new HashMap<>();
uriTemplateVars.put("name", "value");
request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultConversionService());
WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);
@SuppressWarnings("unchecked") Optional<String> result = (Optional<String>) resolver.resolveArgument(paramOptional, mavContainer, webRequest, binderFactory);
assertEquals("PathVariable not resolved correctly", "value", result.get());
@SuppressWarnings("unchecked") Map<String, Object> pathVars = (Map<String, Object>) request.getAttribute(View.PATH_VARIABLES);
assertNotNull(pathVars);
assertEquals(1, pathVars.size());
assertEquals(Optional.of("value"), pathVars.get("name"));
}
use of org.springframework.core.convert.support.DefaultConversionService in project spring-framework by spring-projects.
the class ServletModelAttributeMethodProcessorTests method setup.
@Before
public void setup() throws Exception {
processor = new ServletModelAttributeMethodProcessor(false);
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultConversionService());
binderFactory = new ServletRequestDataBinderFactory(null, initializer);
mavContainer = new ModelAndViewContainer();
request = new MockHttpServletRequest();
webRequest = new ServletWebRequest(request);
Method method = getClass().getDeclaredMethod("modelAttribute", TestBean.class, TestBeanWithoutStringConstructor.class, Optional.class);
testBeanModelAttr = new MethodParameter(method, 0);
testBeanWithoutStringConstructorModelAttr = new MethodParameter(method, 1);
testBeanWithOptionalModelAttr = new MethodParameter(method, 2);
}
use of org.springframework.core.convert.support.DefaultConversionService in project spring-framework by spring-projects.
the class DataBinderTests method testOptionalProperty.
@Test
public void testOptionalProperty() {
OptionalHolder bean = new OptionalHolder();
DataBinder binder = new DataBinder(bean);
binder.setConversionService(new DefaultConversionService());
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("id", "1");
pvs.add("name", null);
binder.bind(pvs);
assertEquals("1", bean.getId());
assertFalse(bean.getName().isPresent());
pvs = new MutablePropertyValues();
pvs.add("id", "2");
pvs.add("name", "myName");
binder.bind(pvs);
assertEquals("2", bean.getId());
assertEquals("myName", bean.getName().get());
}
use of org.springframework.core.convert.support.DefaultConversionService in project spring-framework by spring-projects.
the class MimeTypeTests method withConversionService.
@Test
public void withConversionService() {
ConversionService conversionService = new DefaultConversionService();
assertTrue(conversionService.canConvert(String.class, MimeType.class));
MimeType mimeType = MimeType.valueOf("application/xml");
assertEquals(mimeType, conversionService.convert("application/xml", MimeType.class));
}
use of org.springframework.core.convert.support.DefaultConversionService in project spring-boot by spring-projects.
the class RelaxedDataBinderTests method testBindNestedMapOfEnumRelaxedNames.
@Test
public void testBindNestedMapOfEnumRelaxedNames() throws Exception {
this.conversionService = new DefaultConversionService();
TargetWithNestedMapOfEnum target = new TargetWithNestedMapOfEnum();
bind(target, "nested.the-other: bar\n" + "nested.that_other: 123");
assertThat(target.getNested().get(Bingo.THE_OTHER)).isEqualTo("bar");
assertThat(target.getNested().get(Bingo.THAT_OTHER)).isEqualTo("123");
}
Aggregations