Java Code Examples for org.junit.jupiter.api.extension.ReflectiveInvocationContext

The following examples show how to use org.junit.jupiter.api.extension.ReflectiveInvocationContext. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: allure-java   Source File: AllureJunit5.java    License: Apache License 2.0 6 votes vote down vote up
protected void processFixture(final String type,
                              final Invocation<Void> invocation,
                              final ReflectiveInvocationContext<Method> invocationContext,
                              final ExtensionContext extensionContext) throws Throwable {
    final String uuid = UUID.randomUUID().toString();
    try {
        extensionContext.publishReportEntry(buildStartEvent(
                type,
                uuid,
                invocationContext.getExecutable()
        ));
        invocation.proceed();
        extensionContext.publishReportEntry(buildStopEvent(
                type,
                uuid
        ));
    } catch (Throwable throwable) {
        extensionContext.publishReportEntry(buildFailureEvent(
                type,
                uuid,
                throwable
        ));
        throw throwable;
    }
}
 
Example 2
Source Project: quickperf   Source File: QuickPerfTestExtension.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void interceptTestMethod(  Invocation<Void> invocation
                                , ReflectiveInvocationContext<Method> invocationContext
                                , ExtensionContext extensionContext) throws Throwable {

    if (testExecutionContext.isQuickPerfDisabled()) {
        invocation.proceed();
        return;
    }

    if(SystemProperties.TEST_CODE_EXECUTING_IN_NEW_JVM.evaluate()) {
        executeTestMethodInNewJvmAndRecordPerformance(invocation, invocationContext);
        return;
    }

    JvmOrTestIssue jvmOrTestIssue =
            executeTestMethodAndRecordPerformance(invocation, invocationContext);

    SetOfAnnotationConfigs testAnnotationConfigs = quickPerfConfigs.getTestAnnotationConfigs();

    Collection<PerfIssuesToFormat> groupOfPerfIssuesToFormat
                = perfIssuesEvaluator.evaluatePerfIssuesIfNoJvmIssue(testAnnotationConfigs
                                                                   , testExecutionContext
                                                                   , jvmOrTestIssue);
    testExecutionContext.cleanResources();

    quickPerfReporter.report(jvmOrTestIssue
                           , groupOfPerfIssuesToFormat
                           , testExecutionContext);

}
 
Example 3
Source Project: quickperf   Source File: QuickPerfTestExtension.java    License: Apache License 2.0 5 votes vote down vote up
private void executeTestMethodInNewJvmAndRecordPerformance(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext) throws IllegalAccessException, InvocationTargetException {
    Object[] args = invocationContext.getArguments().toArray();
    Object target = invocationContext.getTarget().orElse(null);
    Method method = makeAccessible(invocationContext.getExecutable());
    invocation.skip();//skip the invocation as we directly invoke the test method

    performanceRecording.start(testExecutionContext);

    try {
        //directly invoke the method to lower the interaction between JUnit, other extensions and QuickPerf.
        method.invoke(target, args);
    } finally {
        performanceRecording.stop(testExecutionContext);
    }
}
 
Example 4
Source Project: quickperf   Source File: QuickPerfTestExtension.java    License: Apache License 2.0 5 votes vote down vote up
private JvmOrTestIssue executeTestMethodAndRecordPerformance(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext) {
    if (testExecutionContext.testExecutionUsesTwoJVMs()) {
        Method testMethod = invocationContext.getExecutable();
        JvmOrTestIssue jvmOrTestIssue = executeTestMethodInNewJwm(testMethod);
        tryToSkipInvocation(invocation); // because the test method is invoked directly inside the 'newJvmTestLauncher'
        return jvmOrTestIssue;
    }
    TestIssue testIssue = executeTestMethodAndRecordPerformanceInSameJvm(invocation);
    return JvmOrTestIssue.buildFrom(testIssue);
}
 
Example 5
Source Project: quarkus   Source File: QuarkusTestExtension.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void interceptBeforeAllMethod(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext,
        ExtensionContext extensionContext) throws Throwable {
    if (isNativeTest(extensionContext)) {
        invocation.proceed();
        return;
    }
    ensureStarted(extensionContext);
    if (failedBoot) {
        throwBootFailureException();
        return;
    }
    runExtensionMethod(invocationContext, extensionContext);
    invocation.skip();
}
 
