diff --git a/src/main/java/org/springframework/hateoas/Link.java b/src/main/java/org/springframework/hateoas/Link.java index 1fb1b14d..8383d844 100755 --- a/src/main/java/org/springframework/hateoas/Link.java +++ b/src/main/java/org/springframework/hateoas/Link.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,7 +44,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; * @author Greg Turnquist */ @JsonInclude(JsonInclude.Include.NON_NULL) -@JsonIgnoreProperties(value = "templated", ignoreUnknown = true) +@JsonIgnoreProperties(value = "templated", ignoreUnknown = true) @AllArgsConstructor(access = AccessLevel.PACKAGE) @Getter @EqualsAndHashCode(of = { "rel", "href", "hreflang", "media", "title", "deprecation", "affordances" }) diff --git a/src/main/java/org/springframework/hateoas/PagedResources.java b/src/main/java/org/springframework/hateoas/PagedResources.java index 98660168..8b40fd14 100644 --- a/src/main/java/org/springframework/hateoas/PagedResources.java +++ b/src/main/java/org/springframework/hateoas/PagedResources.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; * DTO to implement binding response representations of pageable collections. * * @author Oliver Gierke + * @author Greg Turnquist */ public class PagedResources extends Resources { diff --git a/src/main/java/org/springframework/hateoas/Resource.java b/src/main/java/org/springframework/hateoas/Resource.java index 43948b45..51bf6498 100644 --- a/src/main/java/org/springframework/hateoas/Resource.java +++ b/src/main/java/org/springframework/hateoas/Resource.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/main/java/org/springframework/hateoas/ResourceSupport.java b/src/main/java/org/springframework/hateoas/ResourceSupport.java index 9235650a..36741f20 100755 --- a/src/main/java/org/springframework/hateoas/ResourceSupport.java +++ b/src/main/java/org/springframework/hateoas/ResourceSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,6 +31,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; * * @author Oliver Gierke * @author Johhny Lim + * @author Greg Turnquist */ public class ResourceSupport implements Identifiable { diff --git a/src/main/java/org/springframework/hateoas/Resources.java b/src/main/java/org/springframework/hateoas/Resources.java index 5886ad87..8edec923 100644 --- a/src/main/java/org/springframework/hateoas/Resources.java +++ b/src/main/java/org/springframework/hateoas/Resources.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; * General helper to easily create a wrapper for a collection of entities. * * @author Oliver Gierke + * @author Greg Turnquist */ public class Resources extends ResourceSupport implements Iterable { diff --git a/src/main/java/org/springframework/hateoas/VndErrors.java b/src/main/java/org/springframework/hateoas/VndErrors.java index fead6044..c2996e72 100644 --- a/src/main/java/org/springframework/hateoas/VndErrors.java +++ b/src/main/java/org/springframework/hateoas/VndErrors.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,7 @@ import com.fasterxml.jackson.annotation.JsonValue; * * @see https://github.com/blongden/vnd.error * @author Oliver Gierke + * @author Greg Turnquist */ public class VndErrors implements Iterable { @@ -87,7 +88,7 @@ public class VndErrors implements Iterable { /** * Adds an additional {@link VndError} to the wrapper. * - * @param errors + * @param error */ public VndErrors add(VndError error) { this.vndErrors.add(error); diff --git a/src/main/java/org/springframework/hateoas/collectionjson/ResourceSupportMixin.java b/src/main/java/org/springframework/hateoas/collectionjson/ResourceSupportMixin.java index 1c7582f1..ec9af80c 100644 --- a/src/main/java/org/springframework/hateoas/collectionjson/ResourceSupportMixin.java +++ b/src/main/java/org/springframework/hateoas/collectionjson/ResourceSupportMixin.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +19,6 @@ import static org.springframework.hateoas.collectionjson.Jackson2CollectionJsonM import java.util.List; -import javax.xml.bind.annotation.XmlElement; - import org.springframework.hateoas.Link; import org.springframework.hateoas.ResourceSupport; @@ -33,18 +31,17 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; * Jackson 2 mixin to invoke the related serializer/deserializer. * * @author Greg Turnquist + * @author Jens Schauder */ @JsonSerialize(using = CollectionJsonResourceSupportSerializer.class) @JsonDeserialize(using = CollectionJsonResourceSupportDeserializer.class) abstract class ResourceSupportMixin extends ResourceSupport { @Override - @XmlElement(name = "collection") @JsonProperty("collection") @JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonSerialize(using = CollectionJsonLinkListSerializer.class) @JsonDeserialize(using = CollectionJsonLinkListDeserializer.class) public abstract List getLinks(); - } diff --git a/src/main/java/org/springframework/hateoas/hal/ResourceSupportMixin.java b/src/main/java/org/springframework/hateoas/hal/ResourceSupportMixin.java index 37c1848b..b85e4182 100644 --- a/src/main/java/org/springframework/hateoas/hal/ResourceSupportMixin.java +++ b/src/main/java/org/springframework/hateoas/hal/ResourceSupportMixin.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/main/java/org/springframework/hateoas/hal/ResourcesMixin.java b/src/main/java/org/springframework/hateoas/hal/ResourcesMixin.java index d1d3883d..17f33d3e 100644 --- a/src/main/java/org/springframework/hateoas/hal/ResourcesMixin.java +++ b/src/main/java/org/springframework/hateoas/hal/ResourcesMixin.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/main/java/org/springframework/hateoas/hal/forms/Jackson2HalFormsModule.java b/src/main/java/org/springframework/hateoas/hal/forms/Jackson2HalFormsModule.java index 246addb6..3757821c 100644 --- a/src/main/java/org/springframework/hateoas/hal/forms/Jackson2HalFormsModule.java +++ b/src/main/java/org/springframework/hateoas/hal/forms/Jackson2HalFormsModule.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2017 the original author or authors. + * Copyright 2016-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/main/java/org/springframework/hateoas/package-info.java b/src/main/java/org/springframework/hateoas/package-info.java index 836b5fd9..a1c9fc0b 100644 --- a/src/main/java/org/springframework/hateoas/package-info.java +++ b/src/main/java/org/springframework/hateoas/package-info.java @@ -1,9 +1,24 @@ +/* + * Copyright 2012-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /** * Value objects to ease creating {@link org.springframework.hateoas.Link}s and link driven representations for REST webservices. + * + * @author Oliver Drotbohm + * @author Jens Schauder + * @author Greg Turnquist */ -@XmlSchema(xmlns = { @XmlNs(prefix = "atom", namespaceURI = org.springframework.hateoas.Link.ATOM_NAMESPACE) }, elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) package org.springframework.hateoas; - -import javax.xml.bind.annotation.XmlNs; -import javax.xml.bind.annotation.XmlSchema; - diff --git a/src/test/java/org/springframework/hateoas/ResourceIntegrationTest.java b/src/test/java/org/springframework/hateoas/ResourceIntegrationTest.java index a3066c4d..6e13005b 100755 --- a/src/test/java/org/springframework/hateoas/ResourceIntegrationTest.java +++ b/src/test/java/org/springframework/hateoas/ResourceIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,14 +17,6 @@ package org.springframework.hateoas; import static org.assertj.core.api.Assertions.*; -import java.io.StringWriter; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.Marshaller; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlRootElement; - -import org.custommonkey.xmlunit.Diff; import org.junit.Test; import com.fasterxml.jackson.annotation.JsonAutoDetect; @@ -32,8 +24,9 @@ import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; /** * Integration tests for {@link Resource}. - * + * * @author Oliver Gierke + * @author Greg Turnquist */ public class ResourceIntegrationTest extends AbstractJackson2MarshallingIntegrationTest { diff --git a/src/test/java/org/springframework/hateoas/VndErrorsMarshallingTest.java b/src/test/java/org/springframework/hateoas/VndErrorsMarshallingTest.java index 416a7a83..e40569c8 100755 --- a/src/test/java/org/springframework/hateoas/VndErrorsMarshallingTest.java +++ b/src/test/java/org/springframework/hateoas/VndErrorsMarshallingTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2015 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,18 +19,10 @@ import static org.assertj.core.api.Assertions.*; import java.io.FileInputStream; import java.io.IOException; -import java.io.StringReader; -import java.io.StringWriter; -import java.io.Writer; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; import java.nio.charset.Charset; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; - -import org.custommonkey.xmlunit.Diff; import org.junit.Before; import org.junit.Test; import org.springframework.core.io.ClassPathResource; @@ -43,8 +35,9 @@ import com.fasterxml.jackson.databind.SerializationFeature; /** * Integration tests for marshalling of {@link VndErrors}. - * + * * @author Oliver Gierke + * @author Greg Turnquist */ public class VndErrorsMarshallingTest { @@ -55,13 +48,11 @@ public class VndErrorsMarshallingTest { VndErrors errors; String jsonReference; String json2Reference; - String xmlReference; public VndErrorsMarshallingTest() throws IOException { jsonReference = readFile(new ClassPathResource("vnderror.json")); json2Reference = readFile(new ClassPathResource("vnderror2.json")); - xmlReference = readFile(new ClassPathResource("vnderror.xml")); } @Before diff --git a/src/test/java/org/springframework/hateoas/hal/RenderHypermediaForDefaultAcceptHeadersTest.java b/src/test/java/org/springframework/hateoas/hal/RenderHypermediaForDefaultAcceptHeadersTest.java index 10ab4e74..c2c2d3c1 100644 --- a/src/test/java/org/springframework/hateoas/hal/RenderHypermediaForDefaultAcceptHeadersTest.java +++ b/src/test/java/org/springframework/hateoas/hal/RenderHypermediaForDefaultAcceptHeadersTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,19 +17,14 @@ package org.springframework.hateoas.hal; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*; import lombok.Data; import lombok.experimental.Wither; -import java.net.URI; -import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; -import java.util.Map; -import java.util.TreeMap; import org.junit.Before; import org.junit.Test; @@ -45,23 +40,19 @@ import org.springframework.hateoas.config.EnableHypermediaSupport; import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.servlet.config.annotation.EnableWebMvc; /** * @author Greg Turnquist + * @author Jens Schauder */ @RunWith(SpringRunner.class) @WebAppConfiguration @@ -79,36 +70,38 @@ public class RenderHypermediaForDefaultAcceptHeadersTest { /** * Verify the default {@literal Accept} header used by a browser (which favors XML/HTML) still yields HAL-JSON. + * + * @see #695 */ @Test public void browserBasedDefaultAcceptHeadersShouldProduceHalJson() throws Exception { this.mockMvc.perform(get("/employees").accept(MediaType.APPLICATION_XHTML_XML, MediaType.ALL)) // - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(header().string(HttpHeaders.CONTENT_TYPE, MediaTypes.HAL_JSON_UTF8_VALUE)); + .andExpect(status().isOk()) + .andExpect(header().string(HttpHeaders.CONTENT_TYPE, MediaTypes.HAL_JSON_UTF8_VALUE)); } /** * Verify the default {@literal Accept} header used by cURL still yields HAL-JSON. + * + * @see #695 */ @Test public void curlBasedDefaultAcceptHeadersShouldProduceHalJson() throws Exception { this.mockMvc.perform(get("/employees").accept(MediaType.ALL)) // - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(header().string(HttpHeaders.CONTENT_TYPE, MediaTypes.HAL_JSON_UTF8_VALUE)); + .andExpect(status().isOk()) + .andExpect(header().string(HttpHeaders.CONTENT_TYPE, MediaTypes.HAL_JSON_UTF8_VALUE)); } @RestController static class EmployeeController { - private final static Map EMPLOYEES = new TreeMap<>(); + private final static List EMPLOYEES = new ArrayList<>(); static { - EMPLOYEES.put(0, new Employee("Frodo Baggins", "ring bearer")); - EMPLOYEES.put(1, new Employee("Bilbo Baggins", "burglar")); + EMPLOYEES.add(new Employee("Frodo Baggins", "ring bearer")); + EMPLOYEES.add(new Employee("Bilbo Baggins", "burglar")); } @GetMapping("/employees") @@ -141,58 +134,6 @@ public class RenderHypermediaForDefaultAcceptHeadersTest { // Return the affordance + a link back to the entire collection resource. return new Resource<>(EMPLOYEES.get(id), findOneLink, employeesLink); } - - @PostMapping("/employees") - public ResponseEntity newEmployee(@RequestBody Employee employee) { - - int newEmployeeId = EMPLOYEES.size(); - - EMPLOYEES.put(newEmployeeId, employee); - - try { - return ResponseEntity.noContent().location(new URI(findOne(newEmployeeId).getLink(Link.REL_SELF).map(link -> link.expand().getHref()).orElse(""))) - .build(); - } catch (URISyntaxException e) { - return ResponseEntity.badRequest().body(e.getMessage()); - } - } - - @PutMapping("/employees/{id}") - public ResponseEntity updateEmployee(@RequestBody Employee employee, @PathVariable Integer id) { - - EMPLOYEES.put(id, employee); - - try { - return ResponseEntity.noContent().location(new URI(findOne(id).getLink(Link.REL_SELF).map(link -> link.expand().getHref()).orElse(""))) - .build(); - } catch (URISyntaxException e) { - return ResponseEntity.badRequest().body(e.getMessage()); - } - } - - @PatchMapping("/employees/{id}") - public ResponseEntity partiallyUpdateEmployee(@RequestBody Employee employee, @PathVariable Integer id) { - - Employee oldEmployee = EMPLOYEES.get(id); - Employee newEmployee = oldEmployee; - - if (employee.getName() != null) { - newEmployee = newEmployee.withName(employee.getName()); - } - - if (employee.getRole() != null) { - newEmployee = newEmployee.withRole(employee.getRole()); - } - - EMPLOYEES.put(id, newEmployee); - - try { - return ResponseEntity.noContent().location(new URI(findOne(id).getLink(Link.REL_SELF).map(link -> link.expand().getHref()).orElse(""))) - .build(); - } catch (URISyntaxException e) { - return ResponseEntity.badRequest().body(e.getMessage()); - } - } } @Configuration diff --git a/src/test/resources/vnderror.xml b/src/test/resources/vnderror.xml deleted file mode 100644 index 72b07134..00000000 --- a/src/test/resources/vnderror.xml +++ /dev/null @@ -1 +0,0 @@ -Validation failed!Validation failed!Validation failed! \ No newline at end of file