org.springframework.aop.support.NameMatchMethodPointcut Java Examples

The following examples show how to use org.springframework.aop.support.NameMatchMethodPointcut. 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: AbstractAopProxyTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Check that the string is informative.
 */
@Test
public void testProxyConfigString() {
	TestBean target = new TestBean();
	ProxyFactory pc = new ProxyFactory(target);
	pc.setInterfaces(ITestBean.class);
	pc.addAdvice(new NopInterceptor());
	MethodBeforeAdvice mba = new CountingBeforeAdvice();
	Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut(), mba);
	pc.addAdvisor(advisor);
	ITestBean proxied = (ITestBean) createProxy(pc);

	String proxyConfigString = ((Advised) proxied).toProxyConfigString();
	assertTrue(proxyConfigString.contains(advisor.toString()));
	assertTrue(proxyConfigString.contains("1 interface"));
}
 
Example #2
Source File: AbstractAopProxyTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testCanPreventCastToAdvisedUsingOpaque() {
	TestBean target = new TestBean();
	ProxyFactory pc = new ProxyFactory(target);
	pc.setInterfaces(ITestBean.class);
	pc.addAdvice(new NopInterceptor());
	CountingBeforeAdvice mba = new CountingBeforeAdvice();
	Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut().addMethodName("setAge"), mba);
	pc.addAdvisor(advisor);
	assertFalse("Opaque defaults to false", pc.isOpaque());
	pc.setOpaque(true);
	assertTrue("Opaque now true for this config", pc.isOpaque());
	ITestBean proxied = (ITestBean) createProxy(pc);
	proxied.setAge(10);
	assertEquals(10, proxied.getAge());
	assertEquals(1, mba.getCalls());

	assertFalse("Cannot be cast to Advised", proxied instanceof Advised);
}
 
Example #3
Source File: AbstractAopProxyTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Check that the string is informative.
 */
@Test
public void testProxyConfigString() {
	TestBean target = new TestBean();
	ProxyFactory pc = new ProxyFactory(target);
	pc.setInterfaces(ITestBean.class);
	pc.addAdvice(new NopInterceptor());
	MethodBeforeAdvice mba = new CountingBeforeAdvice();
	Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut(), mba);
	pc.addAdvisor(advisor);
	ITestBean proxied = (ITestBean) createProxy(pc);

	String proxyConfigString = ((Advised) proxied).toProxyConfigString();
	assertTrue(proxyConfigString.contains(advisor.toString()));
	assertTrue(proxyConfigString.contains("1 interface"));
}
 
Example #4
Source File: AbstractAopProxyTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testCanPreventCastToAdvisedUsingOpaque() {
	TestBean target = new TestBean();
	ProxyFactory pc = new ProxyFactory(target);
	pc.setInterfaces(ITestBean.class);
	pc.addAdvice(new NopInterceptor());
	CountingBeforeAdvice mba = new CountingBeforeAdvice();
	Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut().addMethodName("setAge"), mba);
	pc.addAdvisor(advisor);
	assertFalse("Opaque defaults to false", pc.isOpaque());
	pc.setOpaque(true);
	assertTrue("Opaque now true for this config", pc.isOpaque());
	ITestBean proxied = (ITestBean) createProxy(pc);
	proxied.setAge(10);
	assertEquals(10, proxied.getAge());
	assertEquals(1, mba.getCalls());

	assertFalse("Cannot be cast to Advised", proxied instanceof Advised);
}
 
Example #5
Source File: AbstractAopProxyTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Check that the string is informative.
 */
@Test
public void testProxyConfigString() {
	TestBean target = new TestBean();
	ProxyFactory pc = new ProxyFactory(target);
	pc.setInterfaces(new Class<?>[] {ITestBean.class});
	pc.addAdvice(new NopInterceptor());
	MethodBeforeAdvice mba = new CountingBeforeAdvice();
	Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut(), mba);
	pc.addAdvisor(advisor);
	ITestBean proxied = (ITestBean) createProxy(pc);

	String proxyConfigString = ((Advised) proxied).toProxyConfigString();
	assertTrue(proxyConfigString.indexOf(advisor.toString()) != -1);
	assertTrue(proxyConfigString.indexOf("1 interface") != -1);
}
 
Example #6
Source File: AbstractAopProxyTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testCanPreventCastToAdvisedUsingOpaque() {
	TestBean target = new TestBean();
	ProxyFactory pc = new ProxyFactory(target);
	pc.setInterfaces(new Class<?>[] {ITestBean.class});
	pc.addAdvice(new NopInterceptor());
	CountingBeforeAdvice mba = new CountingBeforeAdvice();
	Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut().addMethodName("setAge"), mba);
	pc.addAdvisor(advisor);
	assertFalse("Opaque defaults to false", pc.isOpaque());
	pc.setOpaque(true);
	assertTrue("Opaque now true for this config", pc.isOpaque());
	ITestBean proxied = (ITestBean) createProxy(pc);
	proxied.setAge(10);
	assertEquals(10, proxied.getAge());
	assertEquals(1, mba.getCalls());

	assertFalse("Cannot be cast to Advised", proxied instanceof Advised);
}
 
Example #7
Source File: SchedulerProxyScheduledLockAdvisor.java    From ShedLock with Apache License 2.0 4 votes vote down vote up
@Override
public MethodMatcher getMethodMatcher() {
    NameMatchMethodPointcut nameMatchMethodPointcut = new NameMatchMethodPointcut();
    nameMatchMethodPointcut.setMappedNames("schedule", "scheduleAtFixedRate", "scheduleWithFixedDelay");
    return nameMatchMethodPointcut;
}