Example usage for org.springframework.data.web WebTestUtils createApplicationContext

List of usage examples for org.springframework.data.web WebTestUtils createApplicationContext

Introduction

In this page you can find the example usage for org.springframework.data.web WebTestUtils createApplicationContext.

Prototype

public static WebApplicationContext createApplicationContext(Class<?>... configClasses) 

Source Link

Document

Creates a WebApplicationContext from the given configuration classes.

Usage

From source file:org.springframework.data.web.config.EnableSpringDataWebSupportIntegrationTests.java

@Test // DATACMNS-330
public void registersBasicBeanDefinitions() throws Exception {

    ApplicationContext context = WebTestUtils.createApplicationContext(SampleConfig.class);
    List<String> names = Arrays.asList(context.getBeanDefinitionNames());

    assertThat(names).contains("pageableResolver", "sortResolver");

    assertResolversRegistered(context, SortHandlerMethodArgumentResolver.class,
            PageableHandlerMethodArgumentResolver.class);
}

From source file:org.springframework.data.web.config.EnableSpringDataWebSupportIntegrationTests.java

@Test // DATACMNS-330
public void registersHateoasSpecificBeanDefinitions() throws Exception {

    ApplicationContext context = WebTestUtils.createApplicationContext(SampleConfig.class);
    List<String> names = Arrays.asList(context.getBeanDefinitionNames());

    assertThat(names).contains("pagedResourcesAssembler", "pagedResourcesAssemblerArgumentResolver");
    assertResolversRegistered(context, PagedResourcesAssemblerArgumentResolver.class);
}

From source file:org.springframework.data.web.config.EnableSpringDataWebSupportIntegrationTests.java

@Test // DATACMNS-475
public void registersJacksonSpecificBeanDefinitions() throws Exception {

    ApplicationContext context = WebTestUtils.createApplicationContext(SampleConfig.class);
    List<String> names = Arrays.asList(context.getBeanDefinitionNames());

    assertThat(names).contains("jacksonGeoModule");
}

From source file:org.springframework.data.web.config.EnableSpringDataWebSupportIntegrationTests.java

@Test // DATACMNS-626
public void registersFormatters() {

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

    ConversionService conversionService = context.getBean(ConversionService.class);

    assertThat(conversionService.canConvert(String.class, Distance.class)).isTrue();
    assertThat(conversionService.canConvert(Distance.class, String.class)).isTrue();
    assertThat(conversionService.canConvert(String.class, Point.class)).isTrue();
    assertThat(conversionService.canConvert(Point.class, String.class)).isTrue();
}

From source file:org.springframework.data.web.config.EnableSpringDataWebSupportIntegrationTests.java

@Test // DATACMNS-630
public void createsProxyForInterfaceBasedControllerMethodParameter() throws Exception {

    WebApplicationContext applicationContext = WebTestUtils.createApplicationContext(SampleConfig.class);
    MockMvc mvc = MockMvcBuilders.webAppContextSetup(applicationContext).build();

    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("/proxy");
    builder.queryParam("name", "Foo");
    builder.queryParam("shippingAddresses[0].zipCode", "ZIP");
    builder.queryParam("shippingAddresses[0].city", "City");
    builder.queryParam("billingAddress.zipCode", "ZIP");
    builder.queryParam("billingAddress.city", "City");
    builder.queryParam("date", "2014-01-11");

    mvc.perform(post(builder.build().toString())).//
            andExpect(status().isOk());/*w w  w  .  j av  a  2s .  c o m*/
}

From source file:org.springframework.data.web.config.EnableSpringDataWebSupportIntegrationTests.java

@Test // DATACMNS-660
public void picksUpWebConfigurationMixins() {

    ApplicationContext context = WebTestUtils.createApplicationContext(SampleConfig.class);
    List<String> names = Arrays.asList(context.getBeanDefinitionNames());

    assertThat(names).contains("sampleBean");
}

From source file:org.springframework.data.web.config.EnableSpringDataWebSupportIntegrationTests.java

@Test // DATACMNS-822
public void picksUpPageableResolverCustomizer() {

    ApplicationContext context = WebTestUtils.createApplicationContext(PageableResolverCustomizerConfig.class);
    List<String> names = Arrays.asList(context.getBeanDefinitionNames());
    PageableHandlerMethodArgumentResolver resolver = context
            .getBean(PageableHandlerMethodArgumentResolver.class);

    assertThat(names).contains("testPageableResolverCustomizer");
    assertThat((Integer) ReflectionTestUtils.getField(resolver, "maxPageSize")).isEqualTo(100);
}

From source file:org.springframework.data.web.config.EnableSpringDataWebSupportIntegrationTests.java

@Test // DATACMNS-822
public void picksUpSortResolverCustomizer() {

    ApplicationContext context = WebTestUtils.createApplicationContext(SortResolverCustomizerConfig.class);
    List<String> names = Arrays.asList(context.getBeanDefinitionNames());
    SortHandlerMethodArgumentResolver resolver = context.getBean(SortHandlerMethodArgumentResolver.class);

    assertThat(names).contains("testSortResolverCustomizer");
    assertThat((String) ReflectionTestUtils.getField(resolver, "sortParameter")).isEqualTo("foo");
}