Search in sources :

Example 71 with DefaultConversionService

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);
    assertThat(result.get()).as("PathVariable not resolved correctly").isEqualTo("value");
    @SuppressWarnings("unchecked") Map<String, Object> pathVars = (Map<String, Object>) request.getAttribute(View.PATH_VARIABLES);
    assertThat(pathVars).isNotNull();
    assertThat(pathVars.size()).isEqualTo(1);
    assertThat(pathVars.get("name")).isEqualTo(Optional.of("value"));
}
Also used : Optional(java.util.Optional) HashMap(java.util.HashMap) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) WebDataBinderFactory(org.springframework.web.bind.support.WebDataBinderFactory) ConfigurableWebBindingInitializer(org.springframework.web.bind.support.ConfigurableWebBindingInitializer) DefaultDataBinderFactory(org.springframework.web.bind.support.DefaultDataBinderFactory) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 72 with DefaultConversionService

use of org.springframework.core.convert.support.DefaultConversionService in project spring-framework by spring-projects.

the class AbstractPropertyResolver method getConversionService.

@Override
public ConfigurableConversionService getConversionService() {
    // Need to provide an independent DefaultConversionService, not the
    // shared DefaultConversionService used by PropertySourcesPropertyResolver.
    ConfigurableConversionService cs = this.conversionService;
    if (cs == null) {
        synchronized (this) {
            cs = this.conversionService;
            if (cs == null) {
                cs = new DefaultConversionService();
                this.conversionService = cs;
            }
        }
    }
    return cs;
}
Also used : ConfigurableConversionService(org.springframework.core.convert.support.ConfigurableConversionService) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService)

Example 73 with DefaultConversionService

use of org.springframework.core.convert.support.DefaultConversionService in project spring-framework by spring-projects.

the class HeaderMethodArgumentResolverTests method setup.

@BeforeEach
@SuppressWarnings("resource")
public void setup() {
    GenericApplicationContext context = new GenericApplicationContext();
    context.refresh();
    this.resolver = new HeaderMethodArgumentResolver(new DefaultConversionService(), context.getBeanFactory());
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 74 with DefaultConversionService

use of org.springframework.core.convert.support.DefaultConversionService in project spring-framework by spring-projects.

the class HeaderMethodArgumentResolverTests method setup.

@BeforeEach
@SuppressWarnings("resource")
public void setup() {
    GenericApplicationContext context = new GenericApplicationContext();
    context.refresh();
    this.resolver = new HeaderMethodArgumentResolver(new DefaultConversionService(), context.getBeanFactory());
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 75 with DefaultConversionService

use of org.springframework.core.convert.support.DefaultConversionService in project spring-framework by spring-projects.

the class ServletModelAttributeMethodProcessorTests method setup.

@BeforeEach
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);
}
Also used : ConfigurableWebBindingInitializer(org.springframework.web.bind.support.ConfigurableWebBindingInitializer) ModelAndViewContainer(org.springframework.web.method.support.ModelAndViewContainer) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) Method(java.lang.reflect.Method) MethodParameter(org.springframework.core.MethodParameter) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

DefaultConversionService (org.springframework.core.convert.support.DefaultConversionService)84 Test (org.junit.jupiter.api.Test)37 Test (org.junit.Test)29 ConversionService (org.springframework.core.convert.ConversionService)13 MethodParameter (org.springframework.core.MethodParameter)12 GenericConversionService (org.springframework.core.convert.support.GenericConversionService)12 ConfigurableWebBindingInitializer (org.springframework.web.bind.support.ConfigurableWebBindingInitializer)12 WebDataBinderFactory (org.springframework.web.bind.support.WebDataBinderFactory)12 DefaultDataBinderFactory (org.springframework.web.bind.support.DefaultDataBinderFactory)11 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)9 RequestParam (org.springframework.web.bind.annotation.RequestParam)9 Optional (java.util.Optional)8 BeforeEach (org.junit.jupiter.api.BeforeEach)6 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)6 HashMap (java.util.HashMap)5 DefaultDatatypeChannelMessageConverter (org.springframework.integration.support.converter.DefaultDatatypeChannelMessageConverter)5 GenericMessage (org.springframework.messaging.support.GenericMessage)5 Before (org.junit.Before)4 ContentConverter (com.synopsys.integration.alert.common.ContentConverter)3 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)3