DATAREST-654 - Added suport for internationalization of enum values.
RepositoryRestConfiguration now exposes an option to enable enum value serialization and a nested configuration object to tweak the details. If enabled, a Jackson serializer and deserializer is registered trying to resolve the enum values from the Spring Data REST resource bundle using the fully-qualified enum value name as key. If no explicitly configured value is configured a default translation is triggered that capitalizes the lowercased value name replacing the underscores with spaces (e.g. PAYMENT_EXPECTED -> Payment expected). This can be opted out of, of course. On the parsing side the deserializer will also consult the resourcebundle and default translation but also accepting the enum name as is (also opt-outable). Deprecated non-bean-style accessors for projection and metadata configuration on RepositoryRestConfiguration to make these options tweakable via Spring Boot application properties by default.
This commit is contained in:
@@ -17,10 +17,15 @@ package org.springframework.data.rest.webmvc.halbrowser;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.rest.core.config.EnumTranslationConfiguration;
|
||||
import org.springframework.data.rest.core.config.MetadataConfiguration;
|
||||
import org.springframework.data.rest.core.config.ProjectionDefinitionConfiguration;
|
||||
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
@@ -43,7 +48,9 @@ public class HalBrowserUnitTests {
|
||||
@Test
|
||||
public void createsContextRelativeRedirectForBrowser() throws Exception {
|
||||
|
||||
View view = new HalBrowser(new RepositoryRestConfiguration()).browser();
|
||||
RepositoryRestConfiguration configuration = new RepositoryRestConfiguration(new ProjectionDefinitionConfiguration(),
|
||||
new MetadataConfiguration(), mock(EnumTranslationConfiguration.class));
|
||||
View view = new HalBrowser(configuration).browser();
|
||||
|
||||
assertThat(view, is(instanceOf(RedirectView.class)));
|
||||
|
||||
@@ -53,6 +60,6 @@ public class HalBrowserUnitTests {
|
||||
|
||||
((AbstractView) view).render(Collections.<String, Object> emptyMap(), request, response);
|
||||
|
||||
assertThat(response.getHeader(HttpHeaders.LOCATION), startsWith("/context"));
|
||||
assertThat(response.getHeader(HttpHeaders.LOCATION), Matchers.startsWith("/context"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user