Search in sources :

Example 36 with MethodInterceptor

use of org.aopalliance.intercept.MethodInterceptor in project spring-data-commons by spring-projects.

the class ProjectingMethodInterceptorUnitTests method appliesProjectionToNonEmptyMap.

// DATAREST-394, DATAREST-408
@Test
@SuppressWarnings("unchecked")
public void appliesProjectionToNonEmptyMap() throws Throwable {
    MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(new ProxyProjectionFactory(), interceptor, conversionService);
    Object result = methodInterceptor.invoke(mockInvocationOf("getHelperMap", Collections.singletonMap("foo", mock(Helper.class))));
    assertThat(result).isInstanceOf(Map.class);
    Map<String, Object> projections = (Map<String, Object>) result;
    assertThat(projections).hasSize(1);
    assertThat(projections).matches(map -> map.get("foo") instanceof HelperProjection);
}
Also used : MethodInterceptor(org.aopalliance.intercept.MethodInterceptor) Map(java.util.Map) Test(org.junit.Test)

Example 37 with MethodInterceptor

use of org.aopalliance.intercept.MethodInterceptor in project spring-data-commons by spring-projects.

the class ProjectingMethodInterceptorUnitTests method retunsDelegateResultAsIsIfTypesMatch.

// DATAREST-221
@Test
public void retunsDelegateResultAsIsIfTypesMatch() throws Throwable {
    MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(factory, interceptor, conversionService);
    when(invocation.getMethod()).thenReturn(Helper.class.getMethod("getString"));
    when(interceptor.invoke(invocation)).thenReturn("Foo");
    assertThat(methodInterceptor.invoke(invocation)).isEqualTo("Foo");
}
Also used : MethodInterceptor(org.aopalliance.intercept.MethodInterceptor) Test(org.junit.Test)

Example 38 with MethodInterceptor

use of org.aopalliance.intercept.MethodInterceptor in project spring-data-commons by spring-projects.

the class ProjectingMethodInterceptorUnitTests method appliesProjectionToNonEmptySets.

// DATAREST-394, DATAREST-408
@Test
@SuppressWarnings("unchecked")
public void appliesProjectionToNonEmptySets() throws Throwable {
    MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(new ProxyProjectionFactory(), interceptor, conversionService);
    Object result = methodInterceptor.invoke(mockInvocationOf("getHelperCollection", Collections.singleton(mock(Helper.class))));
    assertThat(result).isInstanceOf(Set.class);
    Set<Object> projections = (Set<Object>) result;
    assertThat(projections).hasSize(1);
    assertThat(projections).hasOnlyElementsOfType(HelperProjection.class);
}
Also used : MethodInterceptor(org.aopalliance.intercept.MethodInterceptor) Set(java.util.Set) Test(org.junit.Test)

Example 39 with MethodInterceptor

use of org.aopalliance.intercept.MethodInterceptor in project spring-data-commons by spring-projects.

the class ProjectingMethodInterceptorUnitTests method allowsMaskingAnArrayIntoACollection.

// DATAREST-394, DATAREST-408
@Test
@SuppressWarnings("unchecked")
public void allowsMaskingAnArrayIntoACollection() throws Throwable {
    MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor(new ProxyProjectionFactory(), interceptor, conversionService);
    Object result = methodInterceptor.invoke(mockInvocationOf("getHelperArray", new Helper[] { mock(Helper.class) }));
    assertThat(result).isInstanceOf(Collection.class);
    Collection<Object> projections = (Collection<Object>) result;
    assertThat(projections).hasSize(1);
    assertThat(projections).hasOnlyElementsOfType(HelperProjection.class);
}
Also used : MethodInterceptor(org.aopalliance.intercept.MethodInterceptor) Collection(java.util.Collection) Test(org.junit.Test)

Example 40 with MethodInterceptor

use of org.aopalliance.intercept.MethodInterceptor in project spring-data-commons by spring-projects.

the class PropertyAccessingMethodInterceptorUnitTests method triggersPropertyAccessOnTarget.

// DATAREST-221
@Test
public void triggersPropertyAccessOnTarget() throws Throwable {
    Source source = new Source();
    source.firstname = "Dave";
    when(invocation.getMethod()).thenReturn(Projection.class.getMethod("getFirstname"));
    MethodInterceptor interceptor = new PropertyAccessingMethodInterceptor(source);
    assertThat(interceptor.invoke(invocation)).isEqualTo("Dave");
}
Also used : MethodInterceptor(org.aopalliance.intercept.MethodInterceptor) Test(org.junit.Test)

Aggregations

MethodInterceptor (org.aopalliance.intercept.MethodInterceptor)57 Test (org.junit.Test)30 MethodInvocation (org.aopalliance.intercept.MethodInvocation)28 List (java.util.List)20 Method (java.lang.reflect.Method)19 ArrayList (java.util.ArrayList)18 Test (org.junit.jupiter.api.Test)15 Advice (org.aopalliance.aop.Advice)14 Map (java.util.Map)13 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)13 AopUtils (org.springframework.aop.support.AopUtils)12 TestBean (org.springframework.beans.testfixture.beans.TestBean)12 ProxyFactory (org.springframework.aop.framework.ProxyFactory)11 HashMap (java.util.HashMap)10 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)10 NopInterceptor (org.springframework.aop.testfixture.interceptor.NopInterceptor)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)9 Advisor (org.springframework.aop.Advisor)9 Message (org.springframework.messaging.Message)8