From 9c56c3f21703f7c1b63ff98b57d620a6fe203fb7 Mon Sep 17 00:00:00 2001 From: Greg Turnquist Date: Thu, 8 Aug 2019 10:26:53 -0500 Subject: [PATCH] DATAREST-1421 - Deprecate ALPS_JSON and ALPS_JSON_VALUE. Instead, use Spring HATEAOS's MediaTypes.ALPS_JSON and ALPS_JSON_VALUE. --- .../data/rest/tests/CommonWebTests.java | 2 +- .../alps/AlpsControllerIntegrationTests.java | 18 +++++++++--------- .../webmvc/jpa/ProfileIntegrationTests.java | 5 +++-- .../data/rest/webmvc/RestMediaTypes.java | 11 ++++++++++- .../data/rest/webmvc/alps/AlpsController.java | 6 +++--- .../alps/AlpsJsonHttpMessageConverter.java | 4 ++-- 6 files changed, 28 insertions(+), 18 deletions(-) diff --git a/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/CommonWebTests.java b/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/CommonWebTests.java index c6f321e10..99fa17463 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/CommonWebTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/CommonWebTests.java @@ -89,7 +89,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests { client.follow(profileLink, RestMediaTypes.SCHEMA_JSON).andExpect(status().is2xxSuccessful()); // ALPS - client.follow(profileLink, RestMediaTypes.ALPS_JSON).andExpect(status().is2xxSuccessful()); + client.follow(profileLink, MediaTypes.ALPS_JSON).andExpect(status().is2xxSuccessful()); } } diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/alps/AlpsControllerIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/alps/AlpsControllerIntegrationTests.java index 358f2ba31..0a7b197db 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/alps/AlpsControllerIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/alps/AlpsControllerIntegrationTests.java @@ -21,8 +21,6 @@ import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertThat; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -import net.minidev.json.JSONArray; - import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -33,14 +31,14 @@ import org.springframework.data.rest.core.config.RepositoryRestConfiguration; import org.springframework.data.rest.tests.AbstractControllerIntegrationTests; import org.springframework.data.rest.tests.TestMvcClient; import org.springframework.data.rest.webmvc.ProfileController; -import org.springframework.data.rest.webmvc.RestMediaTypes; import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer; import org.springframework.data.rest.webmvc.jpa.Item; import org.springframework.data.rest.webmvc.jpa.JpaRepositoryConfig; import org.springframework.hateoas.Link; +import org.springframework.hateoas.MediaTypes; +import org.springframework.hateoas.client.JsonPathLinkDiscoverer; import org.springframework.hateoas.client.LinkDiscoverer; import org.springframework.hateoas.client.LinkDiscoverers; -import org.springframework.hateoas.client.JsonPathLinkDiscoverer; import org.springframework.http.MediaType; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.web.WebAppConfiguration; @@ -50,6 +48,8 @@ import org.springframework.web.context.WebApplicationContext; import com.jayway.jsonpath.JsonPath; +import net.minidev.json.JSONArray; + /** * Integration tests for {@link AlpsController}. * @@ -99,7 +99,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio Link profileLink = client.discoverUnique("profile"); Link peopleLink = client.discoverUnique(profileLink, "people", MediaType.ALL); - client.follow(peopleLink, RestMediaTypes.ALPS_JSON)// + client.follow(peopleLink, MediaTypes.ALPS_JSON)// .andExpect(jsonPath("$.alps.version").value("1.0"))// .andExpect(jsonPath("$.alps.descriptor[*].name", hasItems("people", "person"))); } @@ -122,7 +122,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio Link profileLink = client.discoverUnique("profile"); Link itemsLink = client.discoverUnique(profileLink, "items", MediaType.ALL); - client.follow(itemsLink, RestMediaTypes.ALPS_JSON)// + client.follow(itemsLink, MediaTypes.ALPS_JSON)// // Exposes standard property .andExpect(jsonPath("$.alps.descriptor[*].descriptor[*].name", hasItems("name"))) // Does not expose explicitly @JsonIgnored property @@ -139,7 +139,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio assertThat(itemsLink).isNotNull(); - String result = client.follow(itemsLink, RestMediaTypes.ALPS_JSON).andReturn().getResponse().getContentAsString(); + String result = client.follow(itemsLink, MediaTypes.ALPS_JSON).andReturn().getResponse().getContentAsString(); String href = JsonPath. read(result, "$.alps.descriptor[?(@.id == 'item-representation')].href").get(0) .toString(); @@ -157,7 +157,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio jsonPath += "descriptor[?(@.name == 'father')]."; // First father descriptor jsonPath += "rt"; // Return type - String result = client.follow(usersLink, RestMediaTypes.ALPS_JSON).andReturn().getResponse().getContentAsString(); + String result = client.follow(usersLink, MediaTypes.ALPS_JSON).andReturn().getResponse().getContentAsString(); String rt = JsonPath. read(result, jsonPath).get(0).toString(); assertThat(rt).contains(ProfileController.PROFILE_ROOT_MAPPING).endsWith("-representation"); @@ -169,7 +169,7 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio Link profileLink = client.discoverUnique("profile"); Link itemsLink = client.discoverUnique(profileLink, "items", MediaType.ALL); - client.follow(itemsLink, RestMediaTypes.ALPS_JSON)// + client.follow(itemsLink, MediaTypes.ALPS_JSON)// // Exposes identifier if configured to .andExpect(jsonPath("$.alps.descriptor[*].descriptor[*].name", hasItems("id", "name"))); } diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/ProfileIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/ProfileIntegrationTests.java index 5d663a6fc..755eeb5a7 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/ProfileIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/ProfileIntegrationTests.java @@ -31,6 +31,7 @@ import org.springframework.data.rest.webmvc.ProfileResourceProcessor; import org.springframework.data.rest.webmvc.RestMediaTypes; import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer; import org.springframework.hateoas.Link; +import org.springframework.hateoas.MediaTypes; import org.springframework.hateoas.client.LinkDiscoverers; import org.springframework.http.MediaType; import org.springframework.test.context.ContextConfiguration; @@ -102,8 +103,8 @@ public class ProfileIntegrationTests extends AbstractControllerIntegrationTests Link peopleLink = client.discoverUnique(new Link(ROOT_URI), "people"); Link profileLink = client.discoverUnique(peopleLink, ProfileResourceProcessor.PROFILE_REL); - client.follow(profileLink, RestMediaTypes.ALPS_JSON).andExpect(status().is2xxSuccessful()) - .andExpect(content().contentTypeCompatibleWith(RestMediaTypes.ALPS_JSON)); + client.follow(profileLink, MediaTypes.ALPS_JSON).andExpect(status().is2xxSuccessful()) + .andExpect(content().contentTypeCompatibleWith(MediaTypes.ALPS_JSON)); client.follow(profileLink, RestMediaTypes.SCHEMA_JSON).andExpect(status().is2xxSuccessful()) .andExpect(content().contentTypeCompatibleWith(RestMediaTypes.SCHEMA_JSON)); diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RestMediaTypes.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RestMediaTypes.java index 4e2b2cc93..5ad844f08 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RestMediaTypes.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RestMediaTypes.java @@ -32,8 +32,17 @@ public class RestMediaTypes { public static final MediaType JSON_PATCH_JSON = MediaType.valueOf("application/json-patch+json"); public static final MediaType MERGE_PATCH_JSON = MediaType.valueOf("application/merge-patch+json"); + /** + * @deprecated Migrate to {@link MediaTypes#ALPS_JSON_VALUE}. + */ + @Deprecated public static final String ALPS_JSON_VALUE = "application/alps+json"; - public static final MediaType ALPS_JSON = MediaType.parseMediaType(ALPS_JSON_VALUE); + + /** + * @deprecated Migrate to {@link MediaTypes#ALPS_JSON}. + */ + @Deprecated + public static final MediaType ALPS_JSON = MediaType.parseMediaType(MediaTypes.ALPS_JSON_VALUE); public static final String SCHEMA_JSON_VALUE = "application/schema+json"; public static final MediaType SCHEMA_JSON = MediaType.valueOf(SCHEMA_JSON_VALUE); diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/alps/AlpsController.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/alps/AlpsController.java index b7bb18d30..9d2bf5847 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/alps/AlpsController.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/alps/AlpsController.java @@ -25,8 +25,8 @@ import org.springframework.data.rest.core.mapping.ResourceMappings; import org.springframework.data.rest.webmvc.BasePathAwareController; import org.springframework.data.rest.webmvc.ProfileController; import org.springframework.data.rest.webmvc.ResourceNotFoundException; -import org.springframework.data.rest.webmvc.RestMediaTypes; import org.springframework.data.rest.webmvc.RootResourceInformation; +import org.springframework.hateoas.MediaTypes; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -68,7 +68,7 @@ public class AlpsController { * @return */ @RequestMapping(value = ProfileController.RESOURCE_PROFILE_MAPPING, method = OPTIONS, - produces = RestMediaTypes.ALPS_JSON_VALUE) + produces = MediaTypes.ALPS_JSON_VALUE) HttpEntity alpsOptions() { verifyAlpsEnabled(); @@ -86,7 +86,7 @@ public class AlpsController { * @return */ @RequestMapping(value = ProfileController.RESOURCE_PROFILE_MAPPING, method = GET, - produces = { MediaType.ALL_VALUE, RestMediaTypes.ALPS_JSON_VALUE }) + produces = { MediaType.ALL_VALUE, MediaTypes.ALPS_JSON_VALUE }) HttpEntity descriptor(RootResourceInformation information) { verifyAlpsEnabled(); diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/alps/AlpsJsonHttpMessageConverter.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/alps/AlpsJsonHttpMessageConverter.java index ea602300b..532d9f020 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/alps/AlpsJsonHttpMessageConverter.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/alps/AlpsJsonHttpMessageConverter.java @@ -21,8 +21,8 @@ import java.util.Collections; import org.springframework.core.MethodParameter; import org.springframework.core.convert.converter.Converter; -import org.springframework.data.rest.webmvc.RestMediaTypes; import org.springframework.data.rest.webmvc.RootResourceInformation; +import org.springframework.hateoas.MediaTypes; import org.springframework.hateoas.mediatype.alps.Alps; import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConverter; @@ -61,7 +61,7 @@ public class AlpsJsonHttpMessageConverter extends MappingJackson2HttpMessageConv mapper.setSerializationInclusion(Include.NON_EMPTY); setPrettyPrint(true); - setSupportedMediaTypes(Arrays.asList(RestMediaTypes.ALPS_JSON, MediaType.APPLICATION_JSON, MediaType.ALL)); + setSupportedMediaTypes(Arrays.asList(MediaTypes.ALPS_JSON, MediaType.APPLICATION_JSON, MediaType.ALL)); } /*