Java源码示例:org.springframework.aop.support.NameMatchMethodPointcut

示例1
/**
 * 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"));
}
 
示例2
@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);
}
 
示例3
/**
 * 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"));
}
 
示例4
@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);
}
 
示例5
/**
 * 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);
}
 
示例6
@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);
}
 
示例7
@Override
public MethodMatcher getMethodMatcher() {
    NameMatchMethodPointcut nameMatchMethodPointcut = new NameMatchMethodPointcut();
    nameMatchMethodPointcut.setMappedNames("schedule", "scheduleAtFixedRate", "scheduleWithFixedDelay");
    return nameMatchMethodPointcut;
}