DATAREST-93 - Removed compiler warnings.

Removed dependency on jMock.
This commit is contained in:
Oliver Gierke
2013-06-05 23:50:28 +02:00
parent cb4056e351
commit 90c4b62428
45 changed files with 155 additions and 204 deletions

View File

@@ -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));
}

View File

@@ -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;
}

View File

@@ -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");

View File

@@ -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,

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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);
}
}

View File

@@ -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));
}
}

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -34,7 +34,7 @@ public class RepositoryMethodResponse {
return this;
}
public RepositoryMethodResponse addAllResults(Iterator results) {
public RepositoryMethodResponse addAllResults(Iterator<?> results) {
if(null == results) {
return this;
}

View File

@@ -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>());

View File

@@ -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() {

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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);
}};
}

View File

@@ -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"));
}
}