Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Flaky tests #1726

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions src/main/java/org/springframework/hateoas/Link.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

/**
* Value object for links.
Expand All @@ -43,6 +44,7 @@
* @author Jens Schauder
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({"rel", "href", "hreflang", "media", "title", "type", "deprecation", "profile", "name", "template", "affordances"})
@JsonIgnoreProperties(value = { "templated", "template" }, ignoreUnknown = true)
public class Link implements Serializable {

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/springframework/hateoas/PagedModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

/**
* DTO to implement binding response representations of pageable collections.
Expand Down Expand Up @@ -388,6 +389,7 @@ public int hashCode() {
*
* @author Oliver Gierke
*/
@JsonPropertyOrder({"size", "totalElements", "totalPages", "number"})
public static class PageMetadata {

@JsonProperty private long size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

/**
* Describe a parameter for the associated state transition in a HAL-FORMS document. A {@link HalFormsTemplate} may
Expand All @@ -35,6 +36,7 @@
* @see https://mamund.site44.com/misc/hal-forms/
*/
@JsonInclude(Include.NON_DEFAULT)
@JsonPropertyOrder({"name", "prompt", "regex", "placeholder", "value", "templated", "multi", "readOnly", "required", "min", "max", "minLength", "maxLength", "type", "options"})
final class HalFormsProperty implements Named {

private final String name, prompt, regex, placeholder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.springframework.hateoas.mediatype.hal.forms;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;
Expand Down Expand Up @@ -53,7 +53,7 @@ public HalFormsTemplateBuilder(HalFormsConfiguration configuration, MessageResol
*/
public Map<String, HalFormsTemplate> findTemplates(RepresentationModel<?> resource) {

Map<String, HalFormsTemplate> templates = new HashMap<>();
Map<String, HalFormsTemplate> templates = new LinkedHashMap<>();
Link selfLink = resource.getLink(IanaLinkRelations.SELF).orElse(null);

resource.getLinks().stream() //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonUnwrapped;

/**
Expand All @@ -42,6 +43,7 @@
* @author Greg Turnquist
* @author Oliver Drotbohm
*/
@JsonPropertyOrder({"type", "title", "detail", "instance"})
@JsonInclude(Include.NON_NULL)
public class Problem {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -87,6 +88,7 @@ public PersonModel(Person person) {
protected PersonModel() {}
}

@JsonPropertyOrder({"firstname", "lastname"})
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
static class Person {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.springframework.hateoas;

import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

import lombok.Value;

Expand Down Expand Up @@ -107,7 +108,7 @@ void testAllIanaLinkRelationsHaveStringConstant() {
.map(String.class::cast) //
.collect(Collectors.toSet());

assertThat(linkRelations).containsExactlyElementsOf(stringConstants);
assertEquals(linkRelations, stringConstants);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.lang.reflect.Type;
import java.util.Collections;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;

import org.apache.commons.io.output.WriterOutputStream;
import org.junit.jupiter.api.Test;
import org.springframework.hateoas.PagedModel.PageMetadata;
Expand Down Expand Up @@ -86,6 +88,7 @@ interface Sample {
CollectionModel<?> someMethod();
}

@JsonPropertyOrder({"firstname", "lastname"})
static class User {
public String firstname, lastname;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

/**
* Integration tests for {@link EntityModel}.
Expand Down Expand Up @@ -54,6 +55,7 @@ public PersonResource() {
}
}

@JsonPropertyOrder({"firstname", "lastname"})
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
static class Person {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
Expand Down Expand Up @@ -387,6 +388,7 @@ private void assertEmptyEmbed(RepresentationModel<?> model, String name) throws

@Value
@AllArgsConstructor
@JsonPropertyOrder({"name", "born", "died"})
static class Author {

private String name;
Expand All @@ -404,6 +406,7 @@ static class Staff {

@Value
@AllArgsConstructor
@JsonPropertyOrder({"name", "price"})
static class Product {

private String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
Expand Down Expand Up @@ -721,6 +722,9 @@ private ObjectMapper getCuriedObjectMapper(CurieProvider provider, @Nullable Mes
mapper.registerModule(new Jackson2HalModule());
mapper.setHandlerInstantiator(
new HalHandlerInstantiator(new AnnotationLinkRelationProvider(), provider, MessageResolver.of(messageSource)));

// the current alternative SerializationFeature.ORDERED_MAP_ENTRIES_BY_KEYS does not sort nested keys
mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);

return mapper;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import lombok.NoArgsConstructor;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonPropertyOrder({"text", "number"})
@Data
@Getter(onMethod = @__(@JsonProperty))
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.jayway.jsonpath.DocumentContext;
Expand Down Expand Up @@ -668,6 +669,8 @@ private ContextualMapper getCuriedObjectMapper(CurieProvider provider, @Nullable
return MappingTestUtils.createMapper(Jackson2HalFormsIntegrationTest.class, configurer.andThen(it -> {
it.setHandlerInstantiator(new Jackson2HalModule.HalHandlerInstantiator(this.provider, provider,
resolver, new HalConfiguration(), factory));
// the current alternative SerializationFeature.ORDERED_MAP_ENTRIES_BY_KEYS does not sort nested keys
it.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JavaType;
Expand Down Expand Up @@ -332,6 +333,7 @@ static class Sample {
*/
@Value
@Getter(onMethod = @__(@JsonProperty))
@JsonPropertyOrder({"balance", "accounts"})
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(staticName = "empty", force = true)
@With
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

import java.util.Collection;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -218,6 +220,7 @@ private static void assertExpectedUser(User user) {
}

@Data
@JsonPropertyOrder({"firstname", "lastname"})
static class User {
public String firstname, lastname;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javax.validation.constraints.NotNull;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

/**
* @author Greg Turnquist
Expand All @@ -30,6 +31,7 @@
@With
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonPropertyOrder({"name", "role"})
public class Employee {

private @NotNull String name;
Expand Down