DATAREST-93 - Further refactorings and refinements regarding the search resource mapping.

This commit is contained in:
Oliver Gierke
2013-07-12 14:20:32 +02:00
parent f8e53058f8
commit a4d8a22428
20 changed files with 332 additions and 122 deletions

View File

@@ -26,6 +26,7 @@ import org.springframework.util.StringUtils;
public class Path {
private static final String SLASH = "/";
private static final String MATCH_PATTERN = "/?%s";
private final String path;
@@ -48,6 +49,10 @@ public class Path {
this.path = cleanUp ? cleanUp(path) : path;
}
public boolean matches(String reference) {
return this.path.matches(String.format(MATCH_PATTERN, reference));
}
/**
* Appends the given {@link String} to the current {@link Path}.
*

View File

@@ -19,9 +19,10 @@ import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.data.rest.core.Path;
/**
* Unit tests for {@link Path}.
*
* @author Oliver Gierke
*/
public class PathUnitTests {
@@ -46,4 +47,19 @@ public class PathUnitTests {
Path builder = new Path("foo/ ").slash("/ b a r").slash(" //foobar/// ");
assertThat(builder.toString(), is("/foo/bar/foobar"));
}
@Test
public void matchesWithLeadingSlash() {
assertThat(new Path("/foobar").matches("/foobar"), is(true));
}
@Test
public void matchesWithoutLeadingSlash() {
assertThat(new Path("/foobar").matches("foobar"), is(true));
}
@Test
public void doesNotMatchIfDifferent() {
assertThat(new Path("/foobar").matches("barfoo"), is(false));
}
}