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

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

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public <T> T getProxy() 

Source Link

Document

Create a new proxy according to the settings in this factory.

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 {/*from  w  w w  .ja v  a 2 s  .  co 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;/*w w  w.  j av a2 s  . com*/
    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  ww  w.  j  a  v  a2s  . 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 a v a 2  s.c  o  m*/
 */
@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();
}

From source file:org.dspace.app.cris.discovery.CrisSearchService.java

@Override
protected void buildDocument(Context context, Item item) throws SQLException, IOException {
    AspectJProxyFactory pf = new AspectJProxyFactory(item);
    pf.setProxyTargetClass(true);//from   www .  j a va2  s .  co m
    pf.addAdvice(new CrisItemWrapper());
    // ProxyFactory pf = new ProxyFactory(item);
    super.buildDocument(context, (Item) pf.getProxy());
}

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 w  w w  . j a v  a2  s .  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
    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 .  j  a  va2  s .c  om
    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
public void testWithSimpleAspect() throws Exception {
    TestBean bean = new TestBean();
    bean.setAge(2);//from www  . j a  va2  s  . c om
    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();
    ITestBean proxy2 = pf2.getProxy();//from  w w  w  .  j  av  a 2 s  . co  m

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