Example usage for org.springframework.aop.aspectj.annotation AspectJProxyFactory addAspect

List of usage examples for org.springframework.aop.aspectj.annotation AspectJProxyFactory addAspect

Introduction

In this page you can find the example usage for org.springframework.aop.aspectj.annotation AspectJProxyFactory addAspect.

Prototype

public void addAspect(Class<?> aspectClass) 

Source Link

Document

Add an aspect of the supplied type to the end of the advice chain.

Usage

From source file:org.cybercat.automation.annotations.AnnotationBuilder.java

@SuppressWarnings("unchecked")
private final static <T extends IFeature> T createFeature(Class<T> eType) throws AutomationFrameworkException {
    try {//w  w  w .  j a  v  a 2 s .c  o m
        Constructor<T> cons = eType.getDeclaredConstructor();
        T result = cons.newInstance();
        AnnotationBuilder.processCCFeature(result);
        AnnotationBuilder.processCCPageObject(result);
        AspectJProxyFactory proxyFactory = new AspectJProxyFactory(result);
        proxyFactory.addAspect(TestStepAspect.class);
        result = (T) proxyFactory.getProxy();
        log.info(eType.getSimpleName() + " feature has been created.");
        return result;
    } catch (Exception e) {
        // handle test fail
        throw new AutomationFrameworkException("Feature factoring exception. ", e);
    }
}

From source file:org.cybercat.automation.annotations.AnnotationBuilder.java

@SuppressWarnings("unchecked")
private static final <T extends IIntegrationService> T createIntegrationService(Class<T> clazz,
        CCIntegrationService aService) throws AutomationFrameworkException {
    Class<T> cService = versionControlPreprocessor(clazz);
    Constructor<T> cons;// www .ja  v a  2s .c o m
    try {
        cons = cService.getConstructor();
        T result = cons.newInstance();
        processIntegrationService(result, result.getClass());
        result.setup();
        AspectJProxyFactory proxyFactory = new AspectJProxyFactory(result);
        proxyFactory.addAspect(new IntegrationServiceAspect(aService.hasSession()));
        result = (T) proxyFactory.getProxy();
        log.info(cService.getSimpleName() + " integration Service has been created.");
        return result;
    } catch (Exception e) {
        throw new AutomationFrameworkException("Integration service creation problem.", e);
    }
}

From source file:org.cybercat.automation.core.PageFactoryImpl.java

@SuppressWarnings("unchecked")
public <T extends AbstractPageObject> T createPage(Class<T> page) throws PageObjectException {
    Constructor<T> cons;/*from w  w w  .ja v  a  2s.  c  o  m*/
    try {
        cons = page.getConstructor();
        T result = cons.newInstance();
        for (Field field : page.getDeclaredFields()) {
            field.setAccessible(true);
            if (field.getAnnotation(CCProperty.class) != null) {
                AnnotationBuilder.processPropertyField(result, field);
            }
        }
        AspectJProxyFactory proxyFactory = new AspectJProxyFactory(result);
        proxyFactory.addAspect(new PageObjectStateControlAcpect(this));
        result = (T) proxyFactory.getProxy();
        return result;
    } catch (Exception e) {
        throw new PageObjectException("Page object creation problem.", e);
    }
}

From source file:de.rahn.finances.services.securities.SecuritiesServiceMetricsAspectTest.java

/**
 * @throws Exception/*from   w  w  w .  j ava2s . c om*/
 */
@Before
public void setUp() throws Exception {
    counters.clear();
    gauges.clear();

    AspectJProxyFactory factory = new AspectJProxyFactory(service);
    factory.addAspect(classUnderTests);

    serviceProxy = factory.getProxy();

    testSecurity.setId(randomUUID().toString());
    testSecurity.setIsin("DE0000000000");
    testSecurity.setWkn("000000");
    testSecurity.setSymbol("ABC");
    testSecurity.setName("ABC AG");
    testSecurity.setType(stock);

    List<Security> allSecurity = new ArrayList<>();
    allSecurity.add(testSecurity);

    PageImpl<Security> page = new PageImpl<>(allSecurity, new PageRequest(0, 1), allSecurity.size());

    when(service.getSecurities()).thenReturn(allSecurity);
    when(service.getSecurities(any(Pageable.class))).thenReturn(page);
    when(service.save(testSecurity)).thenReturn(testSecurity);
    when(service.save(null)).thenThrow(new SecurityNotFoundException(""));

    doAnswer(invocation -> {
        counters.add((String) invocation.getArguments()[0]);
        return null;

    }).when(counterService).increment(anyString());
    doAnswer(invocation -> {
        gauges.add((String) invocation.getArguments()[0]);
        return null;

    }).when(gaugeService).submit(anyString(), anyDouble());
}

