-
Notifications
You must be signed in to change notification settings - Fork 562
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DATAREST-1458 - Fixed rendering of compact view to association resour…
…ces. The usage of text/uri-list as media type was entirely broken and not even advertised in the reference docs anymore. It's now again supported for both to-one and to-many associations via Collections. Maps are rejected as they cannot be rendered as list of URIs correctly. Updated reference documentation accordingly. Added a custom MapModel implementation of RepresentationModel as apparently using Maps with EntityModel does not unwrap the content properly due to [0]. [0] FasterXML/jackson-databind#171
- Loading branch information
Showing
4 changed files
with
197 additions
and
58 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
...-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/TestMatchers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2019 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 | ||
* | ||
* https://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. | ||
*/ | ||
package org.springframework.data.rest.tests; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.hamcrest.Description; | ||
import org.hamcrest.Matcher; | ||
import org.hamcrest.TypeSafeMatcher; | ||
import org.springframework.util.StringUtils; | ||
|
||
/** | ||
* {@link Matcher} implementations useful in tests | ||
* | ||
* @author Oliver Drotbohm | ||
*/ | ||
public class TestMatchers { | ||
|
||
/** | ||
* Asserts that a {@link String} consists of a given number of lines. | ||
* | ||
* @param number | ||
* @return | ||
*/ | ||
public static Matcher<String> hasNumberOfLines(int number) { | ||
|
||
return new TypeSafeMatcher<String>(String.class) { | ||
|
||
/* | ||
* (non-Javadoc) | ||
* @see org.hamcrest.SelfDescribing#describeTo(org.hamcrest.Description) | ||
*/ | ||
@Override | ||
public void describeTo(Description description) { | ||
description.appendText("contains " + number + " lines"); | ||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* @see org.hamcrest.TypeSafeMatcher#describeMismatchSafely(java.lang.Object, org.hamcrest.Description) | ||
*/ | ||
@Override | ||
protected void describeMismatchSafely(String item, Description mismatchDescription) { | ||
|
||
mismatchDescription.appendText(item) // | ||
.appendText(" contains ") // | ||
.appendValue(numberOfLines(item)) // | ||
.appendText(" lines"); | ||
} | ||
|
||
/* | ||
* (non-Javadoc) | ||
* @see org.hamcrest.TypeSafeMatcher#matchesSafely(java.lang.Object) | ||
*/ | ||
@Override | ||
protected boolean matchesSafely(String item) { | ||
return numberOfLines(item) == number; | ||
} | ||
|
||
private long numberOfLines(String source) { | ||
|
||
return Arrays.stream(source.split("\n")) // | ||
.filter(StringUtils::hasText) // | ||
.count(); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters