DATACMNS-1570 - Made the behaviour consistent between Subject part and Order By part.
The subject part wasn't decapitalizing properties starting with multiple characters properly. Original pull request: #402.
This commit is contained in:
@@ -17,6 +17,7 @@ package org.springframework.data.repository.query.parser;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.beans.Introspector;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -27,7 +28,6 @@ import java.util.regex.Pattern;
|
||||
|
||||
import org.springframework.data.mapping.PropertyPath;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* A single part of a method name that has to be transformed into a query part. The actual transformation is defined by
|
||||
@@ -36,6 +36,7 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Martin Baumgartner
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
@EqualsAndHashCode
|
||||
public class Part {
|
||||
@@ -262,7 +263,7 @@ public class Part {
|
||||
*/
|
||||
public String extractProperty(String part) {
|
||||
|
||||
String candidate = StringUtils.uncapitalize(part);
|
||||
String candidate = Introspector.decapitalize(part);
|
||||
|
||||
for (String keyword : keywords) {
|
||||
if (candidate.endsWith(keyword)) {
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.util.List;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.mapping.PropertyPath;
|
||||
import org.springframework.data.mapping.PropertyReferenceException;
|
||||
import org.springframework.data.repository.query.parser.Part.IgnoreCaseType;
|
||||
import org.springframework.data.repository.query.parser.Part.Type;
|
||||
import org.springframework.data.repository.query.parser.PartTree.OrPart;
|
||||
@@ -45,6 +46,7 @@ import org.springframework.data.repository.query.parser.PartTree.OrPart;
|
||||
* @author Mark Paluch
|
||||
* @author Michael Cramer
|
||||
* @author Mariusz Mączkowski
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
public class PartTreeUnitTests {
|
||||
|
||||
@@ -601,6 +603,44 @@ public class PartTreeUnitTests {
|
||||
assertThat(tree.hasPredicate()).isFalse();
|
||||
}
|
||||
|
||||
/**
|
||||
* This test does not verify a desired behaviour but documents a limitation. If it starts failing and everything else
|
||||
* is green, remove the expectation to fail with an exception.
|
||||
*/
|
||||
@Test // DATACMNS-1570
|
||||
public void specialCapitalizationInSubject() {
|
||||
|
||||
assertThatThrownBy(() -> new PartTree("findByZIndex", SpecialCapitalization.class))
|
||||
.isInstanceOf(PropertyReferenceException.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test does not verify a desired behaviour but documents a limitation. If it starts failing and everything else
|
||||
* is green, remove the expectation to fail with an exception.
|
||||
*/
|
||||
@Test // DATACMNS-1570
|
||||
public void specialCapitalizationInOrderBy() {
|
||||
|
||||
assertThatThrownBy(() -> new PartTree("findByOrderByZIndex", SpecialCapitalization.class))
|
||||
.isInstanceOf(PropertyReferenceException.class);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1570
|
||||
public void allCapsInSubject() {
|
||||
|
||||
PartTree tree = new PartTree("findByURL", SpecialCapitalization.class);
|
||||
|
||||
assertThat(tree).hasSize(1);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1570
|
||||
public void allCapsInOrderBy() {
|
||||
|
||||
PartTree tree = new PartTree("findByOrderByURL", SpecialCapitalization.class);
|
||||
|
||||
assertThat(tree.getSort()).hasSize(1);
|
||||
}
|
||||
|
||||
private static void assertLimiting(String methodName, Class<?> entityType, boolean limiting, Integer maxResults) {
|
||||
assertLimiting(methodName, entityType, limiting, maxResults, false);
|
||||
}
|
||||
@@ -742,4 +782,17 @@ public class PartTreeUnitTests {
|
||||
|
||||
Long getId();
|
||||
}
|
||||
|
||||
public static class SpecialCapitalization {
|
||||
int zIndex;
|
||||
int URL;
|
||||
|
||||
int getZIndex() {
|
||||
return zIndex;
|
||||
}
|
||||
|
||||
int getURL() {
|
||||
return URL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user