org.springframework.aop.interceptor.DebugInterceptor Java Examples

The following examples show how to use org.springframework.aop.interceptor.DebugInterceptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomNamespaceHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testProxyingDecorator() throws Exception {
	ITestBean bean = (ITestBean) this.beanFactory.getBean("debuggingTestBean");
	assertTestBean(bean);
	assertTrue(AopUtils.isAopProxy(bean));
	Advisor[] advisors = ((Advised) bean).getAdvisors();
	assertEquals("Incorrect number of advisors", 1, advisors.length);
	assertEquals("Incorrect advice class", DebugInterceptor.class, advisors[0].getAdvice().getClass());
}
 
Example #2
Source File: ProxyFactoryBeanTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testDetectsInterfaces() throws Exception {
	ProxyFactoryBean fb = new ProxyFactoryBean();
	fb.setTarget(new TestBean());
	fb.addAdvice(new DebugInterceptor());
	fb.setBeanFactory(new DefaultListableBeanFactory());
	ITestBean proxy = (ITestBean) fb.getObject();
	assertTrue(AopUtils.isJdkDynamicProxy(proxy));
}
 
Example #3
Source File: ObjenesisProxyTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void appliesAspectToClassWithComplexConstructor() {
	@SuppressWarnings("resource")
	ApplicationContext context = new ClassPathXmlApplicationContext("ObjenesisProxyTests-context.xml", getClass());

	ClassWithComplexConstructor bean = context.getBean(ClassWithComplexConstructor.class);
	bean.method();

	DebugInterceptor interceptor = context.getBean(DebugInterceptor.class);
	assertThat(interceptor.getCount(), is(1L));
	assertThat(bean.getDependency().getValue(), is(1));
}
 
Example #4
Source File: CustomNamespaceHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testChainedDecorators() throws Exception {
	ITestBean bean = (ITestBean) this.beanFactory.getBean("chainedTestBean");
	assertTestBean(bean);
	assertTrue(AopUtils.isAopProxy(bean));
	Advisor[] advisors = ((Advised) bean).getAdvisors();
	assertEquals("Incorrect number of advisors", 2, advisors.length);
	assertEquals("Incorrect advice class.", DebugInterceptor.class, advisors[0].getAdvice().getClass());
	assertEquals("Incorrect advice class.", NopInterceptor.class, advisors[1].getAdvice().getClass());
}
 
Example #5
Source File: CustomNamespaceHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testProxyingDecorator() throws Exception {
	ITestBean bean = (ITestBean) this.beanFactory.getBean("debuggingTestBean");
	assertTestBean(bean);
	assertTrue(AopUtils.isAopProxy(bean));
	Advisor[] advisors = ((Advised) bean).getAdvisors();
	assertEquals("Incorrect number of advisors", 1, advisors.length);
	assertEquals("Incorrect advice class.", DebugInterceptor.class, advisors[0].getAdvice().getClass());
}
 
Example #6
Source File: ProxyFactoryBeanTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testDetectsInterfaces() throws Exception {
	ProxyFactoryBean fb = new ProxyFactoryBean();
	fb.setTarget(new TestBean());
	fb.addAdvice(new DebugInterceptor());
	fb.setBeanFactory(new DefaultListableBeanFactory());
	ITestBean proxy = (ITestBean) fb.getObject();
	assertTrue(AopUtils.isJdkDynamicProxy(proxy));
}
 
Example #7
Source File: ObjenesisProxyTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void appliesAspectToClassWithComplexConstructor() {
	@SuppressWarnings("resource")
	ApplicationContext context = new ClassPathXmlApplicationContext("ObjenesisProxyTests-context.xml", getClass());

	ClassWithComplexConstructor bean = context.getBean(ClassWithComplexConstructor.class);
	bean.method();

	DebugInterceptor interceptor = context.getBean(DebugInterceptor.class);
	assertThat(interceptor.getCount(), is(1L));
	assertThat(bean.getDependency().getValue(), is(1));
}
 
Example #8
Source File: CustomNamespaceHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testChainedDecorators() throws Exception {
	ITestBean bean = (ITestBean) this.beanFactory.getBean("chainedTestBean");
	assertTestBean(bean);
	assertTrue(AopUtils.isAopProxy(bean));
	Advisor[] advisors = ((Advised) bean).getAdvisors();
	assertEquals("Incorrect number of advisors", 2, advisors.length);
	assertEquals("Incorrect advice class", DebugInterceptor.class, advisors[0].getAdvice().getClass());
	assertEquals("Incorrect advice class", NopInterceptor.class, advisors[1].getAdvice().getClass());
}
 
