List of usage examples for org.aspectj.lang ProceedingJoinPoint getTarget
Object getTarget();
From source file:com.onboard.service.activity.impl.test.ActivityRecorderImplTest.java
License:Apache License
private ProceedingJoinPoint getASampleProceedingJoinPoint() throws Throwable { ProceedingJoinPoint p = mock(ProceedingJoinPoint.class); when(p.getArgs()).thenReturn(new Object[] { original }); when(p.proceed()).thenReturn(identifiable); ActivityService object = mock(ActivityService.class); when(p.getTarget()).thenReturn(object); return p;//from ww w.j a v a2 s .com }
From source file:com.qbao.cat.plugin.cache.RedisPluginTemplate.java
License:Apache License
@Override public Transaction beginLog(ProceedingJoinPoint pjp) { Transaction transaction = null;// www .j a v a 2 s . com BinaryClient jedis = (BinaryClient) pjp.getTarget(); if (jedis != null) { transaction = Cat.newTransaction("Cache.Redis_" + jedis.getHost(), pjp.getSignature().toString()); } return transaction; }
From source file:com.qbao.cat.plugin.db.nosql.NewMongoPluginTemplate.java
License:Apache License
@Override protected Transaction beginLog(ProceedingJoinPoint pjp) { Transaction transaction = null;// w w w . jav a2 s.c o m transaction = newTransaction("MongoDB", String.valueOf(pjp.getSignature().toShortString())); MongoCollection collector = (MongoCollection) pjp.getTarget(); Cat.logEvent("DB.Collection", collector.getNamespace().getFullName()); Cat.logEvent("Method", pjp.getSignature().toString()); return transaction; }
From source file:com.qbao.cat.plugin.db.nosql.OldMongoPluginTemplate.java
License:Apache License
protected Transaction beginLog(ProceedingJoinPoint pjp) { Transaction transaction = null;/*w w w . ja v a2 s.co m*/ transaction = newTransaction("MongoDB", String.valueOf(pjp.getSignature().toShortString())); DBCollection collector = (DBCollection) pjp.getTarget(); Cat.logEvent("Host", collector.getDB().getMongo().getServerAddressList().toString()); Cat.logEvent("Connection", collector.toString()); Cat.logEvent("DB", collector.getDB().getName()); Cat.logEvent("Method", pjp.getSignature().toString()); return transaction; }
From source file:com.qpark.eip.core.spring.statistics.FlowExecutionLog.java
License:Open Source License
/** * Get the interface name of the implementing class. * * @param joinPoint/*from w w w . ja va2 s . co m*/ * the {@link ProceedingJoinPoint}. * @return the name of the interface. */ private String getInterfaceName(final ProceedingJoinPoint joinPoint) { String interfaceName = joinPoint.getTarget().getClass().getSimpleName(); if (interfaceName.toLowerCase().endsWith("impl")) { interfaceName = interfaceName.substring(0, interfaceName.length() - 4); } return interfaceName; }
From source file:com.rockagen.gnext.service.spring.security.aspect.OpAspect.java
License:Apache License
/** * [Main]/* w w w . j a v a 2s . co m*/ * * @param pjp * @return * @throws Throwable */ @Around("pointcutService()") public Object loggerOpt(ProceedingJoinPoint pjp) throws Throwable { Object obj = null; // Obtain the will executing method and target object type String methodName = pjp.getSignature().getName(); if (isPoint(methodName)) { // Get class info Class<? extends Object> targetClass = pjp.getTarget().getClass(); Method method = targetClass.getMethod(methodName); beforeJoinPoint(getMethodDesc(method)); // call target object method obj = pjp.proceed(); afterJoinPoint(getMethodDesc(method)); } else { obj = pjp.proceed(); } return obj; }
From source file:com.seleniumtests.core.aspects.LogAction.java
License:Apache License
/** * Intercept actions/*from ww w . j a v a 2s.c o m*/ * @param joinPoint * @throws Throwable */ @Around("execution(public * com.seleniumtests.uipage.PageObject..* (..)) " + "&& !execution(* com.seleniumtests.uipage.PageObject.get* (..))" + "&& !execution(* com.seleniumtests.uipage.PageObject.close* (..))" + "&& !execution(* com.seleniumtests.uipage.PageObject.param (..))" + "&& !execution(* com.seleniumtests.uipage.PageObject.assert* (..))" + "&& !execution(* com.seleniumtests.uipage.PageObject.addStep* (..))" + "&& !execution(* com.seleniumtests.uipage.PageObject.capture*Snapshot (..))") public Object logPageObjectAction(ProceedingJoinPoint joinPoint) throws Throwable { PageObject page = (PageObject) joinPoint.getTarget(); String pageName = page == null ? "" : "on page " + page.getClass().getSimpleName(); return logAction(joinPoint, pageName); }
From source file:com.seleniumtests.core.aspects.LogAction.java
License:Apache License
@Around("isNoNativeActionOverride(joinPoint)") public Object logNativeAction(ProceedingJoinPoint joinPoint) throws Throwable { // build the name of the element String targetName = joinPoint.getTarget().toString(); if (joinPoint.getTarget() instanceof Select) { targetName = "Select"; } else if (targetName.contains("->")) { try {/*from w w w. ja v a 2 s . co m*/ targetName = "Element located by" + targetName.split("->")[1].replace("]", ""); } catch (IndexOutOfBoundsException e) { } } return logAction(joinPoint, targetName); }
From source file:com.seleniumtests.uipage.aspects.ReplayAction.java
License:Apache License
/** * Replay all HtmlElement actions annotated by ReplayOnError. * Classes which are not subclass of HtmlElement won't go there * See javadoc of the annotation for details * @param joinPoint/*from w w w. j ava 2s. c o m*/ * @throws Throwable */ @Around("execution(public * com.seleniumtests.uipage.htmlelements.HtmlElement+.* (..))" + "&& execution(@com.seleniumtests.uipage.ReplayOnError public * * (..)) && @annotation(replay)") public Object replayHtmlElement(ProceedingJoinPoint joinPoint, ReplayOnError replay) throws Throwable { Instant end = systemClock.instant() .plusSeconds(SeleniumTestsContextManager.getThreadContext().getReplayTimeout()); Object reply = null; // update driver reference of the element // corrects bug of waitElementPresent which threw a SessionNotFoundError because driver reference were not // updated before searching element (it used the driver reference of an old test session) HtmlElement element = (HtmlElement) joinPoint.getTarget(); element.setDriver(WebUIDriver.getWebDriver()); String targetName = joinPoint.getTarget().toString(); TestAction currentAction = null; String methodName = joinPoint.getSignature().getName(); if (methodName != "getCoordinates") { List<String> pwdToReplace = new ArrayList<>(); String actionName = String.format("%s on %s %s", methodName, targetName, LogAction.buildArgString(joinPoint, pwdToReplace, new HashMap<>())); currentAction = new TestAction(actionName, false, pwdToReplace); } // log action before its started. By default, it's OK. Then result may be overwritten if step fails // order of steps is the right one (first called is first displayed) if (currentAction != null && isHtmlElementDirectlyCalled(Thread.currentThread().getStackTrace()) && TestLogging.getParentTestStep() != null) { TestLogging.getParentTestStep().addAction(currentAction); } boolean actionFailed = false; boolean ignoreFailure = false; try { while (end.isAfter(systemClock.instant())) { // in case we have switched to an iframe for using previous webElement, go to default content if (element.getDriver() != null && SeleniumTestsContextManager.isWebTest()) { element.getDriver().switchTo().defaultContent(); // TODO: error when clic is done, closing current window } try { reply = joinPoint.proceed(joinPoint.getArgs()); WaitHelper.waitForMilliSeconds(200); break; } catch (UnhandledAlertException e) { throw e; } catch (WebDriverException e) { // don't prevent TimeoutException to be thrown when coming from waitForPresent // only check that cause is the not found element and not an other error (NoSucheSessionError for example) if ((e instanceof TimeoutException && joinPoint.getSignature().getName().equals("waitForPresent") && e.getCause() instanceof NoSuchElementException) // issue #104: do not log error when waitForPresent raises TimeoutException || (e instanceof NoSuchElementException && isFromExpectedConditions(Thread.currentThread().getStackTrace())) // issue #194: return immediately if the action has been performed from ExpectedConditions class // This way, we let the FluentWait process to retry or re-raise the exception ) { ignoreFailure = true; throw e; } if (end.minusMillis(200).isAfter(systemClock.instant())) { WaitHelper.waitForMilliSeconds(replay.replayDelayMs()); continue; } else { if (e instanceof NoSuchElementException) { throw new NoSuchElementException("Searched element could not be found"); } else if (e instanceof UnreachableBrowserException) { throw new WebDriverException("Browser did not reply, it may have frozen"); } throw e; } } } return reply; } catch (Throwable e) { if (e instanceof NoSuchElementException && joinPoint.getTarget() instanceof HtmlElement && (joinPoint.getSignature().getName().equals("findElements") || joinPoint.getSignature().getName().equals("findHtmlElements"))) { return new ArrayList<WebElement>(); } else { actionFailed = true && !ignoreFailure; throw e; } } finally { if (currentAction != null && isHtmlElementDirectlyCalled(Thread.currentThread().getStackTrace()) && TestLogging.getParentTestStep() != null) { currentAction.setFailed(actionFailed); } } }
From source file:com.seleniumtests.uipage.aspects.ReplayAction.java
License:Apache License
/** * Replay all actions annotated by ReplayOnError if the class is not a subclass of * HtmlElement/*from w w w .j a v a 2 s . c om*/ * @param joinPoint * @throws Throwable */ @Around("!execution(public * com.seleniumtests.uipage.htmlelements.HtmlElement+.* (..))" + "&& execution(@com.seleniumtests.uipage.ReplayOnError public * * (..)) && @annotation(replay)") public Object replay(ProceedingJoinPoint joinPoint, ReplayOnError replay) throws Throwable { int replayDelayMs = replay != null ? replay.replayDelayMs() : 100; Instant end = systemClock.instant() .plusSeconds(SeleniumTestsContextManager.getThreadContext().getReplayTimeout()); Object reply = null; String targetName = joinPoint.getTarget().toString(); TestAction currentAction = null; if (joinPoint.getTarget() instanceof GenericPictureElement) { String methodName = joinPoint.getSignature().getName(); List<String> pwdToReplace = new ArrayList<>(); String actionName = String.format("%s on %s %s", methodName, targetName, LogAction.buildArgString(joinPoint, pwdToReplace, new HashMap<>())); currentAction = new TestAction(actionName, false, pwdToReplace); // log action before its started. By default, it's OK. Then result may be overwritten if step fails // order of steps is the right one (first called is first displayed) if (isHtmlElementDirectlyCalled(Thread.currentThread().getStackTrace()) && TestLogging.getParentTestStep() != null) { TestLogging.getParentTestStep().addAction(currentAction); } } boolean actionFailed = false; try { while (end.isAfter(systemClock.instant())) { try { reply = joinPoint.proceed(joinPoint.getArgs()); WaitHelper.waitForMilliSeconds(200); break; } catch (Throwable e) { // do not replay when error comes from test writing or configuration if (e instanceof ScenarioException || e instanceof ConfigurationException || e instanceof DatasetException) { throw e; } if (end.minusMillis(200).isAfter(systemClock.instant())) { WaitHelper.waitForMilliSeconds(replayDelayMs); continue; } else { throw e; } } } return reply; } catch (Throwable e) { actionFailed = true; throw e; } finally { if (currentAction != null && isHtmlElementDirectlyCalled(Thread.currentThread().getStackTrace()) && TestLogging.getParentTestStep() != null) { currentAction.setFailed(actionFailed); if (joinPoint.getTarget() instanceof GenericPictureElement) { currentAction.setDurationToExclude( ((GenericPictureElement) joinPoint.getTarget()).getActionDuration()); } } } }