Example usage for org.aspectj.lang ProceedingJoinPoint proceed

List of usage examples for org.aspectj.lang ProceedingJoinPoint proceed

Introduction

In this page you can find the example usage for org.aspectj.lang ProceedingJoinPoint proceed.

Prototype

public Object proceed() throws Throwable;

Source Link

Document

Proceed with the next advice or target method invocation

Usage

From source file:com.stee.asm.aop.LoggerAdvice.java

License:Open Source License

@Around("servicePointCut()")
public Object around(ProceedingJoinPoint pjp) throws Throwable {
    logger.doLog(LoggerLevel.INFO, "Invoke --> Class: " + pjp.getTarget().getClass().getSimpleName()
            + " -- Method: " + pjp.getSignature().getName() + " -- Args: " + Arrays.toString(pjp.getArgs()));
    long timeMills = System.currentTimeMillis();
    Object proceed = pjp.proceed();
    logger.doLog(LoggerLevel.INFO,/* w ww .ja v a2 s  .c  om*/
            "Finish --> Return: " + proceed + " -- Cost: " + (System.currentTimeMillis() - timeMills));
    return proceed;
}

From source file:com.stratio.qa.aspects.AssertJAspect.java

License:Apache License

/**
 * @param pjp ProceedingJoinPoint/*from w  w  w.ja  v  a2 s .  c  om*/
 * @return AssertionError
 * @throws Throwable exception
 */
@Around("logAssertJFailurePointcut()")
public AssertionError aroundLogAssertJFailurePointcut(ProceedingJoinPoint pjp) throws Throwable {

    AssertionError ae = (AssertionError) pjp.proceed();
    if (ae.getStackTrace()[2].getMethodName().equals("assertCommandExistsOnTimeOut")
            || ae.getStackTrace()[2].getMethodName().equals("assertSeleniumNElementExistsOnTimeOut")
            || ae.getStackTrace()[2].getMethodName().equals("sendRequestTimeout")) {
        logger.warn("Assertion failed: {}", ae.getMessage());
    } else {
        logger.error("Assertion failed: {}", ae.getMessage());
    }
    return ae;

}

From source file:com.stratio.qa.aspects.BrowsersDataProviderAspect.java

License:Apache License

/**
 * If a System property with FORCE_BROWSER exists then Methods in
 * BrowsersDataProvider will return its value.
 *
 * @param pjp ProceedingJoinPoint//from ww  w  .  jav a  2s .  co  m
 * @return Object
 * @throws Throwable exception
 */
@Around(value = "availableBrowsersCallPointcut()")
public Object availableBrowsersCalls(ProceedingJoinPoint pjp) throws Throwable {

    if (pjp.getArgs().length > 0) {
        if (pjp.getArgs()[0] instanceof ITestContext) {
            if (Arrays.asList(((ITestContext) pjp.getArgs()[0]).getIncludedGroups()).contains("mobile")) {
                return pjp.proceed();
            }
        }
    }

    if (!"".equals(System.getProperty("FORCE_BROWSER", ""))) {
        List<String[]> lData = Lists.newArrayList();
        lData.add(new String[] { System.getProperty("FORCE_BROWSER") });
        logger.debug("Forcing browser to {}", System.getProperty("FORCE_BROWSER"));
        return lData.iterator();
    }
    return pjp.proceed();
}

From source file:com.stratio.qa.aspects.IgnoreTagAspect.java

License:Apache License

/**
 * @param pjp ProceedingJoinPoint/* w ww . jav  a 2 s. c o m*/
 * @param formatter formatter
 * @param reporter reporter
 * @param runtime runtime
 * @throws Throwable exception
 */
@Around(value = "addIgnoreTagPointcutScenario(formatter, reporter, runtime)")
public void aroundAddIgnoreTagPointcut(ProceedingJoinPoint pjp, Formatter formatter, Reporter reporter,
        Runtime runtime) throws Throwable {

    CucumberScenario scen = (CucumberScenario) pjp.getThis();
    Scenario scenario = (Scenario) scen.getGherkinModel();

    Class<?> sc = scen.getClass();
    Method tt = sc.getSuperclass().getDeclaredMethod("tagsAndInheritedTags");
    tt.setAccessible(true);
    Set<Tag> tags = (Set<Tag>) tt.invoke(scen);

    List<String> tagList = new ArrayList<>();
    String scenarioName = scenario.getName();
    tagList = tags.stream().map(Tag::getName).collect(Collectors.toList());

    ignoreReasons exitReason = manageTags(tagList, scenarioName);
    if (exitReason.equals(NOREASON)) {
        logger.error("Scenario '" + scenario.getName() + "' failed due to wrong use of the @ignore tag. ");
    }

    if ((!(exitReason.equals(NOTIGNORED))) && (!(exitReason.equals(NOREASON)))) {
        runtime.buildBackendWorlds(reporter, tags, scenario.getName());
        formatter.startOfScenarioLifeCycle(scenario);
        formatter.endOfScenarioLifeCycle(scenario);
        runtime.disposeBackendWorlds();
    } else {
        pjp.proceed();
    }
}

From source file:com.stratio.qa.aspects.SeleniumAspect.java

License:Apache License

/**
 * If an exception has thrown by selenium, this methods save a screen
 * capture.// w  ww  .  j a v a  2  s. c  o  m
 *
 * @param pjp ProceedingJoinPoint
 * @return Object object
 * @throws Throwable exception
 */