Example #9
Source File: ProxyFactoryBeanTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testDetectsInterfaces() throws Exception {
	ProxyFactoryBean fb = new ProxyFactoryBean();
	fb.setTarget(new TestBean());
	fb.addAdvice(new DebugInterceptor());
	fb.setBeanFactory(new DefaultListableBeanFactory());
	ITestBean proxy = (ITestBean) fb.getObject();
	assertTrue(AopUtils.isJdkDynamicProxy(proxy));
}
 
Example #10
Source File: CustomNamespaceHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testProxyingDecorator() throws Exception {
	ITestBean bean = (ITestBean) this.beanFactory.getBean("debuggingTestBean");
	assertTestBean(bean);
	assertTrue(AopUtils.isAopProxy(bean));
	Advisor[] advisors = ((Advised) bean).getAdvisors();
	assertEquals("Incorrect number of advisors", 1, advisors.length);
	assertEquals("Incorrect advice class", DebugInterceptor.class, advisors[0].getAdvice().getClass());
}
 
Example #11
Source File: ObjenesisProxyTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void appliesAspectToClassWithComplexConstructor() {
	@SuppressWarnings("resource")
	ApplicationContext context = new ClassPathXmlApplicationContext("ObjenesisProxyTests-context.xml", getClass());

	ClassWithComplexConstructor bean = context.getBean(ClassWithComplexConstructor.class);
	bean.method();

	DebugInterceptor interceptor = context.getBean(DebugInterceptor.class);
	assertThat(interceptor.getCount(), is(1L));
	assertThat(bean.getDependency().getValue(), is(1));
}
 
Example #12
Source File: CustomNamespaceHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testChainedDecorators() throws Exception {
	ITestBean bean = (ITestBean) this.beanFactory.getBean("chainedTestBean");
	assertTestBean(bean);
	assertTrue(AopUtils.isAopProxy(bean));
	Advisor[] advisors = ((Advised) bean).getAdvisors();
	assertEquals("Incorrect number of advisors", 2, advisors.length);
	assertEquals("Incorrect advice class", DebugInterceptor.class, advisors[0].getAdvice().getClass());
	assertEquals("Incorrect advice class", NopInterceptor.class, advisors[1].getAdvice().getClass());
}
 
Example #13
Source File: LookupMethodWrappedByCglibProxyTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private void assertInterceptorCount(int count) {
	DebugInterceptor interceptor = getInterceptor();
	assertEquals("Interceptor count is incorrect", count, interceptor.getCount());
}
 
Example #14
Source File: LookupMethodWrappedByCglibProxyTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private void resetInterceptor() {
	DebugInterceptor interceptor = getInterceptor();
	interceptor.resetCount();
}
 
Example #15
Source File: CustomNamespaceHandlerTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
protected BeanDefinition createInterceptorDefinition(Node node) {
	return new RootBeanDefinition(DebugInterceptor.class);
}
 
Example #16
Source File: LookupMethodWrappedByCglibProxyTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private DebugInterceptor getInterceptor() {
	return (DebugInterceptor) applicationContext.getBean("interceptor");
}
 
Example #17
Source File: LookupMethodWrappedByCglibProxyTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private DebugInterceptor getInterceptor() {
	return (DebugInterceptor) applicationContext.getBean("interceptor");
}
 
Example #18
Source File: LookupMethodWrappedByCglibProxyTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private void resetInterceptor() {
	DebugInterceptor interceptor = getInterceptor();
	interceptor.resetCount();
}
 
Example #19
Source File: LookupMethodWrappedByCglibProxyTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private void assertInterceptorCount(int count) {
	DebugInterceptor interceptor = getInterceptor();
	assertEquals("Interceptor count is incorrect", count, interceptor.getCount());
}
 
Example #20
Source File: ProxyFactoryTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Should see effect immediately on behavior.
 */
@Test
public void testCanAddAndRemoveAspectInterfacesOnSingleton() {
	ProxyFactory config = new ProxyFactory(new TestBean());

	assertFalse("Shouldn't implement TimeStamped before manipulation",
			config.getProxy() instanceof TimeStamped);

	long time = 666L;
	TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor();
	ti.setTime(time);

	// Add to front of interceptor chain
	int oldCount = config.getAdvisors().length;
	config.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.class));

	assertTrue(config.getAdvisors().length == oldCount + 1);

	TimeStamped ts = (TimeStamped) config.getProxy();
	assertTrue(ts.getTimeStamp() == time);

	// Can remove
	config.removeAdvice(ti);

	assertTrue(config.getAdvisors().length == oldCount);

	try {
		// Existing reference will fail
		ts.getTimeStamp();
		fail("Existing object won't implement this interface any more");
	}
	catch (RuntimeException ex) {
	}

	assertFalse("Should no longer implement TimeStamped",
			config.getProxy() instanceof TimeStamped);

	// Now check non-effect of removing interceptor that isn't there
	config.removeAdvice(new DebugInterceptor());

	assertTrue(config.getAdvisors().length == oldCount);

	ITestBean it = (ITestBean) ts;
	DebugInterceptor debugInterceptor = new DebugInterceptor();
	config.addAdvice(0, debugInterceptor);
	it.getSpouse();
	assertEquals(1, debugInterceptor.getCount());
	config.removeAdvice(debugInterceptor);
	it.getSpouse();
	// not invoked again
	assertTrue(debugInterceptor.getCount() == 1);
}
 
