Search in sources :

Example 76 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project page-factory-2 by sbtqa.

the class DataAspect method run.

@Around("sendCaseStart(event)")
public Object run(ProceedingJoinPoint joinPoint, TestCaseStarted event) throws Throwable {
    List<PickleTag> tags = event.testCase.getTags().stream().filter(pickleTag -> pickleTag.getName().startsWith(DataUtils.DATA_TAG)).collect(Collectors.toList());
    if (!tags.isEmpty()) {
        String dataTagName = tags.get(tags.size() - 1).getName();
        String data = DataUtils.getDataTagValue(dataTagName);
        for (TestStep testStep : event.testCase.getTestSteps()) {
            if (!(testStep instanceof HookTestStep)) {
                PickleStepTestStep pickleStepTestStep = (PickleStepTestStep) testStep;
                PickleStepTag stepCustom = getPickleStepTag(pickleStepTestStep);
                stepCustom.setDataTag(data);
                replaceByPickleStepTag(pickleStepTestStep, stepCustom);
            }
        }
    }
    return joinPoint.proceed();
}
Also used : Logger(org.slf4j.Logger) TestCaseStarted(cucumber.api.event.TestCaseStarted) LoggerFactory(org.slf4j.LoggerFactory) TestStepStarted(cucumber.api.event.TestStepStarted) Pointcut(org.aspectj.lang.annotation.Pointcut) StepDefinitionMatch(cucumber.runtime.StepDefinitionMatch) cucumber.api(cucumber.api) Collectors(java.util.stream.Collectors) Around(org.aspectj.lang.annotation.Around) PickleStep(gherkin.pickles.PickleStep) EventBus(cucumber.runner.EventBus) DataUtils(ru.sbtqa.tag.pagefactory.data.DataUtils) List(java.util.List) PickleStepTag(ru.sbtqa.tag.pagefactory.optional.PickleStepTag) TestStepFinished(cucumber.api.event.TestStepFinished) Aspect(org.aspectj.lang.annotation.Aspect) PickleTag(gherkin.pickles.PickleTag) FieldUtils(org.apache.commons.lang3.reflect.FieldUtils) DataReplacer(ru.sbtqa.tag.pagefactory.data.DataReplacer) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) PickleStepTag(ru.sbtqa.tag.pagefactory.optional.PickleStepTag) PickleTag(gherkin.pickles.PickleTag) Around(org.aspectj.lang.annotation.Around)

Example 77 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project iobserve-analysis by research-iobserve.

the class AbstractOperationExecutionWithParameterAspect method operation.

@Around("monitoredOperation() && this(thisObject) && notWithinKieker()")
public Object operation(final Object thisObject, final ProceedingJoinPoint thisJoinPoint) throws Throwable {
    // (Throwable)
    if (!AbstractOperationExecutionWithParameterAspect.CTRLINST.isMonitoringEnabled()) {
        return thisJoinPoint.proceed();
    }
    final String operationSignature = this.signatureToLongString(thisJoinPoint.getSignature());
    if (!AbstractOperationExecutionWithParameterAspect.CTRLINST.isProbeActivated(operationSignature)) {
        return thisJoinPoint.proceed();
    }
    // common fields
    TraceMetadata trace = AbstractOperationExecutionWithParameterAspect.TRACEREGISTRY.getTrace();
    final boolean newTrace = trace == null;
    if (newTrace) {
        trace = AbstractOperationExecutionWithParameterAspect.TRACEREGISTRY.registerTrace();
        AbstractOperationExecutionWithParameterAspect.CTRLINST.newMonitoringRecord(trace);
    }
    final long traceId = trace.getTraceId();
    final String clazz = thisObject.getClass().getName();
    /**
     * extension over the original routine.
     */
    final String[] names = ((MethodSignature) thisJoinPoint.getSignature()).getParameterNames();
    final Object[] arguments = thisJoinPoint.getArgs();
    final String[] values = new String[arguments.length];
    int i = 0;
    for (final Object argument : arguments) {
        values[i++] = argument.toString();
    }
    /**
     * exchanged return type.
     */
    // measure before execution
    AbstractOperationExecutionWithParameterAspect.CTRLINST.newMonitoringRecord(new EntryLevelBeforeOperationEvent(AbstractOperationExecutionWithParameterAspect.TIME.getTime(), traceId, trace.getNextOrderId(), operationSignature, clazz, names, values, 0));
    // execution of the called method
    final Object retval;
    try {
        retval = thisJoinPoint.proceed();
    } catch (final Throwable th) {
        // NOPMD NOCS (catch throw might ok here)
        // measure after failed execution
        AbstractOperationExecutionWithParameterAspect.CTRLINST.newMonitoringRecord(new AfterOperationFailedEvent(AbstractOperationExecutionWithParameterAspect.TIME.getTime(), traceId, trace.getNextOrderId(), operationSignature, clazz, th.toString()));
        throw th;
    } finally {
        if (newTrace) {
            // close the trace
            AbstractOperationExecutionWithParameterAspect.TRACEREGISTRY.unregisterTrace();
        }
    }
    // measure after successful execution
    AbstractOperationExecutionWithParameterAspect.CTRLINST.newMonitoringRecord(new AfterOperationEvent(AbstractOperationExecutionWithParameterAspect.TIME.getTime(), traceId, trace.getNextOrderId(), operationSignature, clazz));
    return retval;
}
Also used : AfterOperationEvent(kieker.common.record.flow.trace.operation.AfterOperationEvent) MethodSignature(org.aspectj.lang.reflect.MethodSignature) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) AfterOperationFailedEvent(kieker.common.record.flow.trace.operation.AfterOperationFailedEvent) EntryLevelBeforeOperationEvent(org.iobserve.common.record.EntryLevelBeforeOperationEvent) TraceMetadata(kieker.common.record.flow.trace.TraceMetadata) Around(org.aspectj.lang.annotation.Around)

Aggregations

ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)77 Around (org.aspectj.lang.annotation.Around)32 MethodSignature (org.aspectj.lang.reflect.MethodSignature)16 Method (java.lang.reflect.Method)14 Test (org.junit.Test)14 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)10 SimpleDateFormat (java.text.SimpleDateFormat)8 ArrayList (java.util.ArrayList)8 JoinPoint (org.aspectj.lang.JoinPoint)8 FaseDTO (com.tomasio.projects.trainning.dto.FaseDTO)7 OrganizacaoDTO (com.tomasio.projects.trainning.dto.OrganizacaoDTO)7 PessoaDTO (com.tomasio.projects.trainning.dto.PessoaDTO)7 MockProceedingJoinPoint (org.finra.herd.core.MockProceedingJoinPoint)7 Annotation (java.lang.annotation.Annotation)5 CancelamentoMatriculaDTO (com.tomasio.projects.trainning.dto.CancelamentoMatriculaDTO)4 MatriculaDTO (com.tomasio.projects.trainning.dto.MatriculaDTO)4 Date (java.util.Date)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Action (org.apache.nifi.action.Action)4 MessageHeader (org.finra.herd.model.dto.MessageHeader)4