@Around(value = "exceptionCallPointcut()")
public Object aroundExceptionCalls(ProceedingJoinPoint pjp) throws Throwable {
    Object retVal = null;
    try {
        retVal = pjp.proceed();
        return retVal;
    } catch (Throwable ex) {
        WebDriver driver = null;
        if (ex instanceof WebDriverException) {
            logger.info("Got a selenium exception");
            if (!(pjp.getThis() instanceof WebDriver)) {
                throw ex;
            }
            driver = (WebDriver) pjp.getThis();
        } else if ((pjp.getTarget() instanceof SeleniumAssert) && (ex instanceof AssertionError)) {
            logger.info("Got a SeleniumAssert response");
            SeleniumAssert as = (SeleniumAssert) pjp.getTarget();
            Class<?> c = as.getClass().getSuperclass();
            Field actual = c.getDeclaredField("actual");
            actual.setAccessible(true);
            Object realActual = actual.get(as);

            if (realActual instanceof WebDriver) {
                driver = (WebDriver) actual.get(as);
            } else if (realActual instanceof ArrayList) {
                if (((ArrayList) realActual).get(0) instanceof RemoteWebElement) {
                    driver = ((RemoteWebElement) ((ArrayList) realActual).get(0)).getWrappedDriver();
                }
            } else if ((realActual instanceof PreviousWebElements) || (realActual instanceof Boolean)
                    || (realActual instanceof String) || (realActual == null)) {
                driver = ((CommonG) ((SeleniumAssert) pjp.getTarget()).getCommonspec()).getDriver();
            } else if (realActual instanceof RemoteWebElement) {
                driver = ((RemoteWebElement) actual.get(as)).getWrappedDriver();
            }
        }
        if (driver != null) {
            logger.info("Trying to capture screenshots...");
            CommonG common = null;
            if ((pjp.getThis() instanceof ThenGSpec) && (((ThenGSpec) pjp.getThis()).getCommonSpec() != null)) {
                common = ((ThenGSpec) pjp.getThis()).getCommonSpec();
            } else if ((pjp.getTarget() instanceof SeleniumAssert)
                    && ((SeleniumAssert) pjp.getTarget()).getCommonspec() != null) {
                common = ((CommonG) ((SeleniumAssert) pjp.getTarget()).getCommonspec());
            } else {
                logger.info("Got no Selenium driver to capture a screen");
                throw ex;
            }
            common.captureEvidence(driver, "framehtmlSource", "assert");
            common.captureEvidence(driver, "htmlSource", "assert");
            common.captureEvidence(driver, "screenCapture", "assert");
            logger.info("Screenshots are available at target/executions");
        } else {
            logger.info("Got no Selenium driver to capture a screen");
        }
        throw ex;
    }
}

From source file:com.sun.jersey.spring25.LoggingAdvice.java

License:Open Source License

@Around("execution(* com.sun.jersey.spring25.ProxiedResource.getBaseUri(..))")
public Object log(ProceedingJoinPoint pjp) throws Throwable {
    final Signature signature = pjp.getSignature();
    LOGGER.info("Starting to execute " + signature.getDeclaringTypeName() + "." + signature.getName());
    Object retVal = pjp.proceed();
    LOGGER.info("Finished to execute " + signature.getDeclaringTypeName() + "." + signature.getName());
    return retVal;
}

From source file:com.sun.jersey.spring25.LoggingAdvice.java

License:Open Source License

@Around("execution(* com.sun.jersey.spring25.ProxiedSubResource.getRequestUri(..))")
public Object logSubResource(ProceedingJoinPoint pjp) throws Throwable {
    final Signature signature = pjp.getSignature();
    LOGGER.info("Starting to execute " + signature.getDeclaringTypeName() + "." + signature.getName());
    Object retVal = pjp.proceed();
    LOGGER.info("Finished to execute " + signature.getDeclaringTypeName() + "." + signature.getName());
    return retVal;
}

From source file:com.swcguild.aspects.LoadMonitor.java

public Object timeMethod(ProceedingJoinPoint jp) {
    Object ret = null;// w w w. j  a v  a2  s  .  c o  m

    try {
        long start = System.currentTimeMillis();
        ret = jp.proceed();
        long end = System.currentTimeMillis();
        System.out.println("*************");
        System.out.println("Flooring App Accessed for " + (end - start) / 1000 + " seconds");
        System.out.println("*************");

    } catch (Throwable ex) {
        System.out.println("Exception occurred in SimpleTimerAdvice.timeMethod()");
    }

    return ret;

}

From source file:com.swcguild.aspects.SimpleTimerAdvice.java

public Object timeMethod(ProceedingJoinPoint jp) {
    Object ret = null;//from   ww w. j  a  v a 2 s.  c om

    try {
        long start = System.currentTimeMillis();
        ret = jp.proceed();
        long end = System.currentTimeMillis();
        System.out.println("*************");
        System.out.println(jp.getSignature().getName() + " took " + (end - start) + "ms");
        System.out.println("*************");

    } catch (Throwable ex) {
        System.out.println("Exception occurred in SimpleTimerAdvice.timeMethod()");
    }

    return ret;

}

From source file:com.swcguild.flooringapp.Timer.java

public Object timeMethod(ProceedingJoinPoint jp) {
    Object obj = null;//from w  ww . j ava2  s.c om

    try {
        long begin = System.currentTimeMillis();
        obj = jp.proceed();
        long end = System.currentTimeMillis();

        System.out.printf("%n" + jp.getSignature().getName() + " ran for " + (end - begin) + "ms.%n");
    } catch (Throwable ex) {
        System.out.println("Error: Timer failed in " + Timer.class.getName());
    }

    return obj;
}