Skip to content

Commit

Permalink
Polish "Add config prop for Spring Data Web's serialization mode"
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Sep 6, 2024
1 parent 81c903c commit ac4c24e
Showing 1 changed file with 5 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
import org.springframework.data.web.SortHandlerMethodArgumentResolver;
Expand Down Expand Up @@ -121,22 +119,14 @@ void customizePageSerializationModeViaConfigProps() {

@Test
void customizePageSerializationModeViaCustomBean() {
this.contextRunner.withUserConfiguration(AppConfiguration.class)
.withPropertyValues("spring.data.web.pageable.serialization-mode=VIA_DTO")
this.contextRunner
.withBean("customSpringDataWebSettings", SpringDataWebSettings.class,
() -> new SpringDataWebSettings(PageSerializationMode.VIA_DTO))
.run((context) -> {
assertThat(context).doesNotHaveBean("springDataWebSettings");
SpringDataWebSettings springDataWebSettings = context.getBean(SpringDataWebSettings.class);
assertThat(springDataWebSettings.pageSerializationMode()).isEqualTo(PageSerializationMode.DIRECT);
assertThat(springDataWebSettings.pageSerializationMode()).isEqualTo(PageSerializationMode.VIA_DTO);
});
}

@Configuration
static class AppConfiguration {

@Bean
SpringDataWebSettings springDataWebSettings() {
return new SpringDataWebSettings(PageSerializationMode.DIRECT);
}

}

}

0 comments on commit ac4c24e

Please sign in to comment.