Search in sources :

Example 81 with DefaultConversionService

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

the class MimeTypeTests method withConversionService.

@Test
void withConversionService() {
    ConversionService conversionService = new DefaultConversionService();
    assertThat(conversionService.canConvert(String.class, MimeType.class)).isTrue();
    MimeType mimeType = MimeType.valueOf("application/xml");
    assertThat(conversionService.convert("application/xml", MimeType.class)).isEqualTo(mimeType);
}
Also used : ConversionService(org.springframework.core.convert.ConversionService) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) Test(org.junit.jupiter.api.Test)

Example 82 with DefaultConversionService

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

the class SingleColumnRowMapperTests method useCustomConversionService.

// SPR-16483
@Test
public void useCustomConversionService() throws SQLException {
    Timestamp timestamp = new Timestamp(0);
    DefaultConversionService myConversionService = new DefaultConversionService();
    myConversionService.addConverter(Timestamp.class, MyLocalDateTime.class, source -> new MyLocalDateTime(source.toLocalDateTime()));
    SingleColumnRowMapper<MyLocalDateTime> rowMapper = SingleColumnRowMapper.newInstance(MyLocalDateTime.class, myConversionService);
    ResultSet resultSet = mock(ResultSet.class);
    ResultSetMetaData metaData = mock(ResultSetMetaData.class);
    given(metaData.getColumnCount()).willReturn(1);
    given(resultSet.getMetaData()).willReturn(metaData);
    given(resultSet.getObject(1, MyLocalDateTime.class)).willThrow(new SQLFeatureNotSupportedException());
    given(resultSet.getObject(1)).willReturn(timestamp);
    MyLocalDateTime actualMyLocalDateTime = rowMapper.mapRow(resultSet, 1);
    assertThat(actualMyLocalDateTime).isNotNull();
    assertThat(actualMyLocalDateTime.value).isEqualTo(timestamp.toLocalDateTime());
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) ResultSet(java.sql.ResultSet) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) Timestamp(java.sql.Timestamp) Test(org.junit.jupiter.api.Test)

Example 83 with DefaultConversionService

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

the class ObjectToStringHttpMessageConverterTests method setup.

@BeforeEach
public void setup() {
    ConversionService conversionService = new DefaultConversionService();
    this.converter = new ObjectToStringHttpMessageConverter(conversionService);
    this.servletResponse = new MockHttpServletResponse();
    this.response = new ServletServerHttpResponse(this.servletResponse);
}
Also used : ConversionService(org.springframework.core.convert.ConversionService) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) ServletServerHttpResponse(org.springframework.http.server.ServletServerHttpResponse) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 84 with DefaultConversionService

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

the class ObjectToStringHttpMessageConverterTests method defaultCharsetModified.

@Test
public void defaultCharsetModified() throws IOException {
    ConversionService cs = new DefaultConversionService();
    ObjectToStringHttpMessageConverter converter = new ObjectToStringHttpMessageConverter(cs, StandardCharsets.UTF_16);
    converter.write((byte) 31, null, this.response);
    assertThat(this.servletResponse.getCharacterEncoding()).isEqualTo("UTF-16");
}
Also used : ConversionService(org.springframework.core.convert.ConversionService) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) Test(org.junit.jupiter.api.Test)

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