DATAREST-221 - Improvements in ProxyProjectionFactory.

PropertyAccessingMethodInterceptor now ignores Object methods and forwards them to the proxy target. ProxyProjectionFactory now correctly sets up the SpEL root object for reference in expression on accessors.
This commit is contained in:
Oliver Gierke
2014-03-11 10:36:47 +01:00
parent 6e0d153e08
commit ba71362c15
4 changed files with 49 additions and 13 deletions

View File

@@ -62,6 +62,16 @@ public class PropertyAccessingMethodInterceptorUnitTests {
new PropertyAccessingMethodInterceptor(new Source()).invoke(invocation);
}
/**
* @see DATAREST-221
*/
@Test
public void forwardsObjectMethodInvocation() throws Throwable {
when(invocation.getMethod()).thenReturn(Object.class.getMethod("toString"));
new PropertyAccessingMethodInterceptor(new Source()).invoke(invocation);
}
static class Source {
String firstname;

View File

@@ -20,6 +20,7 @@ import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.aop.TargetClassAware;
import org.springframework.beans.factory.annotation.Value;
/**
* Unit tests for {@link ProxyProjectionFactory}.
@@ -67,15 +68,29 @@ public class ProxyProjectionFactoryUnitTests {
factory.createProjection(new Object(), Object.class);
}
/**
* @see DATAREST-221
*/
@Test
public void exposesSpelInvokingMethod() {
Customer customer = new Customer();
customer.firstname = "Dave";
customer.lastname = "Matthews";
CustomerExcerpt excerpt = factory.createProjection(customer, CustomerExcerpt.class);
assertThat(excerpt.getFullName(), is("Dave Matthews"));
}
static class Customer {
String firstname, lastname;
Address address;
public String firstname, lastname;
public Address address;
}
static class Address {
String zipCode, city;
public String zipCode, city;
}
interface CustomerExcerpt {
@@ -83,6 +98,9 @@ public class ProxyProjectionFactoryUnitTests {
String getFirstname();
AddressExcerpt getAddress();
@Value("#{target.firstname + ' ' + target.lastname}")
String getFullName();
}
interface AddressExcerpt {