DATAREST-93 - Removed compiler warnings.
Removed dependency on jMock.
This commit is contained in:
@@ -34,14 +34,13 @@ ext {
|
||||
junitVersion = "4.11"
|
||||
hamcrestVersion = "1.3"
|
||||
jsonpathVersion = "0.8.1"
|
||||
jmockVersion = "2.6.0"
|
||||
mockitoVersion = "1.9.5"
|
||||
jettyVersion = "8.1.9.v20130131"
|
||||
}
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
maven { url "http://repo.springsource.org/plugins-release" }
|
||||
//maven { url "http://repo.springsource.org/plugins-snapshot" }
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.springframework.build.gradle:docbook-reference-plugin:0.2.6"
|
||||
@@ -85,8 +84,7 @@ configure(allprojects) {
|
||||
testCompile "junit:junit-dep:$junitVersion"
|
||||
testCompile "org.hamcrest:hamcrest-library:$hamcrestVersion"
|
||||
testCompile "com.jayway.jsonpath:json-path:$jsonpathVersion"
|
||||
testCompile "org.jmock:jmock-junit4:$jmockVersion"
|
||||
testCompile "org.jmock:jmock-legacy:$jmockVersion"
|
||||
testCompile "org.mockito:mockito-core:$mockitoVersion"
|
||||
testCompile("org.springframework:spring-test:$springVersion") { force = true }
|
||||
testRuntime("org.springframework:spring-context-support:$springVersion") { force = true }
|
||||
testRuntime "ch.qos.logback:logback-classic:$logbackVersion"
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package org.springframework.data.rest;
|
||||
|
||||
import org.jmock.integration.junit4.JUnitRuleMockery;
|
||||
import org.jmock.lib.legacy.ClassImposteriser;
|
||||
|
||||
/**
|
||||
* Abstract base classes for JUnit tests that use JMock.
|
||||
*
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
public abstract class AbstractJMockTests {
|
||||
|
||||
protected JUnitRuleMockery context = new JUnitRuleMockery() {{
|
||||
setImposteriser(ClassImposteriser.INSTANCE);
|
||||
}};
|
||||
|
||||
}
|
||||
@@ -2,14 +2,17 @@ package org.springframework.data.rest.convert;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.jmock.Expectations;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Matchers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.rest.AbstractJMockTests;
|
||||
import org.springframework.format.support.DefaultFormattingConversionService;
|
||||
|
||||
/**
|
||||
@@ -17,48 +20,44 @@ import org.springframework.format.support.DefaultFormattingConversionService;
|
||||
* org.springframework.core.convert.ConversionService} that is appropriate for the given source and return types.
|
||||
*
|
||||
* @author Jon Brisbin
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class DelegatingConversionServiceUnitTests extends AbstractJMockTests {
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DelegatingConversionServiceUnitTests {
|
||||
|
||||
private static final UUID RANDOM_UUID = UUID.fromString("9deccfd7-f892-4e26-a4d5-c92893392e78");
|
||||
|
||||
private ConversionService conversionService;
|
||||
private DelegatingConversionService delegatingConversionService;
|
||||
@Mock ConversionService conversionService;
|
||||
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));
|
||||
}});
|
||||
delegatingConversionService = new DelegatingConversionService(conversionService, cs);
|
||||
|
||||
when(conversionService.canConvert(String.class, UUID.class)).thenReturn(false);
|
||||
when(conversionService.canConvert(UUID.class, String.class)).thenReturn(false);
|
||||
}
|
||||
|
||||
@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));
|
||||
verifyConversionService();
|
||||
}
|
||||
|
||||
@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()));
|
||||
verifyConversionService();
|
||||
}
|
||||
|
||||
private void verifyConversionService() {
|
||||
verify(conversionService, times(0)).convert(Matchers.any(String.class), eq(UUID.class));
|
||||
verify(conversionService, times(0)).convert(Matchers.any(UUID.class), eq(String.class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class BaseUriAwareResources extends Resources<Resource<?>> {
|
||||
List<Resource<?>> resources = new ArrayList<Resource<?>>();
|
||||
for(Resource<?> resource : super.getContent()) {
|
||||
if(resource instanceof BaseUriAwareResource) {
|
||||
resources.add(((BaseUriAwareResource)resource).setBaseUri(baseUri));
|
||||
resources.add(((BaseUriAwareResource<?>) resource).setBaseUri(baseUri));
|
||||
} else {
|
||||
resources.add(new BaseUriAwareResource<Object>(resource.getContent(), resource.getLinks()).setBaseUri(baseUri));
|
||||
}
|
||||
|
||||
@@ -15,10 +15,9 @@ import org.springframework.hateoas.Resource;
|
||||
public class PersistentEntityResource<T> extends BaseUriAwareResource<T> {
|
||||
|
||||
@JsonIgnore
|
||||
private final PersistentEntity<T, ?> persistentEntity;
|
||||
private final PersistentEntity<?, ?> persistentEntity;
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public static <T> PersistentEntityResource<T> wrap(PersistentEntity persistentEntity,
|
||||
public static <T> PersistentEntityResource<T> wrap(PersistentEntity<?, ?> persistentEntity,
|
||||
T obj,
|
||||
URI baseUri) {
|
||||
PersistentEntityResource<T> resource = new PersistentEntityResource<T>(persistentEntity, obj);
|
||||
@@ -26,25 +25,25 @@ public class PersistentEntityResource<T> extends BaseUriAwareResource<T> {
|
||||
return resource;
|
||||
}
|
||||
|
||||
public PersistentEntityResource(PersistentEntity<T, ?> persistentEntity) {
|
||||
public PersistentEntityResource(PersistentEntity<?, ?> persistentEntity) {
|
||||
this.persistentEntity = persistentEntity;
|
||||
}
|
||||
|
||||
public PersistentEntityResource(PersistentEntity<T, ?> persistentEntity,
|
||||
public PersistentEntityResource(PersistentEntity<?, ?> persistentEntity,
|
||||
T content,
|
||||
Link... links) {
|
||||
super(content, links);
|
||||
this.persistentEntity = persistentEntity;
|
||||
}
|
||||
|
||||
public PersistentEntityResource(PersistentEntity<T, ?> persistentEntity,
|
||||
public PersistentEntityResource(PersistentEntity<?, ?> persistentEntity,
|
||||
T content,
|
||||
Iterable<Link> links) {
|
||||
super(content, links);
|
||||
this.persistentEntity = persistentEntity;
|
||||
}
|
||||
|
||||
public PersistentEntity<T, ?> getPersistentEntity() {
|
||||
public PersistentEntity<?, ?> getPersistentEntity() {
|
||||
return persistentEntity;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,9 @@ import org.springframework.validation.Errors;
|
||||
*/
|
||||
public class RepositoryConstraintViolationException extends DataIntegrityViolationException {
|
||||
|
||||
private Errors errors;
|
||||
private static final long serialVersionUID = -4789377071564956366L;
|
||||
|
||||
private final Errors errors;
|
||||
|
||||
public RepositoryConstraintViolationException(Errors errors) {
|
||||
super("Validation failed");
|
||||
|
||||
@@ -26,7 +26,7 @@ public class UriDomainClassConverter
|
||||
private static TypeDescriptor STRING_TYPE = TypeDescriptor.valueOf(String.class);
|
||||
|
||||
@Autowired
|
||||
private DomainClassConverter domainClassConverter;
|
||||
private DomainClassConverter<?> domainClassConverter;
|
||||
private Set<ConvertiblePair> convertiblePairs = new HashSet<ConvertiblePair>();
|
||||
|
||||
@Override public void afterPropertiesSet() throws Exception {
|
||||
@@ -45,7 +45,7 @@ public class UriDomainClassConverter
|
||||
}
|
||||
|
||||
@Override public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
PersistentEntity entity = repositories.getPersistentEntity(targetType.getType());
|
||||
PersistentEntity<?, ?> entity = repositories.getPersistentEntity(targetType.getType());
|
||||
if(null == entity || !domainClassConverter.matches(STRING_TYPE, targetType)) {
|
||||
throw new ConversionFailedException(
|
||||
sourceType,
|
||||
|
||||
@@ -21,13 +21,15 @@ import org.springframework.validation.ObjectError;
|
||||
*/
|
||||
public class ValidationErrors extends AbstractErrors {
|
||||
|
||||
private String name;
|
||||
private static final long serialVersionUID = 8141826537389141361L;
|
||||
|
||||
private String name;
|
||||
private Object entity;
|
||||
private PersistentEntity persistentEntity;
|
||||
private PersistentEntity<?, ?> persistentEntity;
|
||||
private List<ObjectError> globalErrors = new ArrayList<ObjectError>();
|
||||
private List<FieldError> fieldErrors = new ArrayList<FieldError>();
|
||||
|
||||
public ValidationErrors(String name, Object entity, PersistentEntity persistentEntity) {
|
||||
public ValidationErrors(String name, Object entity, PersistentEntity<?, ?> persistentEntity) {
|
||||
this.name = name;
|
||||
this.entity = entity;
|
||||
this.persistentEntity = persistentEntity;
|
||||
@@ -64,7 +66,7 @@ public class ValidationErrors extends AbstractErrors {
|
||||
}
|
||||
|
||||
@Override public Object getFieldValue(String field) {
|
||||
PersistentProperty prop = (null != persistentEntity ? persistentEntity.getPersistentProperty(field) : null);
|
||||
PersistentProperty<?> prop = persistentEntity != null ? persistentEntity.getPersistentProperty(field) : null;
|
||||
if(null == prop) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@ package org.springframework.data.rest.repository.context;
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
public class AfterCreateEvent extends RepositoryEvent {
|
||||
|
||||
private static final long serialVersionUID = -7673953693485678403L;
|
||||
|
||||
public AfterCreateEvent(Object source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
@@ -5,9 +5,11 @@ package org.springframework.data.rest.repository.context;
|
||||
*
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
public class AfterDeleteEvent
|
||||
extends RepositoryEvent {
|
||||
public AfterDeleteEvent(Object source) {
|
||||
public class AfterDeleteEvent extends RepositoryEvent {
|
||||
|
||||
private static final long serialVersionUID = -6090615345948638970L;
|
||||
|
||||
public AfterDeleteEvent(Object source) {
|
||||
super(source);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,10 @@ package org.springframework.data.rest.repository.context;
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
public class AfterLinkDeleteEvent extends LinkSaveEvent {
|
||||
public AfterLinkDeleteEvent(Object source, Object linked) {
|
||||
|
||||
private static final long serialVersionUID = 3887575011761146290L;
|
||||
|
||||
public AfterLinkDeleteEvent(Object source, Object linked) {
|
||||
super(source, linked);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,11 @@ package org.springframework.data.rest.repository.context;
|
||||
*
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
public class AfterLinkSaveEvent
|
||||
extends LinkSaveEvent {
|
||||
public AfterLinkSaveEvent(Object source, Object child) {
|
||||
public class AfterLinkSaveEvent extends LinkSaveEvent {
|
||||
|
||||
private static final long serialVersionUID = 261522353893713633L;
|
||||
|
||||
public AfterLinkSaveEvent(Object source, Object child) {
|
||||
super(source, child);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,10 @@ package org.springframework.data.rest.repository.context;
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
public class AfterSaveEvent extends RepositoryEvent {
|
||||
public AfterSaveEvent(Object source) {
|
||||
|
||||
private static final long serialVersionUID = 8568843338617401903L;
|
||||
|
||||
public AfterSaveEvent(Object source) {
|
||||
super(source);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@ package org.springframework.data.rest.repository.context;
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
public class BeforeCreateEvent extends RepositoryEvent {
|
||||
|
||||
private static final long serialVersionUID = -1642841708537223975L;
|
||||
|
||||
public BeforeCreateEvent(Object source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,10 @@ package org.springframework.data.rest.repository.context;
|
||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
||||
*/
|
||||
public class BeforeDeleteEvent extends RepositoryEvent {
|
||||
public BeforeDeleteEvent(Object source) {
|
||||
|
||||
private static final long serialVersionUID = 9150212393209433211L;
|
||||
|
||||
public BeforeDeleteEvent(Object source) {
|
||||
super(source);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,10 @@ package org.springframework.data.rest.repository.context;
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
public class BeforeLinkDeleteEvent extends LinkSaveEvent {
|
||||
public BeforeLinkDeleteEvent(Object source, Object linked) {
|
||||
|
||||
private static final long serialVersionUID = -973540913790564962L;
|
||||
|
||||
public BeforeLinkDeleteEvent(Object source, Object linked) {
|
||||
super(source, linked);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,11 @@ package org.springframework.data.rest.repository.context;
|
||||
*
|
||||
* @author Jon Brisbin <jbrisbin@vmware.com>
|
||||
*/
|
||||
public class BeforeLinkSaveEvent
|
||||
extends LinkSaveEvent {
|
||||
public BeforeLinkSaveEvent(Object source, Object linked) {
|
||||
public class BeforeLinkSaveEvent extends LinkSaveEvent {
|
||||
|
||||
private static final long serialVersionUID = 4836932640633578985L;
|
||||
|
||||
public BeforeLinkSaveEvent(Object source, Object linked) {
|
||||
super(source, linked);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ package org.springframework.data.rest.repository.context;
|
||||
* Emitted before an entity is saved into the repository.
|
||||
*/
|
||||
public class BeforeSaveEvent extends RepositoryEvent {
|
||||
|
||||
private static final long serialVersionUID = -1404580942928384726L;
|
||||
|
||||
public BeforeSaveEvent(Object source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,10 @@ package org.springframework.data.rest.repository.context;
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
public class ExceptionEvent extends RepositoryEvent {
|
||||
public ExceptionEvent(Throwable t) {
|
||||
|
||||
private static final long serialVersionUID = 6614805546974091704L;
|
||||
|
||||
public ExceptionEvent(Throwable t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ package org.springframework.data.rest.repository.context;
|
||||
*
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
public abstract class LinkSaveEvent
|
||||
extends RepositoryEvent {
|
||||
public abstract class LinkSaveEvent extends RepositoryEvent {
|
||||
|
||||
private final Object linked;
|
||||
private static final long serialVersionUID = -9071648572128698903L;
|
||||
private final Object linked;
|
||||
|
||||
public LinkSaveEvent(Object source, Object linked) {
|
||||
super(source);
|
||||
|
||||
@@ -8,7 +8,10 @@ import org.springframework.context.ApplicationEvent;
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
public abstract class RepositoryEvent extends ApplicationEvent {
|
||||
protected RepositoryEvent(Object source) {
|
||||
|
||||
private static final long serialVersionUID = -966689410815418259L;
|
||||
|
||||
protected RepositoryEvent(Object source) {
|
||||
super(source);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,9 +74,9 @@ public class ValidatingRepositoryEventListener
|
||||
} else if(entry.getKey().contains("Delete")) {
|
||||
name = entry.getKey().substring(0, entry.getKey().indexOf("Delete") + 6);
|
||||
} else {
|
||||
Annotation anno;
|
||||
|
||||
for(Class<? extends Annotation> annoType : ANNOTATIONS_TO_FIND) {
|
||||
if(null != (anno = findAnnotation(v.getClass(), annoType))) {
|
||||
if(findAnnotation(v.getClass(), annoType) != null) {
|
||||
name = uncapitalize(annoType.getSimpleName().substring(6));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ public class MethodParameterConversionService {
|
||||
|| param.hasParameterAnnotation(ConvertWith.class));
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public <T> T convert(Object source, MethodParameter param) {
|
||||
return convert(source, TypeDescriptor.forObject(source), param);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ public class RepositoryMethodInvoker implements PagingAndSortingRepository<Objec
|
||||
private RepositoryMethod deleteSome;
|
||||
private RepositoryMethod deleteAll;
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public RepositoryMethodInvoker(Object repository,
|
||||
RepositoryInformation repoInfo) {
|
||||
this.repository = repository;
|
||||
|
||||
@@ -34,7 +34,7 @@ public class RepositoryMethodResponse {
|
||||
return this;
|
||||
}
|
||||
|
||||
public RepositoryMethodResponse addAllResults(Iterator results) {
|
||||
public RepositoryMethodResponse addAllResults(Iterator<?> results) {
|
||||
if(null == results) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@ import org.springframework.hateoas.Resource;
|
||||
public class JsonSchema extends Resource<Map<String, JsonSchema.Property>> {
|
||||
|
||||
private final String name;
|
||||
private final String description;
|
||||
@SuppressWarnings("unused")
|
||||
private final String description;
|
||||
|
||||
public JsonSchema(String name, String description) {
|
||||
super(new HashMap<String, Property>());
|
||||
|
||||
@@ -52,6 +52,7 @@ import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
*/
|
||||
public class PersistentEntityJackson2Module extends SimpleModule implements InitializingBean {
|
||||
|
||||
private static final long serialVersionUID = -7289265674870906323L;
|
||||
private static final Logger LOG = LoggerFactory.getLogger(PersistentEntityJackson2Module.class);
|
||||
private static final TypeDescriptor URI_TYPE = TypeDescriptor.valueOf(URI.class);
|
||||
private final ConversionService conversionService;
|
||||
@@ -75,7 +76,7 @@ public class PersistentEntityJackson2Module extends SimpleModule implements Init
|
||||
RepositoryInformation repoInfo,
|
||||
ResourceMapping entityMapping,
|
||||
ResourceMapping propertyMapping,
|
||||
PersistentProperty persistentProperty,
|
||||
PersistentProperty<?> persistentProperty,
|
||||
List<Link> links) {
|
||||
Class<?> propertyType = persistentProperty.getType();
|
||||
if(persistentProperty.isCollectionLike() || persistentProperty.isArray()) {
|
||||
@@ -106,10 +107,10 @@ public class PersistentEntityJackson2Module extends SimpleModule implements Init
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Override public void afterPropertiesSet() throws Exception {
|
||||
for(Class<?> domainType : repositories) {
|
||||
PersistentEntity pe = repositories.getPersistentEntity(domainType);
|
||||
PersistentEntity<?, ?> pe = repositories.getPersistentEntity(domainType);
|
||||
if(null == pe) {
|
||||
if(LOG.isWarnEnabled()) {
|
||||
LOG.warn("The domain class {} does not have PersistentEntity metadata.", domainType.getName());
|
||||
@@ -122,20 +123,20 @@ public class PersistentEntityJackson2Module extends SimpleModule implements Init
|
||||
|
||||
private class ResourceDeserializer<T extends Object> extends StdDeserializer<T> {
|
||||
|
||||
private final PersistentEntity persistentEntity;
|
||||
private static final long serialVersionUID = 8195592798684027681L;
|
||||
private final PersistentEntity<?, ?> persistentEntity;
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
private ResourceDeserializer(final PersistentEntity persistentEntity) {
|
||||
private ResourceDeserializer(final PersistentEntity<?, ?> persistentEntity) {
|
||||
super(persistentEntity.getType());
|
||||
this.persistentEntity = persistentEntity;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
@SuppressWarnings({"unchecked", "incomplete-switch", "null", "unused"})
|
||||
@Override public T deserialize(JsonParser jp,
|
||||
DeserializationContext ctxt) throws IOException,
|
||||
JsonProcessingException {
|
||||
Object entity = instantiateClass(getValueClass());
|
||||
BeanWrapper wrapper = BeanWrapper.create(entity, conversionService);
|
||||
BeanWrapper<?, Object> wrapper = BeanWrapper.create(entity, conversionService);
|
||||
ResourceMapping domainMapping = config.getResourceMappingForDomainType(getValueClass());
|
||||
|
||||
for(JsonToken tok = jp.nextToken(); tok != JsonToken.END_OBJECT; tok = jp.nextToken()) {
|
||||
@@ -157,7 +158,7 @@ public class PersistentEntityJackson2Module extends SimpleModule implements Init
|
||||
continue;
|
||||
}
|
||||
|
||||
PersistentProperty persistentProperty = persistentEntity.getPersistentProperty(name);
|
||||
PersistentProperty<?> persistentProperty = persistentEntity.getPersistentProperty(name);
|
||||
if(null == persistentProperty) {
|
||||
String errMsg = "Property '" + name + "' not found for entity " + getValueClass().getName();
|
||||
if(null == domainMapping) {
|
||||
@@ -197,13 +198,13 @@ public class PersistentEntityJackson2Module extends SimpleModule implements Init
|
||||
// Try and read the value of this attribute.
|
||||
// The method of doing that varies based on the type of the property.
|
||||
if(persistentProperty.isCollectionLike()) {
|
||||
Class<? extends Collection> ctype = (Class<? extends Collection>)persistentProperty.getType();
|
||||
Collection c = (Collection)wrapper.getProperty(persistentProperty, ctype, false);
|
||||
Class<? extends Collection<?>> ctype = (Class<? extends Collection<?>>) persistentProperty.getType();
|
||||
Collection<Object> c = (Collection<Object>) wrapper.getProperty(persistentProperty, ctype, false);
|
||||
if(null == c || c == Collections.EMPTY_LIST || c == Collections.EMPTY_SET) {
|
||||
if(Collection.class.isAssignableFrom(ctype)) {
|
||||
c = new ArrayList();
|
||||
c = new ArrayList<Object>();
|
||||
} else if(Set.class.isAssignableFrom(ctype)) {
|
||||
c = new HashSet();
|
||||
c = new HashSet<Object>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,10 +221,10 @@ public class PersistentEntityJackson2Module extends SimpleModule implements Init
|
||||
throw new HttpMessageNotReadableException("Cannot read a JSON " + tok + " as a Collection.");
|
||||
}
|
||||
} else if(persistentProperty.isMap()) {
|
||||
Class<? extends Map> mtype = (Class<? extends Map>)persistentProperty.getType();
|
||||
Map m = (Map)wrapper.getProperty(persistentProperty, mtype, false);
|
||||
Class<? extends Map<?, ?>> mtype = (Class<? extends Map<?, ?>>)persistentProperty.getType();
|
||||
Map<Object, Object> m = (Map<Object, Object>) wrapper.getProperty(persistentProperty, mtype, false);
|
||||
if(null == m || m == Collections.EMPTY_MAP) {
|
||||
m = new HashMap();
|
||||
m = new HashMap<Object, Object>();
|
||||
}
|
||||
|
||||
if((tok = jp.nextToken()) == JsonToken.START_OBJECT) {
|
||||
@@ -259,6 +260,7 @@ public class PersistentEntityJackson2Module extends SimpleModule implements Init
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private class ResourceSerializer extends StdSerializer<PersistentEntityResource> {
|
||||
|
||||
private ResourceSerializer() {
|
||||
|
||||
@@ -58,9 +58,9 @@ public class PersistentEntityToJsonSchemaConverter
|
||||
return (JsonSchema)convert(domainType, STRING_TYPE, SCHEMA_TYPE);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Override public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
|
||||
PersistentEntity persistentEntity = repositories.getPersistentEntity((Class<?>)source);
|
||||
PersistentEntity<?, ?> persistentEntity = repositories.getPersistentEntity((Class<?>)source);
|
||||
final RepositoryInformation repoInfo = repositories.getRepositoryInformationFor(persistentEntity.getType());
|
||||
final ResourceMapping repoMapping = getResourceMapping(config, repoInfo);
|
||||
final ResourceMapping entityMapping = getResourceMapping(config, persistentEntity);
|
||||
|
||||
@@ -25,15 +25,15 @@ public class DomainObjectMerger {
|
||||
this.conversionService = conversionService;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public void merge(Object from, Object target) {
|
||||
if(null == from || null == target) {
|
||||
return;
|
||||
}
|
||||
final BeanWrapper fromWrapper = BeanWrapper.create(from, conversionService);
|
||||
final BeanWrapper targetWrapper = BeanWrapper.create(target, conversionService);
|
||||
final BeanWrapper<?, Object> fromWrapper = BeanWrapper.create(from, conversionService);
|
||||
final BeanWrapper<?, Object> targetWrapper = BeanWrapper.create(target, conversionService);
|
||||
|
||||
PersistentEntity entity = repositories.getPersistentEntity(target.getClass());
|
||||
PersistentEntity<?, ?> entity = repositories.getPersistentEntity(target.getClass());
|
||||
entity.doWithProperties(new PropertyHandler() {
|
||||
@Override public void doWithPersistentProperty(PersistentProperty persistentProperty) {
|
||||
Object fromVal = fromWrapper.getProperty(persistentProperty);
|
||||
|
||||
@@ -66,7 +66,7 @@ public abstract class RepositoryInformationSupport {
|
||||
}
|
||||
|
||||
protected RepositoryInformation findRepositoryInfoFor(Class<?> domainType) {
|
||||
PersistentEntity entity = repositories.getPersistentEntity(domainType);
|
||||
PersistentEntity<?, ?> entity = repositories.getPersistentEntity(domainType);
|
||||
if(null != entity) {
|
||||
return repositories.getRepositoryInformationFor(domainType);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public abstract class ResourceMappingUtils {
|
||||
|
||||
public static String formatRel(RepositoryRestConfiguration config,
|
||||
RepositoryInformation repoInfo,
|
||||
PersistentProperty persistentProperty) {
|
||||
PersistentProperty<?> persistentProperty) {
|
||||
if(null == persistentProperty) {
|
||||
return null;
|
||||
}
|
||||
@@ -104,7 +104,7 @@ public abstract class ResourceMappingUtils {
|
||||
}
|
||||
|
||||
public static ResourceMapping getResourceMapping(RepositoryRestConfiguration config,
|
||||
PersistentEntity persistentEntity) {
|
||||
PersistentEntity<?, ?> persistentEntity) {
|
||||
if(null == persistentEntity) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package org.springframework.data.rest;
|
||||
|
||||
import org.jmock.integration.junit4.JUnitRuleMockery;
|
||||
import org.jmock.lib.legacy.ClassImposteriser;
|
||||
|
||||
/**
|
||||
* Abstract base classes for JUnit tests that use JMock.
|
||||
*
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
public abstract class AbstractJMockTests {
|
||||
|
||||
protected JUnitRuleMockery context = new JUnitRuleMockery() {{
|
||||
setImposteriser(ClassImposteriser.INSTANCE);
|
||||
}};
|
||||
|
||||
}
|
||||
@@ -7,25 +7,22 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import org.hamcrest.BaseMatcher;
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.repository.support.Repositories;
|
||||
import org.springframework.data.rest.repository.PersistentEntityResource;
|
||||
import org.springframework.data.rest.repository.RepositoryTestsConfig;
|
||||
import org.springframework.data.rest.repository.domain.jpa.Person;
|
||||
import org.springframework.data.rest.repository.domain.jpa.PersonRepository;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.LinkDiscoverer;
|
||||
import org.springframework.hateoas.core.DefaultLinkDiscoverer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -37,15 +34,10 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
public class PersistentEntitySerializationTests {
|
||||
|
||||
private static final String PERSON_JSON_IN = "{\"firstName\": \"John\",\"lastName\": \"Doe\"}";
|
||||
private static final Pattern PERSON_JSON_OUT = Pattern.compile(
|
||||
"\\{\"lastName\":\"Doe\",\"created\":([0-9]+),\"firstName\":\"John\",\"links\":\\[\\{\"rel\":\"people.person.siblings\",\"href\":\"http://localhost/people/2/siblings\"}]}");
|
||||
@Autowired
|
||||
private ObjectMapper mapper;
|
||||
@Autowired
|
||||
private Repositories repositories;
|
||||
@Autowired
|
||||
private PersonRepository people;
|
||||
private LinkDiscoverer links = new DefaultLinkDiscoverer();
|
||||
|
||||
@Autowired ObjectMapper mapper;
|
||||
@Autowired Repositories repositories;
|
||||
@Autowired PersonRepository people;
|
||||
|
||||
public static Matcher<Link> isLinkWithHref(final String href) {
|
||||
return new BaseMatcher<Link>() {
|
||||
@@ -68,18 +60,15 @@ public class PersistentEntitySerializationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void serializesPersonEntity() throws IOException, InterruptedException {
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
mapper.writeValue(out, PersistentEntityResource.wrap(repositories.getPersistentEntity(Person.class),
|
||||
people.save(new Person("John", "Doe")),
|
||||
URI.create("http://localhost")));
|
||||
PersistentEntity<?, ?> persistentEntity = repositories.getPersistentEntity(Person.class);
|
||||
Person person = people.save(new Person("John", "Doe"));
|
||||
mapper.writeValue(out, PersistentEntityResource.wrap(persistentEntity, person, URI.create("http://localhost")));
|
||||
out.flush();
|
||||
String s = new String(out.toByteArray());
|
||||
|
||||
assertThat("Siblings Link looks correct",
|
||||
JsonPath.read(s, "$links[0].href").toString(),
|
||||
endsWith("/2/siblings"));
|
||||
assertThat("Siblings Link looks correct", JsonPath.read(s, "$links[0].href").toString(), endsWith("/2/siblings"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.springframework.web.method.support.ModelAndViewContainer;
|
||||
*
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class PagingAndSortingMethodArgumentResolver implements HandlerMethodArgumentResolver {
|
||||
|
||||
private static final int DEFAULT_PAGE = 1; // We're 1-based, not 0-based
|
||||
|
||||
@@ -30,8 +30,8 @@ public class PersistentEntityResourceHandlerMethodArgumentResolver implements Ha
|
||||
return PersistentEntityResource.class.isAssignableFrom(parameter.getParameterType());
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public Object resolveArgument(MethodParameter parameter,
|
||||
ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest,
|
||||
@@ -49,7 +49,7 @@ public class PersistentEntityResourceHandlerMethodArgumentResolver implements Ha
|
||||
}
|
||||
|
||||
Object obj = converter.read(domainType, request);
|
||||
return new PersistentEntityResource(repoRequest.getPersistentEntity(),
|
||||
return new PersistentEntityResource<Object>(repoRequest.getPersistentEntity(),
|
||||
obj);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@ public class RepositoryRestHandlerMapping extends RequestMappingHandlerMapping {
|
||||
setOrder(Ordered.LOWEST_PRECEDENCE);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
@Override
|
||||
protected HandlerMethod lookupHandlerMethod(String lookupPath,
|
||||
HttpServletRequest origRequest) throws Exception {
|
||||
|
||||
@@ -33,7 +33,7 @@ class RepositoryRestRequest {
|
||||
private final Link repoLink;
|
||||
private final Object repository;
|
||||
private final RepositoryMethodInvoker repoMethodInvoker;
|
||||
private final PersistentEntity persistentEntity;
|
||||
private final PersistentEntity<?, ?> persistentEntity;
|
||||
private final ResourceMapping entityMapping;
|
||||
|
||||
public RepositoryRestRequest(RepositoryRestConfiguration config,
|
||||
@@ -95,7 +95,7 @@ class RepositoryRestRequest {
|
||||
return repoMethodInvoker;
|
||||
}
|
||||
|
||||
PersistentEntity getPersistentEntity() {
|
||||
PersistentEntity<?, ?> getPersistentEntity() {
|
||||
return persistentEntity;
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ class RepositoryRestRequest {
|
||||
return entityMapping;
|
||||
}
|
||||
|
||||
void addNextLink(Page page, List<Link> links) {
|
||||
void addNextLink(Page<?> page, List<Link> links) {
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromUri(baseUri);
|
||||
// Add existing query parameters
|
||||
addQueryParameters(request, builder);
|
||||
@@ -114,7 +114,7 @@ class RepositoryRestRequest {
|
||||
links.add(new Link(builder.build().toString(), "page.next"));
|
||||
}
|
||||
|
||||
void addPrevLink(Page page, List<Link> links) {
|
||||
void addPrevLink(Page<?> page, List<Link> links) {
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromUri(baseUri);
|
||||
// Add existing query parameters
|
||||
addQueryParameters(request, builder);
|
||||
|
||||
@@ -6,7 +6,10 @@ package org.springframework.data.rest.webmvc;
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
public class ResourceNotFoundException extends RuntimeException {
|
||||
public ResourceNotFoundException() {
|
||||
|
||||
private static final long serialVersionUID = 7992904489502842099L;
|
||||
|
||||
public ResourceNotFoundException() {
|
||||
super("Resource not found");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
/**
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
public class BaseUriLinkBuilder extends LinkBuilderSupport {
|
||||
public class BaseUriLinkBuilder extends LinkBuilderSupport<BaseUriLinkBuilder> {
|
||||
|
||||
public BaseUriLinkBuilder(UriComponentsBuilder builder) {
|
||||
super(builder);
|
||||
|
||||
@@ -21,7 +21,7 @@ public class ConstraintViolationExceptionMessage {
|
||||
MessageSource msgSrc,
|
||||
Locale locale) {
|
||||
this.cve = cve;
|
||||
for(ConstraintViolation cv : cve.getConstraintViolations()) {
|
||||
for(ConstraintViolation<?> cv : cve.getConstraintViolations()) {
|
||||
messages.add(new ConstraintViolationMessage(cv, msgSrc, locale));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,15 +10,15 @@ import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.BeanFactoryUtils;
|
||||
import org.springframework.beans.factory.ListableBeanFactory;
|
||||
import org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor;
|
||||
import org.springframework.web.context.request.WebRequestInterceptor;
|
||||
|
||||
/**
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
public class JpaHelper implements BeanFactoryAware {
|
||||
|
||||
private List interceptor = new ArrayList<Object>();
|
||||
private List<WebRequestInterceptor> interceptor = new ArrayList<WebRequestInterceptor>();
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
@Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
String[] beanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
|
||||
(ListableBeanFactory)beanFactory,
|
||||
@@ -32,7 +32,7 @@ public class JpaHelper implements BeanFactoryAware {
|
||||
}
|
||||
}
|
||||
|
||||
public List getInterceptors() {
|
||||
public List<WebRequestInterceptor> getInterceptors() {
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,13 +14,11 @@ import org.springframework.validation.FieldError;
|
||||
*/
|
||||
public class RepositoryConstraintViolationExceptionMessage {
|
||||
|
||||
private final RepositoryConstraintViolationException violationException;
|
||||
private final List<ValidationError> errors = new ArrayList<ValidationError>();
|
||||
|
||||
public RepositoryConstraintViolationExceptionMessage(RepositoryConstraintViolationException violationException,
|
||||
MessageSource msgSrc,
|
||||
Locale locale) {
|
||||
this.violationException = violationException;
|
||||
|
||||
for(FieldError fe : violationException.getErrors().getFieldErrors()) {
|
||||
List<Object> args = new ArrayList<Object>();
|
||||
|
||||
@@ -36,7 +36,7 @@ public class RepositoryEntityLinks extends AbstractEntityLinks {
|
||||
}
|
||||
|
||||
@Override public boolean supports(Class<?> delimiter) {
|
||||
PersistentEntity persistentEntity = repositories.getPersistentEntity(delimiter);
|
||||
PersistentEntity<?, ?> persistentEntity = repositories.getPersistentEntity(delimiter);
|
||||
return (null != persistentEntity);
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class RepositoryEntityLinks extends AbstractEntityLinks {
|
||||
if(null == repoInfo) {
|
||||
throw new IllegalArgumentException(type + " is not managed by any repository.");
|
||||
}
|
||||
PersistentEntity persistentEntity = repositories.getPersistentEntity(type);
|
||||
PersistentEntity<?, ?> persistentEntity = repositories.getPersistentEntity(type);
|
||||
if(null == persistentEntity) {
|
||||
throw new IllegalArgumentException(type + " is not managed by any repository.");
|
||||
}
|
||||
@@ -71,19 +71,20 @@ public class RepositoryEntityLinks extends AbstractEntityLinks {
|
||||
throw new IllegalArgumentException(type + " is not managed by any repository.");
|
||||
}
|
||||
ResourceMapping repoMapping = getResourceMapping(config, repoInfo);
|
||||
PersistentEntity persistentEntity = repositories.getPersistentEntity(type);
|
||||
PersistentEntity<?, ?> persistentEntity = repositories.getPersistentEntity(type);
|
||||
ResourceMapping entityMapping = getResourceMapping(config, persistentEntity);
|
||||
return linkFor(type).slash(id).withRel(repoMapping.getRel() + "." + entityMapping.getRel());
|
||||
}
|
||||
|
||||
private class PersistentEntityLinkBuilder implements LinkBuilder {
|
||||
|
||||
private final UriComponentsBuilder builder;
|
||||
private final ResourceMapping repoMapping;
|
||||
private final ResourceMapping entityMapping;
|
||||
|
||||
private PersistentEntityLinkBuilder(URI baseUri,
|
||||
RepositoryInformation repoInfo,
|
||||
PersistentEntity persistentEntity) {
|
||||
PersistentEntity<?, ?> persistentEntity) {
|
||||
this.repoMapping = getResourceMapping(config, repoInfo);
|
||||
this.entityMapping = getResourceMapping(config, persistentEntity);
|
||||
if(null == baseUri) {
|
||||
@@ -101,7 +102,7 @@ public class RepositoryEntityLinks extends AbstractEntityLinks {
|
||||
@Override public LinkBuilder slash(Object object) {
|
||||
String path = String.format("%s", object);
|
||||
if(object instanceof PersistentProperty) {
|
||||
String propName = ((PersistentProperty)object).getName();
|
||||
String propName = ((PersistentProperty<?>) object).getName();
|
||||
if(entityMapping.hasResourceMappingFor(propName)) {
|
||||
path = entityMapping.getResourceMappingFor(propName).getPath();
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package org.springframework.data.rest.webmvc;
|
||||
|
||||
import org.jmock.integration.junit4.JUnitRuleMockery;
|
||||
import org.jmock.lib.legacy.ClassImposteriser;
|
||||
|
||||
/**
|
||||
* Abstract base classes for JUnit tests that use JMock.
|
||||
*
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
public abstract class AbstractJMockTests {
|
||||
|
||||
protected JUnitRuleMockery context = new JUnitRuleMockery() {{
|
||||
setImposteriser(ClassImposteriser.INSTANCE);
|
||||
}};
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package org.springframework.data.rest.webmvc;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
/**
|
||||
* @author Jon Brisbin
|
||||
*/
|
||||
public abstract class AbstractServerEnabledTest {
|
||||
|
||||
private Server server;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
if(null == server) {
|
||||
server = new Server(0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user