Search in sources :

Example 1 with RepositoryRestConfiguration

use of org.springframework.data.rest.core.config.RepositoryRestConfiguration in project spring-cloud-microservice-example by kbastani.

the class Application method main.

public static void main(String[] args) {
    ConfigurableApplicationContext ctx = SpringApplication.run(Application.class, args);
    RepositoryRestConfiguration restConfiguration = ctx.getBean("config", RepositoryRestConfiguration.class);
    restConfiguration.exposeIdsFor(User.class);
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) RepositoryRestConfiguration(org.springframework.data.rest.core.config.RepositoryRestConfiguration)

Example 2 with RepositoryRestConfiguration

use of org.springframework.data.rest.core.config.RepositoryRestConfiguration in project spring-boot by spring-projects.

the class RepositoryRestMvcAutoConfigurationTests method testWithCustomConfigurer.

@Test
public void testWithCustomConfigurer() {
    load(TestConfigurationWithConfigurer.class, "spring.data.rest.detection-strategy=visibility", "spring.data.rest.default-media-type:application/my-json");
    assertThat(this.context.getBean(RepositoryRestMvcConfiguration.class)).isNotNull();
    RepositoryRestConfiguration bean = this.context.getBean(RepositoryRestConfiguration.class);
    assertThat(bean.getRepositoryDetectionStrategy()).isEqualTo(RepositoryDetectionStrategies.ALL);
    assertThat(bean.getDefaultMediaType()).isEqualTo(MediaType.parseMediaType("application/my-custom-json"));
    assertThat(bean.getMaxPageSize()).isEqualTo(78);
}
Also used : RepositoryRestConfiguration(org.springframework.data.rest.core.config.RepositoryRestConfiguration) Test(org.junit.Test)

Example 3 with RepositoryRestConfiguration

use of org.springframework.data.rest.core.config.RepositoryRestConfiguration in project spring-boot by spring-projects.

the class RepositoryRestMvcAutoConfigurationTests method testWithCustomSettings.

@Test
public void testWithCustomSettings() throws Exception {
    load(TestConfiguration.class, "spring.data.rest.default-page-size:42", "spring.data.rest.max-page-size:78", "spring.data.rest.page-param-name:_page", "spring.data.rest.limit-param-name:_limit", "spring.data.rest.sort-param-name:_sort", "spring.data.rest.detection-strategy=visibility", "spring.data.rest.default-media-type:application/my-json", "spring.data.rest.return-body-on-create:false", "spring.data.rest.return-body-on-update:false", "spring.data.rest.enable-enum-translation:true");
    assertThat(this.context.getBean(RepositoryRestMvcConfiguration.class)).isNotNull();
    RepositoryRestConfiguration bean = this.context.getBean(RepositoryRestConfiguration.class);
    assertThat(bean.getDefaultPageSize()).isEqualTo(42);
    assertThat(bean.getMaxPageSize()).isEqualTo(78);
    assertThat(bean.getPageParamName()).isEqualTo("_page");
    assertThat(bean.getLimitParamName()).isEqualTo("_limit");
    assertThat(bean.getSortParamName()).isEqualTo("_sort");
    assertThat(bean.getRepositoryDetectionStrategy()).isEqualTo(RepositoryDetectionStrategies.VISIBILITY);
    assertThat(bean.getDefaultMediaType()).isEqualTo(MediaType.parseMediaType("application/my-json"));
    assertThat(bean.returnBodyOnCreate(null)).isFalse();
    assertThat(bean.returnBodyOnUpdate(null)).isFalse();
    assertThat(bean.isEnableEnumTranslation()).isTrue();
}
Also used : RepositoryRestConfiguration(org.springframework.data.rest.core.config.RepositoryRestConfiguration) Test(org.junit.Test)

Example 4 with RepositoryRestConfiguration

use of org.springframework.data.rest.core.config.RepositoryRestConfiguration in project spring-boot by spring-projects.

the class RepositoryRestMvcAutoConfigurationTests method backOffWithCustomConfiguration.

@Test
public void backOffWithCustomConfiguration() {
    load(TestConfigurationWithRestMvcConfig.class, "spring.data.rest.base-path:foo");
    assertThat(this.context.getBean(RepositoryRestMvcConfiguration.class)).isNotNull();
    RepositoryRestConfiguration bean = this.context.getBean(RepositoryRestConfiguration.class);
    assertThat(bean.getBaseUri()).isEqualTo(URI.create(""));
}
Also used : RepositoryRestConfiguration(org.springframework.data.rest.core.config.RepositoryRestConfiguration) Test(org.junit.Test)

Example 5 with RepositoryRestConfiguration

use of org.springframework.data.rest.core.config.RepositoryRestConfiguration in project spring-boot by spring-projects.

the class RepositoryRestMvcAutoConfigurationTests method testWithCustomBasePath.

@Test
public void testWithCustomBasePath() throws Exception {
    load(TestConfiguration.class, "spring.data.rest.base-path:foo");
    assertThat(this.context.getBean(RepositoryRestMvcConfiguration.class)).isNotNull();
    RepositoryRestConfiguration bean = this.context.getBean(RepositoryRestConfiguration.class);
    URI expectedUri = URI.create("/foo");
    assertThat(bean.getBaseUri()).as("Custom basePath not set").isEqualTo(expectedUri);
    BaseUri baseUri = this.context.getBean(BaseUri.class);
    assertThat(expectedUri).as("Custom basePath has not been applied to BaseUri bean").isEqualTo(baseUri.getUri());
}
Also used : RepositoryRestConfiguration(org.springframework.data.rest.core.config.RepositoryRestConfiguration) URI(java.net.URI) BaseUri(org.springframework.data.rest.webmvc.BaseUri) Test(org.junit.Test)

Aggregations

RepositoryRestConfiguration (org.springframework.data.rest.core.config.RepositoryRestConfiguration)5 Test (org.junit.Test)4 URI (java.net.URI)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 BaseUri (org.springframework.data.rest.webmvc.BaseUri)1