Example 6
Source Project: quarkus   Source File: QuarkusTestExtension.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public <T> T interceptTestClassConstructor(Invocation<T> invocation,
        ReflectiveInvocationContext<Constructor<T>> invocationContext, ExtensionContext extensionContext) throws Throwable {
    if (isNativeTest(extensionContext)) {
        return invocation.proceed();
    }
    T result;
    ClassLoader old = Thread.currentThread().getContextClassLoader();
    Class<?> requiredTestClass = extensionContext.getRequiredTestClass();
    try {
        Thread.currentThread().setContextClassLoader(requiredTestClass.getClassLoader());
        result = invocation.proceed();
    } catch (NullPointerException e) {
        throw new RuntimeException(
                "When using constructor injection in a test, the only legal operation is to assign the constructor values to fields. Offending class is "
                        + requiredTestClass,
                e);
    } finally {
        Thread.currentThread().setContextClassLoader(old);
    }
    ExtensionState state = ensureStarted(extensionContext);
    if (failedBoot) {
        return result;
    }

    // We do this here as well, because when @TestInstance(Lifecycle.PER_CLASS) is used on a class,
    // interceptTestClassConstructor is called before beforeAll, meaning that the TCCL will not be set correctly
    // (for any test other than the first) unless this is done
    old = null;
    if (runningQuarkusApplication != null) {
        old = setCCL(runningQuarkusApplication.getClassLoader());
    }

    initTestState(extensionContext, state);
    if (old != null) {
        setCCL(old);
    }
    return result;
}
 
Example 7
Source Project: quarkus   Source File: QuarkusTestExtension.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void interceptBeforeEachMethod(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext,
        ExtensionContext extensionContext) throws Throwable {
    if (isNativeTest(extensionContext)) {
        invocation.proceed();
        return;
    }
    runExtensionMethod(invocationContext, extensionContext);
    invocation.skip();
}
 
Example 8
Source Project: quarkus   Source File: QuarkusTestExtension.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void interceptTestMethod(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext,
        ExtensionContext extensionContext) throws Throwable {
    if (isNativeTest(extensionContext)) {
        invocation.proceed();
        return;
    }
    runExtensionMethod(invocationContext, extensionContext);
    invocation.skip();
}
 
Example 9
Source Project: quarkus   Source File: QuarkusTestExtension.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void interceptTestTemplateMethod(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext,
        ExtensionContext extensionContext) throws Throwable {
    if (isNativeTest(extensionContext)) {
        invocation.proceed();
        return;
    }
    runExtensionMethod(invocationContext, extensionContext);
    invocation.skip();
}
 
Example 10
Source Project: quarkus   Source File: QuarkusTestExtension.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public <T> T interceptTestFactoryMethod(Invocation<T> invocation,
        ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext) throws Throwable {
    if (isNativeTest(extensionContext)) {
        return invocation.proceed();
    }
    T result = (T) runExtensionMethod(invocationContext, extensionContext);
    invocation.skip();
    return result;
}
 
Example 11
Source Project: quarkus   Source File: QuarkusTestExtension.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void interceptAfterEachMethod(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext,
        ExtensionContext extensionContext) throws Throwable {
    if (isNativeTest(extensionContext)) {
        invocation.proceed();
        return;
    }
    runExtensionMethod(invocationContext, extensionContext);
    invocation.skip();
}
 
Example 12
Source Project: quarkus   Source File: QuarkusTestExtension.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void interceptAfterAllMethod(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext,
        ExtensionContext extensionContext) throws Throwable {
    if (isNativeTest(extensionContext)) {
        invocation.proceed();
        return;
    }
    runExtensionMethod(invocationContext, extensionContext);
    invocation.skip();
}
 
Example 13
Source Project: quarkus   Source File: QuarkusUnitTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void interceptAfterEachMethod(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext,
        ExtensionContext extensionContext) throws Throwable {
    if (assertException == null) {
        runExtensionMethod(invocationContext);
        invocation.skip();
    } else {
        invocation.proceed();
    }
}
 
Example 14
Source Project: quarkus   Source File: QuarkusUnitTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void interceptAfterAllMethod(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext,
        ExtensionContext extensionContext) throws Throwable {
    if (assertException == null) {
        runExtensionMethod(invocationContext);
    }
    invocation.skip();
}
 
Example 15
Source Project: quarkus   Source File: QuarkusUnitTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void interceptTestMethod(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext,
        ExtensionContext extensionContext) throws Throwable {
    if (assertException == null) {
        runExtensionMethod(invocationContext);
    }
    invocation.skip();
}
 
Example 16
Source Project: quarkus   Source File: QuarkusUnitTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void interceptTestTemplateMethod(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext,
        ExtensionContext extensionContext) throws Throwable {
    if (assertException == null) {
        runExtensionMethod(invocationContext);
    }
    invocation.skip();
}
 
