#695 - Polishing.

* Removed Jaxb annotations from packaga-info.java.
* Simplified Test code by removing unused code a debug output.
* Formatting.
* Updated copyright headers.
This commit is contained in:
Jens Schauder
2018-12-06 10:39:53 +01:00
committed by Greg Turnquist
parent dca65e15f8
commit 367f560745
15 changed files with 56 additions and 116 deletions

View File

@@ -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" })

View File

@@ -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<T> extends Resources<T> {

View File

@@ -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.

View File

@@ -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<Link> {

View File

@@ -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<T> extends ResourceSupport implements Iterable<T> {

View File

@@ -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<VndErrors.VndError> {
@@ -87,7 +88,7 @@ public class VndErrors implements Iterable<VndErrors.VndError> {
/**
* Adds an additional {@link VndError} to the wrapper.
*
* @param errors
* @param error
*/
public VndErrors add(VndError error) {
this.vndErrors.add(error);

View File

@@ -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<Link> getLinks();
}

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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;

View File

@@ -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 {

View File

@@ -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

View File

@@ -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<Integer, Employee> EMPLOYEES = new TreeMap<>();
private final static List<Employee> 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

View File

@@ -1 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><errors xmlns:ns2="http://www.w3.org/2005/Atom"><error logref="42"><ns2:link href="http://..." rel="describes"/><ns2:link href="http://..." rel="help"/><message>Validation failed!</message></error><error logref="42"><ns2:link href="http://..." rel="describes"/><ns2:link href="http://..." rel="help"/><message>Validation failed!</message></error><error logref="42"><ns2:link href="http://..." rel="describes"/><ns2:link href="http://..." rel="help"/><message>Validation failed!</message></error></errors>