Search in sources :

Example 16 with Advised

use of org.springframework.aop.framework.Advised in project spring-framework by spring-projects.

the class PersistenceExceptionTranslationPostProcessorTests method checkWillTranslateExceptions.

protected void checkWillTranslateExceptions(Object o) {
    assertTrue(o instanceof Advised);
    Advised a = (Advised) o;
    for (Advisor advisor : a.getAdvisors()) {
        if (advisor instanceof PersistenceExceptionTranslationAdvisor) {
            return;
        }
    }
    fail("No translation");
}
Also used : Advised(org.springframework.aop.framework.Advised) Advisor(org.springframework.aop.Advisor)

Example 17 with Advised

use of org.springframework.aop.framework.Advised in project spring-framework by spring-projects.

the class AnnotationTransactionAttributeSourceTests method serializable.

@Test
public void serializable() throws Exception {
    TestBean1 tb = new TestBean1();
    CallCountingTransactionManager ptm = new CallCountingTransactionManager();
    AnnotationTransactionAttributeSource tas = new AnnotationTransactionAttributeSource();
    TransactionInterceptor ti = new TransactionInterceptor(ptm, tas);
    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.setInterfaces(ITestBean.class);
    proxyFactory.addAdvice(ti);
    proxyFactory.setTarget(tb);
    ITestBean proxy = (ITestBean) proxyFactory.getProxy();
    proxy.getAge();
    assertEquals(1, ptm.commits);
    ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
    serializedProxy.getAge();
    Advised advised = (Advised) serializedProxy;
    TransactionInterceptor serializedTi = (TransactionInterceptor) advised.getAdvisors()[0].getAdvice();
    CallCountingTransactionManager serializedPtm = (CallCountingTransactionManager) serializedTi.getTransactionManager();
    assertEquals(2, serializedPtm.commits);
}
Also used : TransactionInterceptor(org.springframework.transaction.interceptor.TransactionInterceptor) ProxyFactory(org.springframework.aop.framework.ProxyFactory) Advised(org.springframework.aop.framework.Advised) CallCountingTransactionManager(org.springframework.tests.transaction.CallCountingTransactionManager) Test(org.junit.Test)

Example 18 with Advised

use of org.springframework.aop.framework.Advised in project spring-framework by spring-projects.

the class EnableTransactionManagementIntegrationTests method assertTxProxying.

private void assertTxProxying(AnnotationConfigApplicationContext ctx) {
    FooRepository repo = ctx.getBean(FooRepository.class);
    boolean isTxProxy = false;
    if (AopUtils.isAopProxy(repo)) {
        for (Advisor advisor : ((Advised) repo).getAdvisors()) {
            if (advisor instanceof BeanFactoryTransactionAttributeSourceAdvisor) {
                isTxProxy = true;
                break;
            }
        }
    }
    assertTrue("FooRepository is not a TX proxy", isTxProxy);
    // trigger a transaction
    repo.findAll();
}
Also used : Advised(org.springframework.aop.framework.Advised) Advisor(org.springframework.aop.Advisor) BeanFactoryTransactionAttributeSourceAdvisor(org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor) BeanFactoryTransactionAttributeSourceAdvisor(org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor)

Example 19 with Advised

use of org.springframework.aop.framework.Advised in project spring-security by spring-projects.

the class GlobalMethodSecurityBeanDefinitionParserTests method targetShouldAllowProtectedMethodInvocationWithCorrectRole.

@Test
public void targetShouldAllowProtectedMethodInvocationWithCorrectRole() {
    loadContext();
    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("user", "password");
    SecurityContextHolder.getContext().setAuthentication(token);
    target.someUserMethod1();
    // SEC-1213. Check the order
    Advisor[] advisors = ((Advised) target).getAdvisors();
    assertThat(advisors.length).isEqualTo(1);
    assertThat(((MethodSecurityMetadataSourceAdvisor) advisors[0]).getOrder()).isEqualTo(1001);
}
Also used : MethodSecurityMetadataSourceAdvisor(org.springframework.security.access.intercept.aopalliance.MethodSecurityMetadataSourceAdvisor) Advised(org.springframework.aop.framework.Advised) Advisor(org.springframework.aop.Advisor) MethodSecurityMetadataSourceAdvisor(org.springframework.security.access.intercept.aopalliance.MethodSecurityMetadataSourceAdvisor) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Example 20 with Advised

use of org.springframework.aop.framework.Advised in project spring-security-oauth by spring-projects.

the class AbstractIntegrationTests method clear.

private void clear(TokenStore tokenStore) throws Exception {
    if (tokenStore instanceof Advised) {
        Advised advised = (Advised) tokenStore;
        TokenStore target = (TokenStore) advised.getTargetSource().getTarget();
        clear(target);
        return;
    }
    if (tokenStore instanceof InMemoryTokenStore) {
        ((InMemoryTokenStore) tokenStore).clear();
    }
    if (tokenStore instanceof JdbcTokenStore) {
        JdbcTemplate template = new JdbcTemplate(dataSource);
        template.execute("delete from oauth_access_token");
        template.execute("delete from oauth_refresh_token");
        template.execute("delete from oauth_client_token");
        template.execute("delete from oauth_code");
    }
}
Also used : InMemoryTokenStore(org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore) JdbcTokenStore(org.springframework.security.oauth2.provider.token.store.JdbcTokenStore) Advised(org.springframework.aop.framework.Advised) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) TokenStore(org.springframework.security.oauth2.provider.token.TokenStore) InMemoryTokenStore(org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore) JdbcTokenStore(org.springframework.security.oauth2.provider.token.store.JdbcTokenStore)

Aggregations

Advised (org.springframework.aop.framework.Advised)35 Test (org.junit.Test)22 ITestBean (org.springframework.tests.sample.beans.ITestBean)15 Advisor (org.springframework.aop.Advisor)10 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)10 TestBean (org.springframework.tests.sample.beans.TestBean)4 JoinPoint (org.aspectj.lang.JoinPoint)3 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)3 SyntheticInstantiationAdvisor (org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor)3 ProxyFactory (org.springframework.aop.framework.ProxyFactory)3 ApplicationContext (org.springframework.context.ApplicationContext)3 Person (org.springframework.tests.sample.beans.Person)3 StopWatch (org.springframework.util.StopWatch)3 PrototypeTargetSource (org.springframework.aop.target.PrototypeTargetSource)2 BeanFactory (org.springframework.beans.factory.BeanFactory)2 AnotherTestEvent (org.springframework.context.event.test.AnotherTestEvent)2 TestEvent (org.springframework.context.event.test.TestEvent)2 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)2 SerializableNopInterceptor (org.springframework.tests.aop.interceptor.SerializableNopInterceptor)2 SerializablePerson (org.springframework.tests.sample.beans.SerializablePerson)2