Example 17
Source Project: allure-java   Source File: AllureJunit5.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void interceptBeforeAllMethod(
        final Invocation<Void> invocation,
        final ReflectiveInvocationContext<Method> invocationContext,
        final ExtensionContext extensionContext) throws Throwable {
    processFixture(PREPARE, invocation, invocationContext, extensionContext);
}
 
Example 18
Source Project: allure-java   Source File: AllureJunit5.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void interceptAfterAllMethod(
        final Invocation<Void> invocation,
        final ReflectiveInvocationContext<Method> invocationContext,
        final ExtensionContext extensionContext) throws Throwable {
    processFixture(TEAR_DOWN, invocation, invocationContext, extensionContext);
}
 
Example 19
Source Project: allure-java   Source File: AllureJunit5.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void interceptBeforeEachMethod(
        final Invocation<Void> invocation,
        final ReflectiveInvocationContext<Method> invocationContext,
        final ExtensionContext extensionContext) throws Throwable {
    processFixture(PREPARE, invocation, invocationContext, extensionContext);
}
 
Example 20
Source Project: allure-java   Source File: AllureJunit5.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void interceptAfterEachMethod(
        final Invocation<Void> invocation,
        final ReflectiveInvocationContext<Method> invocationContext,
        final ExtensionContext extensionContext) throws Throwable {
    processFixture(TEAR_DOWN, invocation, invocationContext, extensionContext);
}
 
Example 21
Source Project: taskana   Source File: JaasExtension.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public <T> T interceptTestClassConstructor(
    Invocation<T> invocation,
    ReflectiveInvocationContext<Constructor<T>> invocationContext,
    ExtensionContext extensionContext) {
  return extractAccessIdAndPerformInvocation(invocation, invocationContext.getExecutable());
}
 
Example 22
Source Project: taskana   Source File: JaasExtension.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void interceptBeforeAllMethod(
    Invocation<Void> invocation,
    ReflectiveInvocationContext<Method> invocationContext,
    ExtensionContext extensionContext) {
  extractAccessIdAndPerformInvocation(invocation, invocationContext.getExecutable());
}
 
Example 23
Source Project: taskana   Source File: JaasExtension.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void interceptBeforeEachMethod(
    Invocation<Void> invocation,
    ReflectiveInvocationContext<Method> invocationContext,
    ExtensionContext extensionContext) {
  extractAccessIdAndPerformInvocation(invocation, invocationContext.getExecutable());
}
 
Example 24
Source Project: taskana   Source File: JaasExtension.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void interceptTestMethod(
    Invocation<Void> invocation,
    ReflectiveInvocationContext<Method> invocationContext,
    ExtensionContext extensionContext) {
  if (isAnnotated(invocationContext.getExecutable(), WithAccessIds.class)) {
    throw new JUnitException("Please use @TestTemplate instead of @Test for multiple accessIds");
  }
  extractAccessIdAndPerformInvocation(invocation, invocationContext.getExecutable());
}
 
Example 25
Source Project: taskana   Source File: JaasExtension.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void interceptTestTemplateMethod(
    Invocation<Void> invocation,
    ReflectiveInvocationContext<Method> invocationContext,
    ExtensionContext extensionContext) {
  WithAccessId accessId =
      getStore(extensionContext).get(ACCESS_IDS_STORE_KEY, WithAccessId.class);
  performInvocationWithAccessId(invocation, accessId);
}
 
Example 26
Source Project: taskana   Source File: JaasExtension.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void interceptAfterEachMethod(
    Invocation<Void> invocation,
    ReflectiveInvocationContext<Method> invocationContext,
    ExtensionContext extensionContext) {
  extractAccessIdAndPerformInvocation(invocation, invocationContext.getExecutable());
}
 
Example 27
Source Project: taskana   Source File: JaasExtension.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void interceptAfterAllMethod(
    Invocation<Void> invocation,
    ReflectiveInvocationContext<Method> invocationContext,
    ExtensionContext extensionContext) {
  extractAccessIdAndPerformInvocation(invocation, invocationContext.getExecutable());
}
 
Example 28
Source Project: quarkus   Source File: QuarkusProdModeTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void interceptBeforeAllMethod(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext,
        ExtensionContext extensionContext) throws Throwable {
    doIntercept(invocation);
}
 
Example 29
Source Project: quarkus   Source File: QuarkusProdModeTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void interceptBeforeEachMethod(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext,
        ExtensionContext extensionContext) throws Throwable {
    doIntercept(invocation);
}
 
Example 30
Source Project: quarkus   Source File: QuarkusProdModeTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void interceptTestMethod(Invocation<Void> invocation, ReflectiveInvocationContext<Method> invocationContext,
        ExtensionContext extensionContext) throws Throwable {
    doIntercept(invocation);
}