Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
Related ticket GH-3054.
  • Loading branch information
odrotbohm committed Aug 27, 2024
1 parent e705327 commit d50d9b6
Showing 1 changed file with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.List;

import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
Expand Down Expand Up @@ -68,7 +67,7 @@ class EnableSpringDataWebSupportIntegrationTests {

@Configuration
@EnableWebMvc
@EnableSpringDataWebSupport(pageSerializationMode = EnableSpringDataWebSupport.PageSerializationMode.VIA_DTO)
@EnableSpringDataWebSupport
static class SampleConfig {

@Bean
Expand Down Expand Up @@ -292,35 +291,39 @@ void picksUpEntityPathResolverIfRegistered() {
.isEqualTo(CustomEntityPathResolver.resolver);
}

@Test // GH-3024
void registersSpringDataWebSettingsBean() {
@Test // GH-3024, GH-3054
void doesNotRegistersSpringDataWebSettingsBeanByDefault() {

ApplicationContext context = WebTestUtils.createApplicationContext(SampleConfig.class);

assertThatNoException().isThrownBy(() -> context.getBean(SpringDataWebSettings.class));
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> context.getBean(SpringDataWebSettings.class));
assertThatNoException().isThrownBy(() -> context.getBean(PageModule.class));
}

@Test // GH-3024
@Test // GH-3024, GH-3054
void usesDirectPageSerializationMode() throws Exception {

var applicationContext = WebTestUtils.createApplicationContext(PageSampleConfigWithDirect.class);
var context = WebTestUtils.createApplicationContext(PageSampleConfigWithDirect.class);

// SpringDataWebSettings shouldn't be registered if pageSerializationMode is default
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() -> applicationContext.getBean(SpringDataWebSettings.class));
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> context.getBean(SpringDataWebSettings.class));

var mvc = MockMvcBuilders.webAppContextSetup(applicationContext).build();
var mvc = MockMvcBuilders.webAppContextSetup(context).build();

mvc.perform(post("/page"))//
.andExpect(status().isOk()) //
.andExpect(jsonPath("$.pageable").exists());
}

@Test // GH-3024
@Test // GH-3024, GH-3054
void usesViaDtoPageSerializationMode() throws Exception {

var applicationContext = WebTestUtils.createApplicationContext(PageSampleConfigWithViaDto.class);
var mvc = MockMvcBuilders.webAppContextSetup(applicationContext).build();
var context = WebTestUtils.createApplicationContext(PageSampleConfigWithViaDto.class);

assertThatNoException().isThrownBy(() -> context.getBean(SpringDataWebSettings.class));

var mvc = MockMvcBuilders.webAppContextSetup(context).build();

mvc.perform(post("/page")) //
.andExpect(status().isOk()) //
Expand Down

0 comments on commit d50d9b6

Please sign in to comment.