use of org.aopalliance.intercept.MethodInterceptor in project guice by google.
the class LineNumbersTest method testCanHandleLineNumbersForGuiceGeneratedClasses.
@Test
public void testCanHandleLineNumbersForGuiceGeneratedClasses() {
assumeTrue(InternalFlags.isBytecodeGenEnabled());
try {
Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bindInterceptor(Matchers.only(A.class), Matchers.any(), new MethodInterceptor() {
@Override
public Object invoke(MethodInvocation methodInvocation) {
return null;
}
});
bind(A.class);
}
});
fail();
} catch (CreationException expected) {
assertContains(expected.getMessage(), "No implementation for LineNumbersTest$B was bound.", "for 1st parameter b", "at LineNumbersTest$2.configure");
}
}
use of org.aopalliance.intercept.MethodInterceptor in project guice by google.
the class ElementsTest method testBindIntercepor.
public void testBindIntercepor() {
// Unavoidable since subclassesOf returns raw type
@SuppressWarnings("rawtypes") final Matcher<Class> classMatcher = Matchers.subclassesOf(List.class);
final Matcher<Object> methodMatcher = Matchers.any();
final MethodInterceptor methodInterceptor = new MethodInterceptor() {
@Override
public Object invoke(MethodInvocation methodInvocation) {
return null;
}
};
checkModule(new AbstractModule() {
@Override
protected void configure() {
bindInterceptor(classMatcher, methodMatcher, methodInterceptor);
}
}, new FailingElementVisitor() {
@Override
public Void visit(InterceptorBinding command) {
assertSame(classMatcher, command.getClassMatcher());
assertSame(methodMatcher, command.getMethodMatcher());
assertEquals(Arrays.asList(methodInterceptor), command.getInterceptors());
return null;
}
});
}
use of org.aopalliance.intercept.MethodInterceptor in project spring-security by spring-projects.
the class GlobalMethodSecurityConfigurationTests method methodSecurityInterceptorUsesMetadataSourceBeanWhenProxyingDisabled.
@Test
public void methodSecurityInterceptorUsesMetadataSourceBeanWhenProxyingDisabled() {
this.spring.register(CustomMetadataSourceBeanProxyEnabledConfig.class).autowire();
MethodSecurityInterceptor methodInterceptor = (MethodSecurityInterceptor) this.spring.getContext().getBean(MethodInterceptor.class);
MethodSecurityMetadataSource methodSecurityMetadataSource = this.spring.getContext().getBean(MethodSecurityMetadataSource.class);
assertThat(methodInterceptor.getSecurityMetadataSource()).isSameAs(methodSecurityMetadataSource);
}
use of org.aopalliance.intercept.MethodInterceptor in project shiro by apache.
the class ShiroAopModuleTest method testBindShiroInterceptor.
@Test
public void testBindShiroInterceptor() {
ShiroAopModule underTest = new ShiroAopModule() {
@Override
protected void configureInterceptors(AnnotationResolver resolver) {
bindShiroInterceptor(new MyAnnotationMethodInterceptor());
}
};
List<Element> elements = Elements.getElements(underTest);
for (Element element : elements) {
if (element instanceof InterceptorBinding) {
InterceptorBinding binding = (InterceptorBinding) element;
assertTrue(binding.getClassMatcher().matches(getClass()));
Method method = null;
Class<? extends Annotation> theAnnotation = null;
for (Class<? extends Annotation> annotation : protectedMethods.keySet()) {
if (binding.getMethodMatcher().matches(protectedMethods.get(annotation))) {
method = protectedMethods.get(annotation);
theAnnotation = annotation;
protectedMethods.remove(annotation);
break;
}
}
if (method == null) {
fail("Did not expect interceptor binding " + binding.getInterceptors());
}
List<MethodInterceptor> interceptors = binding.getInterceptors();
assertEquals(1, interceptors.size());
assertTrue(interceptors.get(0) instanceof AopAllianceMethodInterceptorAdapter);
assertTrue(interceptorTypes.get(theAnnotation).isInstance(((AopAllianceMethodInterceptorAdapter) interceptors.get(0)).shiroInterceptor));
}
}
assertTrue("Not all interceptors were bound.", protectedMethods.isEmpty());
}
use of org.aopalliance.intercept.MethodInterceptor in project spring-framework by spring-projects.
the class AbstractAopProxyTests method testDeclaredException.
@Test
public void testDeclaredException() throws Throwable {
final Exception expectedException = new Exception();
// Test return value
MethodInterceptor mi = invocation -> {
throw expectedException;
};
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
pc.addAdvice(mi);
// We don't care about the object
mockTargetSource.setTarget(new TestBean());
pc.setTargetSource(mockTargetSource);
AopProxy aop = createAopProxy(pc);
assertThatExceptionOfType(Exception.class).isThrownBy(() -> {
ITestBean tb = (ITestBean) aop.getProxy();
// Note: exception param below isn't used
tb.exceptional(expectedException);
}).matches(expectedException::equals);
}
Aggregations