Incorporated recent changes to Spring Data Commons and dependent projects that obsoleted the need to manage domain object metadata within Spring Data REST. Required updating to the latest snapshots available for spring-data-commons and spring-data-jpa.

Additional changes include:

* Re-wrote the monolithic Controller into separate controller classes that have a more narrow focus.
* Implemented common functionality as a `HandlerMethodArgumentResolver` rather than as a helper method in a controller class.
* Re-implemented JSONP functionality as an HttpMessageConverter rather than inline within a controller class.
* Updated to Jackson 2 for all JSON handling.
* By relying on spring-data-commons, spring-data-rest now handles all supported Repository types: JPA, MongoDB, and GemFire.

Added support for MongoDB and GemFire repositories by relying on spring-data-commons to provide the metadata rather than maintaining internal metadata information that is store-specific.

Replaced Spock spec tests with JMock unit and integration tests. Started integrating Jetty 8 into the testing so MVC testing can be done against a live server.
This commit is contained in:
Jon Brisbin
2013-01-04 11:13:04 -06:00
parent 269d6f5983
commit 6e4e7da142
242 changed files with 8466 additions and 9335 deletions

View File

@@ -1,48 +0,0 @@
package org.springframework.data.rest.core.spec
import org.springframework.data.rest.core.util.UriUtils
import spock.lang.Specification
/**
* @author Jon Brisbin <jbrisbin@vmware.com>
*/
class UriUtilsSpec extends Specification {
def "merges URIs correctly"() {
given:
// (absolute) URI of the base resource
def baseUri = new URI("http://localhost:8080/baseUrl")
// (relative) URI of the top-level Resource
def uri2 = new URI("resource")
// (relative) URI of the second-level Resource
def uri3 = new URI("1")
// (fragment) URI of the bottom-level Resource
def uri4 = new URI("count")
when:
def uri5 = UriUtils.merge(baseUri, uri2, uri3, uri4)
then:
uri5.toString() == "http://localhost:8080/baseUrl/resource/1/count"
}
def "explodes URIs correctly"() {
given:
// (absolute) URI of the base resource
def baseUri = new URI("http://localhost:8080/baseUrl")
// (absolute) URI of the full resource to get a path to
def resourceUri = new URI("http://localhost:8080/baseUrl/resource/1/property")
when:
def uris = UriUtils.explode(baseUri, resourceUri)
then:
uris.size() == 3
uris[2].path == "property"
}
}

View File

@@ -0,0 +1,20 @@
package org.springframework.data.rest;
import org.jmock.integration.junit4.JMock;
import org.jmock.integration.junit4.JUnit4Mockery;
import org.jmock.lib.legacy.ClassImposteriser;
import org.junit.runner.RunWith;
/**
* Abstract base classes for JUnit tests that use JMock.
*
* @author Jon Brisbin
*/
@RunWith(JMock.class)
public abstract class AbstractJMockTests {
protected JUnit4Mockery context = new JUnit4Mockery() {{
setImposteriser(ClassImposteriser.INSTANCE);
}};
}

View File