From source file:org.craftercms.commons.security.permissions.HasPermissionAnnotationHandlerTest.java

private void createTestService() throws PermissionException {
    AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new MockSecuredServiceImpl());
    proxyFactory.addAspect(annotationHandler);

    service = proxyFactory.getProxy();/*  w ww.j  a  va  2s  .  c  o  m*/
}

From source file:org.osaf.cosmo.event.aop.EventLogAdviceTest.java

/** */
protected void setUp() throws Exception {
    testHelper = new TestHelper();
    securityManager = new MockSecurityManager();
    storage = new MockDaoStorage();
    calendarDao = new MockCalendarDao(storage);
    contentDao = new MockContentDao(storage);
    eventLogDao = new MockEventLogDao();
    service = new StandardContentService();
    lockManager = new SingleVMLockManager();
    service.setCalendarDao(calendarDao);
    service.setContentDao(contentDao);//from  ww  w . jav  a  2  s  .co  m
    service.setLockManager(lockManager);
    service.setTriageStatusQueryProcessor(new StandardTriageStatusQueryProcessor());
    service.init();

    // create a factory that can generate a proxy for the given target object
    AspectJProxyFactory factory = new AspectJProxyFactory(service);

    // add aspect
    EventLogAdvice eva = new EventLogAdvice();
    eva.setEnabled(true);
    eva.setSecurityManager(securityManager);
    eva.setEventLogDao(eventLogDao);
    eva.init();
    factory.addAspect(eva);

    // now get the proxy object...
    proxyService = factory.getProxy();
}

From source file:org.osaf.cosmo.security.aop.SecurityAdviceTest.java

/** */
protected void setUp() throws Exception {
    testHelper = new TestHelper();
    securityManager = new MockSecurityManager();
    storage = new MockDaoStorage();
    calendarDao = new MockCalendarDao(storage);
    contentDao = new MockContentDao(storage);
    userDao = new MockUserDao(storage);
    service = new StandardContentService();
    lockManager = new SingleVMLockManager();
    service.setCalendarDao(calendarDao);
    service.setContentDao(contentDao);//  w  w  w  . ja v  a 2s.c o  m
    service.setLockManager(lockManager);
    service.setTriageStatusQueryProcessor(new StandardTriageStatusQueryProcessor());
    service.init();

    // create a factory that can generate a proxy for the given target object
    AspectJProxyFactory factory = new AspectJProxyFactory(service);

    // add aspect
    SecurityAdvice sa = new SecurityAdvice();
    sa.setEnabled(true);
    sa.setSecurityManager(securityManager);
    sa.setContentDao(contentDao);
    sa.setUserDao(userDao);
    sa.init();
    factory.addAspect(sa);

    // now get the proxy object...
    proxyService = factory.getProxy();
}

From source file:org.springframework.aop.aspectj.annotation.AspectProxyFactoryTests.java

@Test(expected = IllegalArgumentException.class)
public void testWithNonAspect() {
    AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean());
    proxyFactory.addAspect(TestBean.class);
}

From source file:org.springframework.aop.aspectj.annotation.AspectProxyFactoryTests.java

@Test
public void testWithSimpleAspect() throws Exception {
    TestBean bean = new TestBean();
    bean.setAge(2);// ww  w. j  a  va 2  s. c  o  m
    AspectJProxyFactory proxyFactory = new AspectJProxyFactory(bean);
    proxyFactory.addAspect(MultiplyReturnValue.class);
    ITestBean proxy = proxyFactory.getProxy();
    assertEquals("Multiplication did not occur", bean.getAge() * 2, proxy.getAge());
}

From source file:org.springframework.aop.aspectj.annotation.AspectProxyFactoryTests.java

@Test
public void testWithPerThisAspect() throws Exception {
    TestBean bean1 = new TestBean();
    TestBean bean2 = new TestBean();

    AspectJProxyFactory pf1 = new AspectJProxyFactory(bean1);
    pf1.addAspect(PerThisAspect.class);

    AspectJProxyFactory pf2 = new AspectJProxyFactory(bean2);
    pf2.addAspect(PerThisAspect.class);

    ITestBean proxy1 = pf1.getProxy();/*  www. j av a2s .  c  om*/
    ITestBean proxy2 = pf2.getProxy();

    assertEquals(0, proxy1.getAge());
    assertEquals(1, proxy1.getAge());
    assertEquals(0, proxy2.getAge());
    assertEquals(2, proxy1.getAge());
}