Java Code Examples for org.junit.jupiter.api.extension.ExtensionContext#getRoot()

The following examples show how to use org.junit.jupiter.api.extension.ExtensionContext#getRoot() . 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 File: AbstractResourceSetGlobalCompilationExtension.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Get the compilation context.
 *
 * @param context the extension context.
 * @return the compilation context.
 */
ResourceSetGlobalCompilationContext getOrCreateCompilationContext(ExtensionContext context) {
	final ExtensionContext root = context.getRoot();
	return root.getStore(NAMESPACE).getOrComputeIfAbsent(
			ResourceSetGlobalCompilationExtension.CONTEXT_KEY,
			it -> {
				final ResourceSetGlobalCompilationContext ctx = new ResourceSetGlobalCompilationContext(
						context.getRequiredTestClass().getPackage().getName() + ".tests",
						this.injector, this.parseHelper, this.validator);
				final GlobalCompilationTestContribution anno = context.getRequiredTestClass().getAnnotation(GlobalCompilationTestContribution.class);
				if (anno != null) {
					ctx.setValidationRunInEachTestFunction(anno.getValidate());
				}
				return ctx;
			},
			ResourceSetGlobalCompilationContext.class);
}
 
Example 2
Source File: QuarkusTestExtension.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private ExtensionState ensureStarted(ExtensionContext extensionContext) {
    ExtensionContext root = extensionContext.getRoot();
    ExtensionContext.Store store = root.getStore(ExtensionContext.Namespace.GLOBAL);
    ExtensionState state = store.get(ExtensionState.class.getName(), ExtensionState.class);
    TestProfile annotation = extensionContext.getRequiredTestClass().getAnnotation(TestProfile.class);
    Class<? extends QuarkusTestProfile> selectedProfile = null;
    if (annotation != null) {
        selectedProfile = annotation.value();
    }
    boolean wrongProfile = !Objects.equals(selectedProfile, quarkusTestProfile);
    if ((state == null && !failedBoot) || wrongProfile) {
        if (wrongProfile) {
            if (state != null) {
                try {
                    state.close();
                } catch (Throwable throwable) {
                    throwable.printStackTrace();
                }
            }
        }
        PropertyTestUtil.setLogFileProperty();
        try {
            state = doJavaStart(extensionContext, selectedProfile);
            store.put(ExtensionState.class.getName(), state);

        } catch (Throwable e) {
            failedBoot = true;
            firstException = e;
        }
    }
    return state;
}
 
Example 3
Source File: NativeTestExtension.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessTestInstance(Object testInstance, ExtensionContext context) throws Exception {
    TestHTTPResourceManager.inject(testInstance);
    ExtensionContext root = context.getRoot();
    ExtensionContext.Store store = root.getStore(ExtensionContext.Namespace.GLOBAL);
    ExtensionState state = store.get(ExtensionState.class.getName(), ExtensionState.class);
    state.testResourceManager.inject(testInstance);
}
 
Example 4
Source File: AbstractResourceSetGlobalCompilationExtension.java    From sarl with Apache License 2.0 4 votes vote down vote up
/** Remove the compilation context.
 *
 * @param context the extension context.
 */
void clearCompilationContext(ExtensionContext context) {
	final ExtensionContext root = context.getRoot();
	root.getStore(NAMESPACE).remove(ResourceSetGlobalCompilationExtension.CONTEXT_KEY);
}