@@ -0,0 +1,64 @@
package org.springframework.data.rest.convert;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import java.util.UUID;
import org.jmock.Expectations;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.rest.AbstractJMockTests;
import org.springframework.format.support.DefaultFormattingConversionService;
/**
* Tests to ensure the {@link DelegatingConversionService} properly delegates conversions to the {@link
* org.springframework.core.convert.ConversionService} that is appropriate for the given source and return types.
*
* @author Jon Brisbin
*/
public class DelegatingConversionServiceUnitTests extends AbstractJMockTests {
private static final UUID RANDOM_UUID = UUID.fromString("9deccfd7-f892-4e26-a4d5-c92893392e78");
private ConversionService conversionService;
private DelegatingConversionService delegatingConversionService;
@Before
public void setup() {
conversionService = context.mock(ConversionService.class);
DefaultFormattingConversionService cs = new DefaultFormattingConversionService(false);
cs.addConverter(UUIDConverter.INSTANCE);
delegatingConversionService = new DelegatingConversionService(
conversionService,
cs
);
context.checking(new Expectations() {{
allowing(conversionService).canConvert(String.class, UUID.class);
will(returnValue(false));
allowing(conversionService).canConvert(UUID.class, String.class);
will(returnValue(false));
// Ensure the first ConversionService is never asked to convert this String into a UUID
never(conversionService).convert(with(any(String.class)), with(UUID.class));
never(conversionService).convert(with(any(UUID.class)), with(String.class));
}});
}
@Test
public void shouldDelegateToProperConversionService() throws Exception {
assertThat(delegatingConversionService.canConvert(String.class, UUID.class), is(true));
assertThat(delegatingConversionService.convert(RANDOM_UUID.toString(), UUID.class), is(RANDOM_UUID));
}
@Test
public void shouldConvertUUIDToString() throws Exception {
assertThat(delegatingConversionService.canConvert(UUID.class, String.class), is(true));
assertThat(delegatingConversionService.convert(RANDOM_UUID, String.class), is(RANDOM_UUID.toString()));
}
}

View File

@@ -0,0 +1,93 @@
package org.springframework.data.rest.core.util;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
import com.google.common.base.Function;
import org.junit.Test;
/**
* Tests to verify that {@link UriUtils} can manipulate {@link URI}s.
*
* @author Jon Brisbin
*/
public class UriUtilsUnitTests {
private static final String BASE_URI_STR = "http://localhost:8080/data";
private static final URI BASE_URI = URI.create(BASE_URI_STR);
private static final String PERSON_2LVL_STR = BASE_URI_STR + "/person/1";
private static final URI PERSON_2LVL_URI = URI.create(PERSON_2LVL_STR);
@Test
public void shouldValidateBaseURI() throws Exception {
URI uri = new URI(BASE_URI + "/person/1");
assertThat(UriUtils.validBaseUri(BASE_URI, uri), is(true));
}
@Test
public void shouldIterateOverPathElements() throws Exception {
final List<String> paths = new ArrayList<String>();
Function<URI, Void> fn = new Function<URI, Void>() {
@Override public Void apply(URI uri) {
paths.add(uri.getPath());
return null;
}
};
UriUtils.foreach(BASE_URI, PERSON_2LVL_URI, fn);
assertThat(paths, hasSize(2));
assertThat(paths, contains("person", "1"));
}
@Test
public void shouldExplodeRelativeURI() throws Exception {
Stack<URI> uris = UriUtils.explode(BASE_URI, PERSON_2LVL_URI);
assertThat(uris, hasSize(2));
assertThat(uris, contains(URI.create("person"), URI.create("1")));
}
@Test
public void shouldMergeDifferentURIsIntoOne() throws Exception {
String qrystr = "?queryParam=testValue";
URI uriWithQuery = URI.create(qrystr);
URI uriWithPath = URI.create("person/1");
URI uri = UriUtils.merge(BASE_URI, uriWithPath, uriWithQuery);
assertThat(uri.toString(), is(PERSON_2LVL_STR + qrystr));
}
@Test
public void shouldStripTrailingSlashFromPath() throws Exception {
URI uri = URI.create("person/");
String path = UriUtils.path(uri);
assertThat(path, is("person"));
}
@Test
public void shouldStripTheLastPathSegmentFromAURI() throws Exception {
URI uri = UriUtils.tail(BASE_URI, PERSON_2LVL_URI);
assertThat(uri, is(URI.create("1")));
}
@Test
public void shouldBuildURIFromPathSegments() throws Exception {
URI uri = UriUtils.buildUri(BASE_URI, "person", "1");
assertThat(uri, is(PERSON_2LVL_URI));
}
}

View File

@@ -8,8 +8,7 @@
</encoder>
</appender>
<logger name="org.springframework.data.services" level="DEBUG"/>
<logger name="org.springframework" level="INFO"/>
<logger name="org.springframework.data.rest" level="DEBUG"/>
<root level="INFO">
<appender-ref ref="stdout"/>