DATACMNS-448 - Added infrastructure for 'deleteBy' queries.

Add keywords 'delete' and 'remove' to PartTree indicating presence of delete intend.

Original pull request: #72.
This commit is contained in:
Christoph Strobl
2014-03-05 13:57:47 +01:00
committed by Oliver Gierke
parent cc57d38b42
commit 5d0f3b4b6d
2 changed files with 79 additions and 6 deletions

View File

@@ -42,10 +42,11 @@ import org.springframework.data.repository.query.parser.PartTree.OrPart;
* @author Phillip Webb
* @author Thomas Darimont
* @author Martin Baumgartner
* @author Christoph Strobl
*/
public class PartTreeUnitTests {
private String[] PREFIXES = { "find", "read", "get", "query" };
private String[] PREFIXES = { "find", "read", "get", "query", "count", "delete", "remove" };
@Test(expected = IllegalArgumentException.class)
public void rejectsNullSource() throws Exception {
@@ -296,7 +297,7 @@ public class PartTreeUnitTests {
public void parsesBeforeKeywordCorrectly() {
assertType(Arrays.asList("birthdayBefore", "birthdayIsBefore"), Type.BEFORE, "birthday");
}
/**
* @see DATACMNS-433
*/
@@ -304,7 +305,7 @@ public class PartTreeUnitTests {
public void parsesLikeKeywordCorrectly() {
assertType(asList("activeLike", "activeIsLike"), LIKE, "active");
}
/**
* @see DATACMNS-433
*/
@@ -512,6 +513,46 @@ public class PartTreeUnitTests {
assertThat(tree.getSort(), is(new Sort(Direction.ASC, "lastname")));
}
/**
* @see DATACMNS-448
*/
@Test
public void identifiesSimpleDeleteByCorrectly() {
PartTree tree = new PartTree("deleteByLastname", User.class);
assertThat(tree.isDelete(), is(true));
}
/**
* @see DATACMNS-448
*/
@Test
public void identifiesExtendedDeleteByCorrectly() {
PartTree tree = new PartTree("deleteUserByLastname", User.class);
assertThat(tree.isDelete(), is(true));
}
/**
* @see DATACMNS-448
*/
@Test
public void identifiesSimpleRemoveByCorrectly() {
PartTree tree = new PartTree("removeByLastname", User.class);
assertThat(tree.isDelete(), is(true));
}
/**
* @see DATACMNS-448
*/
@Test
public void identifiesExtendedRemoveByCorrectly() {
PartTree tree = new PartTree("removeUserByLastname", User.class);
assertThat(tree.isDelete(), is(true));
}
private static void assertType(Iterable<String> sources, Type type, String property) {
assertType(sources, type, property, 1, true);
}