Search in sources :

Example 1 with IRegistryConfigurator

use of org.eclipse.xtext.testing.IRegistryConfigurator in project xtext-core by eclipse.

the class InjectionExtension method restoreRegistry.

/**
 * @since 2.24
 */
protected void restoreRegistry(IInjectorProvider injectorProvider, ExtensionContext context) {
    if (injectorProvider instanceof IRegistryConfigurator) {
        IRegistryConfigurator registryConfigurator = (IRegistryConfigurator) injectorProvider;
        RegistryReset resetter = context.getStore(Namespace.create(this)).get(registryConfigurator, RegistryReset.class);
        if (resetter != null) {
            try {
                resetter.close();
            } catch (Throwable e) {
                throw new ExtensionConfigurationException("Failed to restore registry", e);
            }
        }
    }
}
Also used : ExtensionConfigurationException(org.junit.jupiter.api.extension.ExtensionConfigurationException) IRegistryConfigurator(org.eclipse.xtext.testing.IRegistryConfigurator)

Example 2 with IRegistryConfigurator

use of org.eclipse.xtext.testing.IRegistryConfigurator in project xtext-core by eclipse.

the class AbstractScenarioRunner method process.

protected void process(String data) throws Exception {
    IInjectorProvider delegate = getOrCreateInjectorProvider().getDelegate();
    if (delegate instanceof IRegistryConfigurator) {
        IRegistryConfigurator registryConfigurator = (IRegistryConfigurator) delegate;
        registryConfigurator.setupRegistry();
        try {
            ScenarioProcessor processor = delegate.getInjector().getInstance(processorClass);
            String preProcessed = processor.preProcess(data);
            if (preProcessed == null) {
                throw new AssumptionViolatedException("Input is filtered by the pre processing step: " + data);
            }
            doProcess(preProcessed, processor);
        } finally {
            registryConfigurator.restoreRegistry();
        }
    }
}
Also used : ScenarioProcessor(org.eclipse.xtext.testing.smoketest.ScenarioProcessor) IInjectorProvider(org.eclipse.xtext.testing.IInjectorProvider) AssumptionViolatedException(org.junit.AssumptionViolatedException) IRegistryConfigurator(org.eclipse.xtext.testing.IRegistryConfigurator)

Example 3 with IRegistryConfigurator

use of org.eclipse.xtext.testing.IRegistryConfigurator in project xtext-core by eclipse.

the class InjectionExtension method setupRegistry.

/**
 * @since 2.24
 */
protected void setupRegistry(IInjectorProvider injectorProvider, ExtensionContext context) {
    if (injectorProvider instanceof IRegistryConfigurator) {
        IRegistryConfigurator registryConfigurator = (IRegistryConfigurator) injectorProvider;
        context.getStore(Namespace.create(this)).getOrComputeIfAbsent(registryConfigurator, RegistryReset::new, RegistryReset.class).setup();
    }
}
Also used : IRegistryConfigurator(org.eclipse.xtext.testing.IRegistryConfigurator)

Example 4 with IRegistryConfigurator

use of org.eclipse.xtext.testing.IRegistryConfigurator in project xtext-core by eclipse.

the class AbstractScenarioRunner method methodBlock.

@Override
protected Statement methodBlock(final FrameworkMethod method) {
    IInjectorProvider injectorProvider = getOrCreateInjectorProvider();
    final IRegistryConfigurator registryConfigurator = (IRegistryConfigurator) injectorProvider;
    registryConfigurator.setupRegistry();
    final Statement methodBlock = superMethodBlock(method);
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            try {
                try {
                    methodBlock.evaluate();
                    throw new AssumptionViolatedException("Method " + method.getName() + " did parse any input");
                } finally {
                    registryConfigurator.restoreRegistry();
                }
            } catch (TestDataCarrier testData) {
                process(testData.getData());
            }
        }
    };
}
Also used : IInjectorProvider(org.eclipse.xtext.testing.IInjectorProvider) AssumptionViolatedException(org.junit.AssumptionViolatedException) Statement(org.junit.runners.model.Statement) IRegistryConfigurator(org.eclipse.xtext.testing.IRegistryConfigurator)

Example 5 with IRegistryConfigurator

use of org.eclipse.xtext.testing.IRegistryConfigurator in project xtext-core by eclipse.

the class AbstractParallelScenarioRunner method childrenInvoker.

@Override
protected Statement childrenInvoker(final RunNotifier notifier) {
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            WrappingInjectorProvider wrapped = getOrCreateInjectorProvider();
            wrapped.setupRegistry();
            try {
                prepareChildren(notifier);
            } finally {
                wrapped.restoreRegistry();
            }
            IInjectorProvider delegate = wrapped.getDelegate();
            if (delegate instanceof IRegistryConfigurator) {
                IRegistryConfigurator registryConfigurator = (IRegistryConfigurator) delegate;
                registryConfigurator.setupRegistry();
                try {
                    runChildren(notifier);
                } finally {
                    registryConfigurator.restoreRegistry();
                }
            } else {
                runChildren(notifier);
            }
        }
    };
}
Also used : IInjectorProvider(org.eclipse.xtext.testing.IInjectorProvider) Statement(org.junit.runners.model.Statement) IRegistryConfigurator(org.eclipse.xtext.testing.IRegistryConfigurator)

Aggregations

IRegistryConfigurator (org.eclipse.xtext.testing.IRegistryConfigurator)5 IInjectorProvider (org.eclipse.xtext.testing.IInjectorProvider)3 AssumptionViolatedException (org.junit.AssumptionViolatedException)2 Statement (org.junit.runners.model.Statement)2 ScenarioProcessor (org.eclipse.xtext.testing.smoketest.ScenarioProcessor)1 ExtensionConfigurationException (org.junit.jupiter.api.extension.ExtensionConfigurationException)1