Example #21
Source File: CustomNamespaceHandlerTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
protected BeanDefinition createInterceptorDefinition(Node node) {
	return new RootBeanDefinition(DebugInterceptor.class);
}
 
Example #22
Source File: CustomNamespaceHandlerTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
protected BeanDefinition createInterceptorDefinition(Node node) {
	return new RootBeanDefinition(DebugInterceptor.class);
}
 
Example #23
Source File: ProxyFactoryTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Should see effect immediately on behavior.
 */
@Test
public void testCanAddAndRemoveAspectInterfacesOnSingleton() {
	ProxyFactory config = new ProxyFactory(new TestBean());

	assertFalse("Shouldn't implement TimeStamped before manipulation",
			config.getProxy() instanceof TimeStamped);

	long time = 666L;
	TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor();
	ti.setTime(time);

	// Add to front of interceptor chain
	int oldCount = config.getAdvisors().length;
	config.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.class));

	assertTrue(config.getAdvisors().length == oldCount + 1);

	TimeStamped ts = (TimeStamped) config.getProxy();
	assertTrue(ts.getTimeStamp() == time);

	// Can remove
	config.removeAdvice(ti);

	assertTrue(config.getAdvisors().length == oldCount);

	try {
		// Existing reference will fail
		ts.getTimeStamp();
		fail("Existing object won't implement this interface any more");
	}
	catch (RuntimeException ex) {
	}

	assertFalse("Should no longer implement TimeStamped",
			config.getProxy() instanceof TimeStamped);

	// Now check non-effect of removing interceptor that isn't there
	config.removeAdvice(new DebugInterceptor());

	assertTrue(config.getAdvisors().length == oldCount);

	ITestBean it = (ITestBean) ts;
	DebugInterceptor debugInterceptor = new DebugInterceptor();
	config.addAdvice(0, debugInterceptor);
	it.getSpouse();
	assertEquals(1, debugInterceptor.getCount());
	config.removeAdvice(debugInterceptor);
	it.getSpouse();
	// not invoked again
	assertTrue(debugInterceptor.getCount() == 1);
}
 
Example #24
Source File: LookupMethodWrappedByCglibProxyTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
private DebugInterceptor getInterceptor() {
	return (DebugInterceptor) applicationContext.getBean("interceptor");
}
 
Example #25
Source File: LookupMethodWrappedByCglibProxyTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
private void resetInterceptor() {
	DebugInterceptor interceptor = getInterceptor();
	interceptor.resetCount();
}
 
Example #26
Source File: LookupMethodWrappedByCglibProxyTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
private void assertInterceptorCount(int count) {
	DebugInterceptor interceptor = getInterceptor();
	assertEquals("Interceptor count is incorrect", count, interceptor.getCount());
}
 
Example #27
Source File: ProxyFactoryTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Should see effect immediately on behavior.
 */
@Test
public void testCanAddAndRemoveAspectInterfacesOnSingleton() {
	ProxyFactory config = new ProxyFactory(new TestBean());

	assertFalse("Shouldn't implement TimeStamped before manipulation",
			config.getProxy() instanceof TimeStamped);

	long time = 666L;
	TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor();
	ti.setTime(time);

	// Add to front of interceptor chain
	int oldCount = config.getAdvisors().length;
	config.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.class));

	assertTrue(config.getAdvisors().length == oldCount + 1);

	TimeStamped ts = (TimeStamped) config.getProxy();
	assertTrue(ts.getTimeStamp() == time);

	// Can remove
	config.removeAdvice(ti);

	assertTrue(config.getAdvisors().length == oldCount);

	try {
		// Existing reference will fail
		ts.getTimeStamp();
		fail("Existing object won't implement this interface any more");
	}
	catch (RuntimeException ex) {
	}

	assertFalse("Should no longer implement TimeStamped",
			config.getProxy() instanceof TimeStamped);

	// Now check non-effect of removing interceptor that isn't there
	config.removeAdvice(new DebugInterceptor());

	assertTrue(config.getAdvisors().length == oldCount);

	ITestBean it = (ITestBean) ts;
	DebugInterceptor debugInterceptor = new DebugInterceptor();
	config.addAdvice(0, debugInterceptor);
	it.getSpouse();
	assertEquals(1, debugInterceptor.getCount());
	config.removeAdvice(debugInterceptor);
	it.getSpouse();
	// not invoked again
	assertTrue(debugInterceptor.getCount() == 1);
}