Update tests.

This commit is contained in:
Jon Brisbin
2013-03-13 15:06:32 -05:00
committed by Jon Brisbin
parent 20d18bd8f2
commit 34c94d1e92

View File

@@ -9,8 +9,8 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.core.MethodParameter;
import org.springframework.data.rest.config.RepositoryRestConfiguration;
import org.springframework.data.rest.webmvc.annotation.BaseURI;
import org.springframework.data.rest.repository.PagingAndSorting;
import org.springframework.data.rest.webmvc.annotation.BaseURI;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.method.support.ModelAndViewContainer;
@@ -20,87 +20,87 @@ import org.springframework.web.method.support.ModelAndViewContainer;
*/
public class CustomMethodArgumentResolverTests extends AbstractJMockTests {
static final MethodParameter BASE_URI;
static final MethodParameter PAGE_SORT;
static final MethodParameter BASE_URI;
static final MethodParameter PAGE_SORT;
static {
try {
BASE_URI = MethodParameter.forMethodOrConstructor(
Methods.class.getDeclaredMethod("baseUri", URI.class),
0
);
PAGE_SORT = MethodParameter.forMethodOrConstructor(
Methods.class.getDeclaredMethod("pagingAndSorting", PagingAndSorting.class),
0
);
} catch(NoSuchMethodException e) {
throw new IllegalStateException(e);
}
}
static {
try {
BASE_URI = MethodParameter.forMethodOrConstructor(
Methods.class.getDeclaredMethod("baseUri", URI.class),
0
);
PAGE_SORT = MethodParameter.forMethodOrConstructor(
Methods.class.getDeclaredMethod("pagingAndSorting", PagingAndSorting.class),
0
);
} catch(NoSuchMethodException e) {
throw new IllegalStateException(e);
}
}
private final RepositoryRestConfiguration config =
new RepositoryRestConfiguration()
.setBaseUri(URI.create("http://localhost:8080"));
private final BaseUriMethodArgumentResolver baseUriResolver =
new BaseUriMethodArgumentResolver(config);
private final PagingAndSortingMethodArgumentResolver pageSortResolver =
new PagingAndSortingMethodArgumentResolver(config);
private ModelAndViewContainer mavContainer;
private WebDataBinderFactory webDataBinderFactory;
private final RepositoryRestConfiguration config =
new RepositoryRestConfiguration()
.setBaseUri(URI.create("http://localhost:8080"));
private final BaseUriMethodArgumentResolver baseUriResolver =
new BaseUriMethodArgumentResolver(config);
private final PagingAndSortingMethodArgumentResolver pageSortResolver =
new PagingAndSortingMethodArgumentResolver(config);
private ModelAndViewContainer mavContainer;
private WebDataBinderFactory webDataBinderFactory;
@Before
public void setup() {
mavContainer = new ModelAndViewContainer();
webDataBinderFactory = context.mock(WebDataBinderFactory.class);
}
@Before
public void setup() {
mavContainer = new ModelAndViewContainer();
webDataBinderFactory = context.mock(WebDataBinderFactory.class);
}
@Test
public void baseUriMethodArgumentResolver() throws Exception {
assertThat("Finds @BaseURI-annotated java.net.URI parameter",
baseUriResolver.supportsParameter(BASE_URI),
is(true));
@Test
public void baseUriMethodArgumentResolver() throws Exception {
assertThat("Finds @BaseURI-annotated java.net.URI parameter",
baseUriResolver.supportsParameter(BASE_URI),
is(true));
// Resolve the base URI
URI baseUri = (URI)baseUriResolver.resolveArgument(
BASE_URI,
mavContainer,
new ServletWebRequest(Requests.ROOT_REQUEST),
webDataBinderFactory
);
// Resolve the base URI
URI baseUri = (URI)baseUriResolver.resolveArgument(
BASE_URI,
mavContainer,
new ServletWebRequest(Requests.ROOT_REQUEST),
webDataBinderFactory
);
assertThat("Base URI should be 'http://localhost:8080'",
baseUri.toString(),
is("http://localhost:8080"));
}
assertThat("Base URI should be 'http://localhost:8080'",
baseUri.toString(),
is("http://localhost:8080"));
}
@Test
public void pagingAndSortingMethodArgumentResolver() throws Exception {
assertThat("Finds PagingAndSorting parameter",
pageSortResolver.supportsParameter(PAGE_SORT),
is(true));
@Test
public void pagingAndSortingMethodArgumentResolver() throws Exception {
assertThat("Finds PagingAndSorting parameter",
pageSortResolver.supportsParameter(PAGE_SORT),
is(true));
// Resolve Page and Sort information
PagingAndSorting pageSort = (PagingAndSorting)pageSortResolver.resolveArgument(
PAGE_SORT,
mavContainer,
new ServletWebRequest(Requests.PAGE_REQUEST),
webDataBinderFactory
);
// Resolve Page and Sort information
PagingAndSorting pageSort = (PagingAndSorting)pageSortResolver.resolveArgument(
PAGE_SORT,
mavContainer,
new ServletWebRequest(Requests.PAGE_REQUEST),
webDataBinderFactory
);
assertThat("Finds page parameter value",
pageSort.getPageNumber(),
is(1));
assertThat("Finds limit parameter value",
pageSort.getPageSize(),
is(5));
}
assertThat("Finds page parameter value",
pageSort.getPageNumber(),
is(1));
assertThat("Finds limit parameter value",
pageSort.getPageSize(),
is(5));
}
static class Methods {
void baseUri(@BaseURI URI baseUri) {
}
static class Methods {
void baseUri(@BaseURI URI baseUri) {
}
void pagingAndSorting(PagingAndSorting pageSort) {
}
}
void pagingAndSorting(PagingAndSorting pageSort) {
}
}
}